Tokenizer: propagate Token::eraseTokens().
No functional change.
This commit is contained in:
parent
282f9104e7
commit
368bacff9a
|
@ -446,19 +446,11 @@ bool Tokenizer::tokenize(std::istream &code, const char FileName[])
|
||||||
// Remove __asm..
|
// Remove __asm..
|
||||||
for (Token *tok = _tokens; tok; tok = tok->next())
|
for (Token *tok = _tokens; tok; tok = tok->next())
|
||||||
{
|
{
|
||||||
if (Token::Match(tok->next(), "__asm|_asm|asm {"))
|
if (Token::Match(tok->next(), "__asm|_asm|asm {") &&
|
||||||
|
tok->tokAt(2)->link() &&
|
||||||
|
tok->tokAt(2)->link()->next())
|
||||||
{
|
{
|
||||||
while (tok->next())
|
Token::eraseTokens(tok, tok->tokAt(2)->link()->next());
|
||||||
{
|
|
||||||
bool last(tok->next()->str() == "}");
|
|
||||||
|
|
||||||
// Unlink and delete tok->next()
|
|
||||||
tok->deleteNext();
|
|
||||||
|
|
||||||
// break if this was the last token to delete..
|
|
||||||
if (last)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -498,8 +490,7 @@ bool Tokenizer::tokenize(std::istream &code, const char FileName[])
|
||||||
{
|
{
|
||||||
if (Token::Match(tok, "%type% %var% [ ] [,;=]"))
|
if (Token::Match(tok, "%type% %var% [ ] [,;=]"))
|
||||||
{
|
{
|
||||||
tok->next()->deleteNext();
|
Token::eraseTokens(tok->next(), tok->tokAt(4));
|
||||||
tok->next()->deleteNext();
|
|
||||||
tok->insertToken("*");
|
tok->insertToken("*");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1204,8 +1195,7 @@ void Tokenizer::simplifyTokenList()
|
||||||
if (Token::Match(tok2, ", %num% )"))
|
if (Token::Match(tok2, ", %num% )"))
|
||||||
{
|
{
|
||||||
tok->deleteNext();
|
tok->deleteNext();
|
||||||
tok2->deleteThis();
|
Token::eraseTokens(tok2->previous(), tok2->tokAt(2));
|
||||||
tok2->deleteThis();
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1364,11 +1354,7 @@ void Tokenizer::simplifyTokenList()
|
||||||
if (Token::Match(tok, "sizeof ( * )"))
|
if (Token::Match(tok, "sizeof ( * )"))
|
||||||
{
|
{
|
||||||
tok->str(MathLib::toString<long>(sizeOfType(tok->strAt(2))));
|
tok->str(MathLib::toString<long>(sizeOfType(tok->strAt(2))));
|
||||||
|
Token::eraseTokens(tok, tok->tokAt(4));
|
||||||
for (int i = 0; i < 3; i++)
|
|
||||||
{
|
|
||||||
tok->deleteNext();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (Token::Match(tok, "sizeof ( %var% )") && tok->tokAt(2)->varId() > 0)
|
else if (Token::Match(tok, "sizeof ( %var% )") && tok->tokAt(2)->varId() > 0)
|
||||||
|
@ -1384,10 +1370,7 @@ void Tokenizer::simplifyTokenList()
|
||||||
if (size > 0)
|
if (size > 0)
|
||||||
{
|
{
|
||||||
tok->str(MathLib::toString<long>(size));
|
tok->str(MathLib::toString<long>(size));
|
||||||
for (int i = 0; i < 3; i++)
|
Token::eraseTokens(tok, tok->tokAt(4));
|
||||||
{
|
|
||||||
tok->deleteNext();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1410,9 +1393,7 @@ void Tokenizer::simplifyTokenList()
|
||||||
if (sz > 0)
|
if (sz > 0)
|
||||||
{
|
{
|
||||||
tok->str(MathLib::toString<long>(sz));
|
tok->str(MathLib::toString<long>(sz));
|
||||||
while (tok->next()->str() != ")")
|
Token::eraseTokens(tok, tok->next()->link()->next());
|
||||||
tok->deleteNext();
|
|
||||||
tok->deleteNext();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1457,11 +1438,7 @@ void Tokenizer::simplifyTokenList()
|
||||||
else if (Token::Match(tok2, "sizeof ( %varid% )", varid))
|
else if (Token::Match(tok2, "sizeof ( %varid% )", varid))
|
||||||
{
|
{
|
||||||
tok2->str(MathLib::toString<long>(total_size));
|
tok2->str(MathLib::toString<long>(total_size));
|
||||||
// Delete the other tokens..
|
Token::eraseTokens(tok2, tok2->tokAt(4));
|
||||||
for (int i = 0; i < 3; i++)
|
|
||||||
{
|
|
||||||
tok2->deleteNext();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1548,10 +1525,10 @@ void Tokenizer::simplifyTokenList()
|
||||||
// Replace pointer casts of 0.. "(char *)0" => "0"
|
// Replace pointer casts of 0.. "(char *)0" => "0"
|
||||||
for (Token *tok = _tokens; tok; tok = tok->next())
|
for (Token *tok = _tokens; tok; tok = tok->next())
|
||||||
{
|
{
|
||||||
if (Token::Match(tok->next(), "( %type% * ) 0") || Token::Match(tok->next(), "( %type% %type% * ) 0"))
|
if (Token::Match(tok->next(), "( %type% * ) 0") ||
|
||||||
|
Token::Match(tok->next(), "( %type% %type% * ) 0"))
|
||||||
{
|
{
|
||||||
while (tok->next()->str() != "0")
|
Token::eraseTokens(tok, tok->next()->link()->next());
|
||||||
tok->deleteNext();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1985,17 +1962,19 @@ bool Tokenizer::simplifyConditions()
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Token::simpleMatch(tok, "( true &&") || Token::simpleMatch(tok, "&& true &&") || Token::simpleMatch(tok->next(), "&& true )"))
|
if (Token::simpleMatch(tok, "( true &&") ||
|
||||||
|
Token::simpleMatch(tok, "&& true &&") ||
|
||||||
|
Token::simpleMatch(tok->next(), "&& true )"))
|
||||||
{
|
{
|
||||||
tok->deleteNext();
|
Token::eraseTokens(tok, tok->tokAt(3));
|
||||||
tok->deleteNext();
|
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (Token::simpleMatch(tok, "( false ||") || Token::simpleMatch(tok, "|| false ||") || Token::simpleMatch(tok->next(), "|| false )"))
|
else if (Token::simpleMatch(tok, "( false ||") ||
|
||||||
|
Token::simpleMatch(tok, "|| false ||") ||
|
||||||
|
Token::simpleMatch(tok->next(), "|| false )"))
|
||||||
{
|
{
|
||||||
tok->deleteNext();
|
Token::eraseTokens(tok, tok->tokAt(3));
|
||||||
tok->deleteNext();
|
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2133,10 +2112,7 @@ bool Tokenizer::simplifyQuestionMark()
|
||||||
// Use code after semicolon, remove code before it.
|
// Use code after semicolon, remove code before it.
|
||||||
semicolon = semicolon->next();
|
semicolon = semicolon->next();
|
||||||
tok = tok->tokAt(-2);
|
tok = tok->tokAt(-2);
|
||||||
while (tok->next() != semicolon)
|
Token::eraseTokens(tok, semicolon);
|
||||||
{
|
|
||||||
tok->deleteNext();
|
|
||||||
}
|
|
||||||
|
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
ret = true;
|
ret = true;
|
||||||
|
@ -2147,8 +2123,7 @@ bool Tokenizer::simplifyQuestionMark()
|
||||||
{
|
{
|
||||||
// delete the condition token and the "?"
|
// delete the condition token and the "?"
|
||||||
tok = tok->tokAt(-2);
|
tok = tok->tokAt(-2);
|
||||||
tok->deleteNext();
|
Token::eraseTokens(tok, tok->tokAt(3));
|
||||||
tok->deleteNext();
|
|
||||||
|
|
||||||
// delete the ":" token and the token after it..
|
// delete the ":" token and the token after it..
|
||||||
semicolon->deleteThis();
|
semicolon->deleteThis();
|
||||||
|
@ -2177,9 +2152,8 @@ bool Tokenizer::simplifyCasts()
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Remove cast..
|
// Remove cast..
|
||||||
while (tok->next()->str() != ")")
|
Token::eraseTokens(tok, tok->next()->link()->next());
|
||||||
tok->deleteNext();
|
|
||||||
tok->deleteNext();
|
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2724,16 +2698,14 @@ bool Tokenizer::simplifyIfNot()
|
||||||
tok = tok->previous();
|
tok = tok->previous();
|
||||||
tok->insertToken("!");
|
tok->insertToken("!");
|
||||||
tok = tok->tokAt(4);
|
tok = tok->tokAt(4);
|
||||||
tok->deleteNext();
|
Token::eraseTokens(tok, tok->tokAt(3));
|
||||||
tok->deleteNext();
|
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (tok->link() && Token::simpleMatch(tok, ") == 0"))
|
else if (tok->link() && Token::simpleMatch(tok, ") == 0"))
|
||||||
{
|
{
|
||||||
tok->deleteNext();
|
Token::eraseTokens(tok, tok->tokAt(3));
|
||||||
tok->deleteNext();
|
|
||||||
if (Token::Match(tok->link()->previous(), "%var%"))
|
if (Token::Match(tok->link()->previous(), "%var%"))
|
||||||
{
|
{
|
||||||
// if( foo(x) == 0 )
|
// if( foo(x) == 0 )
|
||||||
|
@ -2792,8 +2764,7 @@ bool Tokenizer::simplifyIfNotNull()
|
||||||
|
|
||||||
if (deleteFrom)
|
if (deleteFrom)
|
||||||
{
|
{
|
||||||
deleteFrom->deleteNext();
|
Token::eraseTokens(deleteFrom, deleteFrom->tokAt(3));
|
||||||
deleteFrom->deleteNext();
|
|
||||||
tok = deleteFrom;
|
tok = deleteFrom;
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
|
@ -2945,8 +2916,7 @@ bool Tokenizer::simplifyKnownVariables()
|
||||||
const std::string op(tok3->strAt(2));
|
const std::string op(tok3->strAt(2));
|
||||||
if (Token::Match(tok3, "[{};] %any% %any% ;"))
|
if (Token::Match(tok3, "[{};] %any% %any% ;"))
|
||||||
{
|
{
|
||||||
tok3->deleteNext();
|
Token::eraseTokens(tok3, tok3->tokAt(3));
|
||||||
tok3->deleteNext();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -2965,8 +2935,7 @@ bool Tokenizer::simplifyKnownVariables()
|
||||||
tok2->tokAt(2)->str(value);
|
tok2->tokAt(2)->str(value);
|
||||||
if (Token::Match(tok3, "[;{}] %any% %any% ;"))
|
if (Token::Match(tok3, "[;{}] %any% %any% ;"))
|
||||||
{
|
{
|
||||||
tok3->deleteNext();
|
Token::eraseTokens(tok3, tok3->tokAt(3));
|
||||||
tok3->deleteNext();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -3094,8 +3063,7 @@ bool Tokenizer::simplifyCalculations()
|
||||||
{
|
{
|
||||||
if (Token::simpleMatch(tok->next(), "* 1") || Token::simpleMatch(tok->next(), "1 *"))
|
if (Token::simpleMatch(tok->next(), "* 1") || Token::simpleMatch(tok->next(), "1 *"))
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 2; i++)
|
Token::eraseTokens(tok, tok->tokAt(3));
|
||||||
tok->deleteNext();
|
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3110,8 +3078,7 @@ bool Tokenizer::simplifyCalculations()
|
||||||
|
|
||||||
tok->str(MathLib::calculate(tok->str(), tok->tokAt(2)->str(), *(tok->strAt(1))));
|
tok->str(MathLib::calculate(tok->str(), tok->tokAt(2)->str(), *(tok->strAt(1))));
|
||||||
|
|
||||||
tok->deleteNext();
|
Token::eraseTokens(tok, tok->tokAt(3));
|
||||||
tok->deleteNext();
|
|
||||||
|
|
||||||
// evaluate "2 + 2 - 2 - 2"
|
// evaluate "2 + 2 - 2 - 2"
|
||||||
// as (((2 + 2) - 2) - 2) = 0
|
// as (((2 + 2) - 2) - 2) = 0
|
||||||
|
|
Loading…
Reference in New Issue