Refactoring: Extract method: simplifyDoublePlusAndDoubleMinus()
This commit is contained in:
parent
47c666308f
commit
8e6ebd4a22
|
@ -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()
|
||||
|
|
|
@ -458,6 +458,8 @@ public:
|
|||
*/
|
||||
std::set<std::string> simplifyTemplatesExpandSpecialized();
|
||||
|
||||
void simplifyDoublePlusAndDoubleMinus();
|
||||
|
||||
/**
|
||||
* Get template declarations
|
||||
* @return list of template declarations
|
||||
|
|
Loading…
Reference in New Issue