Tokenizer: Move 'else if' simplification to tokenize

This commit is contained in:
Daniel Marjamäki 2014-01-12 17:47:02 +01:00
parent d700114edf
commit ab866be03a
2 changed files with 13 additions and 1 deletions

View File

@ -1786,6 +1786,17 @@ void CheckOther::checkVariableScope()
}
tok = tok->link();
// parse else if blocks..
} else if (Token::simpleMatch(tok, "else { if (") && Token::simpleMatch(tok->linkAt(3), ") {")) {
const Token *endif = tok->linkAt(3)->linkAt(1);
bool elseif = false;
if (Token::simpleMatch(endif, "} }"))
elseif = true;
else if (Token::simpleMatch(endif, "} else {") && Token::simpleMatch(endif->linkAt(2),"} }"))
elseif = true;
if (elseif && Token::findmatch(tok->next(), "%varid%", tok->linkAt(1), var->declarationId()))
reduce = false;
} else if (tok->varId() == var->declarationId() || tok->str() == "goto") {
reduce = false;
break;

View File

@ -3512,6 +3512,8 @@ bool Tokenizer::simplifyTokenList1()
simplifyEmptyNamespaces();
elseif();
return validate();
}
@ -3641,7 +3643,6 @@ bool Tokenizer::simplifyTokenList2()
// Simplify variable declarations
simplifyVarDecl(false);
elseif();
simplifyErrNoInWhile();
simplifyIfAndWhileAssign();
simplifyRedundantParentheses();