diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 1b6f34992..fb0c97295 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1661,60 +1661,60 @@ void Tokenizer::simplifyMulAndParens() if (!list.front()) return; for (Token *tok = list.front()->tokAt(3); tok; tok = tok->next()) { - if (tok->isName()) { - //fix ticket #2784 - improved by ticket #3184 - unsigned int closedpars = 0; - Token *tokend = tok->next(); - Token *tokbegin = tok->previous(); - while (tokend && tokend->str() == ")") { - ++closedpars; - tokend = tokend->next(); - } - if (!tokend || !(tokend->isAssignmentOp())) - continue; - while (Token::Match(tokbegin, "&|(")) { - if (tokbegin->str() == "&") { - if (Token::Match(tokbegin->tokAt(-2), "[;{}&(] *")) { - //remove '* &' - tokbegin = tokbegin->tokAt(-2); - tokbegin->deleteNext(2); - } else if (Token::Match(tokbegin->tokAt(-3), "[;{}&(] * (")) { - if (!closedpars) - break; - --closedpars; - //remove ')' - tok->deleteNext(); - //remove '* ( &' - tokbegin = tokbegin->tokAt(-3); - tokbegin->deleteNext(3); - } else - break; - } else if (tokbegin->str() == "(") { + if (!tok->isName()) + continue; + //fix ticket #2784 - improved by ticket #3184 + unsigned int closedpars = 0; + Token *tokend = tok->next(); + Token *tokbegin = tok->previous(); + while (tokend && tokend->str() == ")") { + ++closedpars; + tokend = tokend->next(); + } + if (!tokend || !(tokend->isAssignmentOp())) + continue; + while (Token::Match(tokbegin, "&|(")) { + if (tokbegin->str() == "&") { + if (Token::Match(tokbegin->tokAt(-2), "[;{}&(] *")) { + //remove '* &' + tokbegin = tokbegin->tokAt(-2); + tokbegin->deleteNext(2); + } else if (Token::Match(tokbegin->tokAt(-3), "[;{}&(] * (")) { if (!closedpars) 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 - unsigned int openpars = 0; - while (tokbegin && tokbegin->str() == "(" && openpars <= closedpars) { - ++openpars; - 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; + //find consecutive opening parentheses + unsigned int openpars = 0; + while (tokbegin && tokbegin->str() == "(" && openpars <= closedpars) { + ++openpars; + 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; } } }