Add simplification of the consecutive braces before the end of 'tokenize()' function.

This commit is contained in:
Edoardo Prezioso 2011-11-12 16:59:20 +01:00
parent 5cbfbe31c1
commit ed6a0e14c4
1 changed files with 17 additions and 10 deletions

View File

@ -2500,6 +2500,16 @@ bool Tokenizer::tokenize(std::istream &code,
tok->next()->deleteNext(); 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(); return validate();
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
@ -4329,9 +4339,7 @@ bool Tokenizer::simplifyTokenList()
simplifyFlowControl(); simplifyFlowControl();
// Remove redundant consecutive braces, i.e. '.. { { .. } } ..' -> '.. { .. } ..'. // Remove redundant consecutive braces, i.e. '.. { { .. } } ..' -> '.. { .. } ..'.
{ for (Token *tok = _tokens; tok; ) {
Token *tok = _tokens;
while (tok) {
if (Token::simpleMatch(tok, "{ {") && Token::simpleMatch(tok->next()->link(), "} }")) { if (Token::simpleMatch(tok, "{ {") && Token::simpleMatch(tok->next()->link(), "} }")) {
//remove internal parentheses //remove internal parentheses
tok->next()->link()->deleteThis(); tok->next()->link()->deleteThis();
@ -4339,7 +4347,6 @@ bool Tokenizer::simplifyTokenList()
} else } else
tok = tok->next(); tok = tok->next();
} }
}
if (!validate()) if (!validate())
return false; return false;