Tokenizer: Don't remove parentheses in 'a?b:(c>0?d:e)'

This commit is contained in:
Daniel Marjamäki 2014-01-08 20:53:33 +01:00
parent 32f2ee422f
commit 4f11086505
2 changed files with 7 additions and 2 deletions

View File

@ -7083,7 +7083,7 @@ bool Tokenizer::simplifyRedundantParentheses()
} }
} }
while (Token::Match(tok->previous(), "[{([,:] ( !!{") && while (Token::Match(tok->previous(), "[{([,] ( !!{") &&
Token::Match(tok->link(), ") [;,])]") && Token::Match(tok->link(), ") [;,])]") &&
!Token::findsimplematch(tok, ",", tok->link())) { !Token::findsimplematch(tok, ",", tok->link())) {
// We have "( ... )", remove the parentheses // We have "( ... )", remove the parentheses

View File

@ -349,6 +349,7 @@ private:
TEST_CASE(removeParentheses14); // Ticket #3309 TEST_CASE(removeParentheses14); // Ticket #3309
TEST_CASE(removeParentheses15); // Ticket #4142 TEST_CASE(removeParentheses15); // Ticket #4142
TEST_CASE(removeParentheses16); // Ticket #4423 '*(x.y)=' TEST_CASE(removeParentheses16); // Ticket #4423 '*(x.y)='
TEST_CASE(removeParentheses17); // Don't remove parentheses in 'a ? b : (c>0 ? d : e);'
TEST_CASE(tokenize_double); TEST_CASE(tokenize_double);
TEST_CASE(tokenize_strings); TEST_CASE(tokenize_strings);
@ -5404,7 +5405,7 @@ private:
void removeParentheses15() { void removeParentheses15() {
ASSERT_EQUALS("a = b ? c : 123 ;", tokenizeAndStringify("a = b ? c : (123);", false)); ASSERT_EQUALS("a = b ? c : 123 ;", tokenizeAndStringify("a = b ? c : (123);", false));
ASSERT_EQUALS("a = b ? c : 579 ;", tokenizeAndStringify("a = b ? c : ((123)+(456));", false)); ASSERT_EQUALS("a = b ? c : ( 579 ) ;", tokenizeAndStringify("a = b ? c : ((123)+(456));", false));
ASSERT_EQUALS("a = b ? 123 : c ;", tokenizeAndStringify("a = b ? (123) : c;", false)); ASSERT_EQUALS("a = b ? 123 : c ;", tokenizeAndStringify("a = b ? (123) : c;", false));
// #4316 // #4316
@ -5417,6 +5418,10 @@ private:
ASSERT_EQUALS("* x . y = 0 ;", tokenizeAndStringify("*(x.y)=0;", false)); ASSERT_EQUALS("* x . y = 0 ;", tokenizeAndStringify("*(x.y)=0;", false));
} }
void removeParentheses17() { // a ? b : (c > 0 ? d : e)
ASSERT_EQUALS("a ? b : ( c > 0 ? d : e ) ;", tokenizeAndStringify("a?b:(c>0?d:e);", false));
}
void tokenize_double() { void tokenize_double() {
const char code[] = "void f()\n" const char code[] = "void f()\n"
"{\n" "{\n"