Fixed #1058 (Preprocessor: extracting configuration for '#if DEF == 1')

This commit is contained in:
Daniel Marjamäki 2009-12-13 15:23:44 +01:00
parent 01cfa3b6bd
commit b4a454fc47
2 changed files with 47 additions and 5 deletions

View File

@ -858,17 +858,59 @@ std::list<std::string> Preprocessor::getcfgs(const std::string &filedata, const
// cleanup unhandled configurations..
for (std::list<std::string>::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;

View File

@ -646,9 +646,9 @@ private:
preprocessor.preprocess(istr, actual, "file.c");
// Compare results..
ASSERT_EQUALS(1, static_cast<unsigned int>(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<unsigned int>(actual.size()));
TODO_ASSERT_EQUALS("\nA\n\n\n\n", actual["LIBVER=101"]);
}
void if_cond2()