preprocessor: insert space. '#if(' => '#if ('

This commit is contained in:
Daniel Marjamäki 2009-01-24 19:28:30 +00:00
parent 04faae2882
commit 5acc6aca31
2 changed files with 862 additions and 836 deletions

View File

@ -55,6 +55,9 @@ std::string Preprocessor::read(std::istream &istr)
// Get filedata from stream..
bool ignoreSpace = true;
// need space.. #if( => #if (
bool needSpace = false;
// For the error report
int lineno = 1;
@ -81,6 +84,16 @@ std::string Preprocessor::read(std::istream &istr)
continue;
ignoreSpace = bool(ch == ' ' || ch == '#' || ch == '/');
if (needSpace)
{
if (ch == '(')
code << " ";
else if (! std::isalpha(ch))
needSpace = false;
}
if (ch == '#')
needSpace = true;
// Remove comments..
if (ch == '/')
{

View File

@ -50,6 +50,7 @@ private:
TEST_CASE(test3);
TEST_CASE(test4);
TEST_CASE(test5);
TEST_CASE(test6);
// Handling include guards (don't create extra configuration for it)
TEST_CASE(includeguard);
@ -274,6 +275,18 @@ private:
ASSERT_EQUALS(3, actual.size());
}
void test6()
{
const char filedata[] = "#if(AAA)\n"
"#if(AAA)\n";
std::istringstream istr(filedata);
const std::string actual(Preprocessor::read(istr));
// Compare results..
ASSERT_EQUALS("#if (AAA)\n#if (AAA)\n", actual);
}
void includeguard()
{