More Fixing of #635 (Preprocessor: remove 'asm(...)')

This commit is contained in:
Daniel Marjamäki 2009-09-11 23:34:24 +02:00
parent ed1c9bed49
commit 37dae83e06
2 changed files with 46 additions and 26 deletions

View File

@ -433,37 +433,57 @@ std::string Preprocessor::removeComments(const std::string &str)
return code.str();
}
static void _removeAsm(std::string &str, const std::string::size_type pos)
{
unsigned int newlines = 0;
bool instr = false;
int parlevel = 0;
std::string::size_type pos2 = pos + 1;
while (pos2 < str.length())
{
if (str[pos2] == '\"')
instr = !instr;
else if (str[pos2] == '\n')
++newlines;
else if (!instr)
{
if (str[pos2] == '(')
++parlevel;
else if (str[pos2] == ')')
{
if (parlevel <= 1)
break;
--parlevel;
}
}
++pos2;
}
str.erase(pos + 1, pos2 - pos);
str.insert(pos, std::string(newlines, '\n'));
}
void Preprocessor::removeAsm(std::string &str)
{
std::string::size_type pos = 0;
while ((pos = str.find("\nasm(", pos)) != std::string::npos)
{
unsigned int newlines = 0;
std::string::size_type pos2 = pos + 5;
while (pos2 < str.length() && str[pos2] != ')')
{
if (str[pos2] == '\n')
++newlines;
++pos2;
}
str.erase(pos + 1, pos2 - pos);
str.insert(pos, std::string(newlines, '\n'));
}
_removeAsm(str, pos);
pos = 0;
while ((pos = str.find("\nasm (", pos)) != std::string::npos)
_removeAsm(str, pos);
pos = 0;
while ((pos = str.find("\nasm __volatile(", pos)) != std::string::npos)
{
unsigned int newlines = 0;
std::string::size_type pos2 = pos + 5;
while (pos2 < str.length() && str[pos2] != ')')
{
if (str[pos2] == '\n')
++newlines;
++pos2;
}
str.erase(pos + 1, pos2 - pos);
str.insert(pos, std::string(newlines, '\n'));
}
_removeAsm(str, pos);
pos = 0;
while ((pos = str.find("\nasm __volatile (", pos)) != std::string::npos)
_removeAsm(str, pos);
}

View File

@ -770,9 +770,9 @@ private:
Preprocessor::removeAsm(str1);
ASSERT_EQUALS("\n\n\n\n;", str1);
std::string str2("\nasm __volatile(\n\n\n);");
std::string str2("\nasm __volatile(\"\nlw iScale, 0x00(pScale)\n\", ());");
Preprocessor::removeAsm(str2);
ASSERT_EQUALS("\n\n\n\n;", str2);
ASSERT_EQUALS("\n\n\n;", str2);
}
void if_defined()