Preprocessor: Better 'normal' preprocessing. Simple handling of '#elif'

This commit is contained in:
Daniel Marjamaki 2011-10-24 07:37:47 +02:00
parent 8f0248040c
commit 3de70a7244
2 changed files with 19 additions and 1 deletions

View File

@ -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))) if (indent == indentmatch && match_cfg_def(defs, line.substr(4)))
indentmatch++; indentmatch++;
++indent; ++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) { } else if (line.compare(0,5,"#else") == 0) {
if (indentmatch == indent) if (indentmatch == indent)
indentmatch = indent - 1; indentmatch = indent - 1;

View File

@ -2869,7 +2869,7 @@ private:
ASSERT_EQUALS("\n\n123\n\n" "\n\n\n\n", actual); ASSERT_EQUALS("\n\n123\n\n" "\n\n\n\n", actual);
} }
// define X 123 - #if // #define => #if
{ {
defs.clear(); defs.clear();
const std::string code("#define X 123\n" const std::string code("#define X 123\n"
@ -2879,6 +2879,19 @@ private:
const std::string actual(preprocessor.handleIncludes(code,filePath,includePaths,defs)); const std::string actual(preprocessor.handleIncludes(code,filePath,includePaths,defs));
ASSERT_EQUALS("\n\n456\n\n", actual); 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);
}
} }
}; };