From 86e517c5d392d81e457008f0ce9c975d65724738 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 24 Sep 2010 21:38:11 +0200 Subject: [PATCH] Fixed #1951 (Preprocessor: Compound macro statements not handled correctly) --- lib/preprocessor.cpp | 13 ++++++++++++- test/testpreprocessor.cpp | 4 ++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index c26475fdb..9abf974b1 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -1176,7 +1176,7 @@ void Preprocessor::simplifyCondition(const std::map &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 &v } } + for (Token *tok = const_cast(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"; diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index 49a54f1db..37ca80744 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -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)); }