Preprocessor: fix handling of -U in Preprocessor::getConfigs()
This commit is contained in:
parent
ff036c8742
commit
d9ebdc6a10
|
@ -156,7 +156,7 @@ static bool sameline(const simplecpp::Token *tok1, const simplecpp::Token *tok2)
|
||||||
return tok1 && tok2 && tok1->location.sameline(tok2->location);
|
return tok1 && tok2 && tok1->location.sameline(tok2->location);
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string readcondition(const simplecpp::Token *iftok, const std::set<std::string> &defined)
|
static std::string readcondition(const simplecpp::Token *iftok, const std::set<std::string> &defined, const std::set<std::string> &undefined)
|
||||||
{
|
{
|
||||||
const simplecpp::Token *cond = iftok->next;
|
const simplecpp::Token *cond = iftok->next;
|
||||||
if (!sameline(iftok,cond))
|
if (!sameline(iftok,cond))
|
||||||
|
@ -183,7 +183,7 @@ static std::string readcondition(const simplecpp::Token *iftok, const std::set<s
|
||||||
}
|
}
|
||||||
|
|
||||||
if (len == 3 && cond->op == '(' && next1->name && next2->op == ')') {
|
if (len == 3 && cond->op == '(' && next1->name && next2->op == ')') {
|
||||||
if (defined.find(next1->str) == defined.end())
|
if (defined.find(next1->str) == defined.end() && undefined.find(next1->str) == undefined.end())
|
||||||
return next1->str;
|
return next1->str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,7 +203,7 @@ static std::string readcondition(const simplecpp::Token *iftok, const std::set<s
|
||||||
break;
|
break;
|
||||||
if (dtok->op == '(')
|
if (dtok->op == '(')
|
||||||
dtok = dtok->next;
|
dtok = dtok->next;
|
||||||
if (sameline(iftok,dtok) && dtok->name && defined.find(dtok->str) == defined.end())
|
if (sameline(iftok,dtok) && dtok->name && defined.find(dtok->str) == defined.end() && undefined.find(dtok->str) == undefined.end())
|
||||||
configset.insert(dtok->str);
|
configset.insert(dtok->str);
|
||||||
}
|
}
|
||||||
std::string cfg;
|
std::string cfg;
|
||||||
|
@ -311,7 +311,7 @@ static void getConfigs(const simplecpp::TokenList &tokens, std::set<std::string>
|
||||||
if (defined.find(config) != defined.end())
|
if (defined.find(config) != defined.end())
|
||||||
config.clear();
|
config.clear();
|
||||||
} else if (cmdtok->str == "if") {
|
} else if (cmdtok->str == "if") {
|
||||||
config = readcondition(cmdtok, defined);
|
config = readcondition(cmdtok, defined, undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// skip undefined configurations..
|
// skip undefined configurations..
|
||||||
|
@ -332,7 +332,7 @@ static void getConfigs(const simplecpp::TokenList &tokens, std::set<std::string>
|
||||||
if (!configs_if.empty())
|
if (!configs_if.empty())
|
||||||
configs_if.pop_back();
|
configs_if.pop_back();
|
||||||
if (cmdtok->str == "elif") {
|
if (cmdtok->str == "elif") {
|
||||||
std::string config = readcondition(cmdtok, defined);
|
std::string config = readcondition(cmdtok, defined, undefined);
|
||||||
if (isUndefined(config,undefined))
|
if (isUndefined(config,undefined))
|
||||||
config.clear();
|
config.clear();
|
||||||
configs_if.push_back(config);
|
configs_if.push_back(config);
|
||||||
|
|
|
@ -2103,7 +2103,7 @@ private:
|
||||||
const char filedata[] = "#if defined(X) || defined(Y) || defined(Z)\n"
|
const char filedata[] = "#if defined(X) || defined(Y) || defined(Z)\n"
|
||||||
"#else\n"
|
"#else\n"
|
||||||
"#endif\n";
|
"#endif\n";
|
||||||
ASSERT_EQUALS("\n", getConfigsStr(filedata, "-UX"));
|
ASSERT_EQUALS("\nY;Z\n", getConfigsStr(filedata, "-UX"));
|
||||||
ASSERT_EQUALS("\nX;Y;Z\n", getConfigsStr(filedata));
|
ASSERT_EQUALS("\nX;Y;Z\n", getConfigsStr(filedata));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue