Fixed #10170 (Preprocessor; Fail to extract some configurations)

This commit is contained in:
Daniel Marjamäki 2021-02-06 12:48:52 +01:00
parent b7c4aeca16
commit 7ab70654ba
2 changed files with 25 additions and 1 deletions

View File

@ -459,6 +459,16 @@ static void getConfigs(const simplecpp::TokenList &tokens, std::set<std::string>
std::vector<std::string> configs(configs_if);
configs.push_back(configs_ifndef.back());
ret.erase(cfg(configs, userDefines));
std::set<std::string> temp;
temp.swap(ret);
for (const std::string &c: temp) {
if (c.find(configs_ifndef.back()) != std::string::npos)
ret.insert(c);
else if (c.empty())
ret.insert(configs.empty() ? configs_ifndef.back() : "");
else
ret.insert(c + ";" + configs_ifndef.back());
}
if (!elseError.empty())
elseError += ';';
elseError += cfg(configs_ifndef, userDefines);

View File

@ -81,6 +81,7 @@ private:
TEST_CASE(error5);
TEST_CASE(error6);
TEST_CASE(error7);
TEST_CASE(error8); // #10170 -> previous #if configurations
TEST_CASE(setPlatformInfo);
@ -427,6 +428,19 @@ private:
ASSERT_EQUALS("\nB\n", getConfigsStr(filedata));
}
void error8() {
const char filedata[] = "#ifdef A\n"
"#ifdef B\n"
"#endif\n"
"#else\n"
"#endif\n"
"\n"
"#ifndef C\n"
"#error aa\n"
"#endif";
ASSERT_EQUALS("A;B;C\nA;C\nC\n", getConfigsStr(filedata));
}
void setPlatformInfo() {
Settings settings;
Preprocessor preprocessor(settings, this);
@ -2134,7 +2148,7 @@ private:
"#error \"!Y\"\n"
"#endif\n"
"#endif\n";
ASSERT_EQUALS("\nX\nY\n", getConfigsStr(filedata2));
ASSERT_EQUALS("\nX;Y\nY\n", getConfigsStr(filedata2));
}
void getConfigsD1() {