Fixed #507 (Preprocessor: Incorrect expanding of inner macros)
This commit is contained in:
parent
acc38a8bbf
commit
724d6bf53a
|
@ -1356,12 +1356,12 @@ public:
|
||||||
std::string Preprocessor::expandMacros(std::string code, const std::string &filename, ErrorLogger *errorLogger)
|
std::string Preprocessor::expandMacros(std::string code, const std::string &filename, ErrorLogger *errorLogger)
|
||||||
{
|
{
|
||||||
// Search for macros and expand them..
|
// Search for macros and expand them..
|
||||||
std::string::size_type defpos = 0;
|
std::string::size_type defpos = std::string::npos;
|
||||||
while ((defpos = code.find("#define ", defpos)) != std::string::npos)
|
while ((defpos > 0) && ((defpos = code.rfind("#define ", defpos)) != std::string::npos))
|
||||||
{
|
{
|
||||||
if (defpos > 0 && code[defpos-1] != '\n')
|
if (defpos > 0 && code[defpos-1] != '\n')
|
||||||
{
|
{
|
||||||
defpos += 6;
|
defpos--;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -114,6 +114,7 @@ private:
|
||||||
TEST_CASE(macro_simple8);
|
TEST_CASE(macro_simple8);
|
||||||
TEST_CASE(macro_simple9);
|
TEST_CASE(macro_simple9);
|
||||||
TEST_CASE(macro_simple10);
|
TEST_CASE(macro_simple10);
|
||||||
|
TEST_CASE(macroInMacro);
|
||||||
TEST_CASE(macro_mismatch);
|
TEST_CASE(macro_mismatch);
|
||||||
TEST_CASE(macro_linenumbers);
|
TEST_CASE(macro_linenumbers);
|
||||||
TEST_CASE(macro_nopar);
|
TEST_CASE(macro_nopar);
|
||||||
|
@ -840,6 +841,14 @@ private:
|
||||||
ASSERT_EQUALS("\nunsigned long x;", OurPreprocessor::expandMacros(filedata));
|
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()
|
void macro_mismatch()
|
||||||
{
|
{
|
||||||
const char filedata[] = "#define AAA(aa,bb) f(aa)\n"
|
const char filedata[] = "#define AAA(aa,bb) f(aa)\n"
|
||||||
|
|
Loading…
Reference in New Issue