Fixed #1024 (Preprocessor: doesn't expand macro in macro)

This commit is contained in:
Daniel Marjamäki 2009-12-09 19:14:07 +01:00
parent 418d93eafb
commit e2473314b5
2 changed files with 41 additions and 12 deletions

View File

@ -302,21 +302,26 @@ void Tokenizer::createTokens(std::istream &code)
}
// If token contains # characters, split it up
std::string temp;
for (std::string::size_type i = 0; i < CurrentToken.length(); ++i)
if (CurrentToken.find("##") == std::string::npos)
addtoken(CurrentToken.c_str(), lineno, FileIndex);
else
{
if (CurrentToken[i] == '#' && CurrentToken.length() + 1 > i && CurrentToken[i+1] == '#')
std::string temp;
for (std::string::size_type i = 0; i < CurrentToken.length(); ++i)
{
addtoken(temp.c_str(), lineno, FileIndex);
temp.clear();
addtoken("##", lineno, FileIndex);
++i;
if (CurrentToken[i] == '#' && CurrentToken.length() + 1 > i && CurrentToken[i+1] == '#')
{
addtoken(temp.c_str(), lineno, FileIndex);
temp.clear();
addtoken("##", lineno, FileIndex);
++i;
}
else
temp += CurrentToken[i];
}
else
temp += CurrentToken[i];
addtoken(temp.c_str(), lineno, FileIndex);
}
addtoken(temp.c_str(), lineno, FileIndex);
CurrentToken.clear();
if (ch == '\n')
@ -341,8 +346,25 @@ void Tokenizer::createTokens(std::istream &code)
CurrentToken += ch;
}
addtoken(CurrentToken.c_str(), lineno, FileIndex);
if (CurrentToken.find("##") == std::string::npos)
addtoken(CurrentToken.c_str(), lineno, FileIndex);
else
{
std::string temp;
for (std::string::size_type i = 0; i < CurrentToken.length(); ++i)
{
if (CurrentToken[i] == '#' && CurrentToken.length() + 1 > i && CurrentToken[i+1] == '#')
{
addtoken(temp.c_str(), lineno, FileIndex);
temp.clear();
addtoken("##", lineno, FileIndex);
++i;
}
else
temp += CurrentToken[i];
}
addtoken(temp.c_str(), lineno, FileIndex);
}
}
void Tokenizer::simplifyTypedef()

View File

@ -1200,6 +1200,13 @@ private:
// Compare results..
ASSERT_EQUALS("\nfoo_20=20;\n", OurPreprocessor::expandMacros(filedata2));
const char filedata3[] = "#define ABCD 123\n"
"#define A(B) A##B\n"
"A(BCD)\n";
// Compare results..
ASSERT_EQUALS("\n\n123\n", OurPreprocessor::expandMacros(filedata3));
}