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();
}
// 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())