Fixed #1951 (Preprocessor: Compound macro statements not handled correctly)
This commit is contained in:
parent
4c98a7e67b
commit
86e517c5d3
|
@ -1176,7 +1176,7 @@ void Preprocessor::simplifyCondition(const std::map<std::string, std::string> &v
|
|||
if (!it->second.empty())
|
||||
tok->str(it->second);
|
||||
else if ((!tok->previous() || tok->strAt(-1) == "||" || tok->strAt(-1) == "&&" || tok->strAt(-1) == "(") &&
|
||||
(!tok->next() || tok->strAt(1) == "||" || tok->strAt(1) == "&&" || tok->strAt(-1) == ")"))
|
||||
(!tok->next() || tok->strAt(1) == "||" || tok->strAt(1) == "&&" || tok->strAt(1) == ")"))
|
||||
tok->str("1");
|
||||
else
|
||||
tok->deleteThis();
|
||||
|
@ -1200,6 +1200,17 @@ void Preprocessor::simplifyCondition(const std::map<std::string, std::string> &v
|
|||
}
|
||||
}
|
||||
|
||||
for (Token *tok = const_cast<Token *>(tokenizer.tokens()); tok; tok = tok->next())
|
||||
{
|
||||
while ((tok->str() == "(" || tok->str() == "||") && (Token::simpleMatch(tok->tokAt(2), "|| 1")))
|
||||
{
|
||||
tok->deleteNext();
|
||||
tok->deleteNext();
|
||||
if (tok->tokAt(-3))
|
||||
tok = tok->tokAt(-3);
|
||||
}
|
||||
}
|
||||
|
||||
if (Token::simpleMatch(tokenizer.tokens(), "( 1 )") ||
|
||||
Token::simpleMatch(tokenizer.tokens(), "( 1 ||"))
|
||||
condition = "1";
|
||||
|
|
|
@ -1143,8 +1143,8 @@ private:
|
|||
const std::string code("#if X || Y\n"
|
||||
"a1;\n"
|
||||
"#endif\n");
|
||||
const std::string actual = Preprocessor::getcode(code, "X", "test.c", NULL, NULL);
|
||||
ASSERT_EQUALS("\na1;\n\n", actual);
|
||||
ASSERT_EQUALS("\na1;\n\n", Preprocessor::getcode(code, "X", "test.c", NULL, NULL));
|
||||
ASSERT_EQUALS("\na1;\n\n", Preprocessor::getcode(code, "Y", "test.c", NULL, NULL));
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue