Preprocessor: skip preprocessor directives in the Preprocessor::validateCfg function
This commit is contained in:
parent
2bd1f1d8dc
commit
8dd5270be3
|
@ -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) {
|
for (std::set<std::string>::const_iterator it = macros.begin(); it != macros.end(); ++it) {
|
||||||
const std::string ¯o = *it;
|
const std::string ¯o = *it;
|
||||||
std::string::size_type pos = 0;
|
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 pos1 = pos;
|
||||||
const std::string::size_type pos2 = pos + macro.size();
|
const std::string::size_type pos2 = pos + macro.size();
|
||||||
pos++;
|
pos++;
|
||||||
|
@ -2592,6 +2592,12 @@ bool Preprocessor::validateCfg(const std::string &code, const std::string &cfg)
|
||||||
++pos;
|
++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?
|
// is macro used in code?
|
||||||
else if (code.compare(pos1,macro.size(),macro) == 0) {
|
else if (code.compare(pos1,macro.size(),macro) == 0) {
|
||||||
if (pos1 > 0 && (std::isalnum(code[pos1-1U]) || code[pos1-1U] == '_'))
|
if (pos1 > 0 && (std::isalnum(code[pos1-1U]) || code[pos1-1U] == '_'))
|
||||||
|
|
|
@ -3546,6 +3546,7 @@ private:
|
||||||
ASSERT_EQUALS(true, preprocessor.validateCfg("\"DEBUG()\"", "DEBUG"));
|
ASSERT_EQUALS(true, preprocessor.validateCfg("\"DEBUG()\"", "DEBUG"));
|
||||||
ASSERT_EQUALS(true, preprocessor.validateCfg("\"\\\"DEBUG()\"", "DEBUG"));
|
ASSERT_EQUALS(true, preprocessor.validateCfg("\"\\\"DEBUG()\"", "DEBUG"));
|
||||||
ASSERT_EQUALS(false, preprocessor.validateCfg("\"DEBUG()\" DEBUG", "DEBUG"));
|
ASSERT_EQUALS(false, preprocessor.validateCfg("\"DEBUG()\" DEBUG", "DEBUG"));
|
||||||
|
ASSERT_EQUALS(true, preprocessor.validateCfg("#undef DEBUG", "DEBUG"));
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue