Fixed #1802 (Preprocessor: macros are expanded wrong)
This commit is contained in:
parent
e2ef26cb2e
commit
a6ff3681bb
|
@ -1894,7 +1894,7 @@ public:
|
||||||
* @param macrocode output string
|
* @param macrocode output string
|
||||||
* @return true if the expanding was successful
|
* @return true if the expanding was successful
|
||||||
*/
|
*/
|
||||||
bool code(const std::vector<std::string> ¶ms2, const std::map<std::string, PreprocessorMacro *> macros, std::string ¯ocode) const
|
bool code(const std::vector<std::string> ¶ms2, const std::map<std::string, PreprocessorMacro *> ¯os, std::string ¯ocode) const
|
||||||
{
|
{
|
||||||
if (_nopar || (_params.empty() && _variadic))
|
if (_nopar || (_params.empty() && _variadic))
|
||||||
{
|
{
|
||||||
|
@ -2008,6 +2008,17 @@ public:
|
||||||
break;
|
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() == "##")
|
if (_variadic && tok->str() == "," && tok->next() && tok->next()->str() == "##")
|
||||||
{
|
{
|
||||||
|
|
|
@ -1411,7 +1411,7 @@ private:
|
||||||
const char filedata[] = "#define A 4\n"
|
const char filedata[] = "#define A 4\n"
|
||||||
"#define B(a) a,A\n"
|
"#define B(a) a,A\n"
|
||||||
"B(2);\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"
|
"#define ab(A,B) AB(A,B)\n"
|
||||||
"ab(a,AB(b,c))\n";
|
"ab(a,AB(b,c))\n";
|
||||||
ASSERT_EQUALS("\n\nabc\n", OurPreprocessor::expandMacros(filedata5));
|
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue