tokenizer: setvarid handle variable declaration at start of token list

This commit is contained in:
Daniel Marjamäki 2009-02-02 19:19:36 +00:00
parent 0059ceefb9
commit 59f95d311b
2 changed files with 8 additions and 5 deletions

View File

@ -471,13 +471,16 @@ void Tokenizer::setVarId()
if (tok != _tokens && !Token::Match(tok, "[;{}(]")) if (tok != _tokens && !Token::Match(tok, "[;{}(]"))
continue; continue;
if (!(firstMatch = Token::Match(tok->next(), "%type% *| %var%")) if ( Token::Match(tok, "[;{}(] %any%") )
&& !Token::Match(tok->next(), "%type% %type% *| %var%")) tok = tok->next();
if (!(firstMatch = Token::Match(tok, "%type% *| %var%"))
&& !Token::Match(tok, "%type% %type% *| %var%"))
continue; continue;
// Determine name of declared variable.. // Determine name of declared variable..
const char *varname = 0; const char *varname = 0;
Token *tok2 = tok->tokAt(firstMatch ? 2 : 3); Token *tok2 = tok->tokAt(firstMatch ? 1 : 2);
while (tok2 && ! Token::Match(tok2, "[;[=(]")) while (tok2 && ! Token::Match(tok2, "[;[=(]"))
{ {
if (tok2->isName()) if (tok2->isName())

View File

@ -878,7 +878,7 @@ private:
void sizeof3() void sizeof3()
{ {
const char code[] = ";int i[10];\n" const char code[] = "int i[10];\n"
"sizeof(i[0]);\n"; "sizeof(i[0]);\n";
// tokenize.. // tokenize..
@ -892,7 +892,7 @@ private:
std::ostringstream ostr; std::ostringstream ostr;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str(); ostr << " " << tok->str();
ASSERT_EQUALS(std::string(" ; int i [ 10 ] ; 4 ;"), ostr.str()); ASSERT_EQUALS(std::string(" int i [ 10 ] ; 4 ;"), ostr.str());
} }
}; };