Preprocessor: skip preprocessor directives in the Preprocessor::validateCfg function

This commit is contained in:
Daniel Marjamäki 2012-07-11 21:20:31 +02:00
parent 2bd1f1d8dc
commit 8dd5270be3
2 changed files with 8 additions and 1 deletions

View File

@ -2577,7 +2577,7 @@ bool Preprocessor::validateCfg(const std::string &code, const std::string &cfg)
for (std::set<std::string>::const_iterator it = macros.begin(); it != macros.end(); ++it) {
const std::string &macro = *it;
std::string::size_type pos = 0;
while ((pos = code.find_first_of(std::string("\"'")+macro[0], pos)) != std::string::npos) {
while ((pos = code.find_first_of(std::string("#\"'")+macro[0], pos)) != std::string::npos) {
const std::string::size_type pos1 = pos;
const std::string::size_type pos2 = pos + macro.size();
pos++;
@ -2592,6 +2592,12 @@ bool Preprocessor::validateCfg(const std::string &code, const std::string &cfg)
++pos;
}
// skip preprocessor statement..
else if (code[pos1] == '#') {
if (pos1 == 0 || code[pos1-1] == '\n')
pos = code.find("\n",pos);
}
// is macro used in code?
else if (code.compare(pos1,macro.size(),macro) == 0) {
if (pos1 > 0 && (std::isalnum(code[pos1-1U]) || code[pos1-1U] == '_'))

View File

@ -3546,6 +3546,7 @@ private:
ASSERT_EQUALS(true, preprocessor.validateCfg("\"DEBUG()\"", "DEBUG"));
ASSERT_EQUALS(true, preprocessor.validateCfg("\"\\\"DEBUG()\"", "DEBUG"));
ASSERT_EQUALS(false, preprocessor.validateCfg("\"DEBUG()\" DEBUG", "DEBUG"));
ASSERT_EQUALS(true, preprocessor.validateCfg("#undef DEBUG", "DEBUG"));
}
};