Tokenizer: improve code and change name of +- concatenation function.

This commit is contained in:
Edoardo Prezioso 2012-12-01 00:43:23 +01:00
parent 3d1d983251
commit f3782935c2
2 changed files with 8 additions and 6 deletions

View File

@ -1642,7 +1642,7 @@ bool Tokenizer::tokenize(std::istream &code,
simplifyMathExpressions();
// combine "- %num%"
concatenateNegativeNumber();
concatenateNegativeNumberAndAnyPositive();
// simplify simple calculations
for (Token *tok = list.front() ? list.front()->next() : NULL; tok; tok = tok->next()) {
@ -2150,14 +2150,16 @@ void Tokenizer::simplifyNull()
}
}
void Tokenizer::concatenateNegativeNumber()
void Tokenizer::concatenateNegativeNumberAndAnyPositive()
{
for (Token *tok = list.front(); tok; tok = tok->next()) {
if (Token::Match(tok, "?|:|,|(|[|{|=|return|case|sizeof|%op% - %num%")) {
if (!Token::Match(tok, "?|:|,|(|[|{|=|return|case|sizeof|%op% +|-"))
continue;
if (tok->next()->str() == "+")
tok->deleteNext();
else if (Token::Match(tok->next(), "- %num%")) {
tok->deleteNext();
tok->next()->str("-" + tok->next()->str());
} else if (Token::Match(tok, "?|:|,|(|[|{|=|return|case|sizeof|%op% +")) {
tok->deleteNext();
}
}
}

View File

@ -429,7 +429,7 @@ public:
void simplifyNull();
void concatenateNegativeNumber();
void concatenateNegativeNumberAndAnyPositive();
void simplifyExternC();