- Re-elaborate 'using' keyword skipping in Tokenizer::setVarId and

Scope::getVariableList;
- Improve setVarId: add possible declaration: 'A f(&x);' and change from:
'if (...){}else{ continue; };' to: 'if (!...) continue;';
- Little refactoring of 'Tokenizer::removeTokens()'.
This commit is contained in:
Edoardo Prezioso 2011-12-31 20:21:39 +01:00
parent 8a6b1dc1c9
commit b9c796d9f8
2 changed files with 28 additions and 20 deletions

View File

@ -1485,9 +1485,10 @@ void Scope::getVariableList()
continue; continue;
} }
//skip 'using (namespace)' keyword
else if (Token::Match(tok, "using namespace| %type% ;")) { else if (tok->str() == "using") {
tok = tok->tokAt(2); if (tok->next() && tok->next()->str() == "namespace")
tok = tok->next();
continue; continue;
} }

View File

@ -2826,6 +2826,11 @@ static void removeTemplates(Token *tok)
continue; continue;
for (const Token *tok2 = tok->next(); tok2; tok2 = tok2->next()) { for (const Token *tok2 = tok->next(); tok2; tok2 = tok2->next()) {
if (tok2->str() == "(") {
tok2 = tok2->link();
}
if (tok2->str() == "{") { if (tok2->str() == "{") {
tok2 = tok2->link()->next(); tok2 = tok2->link()->next();
Token::eraseTokens(tok, tok2); Token::eraseTokens(tok, tok2);
@ -2846,15 +2851,18 @@ static void removeTemplates(Token *tok)
goback = true; goback = true;
break; break;
} }
if (tok2->str() == "(") {
tok2 = tok2->link(); if (tok2->str() == ";") {
} else if (tok2->str() == ";") { tok2 = tok2->next();
Token::eraseTokens(tok, tok2->next()); Token::eraseTokens(tok, tok2);
tok->deleteThis(); tok->deleteThis();
goback = true; goback = true;
break; break;
} else if (Token::Match(tok2, ">|>> class %var% [,)]")) { }
Token::eraseTokens(tok,tok2->next());
if (Token::Match(tok2, ">|>> class|struct %var% [,)]")) {
tok2 = tok2->next();
Token::eraseTokens(tok, tok2);
tok->deleteThis(); tok->deleteThis();
goback = true; goback = true;
break; break;
@ -3659,8 +3667,9 @@ void Tokenizer::setVarId()
if (tok->str() == "unsigned") if (tok->str() == "unsigned")
tok = tok->next(); tok = tok->next();
if (Token::Match(tok, "using namespace| %type% ;")) { if (tok->str() == "using") {
tok = tok->next(); if (tok->next() && tok->next()->str() == "namespace")
tok = tok->next();
continue; continue;
} }
@ -3813,16 +3822,14 @@ void Tokenizer::setVarId()
continue; continue;
// Search for function declaration, e.g. void f( int c ); // Search for function declaration, e.g. void f( int c );
if (Token::Match(tok2->next(), "%num%") || if (!Token::Match(tok2->next(), "%num%") &&
Token::Match(tok2->next(), "%bool%") || !Token::Match(tok2->next(), "%bool%") &&
tok2->next()->str()[0] == '"' || tok2->next()->str()[0] != '"' &&
tok2->next()->str()[0] == '\'' || tok2->next()->str()[0] != '\'' &&
tok2->next()->str() == "*" || tok2->next()->str() != "*" &&
tok2->next()->varId() != 0) { tok2->next()->str() != "&" &&
// This is not a function tok2->next()->varId() == 0)
} else {
continue; continue;
}
} }
// Don't set variable id for 'AAA a[0] = 0;' declaration (#2638) // Don't set variable id for 'AAA a[0] = 0;' declaration (#2638)