Tokenizer: Improved simplifyRedundantParanthesis

This commit is contained in:
Daniel Marjamäki 2012-09-06 16:16:29 +02:00
parent 6edec7bdce
commit 1c7027140a
2 changed files with 8 additions and 6 deletions

View File

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

View File

@ -295,6 +295,7 @@ private:
TEST_CASE(removeParentheses12); // Ticket #2760 ',(b)='
TEST_CASE(removeParentheses13);
TEST_CASE(removeParentheses14); // Ticket #3309
TEST_CASE(removeParentheses15); // Ticket #4142
TEST_CASE(tokenize_double);
TEST_CASE(tokenize_strings);
@ -4577,6 +4578,10 @@ private:
ASSERT_EQUALS("; if ( ! ( i & 1 ) ) { ; } ;", tokenizeAndStringify("; if ( (i & 1) == 0 ); ;", false));
}
void removeParentheses15() {
ASSERT_EQUALS("a = b ? c : 123 ;", tokenizeAndStringify("a = b ? c : (123);", false));
}
void tokenize_double() {
const char code[] = "void f()\n"
"{\n"