preprocessor: Make sure that "#define ABC (a+b+c)" is expanded correctly

This commit is contained in:
Daniel Marjamäki 2009-01-18 16:56:12 +00:00
parent 8785483878
commit 965daabe60
2 changed files with 19 additions and 8 deletions

View File

@ -466,18 +466,21 @@ public:
if (tokens() && tokens()->isName())
_name = tokens()->str();
// Extract macro parameters
if (Token::Match(tokens(), "%var% ( %var%"))
std::string::size_type pos = macro.find_first_of(" (");
if ( pos != std::string::npos && macro[pos] == '(' )
{
for (const Token *tok = tokens()->tokAt(2); tok; tok = tok->next())
// Extract macro parameters
if (Token::Match(tokens(), "%var% ( %var%"))
{
if (tok->str() == ")")
break;
if (tok->isName())
_params.push_back(tok->str());
for (const Token *tok = tokens()->tokAt(2); tok; tok = tok->next())
{
if (tok->str() == ")")
break;
if (tok->isName())
_params.push_back(tok->str());
}
}
}
}
const Token *tokens() const

View File

@ -75,6 +75,7 @@ private:
TEST_CASE(macro_simple3);
TEST_CASE(macro_simple4);
TEST_CASE(macro_simple5);
TEST_CASE(macro_simple6);
TEST_CASE(macro_mismatch);
TEST_CASE(preprocessor_inside_string);
TEST_CASE(preprocessor_undef);
@ -486,6 +487,13 @@ private:
ASSERT_EQUALS("\n\nvoid foo()\n{\n int temp = 0;\n if( temp > 0 ) return 1;\n}\n", Preprocessor::expandMacros(filedata));
}
void macro_simple6()
{
const char filedata[] = "#define ABC (a+b+c)\n"
"ABC";
ASSERT_EQUALS("\n(a+b+c)", Preprocessor::expandMacros(filedata));
}
void macro_mismatch()
{
const char filedata[] = "#define AAA(aa,bb) f(aa)\n"