Distinguish variables with same names

...to resolve C4457 warnings.
This commit is contained in:
Simon Rozman 2018-09-07 19:32:54 +02:00
parent 073311be78
commit 3831012af9
6 changed files with 66 additions and 82 deletions

View File

@ -638,7 +638,7 @@ bool ZRCola::DBSource::GetTagNames(const winstd::com_obj<ADOField>& f, LCID lcid
// Parse the field. Must be "name, name, name..." sequence. // Parse the field. Must be "name, name, name..." sequence.
names.clear(); names.clear();
for (UINT i = 0, n = ::SysStringLen(V_BSTR(&v)); i < n && V_BSTR(&v)[i];) { for (UINT i = 0, i_end = ::SysStringLen(V_BSTR(&v)); i < i_end && V_BSTR(&v)[i];) {
if (iswspace(V_BSTR(&v)[i])) { if (iswspace(V_BSTR(&v)[i])) {
// Skip leading white space. // Skip leading white space.
i++; continue; i++; continue;
@ -646,7 +646,7 @@ bool ZRCola::DBSource::GetTagNames(const winstd::com_obj<ADOField>& f, LCID lcid
// Parse name. // Parse name.
UINT j = i, j_end = i; UINT j = i, j_end = i;
for (; i < n && V_BSTR(&v)[i]; i++) { for (; i < i_end && V_BSTR(&v)[i]; i++) {
if (V_BSTR(&v)[i] == L',' || V_BSTR(&v)[i] == L';') { if (V_BSTR(&v)[i] == L',' || V_BSTR(&v)[i] == L';') {
// Delimiter found. // Delimiter found.
i++; break; i++; break;
@ -793,9 +793,9 @@ bool ZRCola::DBSource::GetTranslation(const com_obj<ADORecordset>& rs, ZRCola::D
wxVERIFY(SUCCEEDED(flds->get_Item(variant(L"Kanoniziraj"), &f))); wxVERIFY(SUCCEEDED(flds->get_Item(variant(L"Kanoniziraj"), &f)));
wxCHECK(GetValue(f, norm), false); wxCHECK(GetValue(f, norm), false);
if (norm) { if (norm) {
com_obj<ADOField> f; com_obj<ADOField> f2;
wxVERIFY(SUCCEEDED(flds->get_Item(variant(L"Kano"), &f))); wxVERIFY(SUCCEEDED(flds->get_Item(variant(L"Kano"), &f2)));
wxCHECK(GetValue(f, t.norm), false); wxCHECK(GetValue(f2, t.norm), false);
} else } else
t.norm.clear(); t.norm.clear();
} }
@ -927,10 +927,10 @@ bool ZRCola::DBSource::GetTranslationSeq(const com_obj<ADORecordset>& rs, ZRCola
{ {
ts.sets.clear(); ts.sets.clear();
com_obj<ADOFields> flds; com_obj<ADOFields> flds2;
wxVERIFY(SUCCEEDED(rs_chars->get_Fields(&flds))); wxVERIFY(SUCCEEDED(rs_chars->get_Fields(&flds2)));
com_obj<ADOField> f_set; com_obj<ADOField> f_set;
wxVERIFY(SUCCEEDED(flds->get_Item(variant(L"Script"), &f_set))); wxVERIFY(SUCCEEDED(flds2->get_Item(variant(L"Script"), &f_set)));
size_t n = 0; size_t n = 0;
for (VARIANT_BOOL eof = VARIANT_TRUE; SUCCEEDED(rs_chars->get_EOF(&eof)) && !eof; rs_chars->MoveNext(), n++) { for (VARIANT_BOOL eof = VARIANT_TRUE; SUCCEEDED(rs_chars->get_EOF(&eof)) && !eof; rs_chars->MoveNext(), n++) {
int set; int set;
@ -1188,11 +1188,11 @@ bool ZRCola::DBSource::GetCharacterGroup(const com_obj<ADORecordset>& rs, chrgrp
{ {
cg.chars.clear(); cg.chars.clear();
cg.show.clear(); cg.show.clear();
com_obj<ADOFields> flds; com_obj<ADOFields> flds2;
wxVERIFY(SUCCEEDED(rs_chars->get_Fields(&flds))); wxVERIFY(SUCCEEDED(rs_chars->get_Fields(&flds2)));
com_obj<ADOField> f_char, f_show; com_obj<ADOField> f_char, f_show;
wxVERIFY(SUCCEEDED(flds->get_Item(variant(L"Znak" ), &f_char))); wxVERIFY(SUCCEEDED(flds2->get_Item(variant(L"Znak" ), &f_char)));
wxVERIFY(SUCCEEDED(flds->get_Item(variant(L"pogost"), &f_show))); wxVERIFY(SUCCEEDED(flds2->get_Item(variant(L"pogost"), &f_show)));
size_t n = 0; size_t n = 0;
for (VARIANT_BOOL eof = VARIANT_TRUE; SUCCEEDED(rs_chars->get_EOF(&eof)) && !eof; rs_chars->MoveNext(), n++) { for (VARIANT_BOOL eof = VARIANT_TRUE; SUCCEEDED(rs_chars->get_EOF(&eof)) && !eof; rs_chars->MoveNext(), n++) {
wstring c; wstring c;

View File

@ -449,8 +449,7 @@ int _tmain(int argc, _TCHAR *argv[])
// Get translations. // Get translations.
com_obj<ADORecordset> rs_tran; com_obj<ADORecordset> rs_tran;
if (src.SelectTranslations(ts.set, rs_tran)) { if (src.SelectTranslations(ts.set, rs_tran)) {
size_t count = src.GetRecordsetCount(rs_tran); if (src.GetRecordsetCount(rs_tran) < 0xffffffff) { // 4G check (-1 is reserved for error condition)
if (count < 0xffffffff) { // 4G check (-1 is reserved for error condition)
// Parse translations and build temporary database. // Parse translations and build temporary database.
ZRCola::DBSource::translation trans; ZRCola::DBSource::translation trans;
trans.set = ts.set; trans.set = ts.set;
@ -747,11 +746,11 @@ int _tmain(int argc, _TCHAR *argv[])
ZRCola::DBSource::character_desc_idx idxChrDsc, idxChrDscSub; ZRCola::DBSource::character_desc_idx idxChrDsc, idxChrDscSub;
ZRCola::DBSource::character_bank chrs; ZRCola::DBSource::character_bank chrs;
ZRCola::DBSource::character chr;
// Phase 1: Parse characters and build indexes. // Phase 1: Parse characters and build indexes.
for (; !ZRCola::DBSource::IsEOF(rs); rs->MoveNext()) { for (; !ZRCola::DBSource::IsEOF(rs); rs->MoveNext()) {
// Read character from the database. // Read character from the database.
ZRCola::DBSource::character chr;
if (src.GetCharacter(rs, chr)) if (src.GetCharacter(rs, chr))
chrs[chr.first] = std::move(chr.second); chrs[chr.first] = std::move(chr.second);
else else
@ -936,9 +935,9 @@ int _tmain(int argc, _TCHAR *argv[])
if (!has_errors && build_pot) { if (!has_errors && build_pot) {
const wxString& filenamePot = parser.GetParam(2); const wxString& filenamePot = parser.GetParam(2);
fstream dst((LPCTSTR)filenamePot, ios_base::out | ios_base::trunc); fstream dst_pot((LPCTSTR)filenamePot, ios_base::out | ios_base::trunc);
if (dst.good()) { if (dst_pot.good()) {
dst << "msgid \"\"" << endl dst_pot << "msgid \"\"" << endl
<< "msgstr \"\"" << endl << "msgstr \"\"" << endl
<< "\"Project-Id-Version: ZRCola.zrcdb\\n\"" << endl << "\"Project-Id-Version: ZRCola.zrcdb\\n\"" << endl
<< "\"Language: en\\n\"" << endl << "\"Language: en\\n\"" << endl
@ -948,9 +947,9 @@ int _tmain(int argc, _TCHAR *argv[])
<< "\"X-Generator: ZRColaCompile\\n\"" << endl; << "\"X-Generator: ZRColaCompile\\n\"" << endl;
wstring_convert<codecvt_utf8<wchar_t>> conv; wstring_convert<codecvt_utf8<wchar_t>> conv;
for (auto i = pot.cbegin(); i != pot.cend(); ++i) { for (auto p = pot.cbegin(); p != pot.cend(); ++p) {
// Convert UTF-16 to UTF-8 and escape. // Convert UTF-16 to UTF-8 and escape.
string t(conv.to_bytes(*i)), u; string t(conv.to_bytes(*p)), u;
for (size_t i = 0, n = t.size(); i < n; i++) { for (size_t i = 0, n = t.size(); i < n; i++) {
char c = t[i]; char c = t[i];
switch (c) { switch (c) {
@ -961,17 +960,17 @@ int _tmain(int argc, _TCHAR *argv[])
default : u += c; default : u += c;
} }
} }
dst << endl dst_pot << endl
<< "msgid \"" << u << "\"" << endl << "msgid \"" << u << "\"" << endl
<< "msgstr \"\"" << endl; << "msgstr \"\"" << endl;
} }
if (dst.fail()) { if (dst_pot.fail()) {
_ftprintf(stderr, wxT("%s: error ZCC0013: Writing to POT catalog failed.\n"), (LPCTSTR)filenameOut.c_str()); _ftprintf(stderr, wxT("%s: error ZCC0013: Writing to POT catalog failed.\n"), (LPCTSTR)filenameOut.c_str());
has_errors = true; has_errors = true;
} }
dst.close(); dst_pot.close();
} else { } else {
_ftprintf(stderr, wxT("%s: error ZCC0012: Error opening POT catalog.\n"), filenameOut.fn_str()); _ftprintf(stderr, wxT("%s: error ZCC0012: Error opening POT catalog.\n"), filenameOut.fn_str());
has_errors = true; has_errors = true;

View File

@ -363,16 +363,14 @@ namespace ZRCola {
else { else {
// Narrow the search area on the left to start at the first element in the run. // Narrow the search area on the left to start at the first element in the run.
for (size_type end2 = m; start < end2;) { for (size_type end2 = m; start < end2;) {
size_type m = (start + end2) / 2; size_type m2 = (start + end2) / 2;
int r = compare(el, at(m)); if (compare(el, at(m2)) <= 0) end2 = m2; else start = m2 + 1;
if (r <= 0) end2 = m; else start = m + 1;
} }
// Narrow the search area on the right to end at the first element not in the run. // Narrow the search area on the right to end at the first element not in the run.
for (size_type start2 = m + 1; start2 < end;) { for (size_type start2 = m + 1; start2 < end;) {
size_type m = (start2 + end) / 2; size_type m2 = (start2 + end) / 2;
int r = compare(el, at(m)); if (0 <= compare(el, at(m2))) start2 = m2 + 1; else end = m2;
if (0 <= r) start2 = m + 1; else end = m;
} }
return true; return true;
@ -404,9 +402,8 @@ namespace ZRCola {
else { else {
// Narrow the search area on the left to start at the first element in the run. // Narrow the search area on the left to start at the first element in the run.
for (size_type end2 = m; start < end2;) { for (size_type end2 = m; start < end2;) {
size_type m = (start + end2) / 2; m = (start + end2) / 2;
int r = compare(el, at(m)); if (compare(el, at(m)) <= 0) end2 = m; else start = m + 1;
if (r <= 0) end2 = m; else start = m + 1;
} }
return true; return true;
@ -478,7 +475,7 @@ namespace ZRCola {
else if (r > 0) start = m + 1; else if (r > 0) start = m + 1;
else { else {
// Get values at position m. // Get values at position m.
size_t start = base_t::at(m ).idx_val; start = base_t::at(m ).idx_val;
*val_len = (m < size() ? base_t::at(m + 1).idx_val : values.size()) - start; *val_len = (m < size() ? base_t::at(m + 1).idx_val : values.size()) - start;
*val = &values.at(start); *val = &values.at(start);
return true; return true;

View File

@ -71,42 +71,42 @@ bool ZRCola::character_db::Search(_In_z_ const wchar_t *str, _In_ const std::set
if (fn_abort && fn_abort(cookie)) return false; if (fn_abort && fn_abort(cookie)) return false;
const wchar_t *data; const wchar_t *val;
size_t len; size_t val_len;
if (idxDsc.find(term.c_str(), term.size(), &data, &len)) { if (idxDsc.find(term.c_str(), term.size(), &val, &val_len)) {
// The term was found. // The term was found.
for (size_t i = 0, j = 0; i < len; i += j + 1) { for (size_t i = 0, j = 0; i < val_len; i += j + 1) {
if (fn_abort && fn_abort(cookie)) return false; if (fn_abort && fn_abort(cookie)) return false;
j = wcsnlen(data + i, len - i); j = wcsnlen(val + i, val_len - i);
if (cats.find(GetCharCat(data + i, j)) != cats.end()) { if (cats.find(GetCharCat(val + i, j)) != cats.end()) {
std::wstring c(data + i, j); std::wstring c(val + i, j);
auto idx = hits.find(c); auto idx = hits.find(c);
if (idx == hits.end()) { if (idx == hits.end()) {
// New character. // New character.
hits.insert(std::make_pair(std::move(c), 1.0/len)); hits.insert(std::make_pair(std::move(c), 1.0/val_len));
} else { } else {
// Increase rating of existing character. // Increase rating of existing character.
idx->second += 1.0/len; idx->second += 1.0/val_len;
} }
} }
} }
} }
if (idxDscSub.find(term.c_str(), term.size(), &data, &len)) { if (idxDscSub.find(term.c_str(), term.size(), &val, &val_len)) {
// The term was found in the sub-term index. // The term was found in the sub-term index.
for (size_t i = 0, j = 0; i < len; i += j + 1) { for (size_t i = 0, j = 0; i < val_len; i += j + 1) {
if (fn_abort && fn_abort(cookie)) return false; if (fn_abort && fn_abort(cookie)) return false;
j = wcsnlen(data + i, len - i); j = wcsnlen(val + i, val_len - i);
if (cats.find(GetCharCat(data + i, j)) != cats.end()) { if (cats.find(GetCharCat(val + i, j)) != cats.end()) {
std::wstring c(data + i, j); std::wstring c(val + i, j);
auto idx = hits_sub.find(c); auto idx = hits_sub.find(c);
if (idx == hits_sub.end()) { if (idx == hits_sub.end()) {
// New character. // New character.
hits_sub.insert(std::make_pair(c, 1.0/len)); hits_sub.insert(std::make_pair(c, 1.0/val_len));
} else { } else {
// Increase rating of existing character. // Increase rating of existing character.
idx->second += 1.0/len; idx->second += 1.0/val_len;
} }
} }
} }

View File

@ -102,11 +102,11 @@ bool ZRCola::tagname_db::Search(_In_z_ const wchar_t *str, _In_ LCID locale, _In
// The name was found. // The name was found.
for (size_t i = start; i < end; i++) { for (size_t i = start; i < end; i++) {
if (fn_abort && fn_abort(cookie)) return false; if (fn_abort && fn_abort(cookie)) return false;
const tagname &name = idxName[i]; const tagname &val = idxName[i];
auto idx = hits.find(name.tag); auto idx = hits.find(val.tag);
if (idx == hits.end()) { if (idx == hits.end()) {
// New tag. // New tag.
hits.insert(std::make_pair(name.tag, 1)); hits.insert(std::make_pair(val.tag, 1));
} else { } else {
// Increase count for existing tag. // Increase count for existing tag.
idx->second++; idx->second++;

View File

@ -50,8 +50,7 @@ void ZRCola::translation_db::Translate(_In_ transetid_t set, _In_z_count_(inputM
// Get the j-th character of the translation. // Get the j-th character of the translation.
// All translations that get short on characters are lexically ordered before. // All translations that get short on characters are lexically ordered before.
// Thus the j-th character is considered 0. // Thus the j-th character is considered 0.
const translation &trans = idxSrc[m]; wchar_t s = idxSrc[m].src_at(j);
wchar_t s = trans.src_at(j);
// Do the bisection test. // Do the bisection test.
if (c < s) r = m; if (c < s) r = m;
@ -60,23 +59,18 @@ void ZRCola::translation_db::Translate(_In_ transetid_t set, _In_z_count_(inputM
// Character found. // Character found.
// Narrow the search area on the left to start at the first translation in the run. // Narrow the search area on the left to start at the first translation in the run.
for (size_t rr = m; l < rr;) { for (size_t r2 = m; l < r2;) {
size_t m = (l + rr) / 2; size_t m2 = (l + r2) / 2;
const translation &trans = idxSrc[m]; if (c <= idxSrc[m2].src_at(j)) r2 = m2; else l = m2 + 1;
wchar_t s = trans.src_at(j);
if (c <= s) rr = m; else l = m + 1;
} }
// Narrow the search area on the right to end at the first translation not in the run. // Narrow the search area on the right to end at the first translation not in the run.
for (size_t ll = m + 1; ll < r;) { for (size_t l2 = m + 1; l2 < r;) {
size_t m = (ll + r) / 2; size_t m2 = (l2 + r) / 2;
const translation &trans = idxSrc[m]; if (idxSrc[m2].src_at(j) <= c) l2 = m2 + 1; else r = m2;
wchar_t s = trans.src_at(j);
if (s <= c) ll = m + 1; else r = m;
} }
const translation &trans = idxSrc[l]; if (j + 1 == idxSrc[l].src_len()) {
if (j + 1 == trans.src_len()) {
// The first translation of the run was a match (thus far). Save it. // The first translation of the run was a match (thus far). Save it.
l_match = l; l_match = l;
} }
@ -134,8 +128,7 @@ void ZRCola::translation_db::TranslateInv(_In_ transetid_t set, _In_z_count_(inp
// Get the j-th character of the inverse translation. // Get the j-th character of the inverse translation.
// All inverse translations that get short on characters are lexically ordered before. // All inverse translations that get short on characters are lexically ordered before.
// Thus the j-th character is considered 0. // Thus the j-th character is considered 0.
const translation &trans = idxDst[m]; wchar_t s = idxDst[m].dst_at(j);
wchar_t s = trans.dst_at(j);
// Do the bisection test. // Do the bisection test.
if (c < s) r = m; if (c < s) r = m;
@ -144,23 +137,18 @@ void ZRCola::translation_db::TranslateInv(_In_ transetid_t set, _In_z_count_(inp
// Character found. // Character found.
// Narrow the search area on the left to start at the first inverse translation in the run. // Narrow the search area on the left to start at the first inverse translation in the run.
for (size_t rr = m; l < rr;) { for (size_t r2 = m; l < r2;) {
size_t m = (l + rr) / 2; size_t m2 = (l + r2) / 2;
const translation &trans = idxDst[m]; if (c <= idxDst[m2].dst_at(j)) r2 = m2; else l = m2 + 1;
wchar_t s = trans.dst_at(j);
if (c <= s) rr = m; else l = m + 1;
} }
// Narrow the search area on the right to end at the first inverse translation not in the run. // Narrow the search area on the right to end at the first inverse translation not in the run.
for (size_t ll = m + 1; ll < r;) { for (size_t l2 = m + 1; l2 < r;) {
size_t m = (ll + r) / 2; size_t m2 = (l2 + r) / 2;
const translation &trans = idxDst[m]; if (idxDst[m2].dst_at(j) <= c) l2 = m2 + 1; else r = m2;
wchar_t s = trans.dst_at(j);
if (s <= c) ll = m + 1; else r = m;
} }
const translation &trans = idxDst[l]; if (j + 1 == idxDst[l].dst_len()) {
if (j + 1 == trans.dst_len()) {
// The first inverse translation of the run was a match (thus far). Save it. // The first inverse translation of the run was a match (thus far). Save it.
l_match = l; l_match = l;
} }