varid: speedup of the algorithm for setting variable ids
This commit is contained in:
parent
f6d6a3855e
commit
c9eab77683
108
src/tokenize.cpp
108
src/tokenize.cpp
|
@ -738,53 +738,83 @@ void Tokenizer::setVarId()
|
|||
{
|
||||
const std::string &classname(tok->next()->str());
|
||||
|
||||
unsigned int indentlevel = 0;
|
||||
|
||||
// What member variables are there in this class?
|
||||
for (const Token *tok2 = tok; tok2; tok2 = tok2->next())
|
||||
std::list<const Token *> varlist;
|
||||
{
|
||||
// Indentation..
|
||||
if (tok2->str() == "{")
|
||||
++indentlevel;
|
||||
else if (tok2->str() == "}")
|
||||
unsigned int indentlevel = 0;
|
||||
for (const Token *tok2 = tok; tok2; tok2 = tok2->next())
|
||||
{
|
||||
if (indentlevel <= 1)
|
||||
break;
|
||||
--indentlevel;
|
||||
}
|
||||
|
||||
// If a variable id is found in the class declaration, start
|
||||
// updating the variable ids in member functions..
|
||||
else if (indentlevel == 1 && tok2->varId() > 0)
|
||||
{
|
||||
const unsigned int varid(tok2->varId());
|
||||
const std::string &varname(tok2->str());
|
||||
|
||||
for (Token *tok3 = tok; tok3; tok3 = tok3->next())
|
||||
// Indentation..
|
||||
if (tok2->str() == "{")
|
||||
++indentlevel;
|
||||
else if (tok2->str() == "}")
|
||||
{
|
||||
// Found a class function..
|
||||
if (Token::Match(tok3, (classname + " :: %var% (").c_str()))
|
||||
if (indentlevel <= 1)
|
||||
break;
|
||||
--indentlevel;
|
||||
}
|
||||
|
||||
// Found a member variable..
|
||||
else if (indentlevel == 1 && tok2->varId() > 0)
|
||||
varlist.push_back(tok2);
|
||||
}
|
||||
}
|
||||
|
||||
// Are there any member variables in this class?
|
||||
if (varlist.empty())
|
||||
continue;
|
||||
|
||||
|
||||
// Member functions for this class..
|
||||
std::list<Token *> funclist;
|
||||
{
|
||||
const std::string funcpattern(classname + " :: %var% (");
|
||||
for (Token *tok2 = tok; tok2; tok2 = tok2->next())
|
||||
{
|
||||
// Found a class function..
|
||||
if (Token::Match(tok2, funcpattern.c_str()))
|
||||
{
|
||||
// Goto the end paranthesis..
|
||||
while (tok2 && tok2->str() != ")")
|
||||
tok2 = tok2->next();
|
||||
if (!tok2)
|
||||
break;
|
||||
|
||||
// If this is a function implementation.. add it to funclist
|
||||
if (Token::Match(tok2, ") const|volatile| {"))
|
||||
funclist.push_back(tok2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Are there any member functions for this class?
|
||||
if (funclist.empty())
|
||||
continue;
|
||||
|
||||
|
||||
// Update the variable ids..
|
||||
for (std::list<const Token *>::const_iterator var = varlist.begin(); var != varlist.end(); ++var)
|
||||
{
|
||||
const unsigned int varid((*var)->varId());
|
||||
const std::string &varname((*var)->str());
|
||||
|
||||
// Parse each function..
|
||||
for (std::list<Token *>::iterator func = funclist.begin(); func != funclist.end(); ++func)
|
||||
{
|
||||
unsigned int indentlevel = 0;
|
||||
for (Token *tok2 = *func; tok2; tok2 = tok2->next())
|
||||
{
|
||||
if (tok2->str() == "{")
|
||||
++indentlevel;
|
||||
else if (tok2->str() == "}")
|
||||
{
|
||||
unsigned int indentlevel2 = 0;
|
||||
while (tok3)
|
||||
{
|
||||
if (tok3->str() == "{")
|
||||
++indentlevel2;
|
||||
else if (tok3->str() == "}")
|
||||
{
|
||||
if (indentlevel2 <= 1)
|
||||
break;
|
||||
--indentlevel2;
|
||||
}
|
||||
else if (indentlevel2 == 0 && tok3->str() == ";")
|
||||
break;
|
||||
else if (indentlevel2 > 0 && tok3->varId() == 0 && tok3->str() == varname)
|
||||
tok3->varId(varid);
|
||||
tok3 = tok3->next();
|
||||
}
|
||||
if (!tok3)
|
||||
if (indentlevel <= 1)
|
||||
break;
|
||||
--indentlevel;
|
||||
}
|
||||
else if (indentlevel > 0 && tok2->str() == varname && tok2->varId() == 0)
|
||||
tok2->varId(varid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue