Fixed #1802 (Preprocessor: macros are expanded wrong)

This commit is contained in:
Daniel Marjamäki 2010-09-18 22:20:01 +02:00
parent e2ef26cb2e
commit a6ff3681bb
2 changed files with 21 additions and 2 deletions

View File

@ -1894,7 +1894,7 @@ public:
* @param macrocode output string
* @return true if the expanding was successful
*/
bool code(const std::vector<std::string> &params2, const std::map<std::string, PreprocessorMacro *> macros, std::string &macrocode) const
bool code(const std::vector<std::string> &params2, const std::map<std::string, PreprocessorMacro *> &macros, std::string &macrocode) const
{
if (_nopar || (_params.empty() && _variadic))
{
@ -2008,6 +2008,17 @@ public:
break;
}
}
// 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)
{
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

@ -1411,7 +1411,7 @@ private:
const char filedata[] = "#define A 4\n"
"#define B(a) a,A\n"
"B(2);\n";
ASSERT_EQUALS("\n\n2,4;\n", OurPreprocessor::expandMacros(filedata));
ASSERT_EQUALS("\n\n2, 4;\n", OurPreprocessor::expandMacros(filedata));
}
{
@ -1642,6 +1642,14 @@ private:
"#define ab(A,B) AB(A,B)\n"
"ab(a,AB(b,c))\n";
ASSERT_EQUALS("\n\nabc\n", OurPreprocessor::expandMacros(filedata5));
// Ticket #1802
const char filedata6[] = "#define AB_(A,B) A ## B\n"
"#define AB(A,B) AB_(A,B)\n"
"#define ab(suf) AB(X, AB_(_, suf))\n"
"#define X x\n"
"ab(y)\n";
ASSERT_EQUALS("\n\n\n\nx_y\n", OurPreprocessor::expandMacros(filedata6));
}