preprocessor: fixed a small bug when expanding macro without parameter
This commit is contained in:
parent
da881fdd0a
commit
ea6c48b2bd
@ -493,7 +493,7 @@ std::string Preprocessor::expandMacros(std::string code)
|
|||||||
|
|
||||||
std::vector<std::string> params;
|
std::vector<std::string> params;
|
||||||
std::string::size_type pos2 = pos1 + macroname.length();
|
std::string::size_type pos2 = pos1 + macroname.length();
|
||||||
if (pos2 >= macro.length())
|
if (macroparams.size() && pos2 >= code.length())
|
||||||
continue;
|
continue;
|
||||||
if (macroparams.size())
|
if (macroparams.size())
|
||||||
{
|
{
|
||||||
|
@ -72,6 +72,7 @@ private:
|
|||||||
TEST_CASE(macro_simple2);
|
TEST_CASE(macro_simple2);
|
||||||
TEST_CASE(macro_simple3);
|
TEST_CASE(macro_simple3);
|
||||||
TEST_CASE(macro_simple4);
|
TEST_CASE(macro_simple4);
|
||||||
|
TEST_CASE(macro_simple5);
|
||||||
TEST_CASE(macro_mismatch);
|
TEST_CASE(macro_mismatch);
|
||||||
TEST_CASE(preprocessor_inside_string);
|
TEST_CASE(preprocessor_inside_string);
|
||||||
}
|
}
|
||||||
@ -458,6 +459,18 @@ private:
|
|||||||
ASSERT_EQUALS("\nif( temp > 0 ) return 1;\n", Preprocessor::expandMacros(filedata));
|
ASSERT_EQUALS("\nif( temp > 0 ) return 1;\n", Preprocessor::expandMacros(filedata));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void macro_simple5()
|
||||||
|
{
|
||||||
|
const char filedata[] = "#define ABC if( temp > 0 ) return 1;\n"
|
||||||
|
"\n"
|
||||||
|
"void foo()\n"
|
||||||
|
"{\n"
|
||||||
|
" int temp = 0;\n"
|
||||||
|
" ABC\n"
|
||||||
|
"}\n";
|
||||||
|
ASSERT_EQUALS("\n\nvoid foo()\n{\n int temp = 0;\n if( temp > 0 ) return 1;\n}\n", Preprocessor::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…
x
Reference in New Issue
Block a user