Preprocessor: Fixed expandMacros problem. Ticket: #2707

This commit is contained in:
Daniel Marjamaki 2011-04-07 16:53:42 +02:00
parent 1752cb62dc
commit fbc8223a6b
2 changed files with 21 additions and 9 deletions

View File

@ -2378,14 +2378,17 @@ public:
}
// expand nopar macro
const std::map<std::string, PreprocessorMacro *>::const_iterator it = macros.find(str);
if (it != macros.end() && it->second->_macro.find("(") == std::string::npos)
if (tok->strAt(-1) != "##")
{
str = it->second->_macro;
if (str.find(" ") != std::string::npos)
str.erase(0, str.find(" "));
else
str = "";
const std::map<std::string, PreprocessorMacro *>::const_iterator it = macros.find(str);
if (it != macros.end() && it->second->_macro.find("(") == std::string::npos)
{
str = it->second->_macro;
if (str.find(" ") != std::string::npos)
str.erase(0, str.find(" "));
else
str = "";
}
}
}
if (_variadic && tok->str() == "," && tok->next() && tok->next()->str() == "##")

View File

@ -159,7 +159,8 @@ private:
TEST_CASE(macro_simple13);
TEST_CASE(macro_simple14);
TEST_CASE(macro_simple15);
TEST_CASE(macroInMacro);
TEST_CASE(macroInMacro1);
TEST_CASE(macroInMacro2);
TEST_CASE(macro_mismatch);
TEST_CASE(macro_linenumbers);
TEST_CASE(macro_nopar);
@ -1692,7 +1693,7 @@ private:
ASSERT_EQUALS("\n\"foo\"\n", OurPreprocessor::expandMacros(filedata));
}
void macroInMacro()
void macroInMacro1()
{
{
const char filedata[] = "#define A(m) long n = m; n++;\n"
@ -1793,6 +1794,14 @@ private:
}
}
void macroInMacro2()
{
const char filedata[] = "#define A(x) a##x\n"
"#define B 0\n"
"A(B)\n";
ASSERT_EQUALS("\n\naB\n", OurPreprocessor::expandMacros(filedata));
}
void macro_mismatch()
{
const char filedata[] = "#define AAA(aa,bb) f(aa)\n"