From ed6a0e14c4fc8ae5b9ac6d41a24b02b5b55a787b Mon Sep 17 00:00:00 2001 From: Edoardo Prezioso Date: Sat, 12 Nov 2011 16:59:20 +0100 Subject: [PATCH] Add simplification of the consecutive braces before the end of 'tokenize()' function. --- lib/tokenize.cpp | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 02234059e..7fba23ec6 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2500,6 +2500,16 @@ bool Tokenizer::tokenize(std::istream &code, tok->next()->deleteNext(); } + // Remove redundant consecutive braces, i.e. '.. { { .. } } ..' -> '.. { .. } ..'. + for (Token *tok = _tokens; tok; ) { + if (Token::simpleMatch(tok, "{ {") && Token::simpleMatch(tok->next()->link(), "} }")) { + //remove internal parentheses + tok->next()->link()->deleteThis(); + tok->deleteNext(); + } else + tok = tok->next(); + } + return validate(); } //--------------------------------------------------------------------------- @@ -4329,16 +4339,13 @@ bool Tokenizer::simplifyTokenList() simplifyFlowControl(); // Remove redundant consecutive braces, i.e. '.. { { .. } } ..' -> '.. { .. } ..'. - { - Token *tok = _tokens; - while (tok) { - if (Token::simpleMatch(tok, "{ {") && Token::simpleMatch(tok->next()->link(), "} }")) { - //remove internal parentheses - tok->next()->link()->deleteThis(); - tok->deleteNext(); - } else - tok = tok->next(); - } + for (Token *tok = _tokens; tok; ) { + if (Token::simpleMatch(tok, "{ {") && Token::simpleMatch(tok->next()->link(), "} }")) { + //remove internal parentheses + tok->next()->link()->deleteThis(); + tok->deleteNext(); + } else + tok = tok->next(); } if (!validate())