Fixed #1024 (Preprocessor: doesn't expand macro in macro)
This commit is contained in:
parent
418d93eafb
commit
e2473314b5
|
@ -302,6 +302,10 @@ void Tokenizer::createTokens(std::istream &code)
|
|||
}
|
||||
|
||||
// If token contains # characters, split it up
|
||||
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)
|
||||
{
|
||||
|
@ -315,8 +319,9 @@ void Tokenizer::createTokens(std::istream &code)
|
|||
else
|
||||
temp += CurrentToken[i];
|
||||
}
|
||||
|
||||
addtoken(temp.c_str(), lineno, FileIndex);
|
||||
}
|
||||
|
||||
CurrentToken.clear();
|
||||
|
||||
if (ch == '\n')
|
||||
|
@ -341,8 +346,25 @@ void Tokenizer::createTokens(std::istream &code)
|
|||
|
||||
CurrentToken += ch;
|
||||
}
|
||||
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()
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue