Fixed #4372 (Tokenizer misidentifying which function a variable belongs to)

This commit is contained in:
Daniel Marjamäki 2012-12-29 21:07:41 +01:00
parent dde4cc39e5
commit 4378357d7e
2 changed files with 27 additions and 2 deletions

View File

@ -2639,6 +2639,17 @@ static void setVarIdClassFunction(Token * const startToken,
}
}
static bool isInitList(const Token *tok)
{
if (!Token::Match(tok, ") : %var% ("))
return false;
tok = tok->linkAt(3);
while (Token::Match(tok, ") , %var% ("))
tok = tok->linkAt(3);
return Token::Match(tok, ") {");
}
void Tokenizer::setVarId()
{
@ -2666,13 +2677,16 @@ void Tokenizer::setVarId()
executableScope.push(false);
std::stack<unsigned int> scopestartvarid; // varid when scope starts
scopestartvarid.push(0);
bool initlist = false;
for (Token *tok = list.front(); tok; tok = tok->next()) {
// scope info to handle shadow variables..
if (tok->str() == "(" &&
(Token::simpleMatch(tok->link(), ") {") || Token::Match(tok->link(), ") %type% {"))) {
if (!initlist && tok->str() == "(" &&
(Token::simpleMatch(tok->link(), ") {") || Token::Match(tok->link(), ") %type% {") || isInitList(tok->link()))) {
scopeInfo.push(variableId);
initlist = Token::simpleMatch(tok->link(), ") :");
} else if (tok->str() == "{") {
initlist = false;
// parse anonymous unions as part of the current scope
if (!(Token::simpleMatch(tok->previous(), "union") && Token::simpleMatch(tok->link(), "} ;"))) {
scopestartvarid.push(_varId);

View File

@ -4086,6 +4086,17 @@ private:
"4: } ;\n"
"5: A :: A ( int x@3 ) : x@2 ( x@3 ) { }\n",
tokenizeDebugListing(code3));
const char code4[] = "struct A {\n"
" int x;\n"
" A(int x) : x(x) {}\n"
"};\n";
ASSERT_EQUALS("\n\n##file 0\n"
"1: struct A {\n"
"2: int x@1 ;\n"
"3: A ( int x@2 ) : x@1 ( x@2 ) { }\n"
"4: } ;\n",
tokenizeDebugListing(code4));
}
void varid_operator() {