Fixed #4086: Set varId in initialization list.

This commit is contained in:
PKEuS 2012-08-28 12:44:40 +02:00
parent 9fe9944adb
commit ea85dd305a
2 changed files with 34 additions and 15 deletions

View File

@ -2585,27 +2585,32 @@ static void setVarIdClassDeclaration(Token * const startToken,
// replace varids..
unsigned int indentlevel = 0;
bool initList = false;
for (Token *tok = startToken->next(); tok != endToken; tok = tok->next()) {
if (tok->str() == "{")
if (tok->str() == "{") {
initList = false;
++indentlevel;
else if (tok->str() == "}")
} else if (tok->str() == "}")
--indentlevel;
else if (indentlevel > 0 && tok->isName() && tok->varId() <= scopeStartVarId) {
if (Token::Match(tok->previous(), "::|."))
continue;
if (tok->next()->str() == "::") {
if (tok->str() == className)
tok = tok->tokAt(2);
else
else if (tok->isName() && tok->varId() <= scopeStartVarId) {
if (indentlevel > 0 || (initList && indentlevel == 0 && (tok->strAt(-1) == "," || tok->strAt(-1) == ":"))) {
if (Token::Match(tok->previous(), "::|."))
continue;
}
if (tok->next()->str() == "::") {
if (tok->str() == className)
tok = tok->tokAt(2);
else
continue;
}
const std::map<std::string, unsigned int>::const_iterator it = variableId.find(tok->str());
if (it != variableId.end()) {
tok->varId(it->second);
setVarIdStructMembers(&tok, structMembers, _varId);
const std::map<std::string, unsigned int>::const_iterator it = variableId.find(tok->str());
if (it != variableId.end()) {
tok->varId(it->second);
setVarIdStructMembers(&tok, structMembers, _varId);
}
}
}
} else if (indentlevel == 0 && tok->str() == ":")
initList = true;
}
}

View File

@ -243,6 +243,7 @@ private:
TEST_CASE(varid_in_class6); // #3755
TEST_CASE(varid_in_class7); // set variable id for struct members
TEST_CASE(varid_in_class8); // unknown macro in class
TEST_CASE(varid_initList);
TEST_CASE(varid_operator);
TEST_CASE(varid_throw);
TEST_CASE(varid_unknown_macro); // #2638 - unknown macro is not type
@ -3777,6 +3778,19 @@ private:
tokenizeDebugListing(code));
}
void varid_initList() {
const char code[] = "class A {\n"
" A() : x(0) {}\n"
" int x;\n"
"};";
ASSERT_EQUALS("\n\n##file 0\n"
"1: class A {\n"
"2: A ( ) : x@1 ( 0 ) { }\n"
"3: int x@1 ;\n"
"4: } ;\n",
tokenizeDebugListing(code));
}
void varid_operator() {
{
const std::string actual = tokenizeDebugListing(