Fixed #3573 (Preprocessor: handle '!(X)' the same as '!X')

This commit is contained in:
Daniel Marjamäki 2012-03-26 19:01:45 +02:00
parent 81caeb0232
commit c07044b3d3
2 changed files with 16 additions and 0 deletions

View File

@ -6701,6 +6701,13 @@ bool Tokenizer::simplifyRedundantParenthesis()
ret = true; ret = true;
} }
if (Token::Match(tok->previous(), "! ( %var% )")) {
// Remove the parenthesis
tok->deleteThis();
tok->deleteNext();
ret = true;
}
while (Token::Match(tok->previous(), "[,;{}(] ( %var% (") && while (Token::Match(tok->previous(), "[,;{}(] ( %var% (") &&
tok->link()->previous() == tok->linkAt(2)) { tok->link()->previous() == tok->linkAt(2)) {
// We have "( func ( *something* ))", remove the outer // We have "( func ( *something* ))", remove the outer

View File

@ -124,6 +124,7 @@ private:
TEST_CASE(if_cond11); TEST_CASE(if_cond11);
TEST_CASE(if_cond12); TEST_CASE(if_cond12);
TEST_CASE(if_cond13); TEST_CASE(if_cond13);
TEST_CASE(if_cond14);
TEST_CASE(if_or_1); TEST_CASE(if_or_1);
TEST_CASE(if_or_2); TEST_CASE(if_or_2);
@ -1464,6 +1465,14 @@ private:
ASSERT_EQUALS("\n123\n\n", preprocessor.getcode(filedata,"","")); ASSERT_EQUALS("\n123\n\n", preprocessor.getcode(filedata,"",""));
} }
void if_cond14() {
const char filedata[] = "#if !(A)\n"
"123\n"
"#endif\n";
Preprocessor preprocessor(NULL, this);
ASSERT_EQUALS("\n123\n\n", preprocessor.getcode(filedata,"",""));
}
void if_or_1() { void if_or_1() {