Symbol database: variable fix. ticket: #2629

This commit is contained in:
Daniel Marjamäki 2011-03-06 21:21:42 +01:00
parent 80235b0d53
commit e26a7819d3
2 changed files with 81 additions and 62 deletions

View File

@ -424,9 +424,13 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
else if (Token::simpleMatch(tok, "for (") &&
Token::simpleMatch(tok->next()->link(), ") {"))
{
// save location of initialization
const Token *tok1 = tok->tokAt(2);
scope = new Scope(this, tok, scope, Scope::eFor, tok->next()->link()->next());
tok = tok->next()->link()->next();
scopeList.push_back(scope);
// check for variable declaration and add it to new scope if found
scope->checkVariable(tok1, Local);
}
else if (Token::simpleMatch(tok, "while (") &&
Token::simpleMatch(tok->next()->link(), ") {"))
@ -1401,6 +1405,12 @@ void Scope::getVariableList()
else if (Token::Match(tok, ";|{|}"))
continue;
tok = checkVariable(tok, varaccess);
}
}
const Token *Scope::checkVariable(const Token *tok, AccessControl varaccess)
{
// This is the start of a statement
const Token *vartok = NULL;
const Token *typetok = NULL;
@ -1454,7 +1464,7 @@ void Scope::getVariableList()
if (vartok && vartok->str() != "operator")
{
if (vartok->varId() == 0 && !vartok->isBoolean())
check->debugMessage(vartok, "Scope::getVariableList found variable \'" + vartok->str() + "\' with varid 0.");
check->debugMessage(vartok, "Scope::checkVariable found variable \'" + vartok->str() + "\' with varid 0.");
const Scope *scope = NULL;
@ -1463,7 +1473,8 @@ void Scope::getVariableList()
addVariable(vartok, typestart, vartok->previous(), varaccess, isMutable, isStatic, isConst, isClass, scope, this, isArray);
}
}
return tok;
}
const Token* skipScopeIdentifiers(const Token* tok)

View File

@ -452,6 +452,14 @@ public:
AccessControl defaultAccess() const;
/**
* @brief check if statement is variable declaration and add it if it is
* @param tok pointer to start of statement
* @param varaccess access control of statement
* @return pointer to last token
*/
const Token *checkVariable(const Token *tok, AccessControl varaccess);
private:
/**
* @brief helper function for getVariableList()