tokenizer: fixed issues related to variable ids

* use setVarId in simplifyTokenList
 * make sure function parameters and variables declared in for example for loops get variable ids
This commit is contained in:
Daniel Marjamäki 2009-02-16 17:41:33 +00:00
parent ba28c07f9d
commit 4aef89c311
2 changed files with 11 additions and 7 deletions

View File

@ -541,7 +541,13 @@ void Tokenizer::setVarId()
else if (tok2->str() == "(")
++parlevel;
else if (tok2->str() == ")")
{
// Is this a function parameter or a variable declared in for example a for loop?
if (parlevel==0 && indentlevel==0 && Token::Match(tok2, ") const| {"))
;
else
--parlevel;
}
else if (parlevel < 0 && tok2->str() == ";")
break;
dot = bool(tok2->str() == ".");
@ -922,8 +928,6 @@ void Tokenizer::simplifyTokenList()
if (Token::Match(next, "* ( %var% + %num% )"))
{
unsigned int varid = tok->tokAt(3)->varId();
const char *str[4] = {"var", "[", "num", "]"};
str[0] = tok->strAt(3);
str[2] = tok->strAt(5);
@ -932,8 +936,6 @@ void Tokenizer::simplifyTokenList()
{
tok = tok->next();
tok->str(str[i]);
if (i == 0)
tok->varId(varid);
}
tok->deleteNext();
@ -1052,6 +1054,9 @@ void Tokenizer::simplifyTokenList()
}
}
// In case variable declarations have been updated...
setVarId();
// Replace NULL with 0..
for (Token *tok = _tokens; tok; tok = tok->next())
{

View File

@ -94,7 +94,7 @@ private:
TEST_CASE(varid2);
TEST_CASE(varid3);
TEST_CASE(varid4);
// TODO TEST_CASE(varid5); // There is currently a problem for "int a,b;" => "int a; int b;"
TEST_CASE(varid5);
TEST_CASE(file1);
TEST_CASE(file2);
@ -745,7 +745,6 @@ private:
Tokenizer tokenizer;
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
tokenizer.setVarId();
tokenizer.simplifyTokenList();
// result..