Fixed #1466 (false positive: Invalid number of character ({) when these macros are defined: '')

This commit is contained in:
Daniel Marjamäki 2010-03-04 18:51:25 +01:00
parent d643bbe864
commit 4bb5272760
2 changed files with 36 additions and 1 deletions

View File

@ -97,7 +97,7 @@ std::string Preprocessor::read(std::istream &istr, const std::string &filename,
if (needSpace)
{
if (ch == '(')
if (ch == '(' || ch == '!')
code << " ";
else if (!std::isalpha(ch))
needSpace = false;
@ -943,6 +943,24 @@ void Preprocessor::simplifyCondition(const std::map<std::string, std::string> &v
std::istringstream istr(("(" + condition + ")").c_str());
tokenizer.tokenize(istr, "");
if (Token::Match(tokenizer.tokens(), "( %var% )"))
{
if (variables.find(tokenizer.tokens()->strAt(1)) != variables.end())
condition = "1";
else if (match)
condition = "0";
return;
}
if (Token::Match(tokenizer.tokens(), "( ! %var% )"))
{
if (variables.find(tokenizer.tokens()->strAt(2)) == variables.end())
condition = "1";
else if (match)
condition = "0";
return;
}
// replace variable names with values..
for (Token *tok = const_cast<Token *>(tokenizer.tokens()); tok; tok = tok->next())
{

View File

@ -816,6 +816,23 @@ private:
ASSERT_EQUALS("\n\n\n", actual[""]);
ASSERT_EQUALS("\nfoo();\n\n", actual["A"]);
}
{
const char filedata[] = "#if! A\n"
"foo();\n"
"#endif\n";
// Preprocess => actual result..
std::istringstream istr(filedata);
std::map<std::string, std::string> actual;
Preprocessor preprocessor;
preprocessor.preprocess(istr, actual, "file.c");
// Compare results..
ASSERT_EQUALS(1, static_cast<unsigned int>(actual.size()));
TODO_ASSERT_EQUALS(2, static_cast<unsigned int>(actual.size()));
ASSERT_EQUALS("\nfoo();\n\n", actual[""]);
}
}
void if_cond5()