Tokenizer: Improved simplifyRedundantParanthesis
This commit is contained in:
parent
6edec7bdce
commit
1c7027140a
|
@ -6587,14 +6587,11 @@ bool Tokenizer::simplifyRedundantParenthesis()
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Token::Match(tok->previous(), "(|[|,| ( %var% %op% %var% ) ,|]|)") ||
|
while (Token::Match(tok->previous(), "[{([,:] ( !!{") && Token::Match(tok->link(), ") [;,])]")) {
|
||||||
Token::Match(tok->previous(), "(|[|,| ( %var% %op% %num% ) ,|]|)")) {
|
// We have "( ... )", remove the parenthesis
|
||||||
// We have "( var %op% var )", remove the parenthesis
|
tok->link()->deleteThis();
|
||||||
tok->deleteThis();
|
tok->deleteThis();
|
||||||
tok = tok->tokAt(2);
|
|
||||||
tok->deleteNext();
|
|
||||||
ret = true;
|
ret = true;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Token::Match(tok, "( ( %bool% )") ||
|
if (Token::Match(tok, "( ( %bool% )") ||
|
||||||
|
|
|
@ -295,6 +295,7 @@ private:
|
||||||
TEST_CASE(removeParentheses12); // Ticket #2760 ',(b)='
|
TEST_CASE(removeParentheses12); // Ticket #2760 ',(b)='
|
||||||
TEST_CASE(removeParentheses13);
|
TEST_CASE(removeParentheses13);
|
||||||
TEST_CASE(removeParentheses14); // Ticket #3309
|
TEST_CASE(removeParentheses14); // Ticket #3309
|
||||||
|
TEST_CASE(removeParentheses15); // Ticket #4142
|
||||||
|
|
||||||
TEST_CASE(tokenize_double);
|
TEST_CASE(tokenize_double);
|
||||||
TEST_CASE(tokenize_strings);
|
TEST_CASE(tokenize_strings);
|
||||||
|
@ -4577,6 +4578,10 @@ private:
|
||||||
ASSERT_EQUALS("; if ( ! ( i & 1 ) ) { ; } ;", tokenizeAndStringify("; if ( (i & 1) == 0 ); ;", false));
|
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() {
|
void tokenize_double() {
|
||||||
const char code[] = "void f()\n"
|
const char code[] = "void f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
|
Loading…
Reference in New Issue