From b4a454fc4732af8571c45022662507c2ee90fa94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 13 Dec 2009 15:23:44 +0100 Subject: [PATCH] Fixed #1058 (Preprocessor: extracting configuration for '#if DEF == 1') --- lib/preprocessor.cpp | 48 ++++++++++++++++++++++++++++++++++++--- test/testpreprocessor.cpp | 4 ++-- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index aee5fd833..3b175eabf 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -858,17 +858,59 @@ std::list Preprocessor::getcfgs(const std::string &filedata, const // cleanup unhandled configurations.. for (std::list::iterator it = ret.begin(); it != ret.end();) { - const std::string &s(*it); - if (s.find("&&") != std::string::npos || s.find("||") != std::string::npos) + const std::string s(*it + ";"); + + bool unhandled = false; + + for (std::string::size_type pos = 0; pos < s.length(); ++pos) + { + const unsigned char c = s[pos]; + + // ok with ";" + if (c == ';') + continue; + + // identifier.. + if (std::isalpha(c) || c == '_') + { + while (std::isalnum(s[pos]) || s[pos] == '_') + ++pos; + if (s[pos] == '=') + { + ++pos; + while (std::isdigit(s[pos])) + ++pos; + if (s[pos] != ';') + { + unhandled = true; + break; + } + } + + --pos; + continue; + } + + // not ok.. + else + { + unhandled = true; + break; + } + } + + if (unhandled) { // unhandled ifdef configuration.. if (_errorLogger && _settings && _settings->_debug) - _errorLogger->reportOut("unhandled configuration: " + s); + _errorLogger->reportOut("unhandled configuration: " + *it); ret.erase(it++); } else + { ++it; + } } return ret; diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index 54f946f0d..ff3c59f50 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -646,9 +646,9 @@ private: preprocessor.preprocess(istr, actual, "file.c"); // Compare results.. + ASSERT_EQUALS(1, static_cast(actual.size())); ASSERT_EQUALS("\n\n\nB\n\n", actual[""]); - ASSERT_EQUALS("\nA\n\n\n\n", actual["LIBVER>100"]); - ASSERT_EQUALS(2, static_cast(actual.size())); + TODO_ASSERT_EQUALS("\nA\n\n\n\n", actual["LIBVER=101"]); } void if_cond2()