diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 45298c022..aa2e49fcc 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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() diff --git a/lib/tokenize.h b/lib/tokenize.h index 503b2d3e2..66fda86d7 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -458,6 +458,8 @@ public: */ std::set simplifyTemplatesExpandSpecialized(); + void simplifyDoublePlusAndDoubleMinus(); + /** * Get template declarations * @return list of template declarations