Fixed #1951 (Preprocessor: Compound macro statements not handled correctly)

This commit is contained in:
Daniel Marjamäki 2010-08-26 21:33:45 +02:00
parent 499a12c896
commit 1d9e484053
2 changed files with 18 additions and 5 deletions

View File

@ -1104,10 +1104,13 @@ void Preprocessor::simplifyCondition(const std::map<std::string, std::string> &v
const std::map<std::string, std::string>::const_iterator it = variables.find(tok->str()); const std::map<std::string, std::string>::const_iterator it = variables.find(tok->str());
if (it != variables.end()) if (it != variables.end())
{ {
if (it->second.empty()) if (!it->second.empty())
tok->deleteThis();
else
tok->str(it->second); 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->str("1");
else
tok->deleteThis();
} }
} }

View File

@ -111,7 +111,8 @@ private:
TEST_CASE(if_cond9); TEST_CASE(if_cond9);
TEST_CASE(if_cond10); TEST_CASE(if_cond10);
TEST_CASE(if_or); TEST_CASE(if_or_1);
TEST_CASE(if_or_2);
TEST_CASE(multiline1); TEST_CASE(multiline1);
TEST_CASE(multiline2); TEST_CASE(multiline2);
@ -1068,7 +1069,7 @@ private:
void if_or() void if_or_1()
{ {
const char filedata[] = "#if defined(DEF_10) || defined(DEF_11)\n" const char filedata[] = "#if defined(DEF_10) || defined(DEF_11)\n"
"a1;\n" "a1;\n"
@ -1097,6 +1098,15 @@ private:
} }
void if_or_2()
{
const std::string code("#if X || Y\n"
"a1;\n"
"#endif\n");
const std::string actual = Preprocessor::getcode(code, "X", "test.c", NULL);
ASSERT_EQUALS("\na1;\n\n", actual);
}
void multiline1() void multiline1()
{ {