preprocessor: stringify macros

This commit is contained in:
Daniel Marjamäki 2009-01-25 13:30:15 +00:00
parent ed2758b082
commit 9c51729be6
2 changed files with 24 additions and 2 deletions

View File

@ -637,12 +637,21 @@ public:
std::string str = tok->str();
if (str == "##")
continue;
if (tok->isName())
if (str[0] == '#' || tok->isName())
{
bool stringify = false;
if (str[0] == '#')
{
str = str.erase(0, 1);
stringify = true;
}
for (unsigned int i = 0; i < _params.size(); ++i)
{
if (str == _params[i])
{
if (stringify)
str = "\"" + params2[i] + "\"";
else
str = params2[i];
break;
}

View File

@ -91,6 +91,8 @@ private:
// TODO TEST_CASE(fmt);
TEST_CASE(multi_character_character);
// TODO TEST_CASE(preprocessor_and_operation);
TEST_CASE(stringify);
}
@ -682,6 +684,17 @@ private:
}
void stringify()
{
const char filedata[] = "#define STRINGIFY(x) #x\n"
"STRINGIFY(abc)";
// expand macros..
std::string actual = Preprocessor::expandMacros(filedata);
ASSERT_EQUALS("\n\"abc\"", actual);
}
};
REGISTER_TEST(TestPreprocessor)