From 59f95d311bee4f47202e82eb170d2bd812cc2d25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 2 Feb 2009 19:19:36 +0000 Subject: [PATCH] tokenizer: setvarid handle variable declaration at start of token list --- src/tokenize.cpp | 9 ++++++--- test/testtokenize.cpp | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/tokenize.cpp b/src/tokenize.cpp index c3503ef86..be49e0b5f 100644 --- a/src/tokenize.cpp +++ b/src/tokenize.cpp @@ -471,13 +471,16 @@ void Tokenizer::setVarId() if (tok != _tokens && !Token::Match(tok, "[;{}(]")) continue; - if (!(firstMatch = Token::Match(tok->next(), "%type% *| %var%")) - && !Token::Match(tok->next(), "%type% %type% *| %var%")) + if ( Token::Match(tok, "[;{}(] %any%") ) + tok = tok->next(); + + if (!(firstMatch = Token::Match(tok, "%type% *| %var%")) + && !Token::Match(tok, "%type% %type% *| %var%")) continue; // Determine name of declared variable.. const char *varname = 0; - Token *tok2 = tok->tokAt(firstMatch ? 2 : 3); + Token *tok2 = tok->tokAt(firstMatch ? 1 : 2); while (tok2 && ! Token::Match(tok2, "[;[=(]")) { if (tok2->isName()) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 1aff351c1..e2e43edfb 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -878,7 +878,7 @@ private: void sizeof3() { - const char code[] = ";int i[10];\n" + const char code[] = "int i[10];\n" "sizeof(i[0]);\n"; // tokenize.. @@ -892,7 +892,7 @@ private: std::ostringstream ostr; for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) ostr << " " << tok->str(); - ASSERT_EQUALS(std::string(" ; int i [ 10 ] ; 4 ;"), ostr.str()); + ASSERT_EQUALS(std::string(" int i [ 10 ] ; 4 ;"), ostr.str()); } };