From 38b480a4b543be174bdab204669d1d4009512a39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 2 Jan 2010 20:54:52 +0100 Subject: [PATCH] Fixed #1203 (Preprocessor: Doesn't handle macros usage that contain ';') --- lib/preprocessor.cpp | 9 +++++++-- test/testpreprocessor.cpp | 8 ++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 9f830cbac..763ffe8e9 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -1624,6 +1624,7 @@ static bool getlines(std::istream &istr, std::string &line) if (!istr.good()) return false; line = ""; + int parlevel = 0; for (unsigned char ch = (unsigned char)istr.get(); istr.good(); ch = (unsigned char)istr.get()) { if (ch == '\'' || ch == '\"') @@ -1649,7 +1650,11 @@ static bool getlines(std::istream &istr, std::string &line) } continue; } - if (ch == '\n') + if (ch == '(') + ++parlevel; + else if (ch == ')') + --parlevel; + else if (ch == '\n') { if (line.compare(0, 1, "#") == 0) return true; @@ -1660,7 +1665,7 @@ static bool getlines(std::istream &istr, std::string &line) return true; } } - else if (line.compare(0, 1, "#") != 0 && ch == ';') + else if (line.compare(0, 1, "#") != 0 && parlevel <= 0 && ch == ';') { line += ";"; return true; diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index e377a807c..44755f532 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -131,6 +131,7 @@ private: TEST_CASE(macro_simple10); TEST_CASE(macro_simple11); TEST_CASE(macro_simple12); + TEST_CASE(macro_simple13); TEST_CASE(macroInMacro); TEST_CASE(macro_mismatch); TEST_CASE(macro_linenumbers); @@ -1107,6 +1108,13 @@ private: ASSERT_EQUALS("\nab.AB.CD\n", OurPreprocessor::expandMacros(filedata)); } + void macro_simple13() + { + const char filedata[] = "#define TRACE(x)\n" + "TRACE(;if(a))\n"; + ASSERT_EQUALS("\n\n", OurPreprocessor::expandMacros(filedata)); + } + void macroInMacro() { {