- 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;
}
else if (Token::Match(tok, "using namespace| %type% ;")) {
tok = tok->tokAt(2);
//skip 'using (namespace)' keyword
else if (tok->str() == "using") {
if (tok->next() && tok->next()->str() == "namespace")
tok = tok->next();
continue;
}

View File

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