Refactoring, use continue

This commit is contained in:
Daniel Marjamäki 2017-07-30 12:46:04 +02:00
parent 23ed35b1e6
commit 29265cdd49
1 changed files with 50 additions and 50 deletions

View File

@ -1661,60 +1661,60 @@ void Tokenizer::simplifyMulAndParens()
if (!list.front()) if (!list.front())
return; return;
for (Token *tok = list.front()->tokAt(3); tok; tok = tok->next()) { for (Token *tok = list.front()->tokAt(3); tok; tok = tok->next()) {
if (tok->isName()) { if (!tok->isName())
//fix ticket #2784 - improved by ticket #3184 continue;
unsigned int closedpars = 0; //fix ticket #2784 - improved by ticket #3184
Token *tokend = tok->next(); unsigned int closedpars = 0;
Token *tokbegin = tok->previous(); Token *tokend = tok->next();
while (tokend && tokend->str() == ")") { Token *tokbegin = tok->previous();
++closedpars; while (tokend && tokend->str() == ")") {
tokend = tokend->next(); ++closedpars;
} tokend = tokend->next();
if (!tokend || !(tokend->isAssignmentOp())) }
continue; if (!tokend || !(tokend->isAssignmentOp()))
while (Token::Match(tokbegin, "&|(")) { continue;
if (tokbegin->str() == "&") { while (Token::Match(tokbegin, "&|(")) {
if (Token::Match(tokbegin->tokAt(-2), "[;{}&(] *")) { if (tokbegin->str() == "&") {
//remove '* &' if (Token::Match(tokbegin->tokAt(-2), "[;{}&(] *")) {
tokbegin = tokbegin->tokAt(-2); //remove '* &'
tokbegin->deleteNext(2); tokbegin = tokbegin->tokAt(-2);
} else if (Token::Match(tokbegin->tokAt(-3), "[;{}&(] * (")) { tokbegin->deleteNext(2);
if (!closedpars) } else if (Token::Match(tokbegin->tokAt(-3), "[;{}&(] * (")) {
break;
--closedpars;
//remove ')'
tok->deleteNext();
//remove '* ( &'
tokbegin = tokbegin->tokAt(-3);
tokbegin->deleteNext(3);
} else
break;
} else if (tokbegin->str() == "(") {
if (!closedpars) if (!closedpars)
break; break;
--closedpars;
//remove ')'
tok->deleteNext();
//remove '* ( &'
tokbegin = tokbegin->tokAt(-3);
tokbegin->deleteNext(3);
} else
break;
} else if (tokbegin->str() == "(") {
if (!closedpars)
break;
//find consecutive opening parentheses //find consecutive opening parentheses
unsigned int openpars = 0; unsigned int openpars = 0;
while (tokbegin && tokbegin->str() == "(" && openpars <= closedpars) { while (tokbegin && tokbegin->str() == "(" && openpars <= closedpars) {
++openpars; ++openpars;
tokbegin = tokbegin->previous(); tokbegin = tokbegin->previous();
}
if (!tokbegin || openpars > closedpars)
break;
if ((openpars == closedpars && Token::Match(tokbegin, "[;{}]")) ||
Token::Match(tokbegin->tokAt(-2), "[;{}&(] * &") ||
Token::Match(tokbegin->tokAt(-3), "[;{}&(] * ( &")) {
//remove the excessive parentheses around the variable
while (openpars) {
tok->deleteNext();
tokbegin->deleteNext();
--closedpars;
--openpars;
}
} else
break;
} }
if (!tokbegin || openpars > closedpars)
break;
if ((openpars == closedpars && Token::Match(tokbegin, "[;{}]")) ||
Token::Match(tokbegin->tokAt(-2), "[;{}&(] * &") ||
Token::Match(tokbegin->tokAt(-3), "[;{}&(] * ( &")) {
//remove the excessive parentheses around the variable
while (openpars) {
tok->deleteNext();
tokbegin->deleteNext();
--closedpars;
--openpars;
}
} else
break;
} }
} }
} }