Tokenizer: Moved a few basic simplifications from simplifyTokenList to tokenize
This commit is contained in:
parent
168bd2ebfc
commit
bb3c135d81
104
lib/tokenize.cpp
104
lib/tokenize.cpp
|
@ -2487,6 +2487,58 @@ bool Tokenizer::tokenize(std::istream &code,
|
||||||
simplifyInitVar();
|
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();
|
_tokens->assignProgressValues();
|
||||||
|
|
||||||
removeRedundantSemicolons();
|
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();
|
simplifySizeof();
|
||||||
|
|
||||||
// replace strlen(str)
|
// replace strlen(str)
|
||||||
|
|
Loading…
Reference in New Issue