From edd1c32e5b0e662cd0507a52cea6df5c4a871757 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 2 Apr 2017 09:03:43 +0200 Subject: [PATCH] Preprocessor::getConfigs: Better handling of ! in #if --- lib/preprocessor.cpp | 10 ++++++++-- test/testpreprocessor.cpp | 6 +++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index b76c0fd03..402fa24b4 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -196,8 +196,14 @@ static std::string readcondition(const simplecpp::Token *iftok, const std::set configset; for (; sameline(iftok,cond); cond = cond->next) { - if (cond->op == '!') - break; + if (cond->op == '!') { + if (!sameline(iftok,cond->next) || !cond->next->name) + break; + if (cond->next->str == "defined") + continue; + configset.insert(cond->next->str + "=0"); + continue; + } if (cond->str != "defined") continue; const simplecpp::Token *dtok = cond->next; diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index d0dbc8691..4aee7423a 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -558,7 +558,7 @@ private: "#elif !defined(B)\n" "!b\n" "#endif\n"; - TODO_ASSERT_EQUALS("\nA\nA;B", "\n", getConfigsStr(filedata)); + ASSERT_EQUALS("\nA\nB\n", getConfigsStr(filedata)); } void if_cond3() { @@ -612,7 +612,7 @@ private: const char filedata[] = "#if! A\n" "foo();\n" "#endif\n"; - ASSERT_EQUALS("\n", getConfigsStr(filedata)); + ASSERT_EQUALS("\nA=0\n", getConfigsStr(filedata)); } } @@ -645,7 +645,7 @@ private: const char filedata[] = "#if !defined _A\n" "abc\n" "#endif\n"; - ASSERT_EQUALS("\n", getConfigsStr(filedata)); + ASSERT_EQUALS("\n_A\n", getConfigsStr(filedata)); } void if_cond10() {