From c6f913ac3e946db2d5f3543699c4622bbe21498d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 11 Dec 2009 22:32:44 +0100 Subject: [PATCH] Preprocessor: Fixed TODO_ASSERT_EQUALS --- lib/preprocessor.cpp | 16 +++++++++++++++- test/testpreprocessor.cpp | 4 ++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 279512db1..aee5fd833 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -920,7 +920,21 @@ void Preprocessor::simplifyCondition(const std::map &v } // simplify calculations.. - tokenizer.simplifyCalculations(); + bool modified = true; + while (modified) + { + modified = false; + tokenizer.simplifyCalculations(); + for (Token *tok = const_cast(tokenizer.tokens()); tok; tok = tok->next()) + { + if (Token::Match(tok, "! %num%")) + { + tok->deleteThis(); + tok->str(tok->str() == "0" ? "1" : "0"); + modified = true; + } + } + } if (Token::simpleMatch(tokenizer.tokens(), "( 1 )") || Token::simpleMatch(tokenizer.tokens(), "( 1 ||")) diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index c2044de36..54f946f0d 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -611,10 +611,10 @@ private: cfg["ABC"] = ""; ASSERT_EQUALS(false, Preprocessor::match_cfg_def(cfg, "defined(A)")); - TODO_ASSERT_EQUALS(true, Preprocessor::match_cfg_def(cfg, "!defined(A)")); + ASSERT_EQUALS(true, Preprocessor::match_cfg_def(cfg, "!defined(A)")); ASSERT_EQUALS(false, Preprocessor::match_cfg_def(cfg, "!defined(ABC)&&!defined(DEF)")); - TODO_ASSERT_EQUALS(true, Preprocessor::match_cfg_def(cfg, "!defined(A)&&!defined(B)")); + ASSERT_EQUALS(true, Preprocessor::match_cfg_def(cfg, "!defined(A)&&!defined(B)")); } {