Tokenizer: Moved a few basic simplifications from simplifyTokenList to tokenize

This commit is contained in:
Daniel Marjamäki 2011-05-01 08:36:27 +02:00
parent 168bd2ebfc
commit bb3c135d81
1 changed files with 52 additions and 52 deletions

View File

@ -2487,6 +2487,58 @@ bool Tokenizer::tokenize(std::istream &code,
simplifyInitVar();
}
// Convert e.g. atol("0") into 0
simplifyMathFunctions();
// Convert + + into + and + - into -
for (Token *tok = _tokens; tok; tok = tok->next())
{
while (tok->next())
{
if (tok->str() == "+")
{
if (tok->next()->str() == "+")
{
tok->deleteNext();
continue;
}
else if (tok->next()->str() == "-")
{
tok->str("-");
tok->deleteNext();
continue;
}
}
else if (tok->str() == "-")
{
if (tok->next()->str() == "-")
{
tok->str("+");
tok->deleteNext();
continue;
}
else if (tok->next()->str() == "+")
{
tok->deleteNext();
continue;
}
}
break;
}
}
// 0[a] -> a[0]
for (Token *tok = _tokens; tok; tok = tok->next())
{
if (Token::Match(tok, "%num% [ %var% ]"))
{
const std::string temp = tok->str();
tok->str(tok->tokAt(2)->str());
tok->tokAt(2)->str(temp);
}
}
_tokens->assignProgressValues();
removeRedundantSemicolons();
@ -4279,58 +4331,6 @@ bool Tokenizer::simplifyTokenList()
}
}
// Convert e.g. atol("0") into 0
simplifyMathFunctions();
// Convert + + into + and + - into -
for (Token *tok = _tokens; tok; tok = tok->next())
{
while (tok->next())
{
if (tok->str() == "+")
{
if (tok->next()->str() == "+")
{
tok->deleteNext();
continue;
}
else if (tok->next()->str() == "-")
{
tok->str("-");
tok->deleteNext();
continue;
}
}
else if (tok->str() == "-")
{
if (tok->next()->str() == "-")
{
tok->str("+");
tok->deleteNext();
continue;
}
else if (tok->next()->str() == "+")
{
tok->deleteNext();
continue;
}
}
break;
}
}
// 0[a] -> a[0]
for (Token *tok = _tokens; tok; tok = tok->next())
{
if (Token::Match(tok, "%num% [ %var% ]"))
{
const std::string temp = tok->str();
tok->str(tok->tokAt(2)->str());
tok->tokAt(2)->str(temp);
}
}
simplifySizeof();
// replace strlen(str)