save start of function '{' and start of variable declaration in symbol database so checks don't have to find them

This commit is contained in:
Robert Reif 2011-02-20 08:25:42 -05:00
parent 1cfb18be08
commit 597aea9f15
2 changed files with 42 additions and 7 deletions

View File

@ -220,7 +220,7 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
function.isConst = true;
// pure virtual function
if (Token::Match(end, ") const| = %any% ;"))
if (Token::Match(end, ") const| = %any%"))
function.isPure = true;
// count the number of constructors
@ -248,6 +248,13 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
function.isInline = true;
function.hasBody = true;
// find start of function '{'
while (end && end->str() != "{")
end = end->next();
// save start of function
function.start = end;
scope->functionList.push_back(function);
const Token *tok2 = funcStart;
@ -768,6 +775,10 @@ void SymbolDatabase::addFunction(Scope **scope, const Token **tok, const Token *
func->hasBody = true;
func->token = *tok;
func->arg = argStart;
const Token *start = argStart->link()->next();
while (start && start->str() != "{")
start = start->next();
func->start = start;
}
}
else if (func->tokenDef->str() == (*tok)->str() && (*tok)->previous()->str() != "~")
@ -783,6 +794,10 @@ void SymbolDatabase::addFunction(Scope **scope, const Token **tok, const Token *
func->hasBody = true;
func->token = *tok;
func->arg = argStart;
const Token *start = argStart->link()->next();
while (start && start->str() != "{")
start = start->next();
func->start = start;
}
}
@ -793,6 +808,10 @@ void SymbolDatabase::addFunction(Scope **scope, const Token **tok, const Token *
func->hasBody = true;
func->token = *tok;
func->arg = argStart;
const Token *start = argStart->link()->next()->next()->link()->next();
while (start && start->str() != "{")
start = start->next();
func->start = start;
}
}
}
@ -1153,6 +1172,7 @@ void Scope::getVariableList()
// This is the start of a statement
const Token *vartok = NULL;
const Token *typetok = NULL;
const Token *typestart = tok;
// Is it const..?
bool isConst = false;
@ -1222,7 +1242,7 @@ void Scope::getVariableList()
if (typetok)
scope = check->findVariableType(this, typetok);
addVariable(vartok, varaccess, isMutable, isStatic, isConst, isClass, scope);
addVariable(vartok, typestart, varaccess, isMutable, isStatic, isConst, isClass, scope);
}
}
}

View File

@ -73,10 +73,11 @@ class Variable
}
public:
Variable(const Token *name_, std::size_t index_, AccessControl access_,
bool mutable_, bool static_, bool const_, bool class_,
const Scope *type_)
Variable(const Token *name_, const Token *start_, std::size_t index_,
AccessControl access_, bool mutable_, bool static_, bool const_,
bool class_, const Scope *type_)
: _name(name_),
_start(start_),
_index(index_),
_access(access_),
_flags(0),
@ -97,6 +98,15 @@ public:
return _name;
}
/**
* Get type start token.
* @return type start token
*/
const Token *typeStartToken() const
{
return _start;
}
/**
* Get name string.
* @return name string
@ -200,6 +210,9 @@ private:
/** @brief variable name token */
const Token *_name;
/** @brief variable type start token */
const Token *_start;
/** @brief order declared */
std::size_t _index;
@ -223,6 +236,7 @@ public:
argDef(NULL),
token(NULL),
arg(NULL),
start(NULL),
access(Public),
hasBody(false),
isInline(false),
@ -245,6 +259,7 @@ public:
const Token *argDef; // function argument start '(' in class definition
const Token *token; // function name token in implementation
const Token *arg; // function argument start '('
const Token *start; // function start '{'
AccessControl access; // public/protected/private
bool hasBody; // has implementation
bool isInline; // implementation in class definition
@ -317,9 +332,9 @@ public:
*/
Scope * findInNestedListRecursive(const std::string & name);
void addVariable(const Token *token_, AccessControl access_, bool mutable_, bool static_, bool const_, bool class_, const Scope *type_)
void addVariable(const Token *token_, const Token *start_, AccessControl access_, bool mutable_, bool static_, bool const_, bool class_, const Scope *type_)
{
varlist.push_back(Variable(token_, varlist.size(), access_, mutable_, static_, const_, class_, type_));
varlist.push_back(Variable(token_, start_, varlist.size(), access_, mutable_, static_, const_, class_, type_));
}
/** @brief initialize varlist */