diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index d3f2dec76..9eb2dbfd5 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2128,14 +2128,7 @@ bool Tokenizer::tokenize(std::istream &code, _tokens->assignProgressValues(); - // remove redundant semicolon: - for (Token *tok = _tokens; tok; tok = tok->next()) - { - if (tok->str() == "(") - tok = tok->link(); - while (Token::simpleMatch(tok, "; ;")) - tok->deleteNext(); - } + removeRedundantSemicolons(); return validate(); } @@ -3954,15 +3947,7 @@ bool Tokenizer::simplifyTokenList() _tokens->assignProgressValues(); - // remove redundant semicolon: - for (Token *tok = _tokens; tok; tok = tok->next()) - { - if (tok->str() == "(") - tok = tok->link(); - while (Token::simpleMatch(tok, "; ;")) - tok->deleteNext(); - } - + removeRedundantSemicolons(); return validate(); } @@ -4151,6 +4136,22 @@ bool Tokenizer::removeReduntantConditions() } +void Tokenizer::removeRedundantSemicolons() +{ + for (Token *tok = _tokens; tok; tok = tok->next()) + { + if (tok->str() == "(") + { + tok = tok->link(); + } + while (Token::simpleMatch(tok, "; ;")) + { + tok->deleteNext(); + } + } +} + + void Tokenizer::simplifyIfAddBraces() { for (Token *tok = _tokens; tok; tok = tok ? tok->next() : NULL) diff --git a/lib/tokenize.h b/lib/tokenize.h index c0b7d7e29..e676bc9f1 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -290,6 +290,11 @@ public: */ bool removeReduntantConditions(); + /** + * Reduces "; ;" to ";", except in "( ; ; )" + */ + void removeRedundantSemicolons(); + /** Simplify function calls - constant return value * @return true if something is modified * false if nothing is done.