From ed6673a9aaf05532a90fdcebc70c1ad2e483088f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 22 Apr 2012 09:18:27 +0200 Subject: [PATCH] Tokenizer::setVarIdNew: Fixed TestTokenizer::varid44 --- lib/tokenize.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index fad2a4f12..482945e74 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2942,6 +2942,16 @@ void Tokenizer::setVarIdNew() for (Token *tok = _tokens; tok; tok = tok->next()) tok->varId(0); + // Variable declarations can't start with "return" etc. + std::set notstart; + notstart.insert("goto"); + notstart.insert("NOT"); + notstart.insert("return"); + if (!isC()) { + const char *str[] = {"delete","friend","new","throw","using","virtual"}; + notstart.insert(str, str+(sizeof(str)/sizeof(*str))); + } + // variable id _varId = 0; std::map variableId; @@ -3001,8 +3011,7 @@ void Tokenizer::setVarIdNew() break; // Variable declaration can't start with "return", etc - if (tok2->str() == "return" || tok2->str() == "NOT" || tok2->str() == "goto" || - (!isC() && (tok2->str() == "delete" || tok2->str() == "friend" || tok2->str() == "new" || tok2->str() == "throw" || tok2->str() == "using" || tok2->str() == "virtual"))) + if (notstart.find(tok2->str()) != notstart.end()) continue; const bool decl = setVarIdParseDeclaration(&tok2, variableId, executableScope.top()); @@ -3045,6 +3054,12 @@ void Tokenizer::setVarIdNew() } else if (Token::Match(tok, "::|. %var%")) { // Don't set varid after a :: or . token tok = tok->next(); + } else if (tok->str() == ":" && Token::Match(tok->tokAt(-2), "class %type%")) { + do { + tok = tok->next(); + } while (tok && (tok->isName() || tok->str() == ",")); + if (!tok) + break; } }