Fixed #507 (Preprocessor: Incorrect expanding of inner macros)

This commit is contained in:
Daniel Marjamäki 2009-08-22 13:03:52 +02:00
parent acc38a8bbf
commit 724d6bf53a
2 changed files with 12 additions and 3 deletions

View File

@ -1356,12 +1356,12 @@ public:
std::string Preprocessor::expandMacros(std::string code, const std::string &filename, ErrorLogger *errorLogger)
{
// Search for macros and expand them..
std::string::size_type defpos = 0;
while ((defpos = code.find("#define ", defpos)) != std::string::npos)
std::string::size_type defpos = std::string::npos;
while ((defpos > 0) && ((defpos = code.rfind("#define ", defpos)) != std::string::npos))
{
if (defpos > 0 && code[defpos-1] != '\n')
{
defpos += 6;
defpos--;
continue;
}

View File

@ -114,6 +114,7 @@ private:
TEST_CASE(macro_simple8);
TEST_CASE(macro_simple9);
TEST_CASE(macro_simple10);
TEST_CASE(macroInMacro);
TEST_CASE(macro_mismatch);
TEST_CASE(macro_linenumbers);
TEST_CASE(macro_nopar);
@ -840,6 +841,14 @@ private:
ASSERT_EQUALS("\nunsigned long x;", OurPreprocessor::expandMacros(filedata));
}
void macroInMacro()
{
const char filedata[] = "#define A(m) long n = m; n++;\n"
"#define B(n) A(n)\n"
"B(0)";
ASSERT_EQUALS("\n\nlong n=0;n++;", OurPreprocessor::expandMacros(filedata));
}
void macro_mismatch()
{
const char filedata[] = "#define AAA(aa,bb) f(aa)\n"