Preprocessor: Let the Tokenizer handle NULL

This commit is contained in:
Daniel Marjamäki 2013-01-13 15:01:31 +01:00
parent dc0ecb1082
commit f0ce26a2aa
2 changed files with 7 additions and 1 deletions

View File

@ -2765,7 +2765,7 @@ std::string Preprocessor::expandMacros(const std::string &code, std::string file
// defining a macro..
if (line.compare(0, 8, "#define ") == 0) {
PreprocessorMacro *macro = new PreprocessorMacro(line.substr(8));
if (macro->name().empty()) {
if (macro->name().empty() || macro->name() == "NULL") {
delete macro;
} else if (macro->name() == "BOOST_FOREACH") {
// BOOST_FOREACH is currently too complex to parse, so skip it.

View File

@ -182,6 +182,7 @@ private:
TEST_CASE(macro_linenumbers);
TEST_CASE(macro_nopar);
TEST_CASE(macro_switchCase);
TEST_CASE(macro_NULL); // skip #define NULL .. it is replaced in the tokenizer
TEST_CASE(string1);
TEST_CASE(string2);
TEST_CASE(string3);
@ -2084,6 +2085,11 @@ private:
}
}
void macro_NULL() {
ASSERT_EQUALS("\n$0", OurPreprocessor::expandMacros("#define null 0\nnull"));
ASSERT_EQUALS("\nNULL", OurPreprocessor::expandMacros("#define NULL 0\nNULL"));
}
void string1() {
const char filedata[] = "int main()"
"{"