Tokenizer::setVarIdNew: Improved C++ handling. All the TestTokenizer::varidclass?? tests pass now.

This commit is contained in:
Daniel Marjamäki 2012-04-21 17:25:44 +02:00
parent 6071a5afc3
commit b86295fbcd
1 changed files with 19 additions and 1 deletions

View File

@ -2853,6 +2853,17 @@ static void setVarIdClassDeclaration(Token * const startToken, const std::map<st
// end of scope // end of scope
const Token * const endToken = startToken->link(); const Token * const endToken = startToken->link();
// 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.. // replace varids..
unsigned int indentlevel = 0; unsigned int indentlevel = 0;
for (Token *tok = startToken->next(); tok != endToken; tok = tok->next()) { for (Token *tok = startToken->next(); tok != endToken; tok = tok->next()) {
@ -2861,8 +2872,15 @@ static void setVarIdClassDeclaration(Token * const startToken, const std::map<st
else if (tok->str() == "}") else if (tok->str() == "}")
--indentlevel; --indentlevel;
else if (indentlevel > 0 && tok->isName() && tok->varId() <= scopeStartVarId) { else if (indentlevel > 0 && tok->isName() && tok->varId() <= scopeStartVarId) {
if (tok->previous()->str() == "::" || tok->next()->str() == "::") if (tok->previous()->str() == "::")
continue; continue;
if (tok->next()->str() == "::") {
if (tok->str() == className)
tok = tok->tokAt(2);
else
continue;
}
const std::map<std::string, unsigned int>::const_iterator it = variableId.find(tok->str()); const std::map<std::string, unsigned int>::const_iterator it = variableId.find(tok->str());
if (it != variableId.end()) { if (it != variableId.end()) {
tok->varId(it->second); tok->varId(it->second);