Fixed #1203 (Preprocessor: Doesn't handle macros usage that contain ';')

This commit is contained in:
Daniel Marjamäki 2010-01-02 20:54:52 +01:00
parent d82079e86f
commit 38b480a4b5
2 changed files with 15 additions and 2 deletions

View File

@ -1624,6 +1624,7 @@ static bool getlines(std::istream &istr, std::string &line)
if (!istr.good())
return false;
line = "";
int parlevel = 0;
for (unsigned char ch = (unsigned char)istr.get(); istr.good(); ch = (unsigned char)istr.get())
{
if (ch == '\'' || ch == '\"')
@ -1649,7 +1650,11 @@ static bool getlines(std::istream &istr, std::string &line)
}
continue;
}
if (ch == '\n')
if (ch == '(')
++parlevel;
else if (ch == ')')
--parlevel;
else if (ch == '\n')
{
if (line.compare(0, 1, "#") == 0)
return true;
@ -1660,7 +1665,7 @@ static bool getlines(std::istream &istr, std::string &line)
return true;
}
}
else if (line.compare(0, 1, "#") != 0 && ch == ';')
else if (line.compare(0, 1, "#") != 0 && parlevel <= 0 && ch == ';')
{
line += ";";
return true;

View File

@ -131,6 +131,7 @@ private:
TEST_CASE(macro_simple10);
TEST_CASE(macro_simple11);
TEST_CASE(macro_simple12);
TEST_CASE(macro_simple13);
TEST_CASE(macroInMacro);
TEST_CASE(macro_mismatch);
TEST_CASE(macro_linenumbers);
@ -1107,6 +1108,13 @@ private:
ASSERT_EQUALS("\nab.AB.CD\n", OurPreprocessor::expandMacros(filedata));
}
void macro_simple13()
{
const char filedata[] = "#define TRACE(x)\n"
"TRACE(;if(a))\n";
ASSERT_EQUALS("\n\n", OurPreprocessor::expandMacros(filedata));
}
void macroInMacro()
{
{