Preprocessor::getConfigs: Better handling of ! in #if

This commit is contained in:
Daniel Marjamäki 2017-04-02 09:03:43 +02:00
parent b7dcdc00d0
commit edd1c32e5b
2 changed files with 11 additions and 5 deletions

View File

@ -196,8 +196,14 @@ static std::string readcondition(const simplecpp::Token *iftok, const std::set<s
std::set<std::string> configset;
for (; sameline(iftok,cond); cond = cond->next) {
if (cond->op == '!')
if (cond->op == '!') {
if (!sameline(iftok,cond->next) || !cond->next->name)
break;
if (cond->next->str == "defined")
continue;
configset.insert(cond->next->str + "=0");
continue;
}
if (cond->str != "defined")
continue;
const simplecpp::Token *dtok = cond->next;

View File

@ -558,7 +558,7 @@ private:
"#elif !defined(B)\n"
"!b\n"
"#endif\n";
TODO_ASSERT_EQUALS("\nA\nA;B", "\n", getConfigsStr(filedata));
ASSERT_EQUALS("\nA\nB\n", getConfigsStr(filedata));
}
void if_cond3() {
@ -612,7 +612,7 @@ private:
const char filedata[] = "#if! A\n"
"foo();\n"
"#endif\n";
ASSERT_EQUALS("\n", getConfigsStr(filedata));
ASSERT_EQUALS("\nA=0\n", getConfigsStr(filedata));
}
}
@ -645,7 +645,7 @@ private:
const char filedata[] = "#if !defined _A\n"
"abc\n"
"#endif\n";
ASSERT_EQUALS("\n", getConfigsStr(filedata));
ASSERT_EQUALS("\n_A\n", getConfigsStr(filedata));
}
void if_cond10() {