Revert "Optimization: Made Tokenizer::setVarId a bit faster by temporarily assigning 'string id'. This means less string comparisons are needed."
This reverts commit 4b8080e425
.
This commit is contained in:
parent
05eb894b82
commit
38a3fe37f9
|
@ -2187,57 +2187,27 @@ void Tokenizer::updateClassList()
|
|||
|
||||
void Tokenizer::setVarId()
|
||||
{
|
||||
unsigned int _varId = 0;
|
||||
|
||||
// Assign string ids so that string comparisons will not be needed
|
||||
{
|
||||
std::map<std::string, unsigned int> id1;
|
||||
unsigned int strid = 0;
|
||||
|
||||
// Initialize id according to strings..
|
||||
for (Token *tok = _tokens; tok; tok = tok->next())
|
||||
{
|
||||
if (!tok->isName())
|
||||
tok->varId(0);
|
||||
else
|
||||
{
|
||||
std::map<std::string, unsigned int>::const_iterator it;
|
||||
it = id1.find(tok->str());
|
||||
if (it != id1.end())
|
||||
tok->varId(it->second);
|
||||
else
|
||||
{
|
||||
++strid;
|
||||
id1[tok->str()] = strid;
|
||||
tok->varId(strid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_varId = strid + 1;
|
||||
}
|
||||
|
||||
const unsigned int varId1(_varId);
|
||||
// Clear all variable ids
|
||||
for (Token *tok = _tokens; tok; tok = tok->next())
|
||||
tok->varId(0);
|
||||
|
||||
// Set variable ids..
|
||||
unsigned int _varId = 0;
|
||||
for (Token *tok = _tokens; tok; tok = tok->next())
|
||||
{
|
||||
if (tok != _tokens && !Token::Match(tok, "[,;{}(] %var%"))
|
||||
if (tok != _tokens && !Token::Match(tok, "[,;{}(] %type%"))
|
||||
continue;
|
||||
|
||||
if (Token::Match(tok, "[,;{}(] %var%"))
|
||||
if (Token::Match(tok, "[,;{}(] %type%"))
|
||||
tok = tok->next();
|
||||
|
||||
if (tok->varId() >= varId1)
|
||||
continue;
|
||||
|
||||
if (tok->str() == "new")
|
||||
continue;
|
||||
|
||||
if (tok->str() == "unsigned")
|
||||
tok = tok->next();
|
||||
|
||||
if (Token::Match(tok, "class|struct %var% :|{|;"))
|
||||
if (Token::Match(tok, "class|struct %type% :|{|;"))
|
||||
continue;
|
||||
|
||||
if (Token::Match(tok, "else|return|typedef|delete|sizeof"))
|
||||
|
@ -2250,7 +2220,7 @@ void Tokenizer::setVarId()
|
|||
tok = tok->tokAt(2);
|
||||
|
||||
// Skip template arguments..
|
||||
if (Token::Match(tok, "%var% <"))
|
||||
if (Token::Match(tok, "%type% <"))
|
||||
{
|
||||
int level = 1;
|
||||
bool again;
|
||||
|
@ -2263,13 +2233,13 @@ void Tokenizer::setVarId()
|
|||
while (Token::Match(tok2, "%var% ::"))
|
||||
tok2 = tok2->tokAt(2);
|
||||
|
||||
if (Token::Match(tok2, "%var% <"))
|
||||
if (Token::Match(tok2, "%type% <"))
|
||||
{
|
||||
level++;
|
||||
tok2 = tok2->tokAt(2);
|
||||
again = true;
|
||||
}
|
||||
else if (Token::Match(tok2, "%var% ,"))
|
||||
else if (Token::Match(tok2, "%type% ,"))
|
||||
{
|
||||
tok2 = tok2->tokAt(2);
|
||||
again = true;
|
||||
|
@ -2307,13 +2277,13 @@ void Tokenizer::setVarId()
|
|||
while (again);
|
||||
}
|
||||
|
||||
// Determine "string id" for variable..
|
||||
unsigned int strid = 0;
|
||||
// Determine name of declared variable..
|
||||
std::string varname;
|
||||
Token *tok2 = tok->tokAt(1);
|
||||
while (tok2)
|
||||
{
|
||||
if (tok2->isName())
|
||||
strid = (tok2->str() == "operator") ? 0 : tok2->varId();
|
||||
varname = tok2->str();
|
||||
else if (tok2->str() != "*" && tok2->str() != "&")
|
||||
break;
|
||||
tok2 = tok2->next();
|
||||
|
@ -2323,7 +2293,7 @@ void Tokenizer::setVarId()
|
|||
if (!tok2)
|
||||
break;
|
||||
|
||||
if (strid == 0)
|
||||
if (varname == "operator" && Token::Match(tok2, "=|+|-|*|/|[| ]| ("))
|
||||
continue;
|
||||
|
||||
// Is it a function?
|
||||
|
@ -2337,7 +2307,7 @@ void Tokenizer::setVarId()
|
|||
if (Token::Match(tok2->next(), "%num%") ||
|
||||
Token::Match(tok2->next(), "%bool%") ||
|
||||
tok2->next()->str()[0] == '"' ||
|
||||
tok2->next()->varId() >= varId1)
|
||||
tok2->next()->varId() != 0)
|
||||
{
|
||||
// This is not a function
|
||||
}
|
||||
|
@ -2348,7 +2318,7 @@ void Tokenizer::setVarId()
|
|||
}
|
||||
|
||||
// Variable declaration found => Set variable ids
|
||||
if (Token::Match(tok2, "[,();[=]"))
|
||||
if (Token::Match(tok2, "[,();[=]") && !varname.empty())
|
||||
{
|
||||
++_varId;
|
||||
int indentlevel = 0;
|
||||
|
@ -2357,7 +2327,7 @@ void Tokenizer::setVarId()
|
|||
bool funcDeclaration = false;
|
||||
for (tok2 = tok->next(); tok2; tok2 = tok2->next())
|
||||
{
|
||||
if (!dot && tok2->varId() == strid && !Token::Match(tok2->previous(), "struct|union"))
|
||||
if (!dot && tok2->str() == varname && !Token::Match(tok2->previous(), "struct|union"))
|
||||
tok2->varId(_varId);
|
||||
else if (tok2->str() == "{")
|
||||
++indentlevel;
|
||||
|
@ -2393,13 +2363,13 @@ void Tokenizer::setVarId()
|
|||
{
|
||||
// str.clear is a variable
|
||||
// str.clear() is a member function
|
||||
if (tok->varId() > varId1 &&
|
||||
if (tok->varId() != 0 &&
|
||||
Token::Match(tok->next(), ". %var% !!(") &&
|
||||
tok->tokAt(2)->varId() <= varId1)
|
||||
tok->tokAt(2)->varId() == 0)
|
||||
{
|
||||
++_varId;
|
||||
|
||||
const std::string pattern("%varid% . " + tok->strAt(2));
|
||||
const std::string pattern(std::string("%varid% . ") + tok->strAt(2));
|
||||
for (Token *tok2 = tok; tok2; tok2 = tok2->next())
|
||||
{
|
||||
if (Token::Match(tok2, pattern.c_str(), tok->varId()))
|
||||
|
@ -2418,7 +2388,7 @@ void Tokenizer::setVarId()
|
|||
{
|
||||
if (Token::simpleMatch(tok2->tokAt(3), "("))
|
||||
allMemberFunctions.push_back(tok2);
|
||||
else if (tok2->tokAt(2)->varId() >= _varId)
|
||||
else if (tok2->tokAt(2)->varId() != 0)
|
||||
allMemberVars.push_back(tok2);
|
||||
}
|
||||
}
|
||||
|
@ -2431,6 +2401,7 @@ void Tokenizer::setVarId()
|
|||
{
|
||||
const std::string &classname(tok->next()->str());
|
||||
|
||||
|
||||
// What member variables are there in this class?
|
||||
std::map<std::string, unsigned int> varlist;
|
||||
{
|
||||
|
@ -2448,7 +2419,7 @@ void Tokenizer::setVarId()
|
|||
}
|
||||
|
||||
// Found a member variable..
|
||||
else if (indentlevel == 1 && tok2->varId() >= varId1)
|
||||
else if (indentlevel == 1 && tok2->varId() > 0)
|
||||
varlist[tok2->str()] = tok2->varId();
|
||||
}
|
||||
}
|
||||
|
@ -2507,7 +2478,7 @@ void Tokenizer::setVarId()
|
|||
--indentlevel;
|
||||
}
|
||||
else if (indentlevel > 0 &&
|
||||
tok2->varId() > 0 &&
|
||||
tok2->varId() == 0 &&
|
||||
varlist.find(tok2->str()) != varlist.end())
|
||||
{
|
||||
tok2->varId(varlist[tok2->str()]);
|
||||
|
@ -2517,18 +2488,6 @@ void Tokenizer::setVarId()
|
|||
|
||||
}
|
||||
}
|
||||
|
||||
// Cleanup string ids..
|
||||
for (Token *tok = _tokens; tok; tok = tok->next())
|
||||
{
|
||||
if (tok->varId())
|
||||
{
|
||||
if (tok->varId() >= varId1)
|
||||
tok->varId(tok->varId() - varId1);
|
||||
else
|
||||
tok->varId(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue