More simplifyRedundantParenthesis changes:

simplify also '( var . var . ... . var )' parenthesis.
This commit is contained in:
Edoardo Prezioso 2012-11-04 22:38:18 +01:00
parent b6b359d1c6
commit 24bf6f99e1
2 changed files with 19 additions and 6 deletions

View File

@ -6544,11 +6544,17 @@ bool Tokenizer::simplifyRedundantParenthesis()
ret = true;
}
if (Token::Match(tok->previous(), "[(,!] ( %var% . %var% )")) {
// We have "( var . var )", remove the parenthesis
tok->deleteThis();
tok = tok->tokAt(2);
while (Token::Match(tok->previous(), ";|{|}|[|]|(|)|.|,|! ( %var% .")) {
Token *tok2 = tok->tokAt(2);
while (Token::Match(tok2, ". %var%")) {
tok2 = tok2->tokAt(2);
}
if (tok2 != tok->link())
break;
// We have "( var . var . ... . var )", remove the parenthesis
tok = tok->previous();
tok->deleteNext();
tok2->deleteThis();
ret = true;
continue;
}

View File

@ -4710,8 +4710,15 @@ private:
// "!(abc.a)" => "!abc.a"
void removeParentheses6() {
const char code[] = "(!(abc.a))";
ASSERT_EQUALS("( ! abc . a )", tokenizeAndStringify(code));
{
const char code[] = "(!(abc.a))";
ASSERT_EQUALS("( ! abc . a )", tokenizeAndStringify(code));
}
//handle more complex member selections
{
const char code[] = "(!(a.b.c.d));";
ASSERT_EQUALS("( ! a . b . c . d ) ;", tokenizeAndStringify(code));
}
}
void removeParentheses7() {