Preprocessor: initial variadic macro support; passing now on fmt1 case.

This commit is contained in:
Leandro Penz 2009-02-13 13:31:40 +00:00
parent 8485e95341
commit d511863b57
2 changed files with 26 additions and 2 deletions

View File

@ -563,6 +563,7 @@ private:
std::vector<std::string> _params;
std::string _name;
std::string _macro;
bool _variadic;
public:
Macro(const std::string &macro)
@ -576,6 +577,8 @@ public:
if (tokens() && tokens()->isName())
_name = tokens()->str();
_variadic = false;
std::string::size_type pos = macro.find_first_of(" (");
if (pos != std::string::npos && macro[pos] == '(')
{
@ -586,6 +589,11 @@ public:
{
if (tok->str() == ")")
break;
if (Token::Match(tok, ". . . )"))
{
_variadic = true;
break;
}
if (tok->isName())
_params.push_back(tok->str());
}
@ -603,6 +611,11 @@ public:
return _params;
}
bool variadic() const
{
return _variadic;
}
const std::string &name() const
{
return _name;
@ -649,6 +662,17 @@ public:
{
if (str == _params[i])
{
if (_variadic && i == _params.size() - 1)
{
str = "";
for (unsigned int j = _params.size() - 1; j < params2.size(); ++j)
{
if (j > _params.size() - 1)
str += ",";
str += params2[j];
}
break;
}
if (stringify)
str = "\"" + params2[i] + "\"";
else
@ -828,7 +852,7 @@ std::string Preprocessor::expandMacros(std::string code)
}
// Same number of parameters..
if (params.size() != macro.params().size())
if (!macro.variadic() && params.size() != macro.params().size())
continue;
// Create macro code..

View File

@ -101,7 +101,7 @@ private:
TEST_CASE(defdef); // Defined multiple times
TEST_CASE(preprocessor_doublesharp);
TEST_CASE(preprocessor_include_in_str);
// TODO TEST_CASE(fmt1);
TEST_CASE(fmt1);
// TODO TEST_CASE(fmt2);
TEST_CASE(multi_character_character);