Preprocessor::getConfigs: Remove bad configurations when #error is seen

This commit is contained in:
Daniel Marjamäki 2017-04-02 12:15:53 +02:00
parent 7eb95aac2a
commit d403a6a883
2 changed files with 8 additions and 3 deletions

View File

@ -371,6 +371,8 @@ static void getConfigs(const simplecpp::TokenList &tokens, std::set<std::string>
configs_ifndef.pop_back(); configs_ifndef.pop_back();
} else if (cmdtok->str == "error") { } else if (cmdtok->str == "error") {
if (!configs_ifndef.empty() && !configs_ifndef.back().empty()) { if (!configs_ifndef.empty() && !configs_ifndef.back().empty()) {
if (configs_ifndef.size() == 1U)
ret.erase("");
std::vector<std::string> configs(configs_if); std::vector<std::string> configs(configs_if);
configs.push_back(configs_ifndef.back()); configs.push_back(configs_ifndef.back());
ret.insert(cfg(configs, userDefines)); ret.insert(cfg(configs, userDefines));
@ -379,8 +381,11 @@ static void getConfigs(const simplecpp::TokenList &tokens, std::set<std::string>
const std::string &last = configs_if.back(); const std::string &last = configs_if.back();
if (last.size() > 2U && last.compare(last.size()-2U,2,"=0") == 0) { if (last.size() > 2U && last.compare(last.size()-2U,2,"=0") == 0) {
std::vector<std::string> configs(configs_if); std::vector<std::string> configs(configs_if);
ret.erase(cfg(configs, userDefines));
configs[configs.size() - 1U] = last.substr(0,last.size()-2U); configs[configs.size() - 1U] = last.substr(0,last.size()-2U);
ret.insert(cfg(configs, userDefines)); ret.insert(cfg(configs, userDefines));
if (configs.size() == 1U)
ret.erase("");
} }
} }
} else if (cmdtok->str == "define" && sameline(tok, cmdtok->next) && cmdtok->next->name) { } else if (cmdtok->str == "define" && sameline(tok, cmdtok->next) && cmdtok->next->name) {

View File

@ -324,12 +324,12 @@ private:
const char filedata1[] = "#ifndef A\n" const char filedata1[] = "#ifndef A\n"
"#error\n" "#error\n"
"#endif\n"; "#endif\n";
TODO_ASSERT_EQUALS("A\n", "\nA\n", getConfigsStr(filedata1)); ASSERT_EQUALS("A\n", getConfigsStr(filedata1));
const char filedata2[] = "#if !A\n" const char filedata2[] = "#if !A\n"
"#error\n" "#error\n"
"#endif\n"; "#endif\n";
TODO_ASSERT_EQUALS("A\n", "\nA\nA=0\n", getConfigsStr(filedata2)); ASSERT_EQUALS("A\n", getConfigsStr(filedata2));
} }
void error3() { void error3() {
@ -2098,7 +2098,7 @@ private:
const char filedata1[] = "#ifndef X\n" const char filedata1[] = "#ifndef X\n"
"#error \"!X\"\n" "#error \"!X\"\n"
"#endif\n"; "#endif\n";
ASSERT_EQUALS("\nX\n", getConfigsStr(filedata1)); ASSERT_EQUALS("X\n", getConfigsStr(filedata1));
const char filedata2[] = "#ifdef X\n" const char filedata2[] = "#ifdef X\n"
"#ifndef Y\n" "#ifndef Y\n"