Preprocessor: Better 'normal' preprocessing. Simple handling of '#elif'
This commit is contained in:
parent
8f0248040c
commit
3de70a7244
|
@ -1746,6 +1746,11 @@ std::string Preprocessor::handleIncludes(const std::string &code, const std::str
|
|||
if (indent == indentmatch && match_cfg_def(defs, line.substr(4)))
|
||||
indentmatch++;
|
||||
++indent;
|
||||
} else if (line.compare(0,6,"#elif ") == 0) {
|
||||
if (indentmatch == indent)
|
||||
indentmatch = indent - 1; // TODO: Make sure all remaining #elif and #else are skipped
|
||||
else if (indentmatch == indent - 1 && match_cfg_def(defs, line.substr(6)))
|
||||
indentmatch = indent;
|
||||
} else if (line.compare(0,5,"#else") == 0) {
|
||||
if (indentmatch == indent)
|
||||
indentmatch = indent - 1;
|
||||
|
|
|
@ -2869,7 +2869,7 @@ private:
|
|||
ASSERT_EQUALS("\n\n123\n\n" "\n\n\n\n", actual);
|
||||
}
|
||||
|
||||
// define X 123 - #if
|
||||
// #define => #if
|
||||
{
|
||||
defs.clear();
|
||||
const std::string code("#define X 123\n"
|
||||
|
@ -2879,6 +2879,19 @@ private:
|
|||
const std::string actual(preprocessor.handleIncludes(code,filePath,includePaths,defs));
|
||||
ASSERT_EQUALS("\n\n456\n\n", actual);
|
||||
}
|
||||
|
||||
// #elif
|
||||
{
|
||||
defs.clear();
|
||||
defs["B"] = "";
|
||||
const std::string code("#if defined(A)\n"
|
||||
"123\n"
|
||||
"#elif defined(B)\n"
|
||||
"456\n"
|
||||
"#endif");
|
||||
const std::string actual(preprocessor.handleIncludes(code,filePath,includePaths,defs));
|
||||
ASSERT_EQUALS("\n\n\n456\n\n", actual);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue