From b86295fbcdee980552e2222fad7ac76ebb555fa5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 21 Apr 2012 17:25:44 +0200 Subject: [PATCH] Tokenizer::setVarIdNew: Improved C++ handling. All the TestTokenizer::varidclass?? tests pass now. --- lib/tokenize.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index e037f0329..3fba1f374 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2853,6 +2853,17 @@ static void setVarIdClassDeclaration(Token * const startToken, const std::maplink(); + // determine class name + std::string className; + for (const Token *tok = startToken->previous(); tok; tok = tok->previous()) { + if (!tok->isName() && tok->str() != ":") + break; + if (Token::Match(tok, "class|struct %type% [:{]")) { + className = tok->next()->str(); + break; + } + } + // replace varids.. unsigned int indentlevel = 0; for (Token *tok = startToken->next(); tok != endToken; tok = tok->next()) { @@ -2861,8 +2872,15 @@ static void setVarIdClassDeclaration(Token * const startToken, const std::mapstr() == "}") --indentlevel; else if (indentlevel > 0 && tok->isName() && tok->varId() <= scopeStartVarId) { - if (tok->previous()->str() == "::" || tok->next()->str() == "::") + if (tok->previous()->str() == "::") continue; + if (tok->next()->str() == "::") { + if (tok->str() == className) + tok = tok->tokAt(2); + else + continue; + } + const std::map::const_iterator it = variableId.find(tok->str()); if (it != variableId.end()) { tok->varId(it->second);