From c3fba356c095a0a28350654aa51423b35339b1af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 20 Feb 2011 20:57:28 +0100 Subject: [PATCH] Fixed #2563 (#if equality testing does not ignore parentheses) --- lib/preprocessor.cpp | 28 +++++++++++++++++++++++++++- test/testpreprocessor.cpp | 9 +-------- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 8050770bb..a232a432d 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -1330,7 +1330,33 @@ void Preprocessor::simplifyCondition(const std::map &v if (it != variables.end()) { if (!it->second.empty()) - tok->str(it->second); + { + // Tokenize the value + Tokenizer tokenizer2(&settings,NULL); + std::istringstream istr2(it->second); + tokenizer2.tokenize(istr2,"","",true); + + // Copy the value tokens + std::stack link; + for (const Token *tok2 = tokenizer2.tokens(); tok2; tok2 = tok2->next()) + { + tok->str(tok2->str()); + + if (Token::Match(tok2,"[{([]")) + link.push(tok); + else if (!link.empty() && Token::Match(tok2,"[})]]")) + { + Token::createMutualLinks(link.top(), tok); + link.pop(); + } + + if (tok2->next()) + { + tok->insertToken(""); + tok = tok->next(); + } + } + } 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"); diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index b3ca40855..faba401a5 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -1343,18 +1343,11 @@ private: void if_cond12() { - errout.str(""); const char filedata[] = "#define A (1)\n" "#if A == 1\n" ";\n" "#endif\n"; - std::istringstream istr(filedata); - std::map actual; - Settings settings; - Preprocessor preprocessor(&settings, this); - preprocessor.preprocess(istr, actual, "file.c"); - ASSERT_EQUALS("", errout.str()); - TODO_ASSERT_EQUALS("\n\n;\n\n", "\n\n\n\n", actual[""]); + ASSERT_EQUALS("\n\n;\n\n", Preprocessor::getcode(filedata,"","",NULL,NULL)); }