Refactoring: Extract method: simplifyDoublePlusAndDoubleMinus()

This commit is contained in:
Reijo Tomperi 2011-12-24 22:51:55 +02:00
parent 47c666308f
commit 8e6ebd4a22
2 changed files with 33 additions and 26 deletions

View File

@ -2537,32 +2537,7 @@ bool Tokenizer::tokenize(std::istream &code,
// 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;
}
}
simplifyDoublePlusAndDoubleMinus();
// 0[a] -> a[0]
for (Token *tok = _tokens; tok; tok = tok->next()) {
@ -2603,6 +2578,36 @@ bool Tokenizer::tokenize(std::istream &code,
}
//---------------------------------------------------------------------------
void Tokenizer::simplifyDoublePlusAndDoubleMinus()
{
// 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;
}
}
}
/** Specify array size if it hasn't been given */
void Tokenizer::arraySize()

View File

@ -458,6 +458,8 @@ public:
*/
std::set<std::string> simplifyTemplatesExpandSpecialized();
void simplifyDoublePlusAndDoubleMinus();
/**
* Get template declarations
* @return list of template declarations