Fixed #2563 (#if equality testing does not ignore parentheses)

This commit is contained in:
Daniel Marjamäki 2011-02-20 20:57:28 +01:00
parent f6e6fa685e
commit c3fba356c0
2 changed files with 28 additions and 9 deletions

View File

@ -1330,7 +1330,33 @@ void Preprocessor::simplifyCondition(const std::map<std::string, std::string> &v
if (it != variables.end()) if (it != variables.end())
{ {
if (!it->second.empty()) 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<Token *> 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) == "(") && 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->next() || tok->strAt(1) == "||" || tok->strAt(1) == "&&" || tok->strAt(1) == ")"))
tok->str("1"); tok->str("1");

View File

@ -1343,18 +1343,11 @@ private:
void if_cond12() void if_cond12()
{ {
errout.str("");
const char filedata[] = "#define A (1)\n" const char filedata[] = "#define A (1)\n"
"#if A == 1\n" "#if A == 1\n"
";\n" ";\n"
"#endif\n"; "#endif\n";
std::istringstream istr(filedata); ASSERT_EQUALS("\n\n;\n\n", Preprocessor::getcode(filedata,"","",NULL,NULL));
std::map<std::string, std::string> 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[""]);
} }