tokenizer: don't replace sizeof when size can't be determined (#233)

This commit is contained in:
Daniel Marjamäki 2009-03-29 16:36:34 +02:00
parent bd66f12e60
commit e45bb20f92
2 changed files with 16 additions and 5 deletions

View File

@ -1010,12 +1010,15 @@ void Tokenizer::simplifyTokenList()
} }
} }
std::ostringstream ostr; if (sz > 0)
ostr << sz; {
tok->str(ostr.str().c_str()); std::ostringstream ostr;
while (tok->next()->str() != ")") ostr << sz;
tok->str(ostr.str().c_str());
while (tok->next()->str() != ")")
tok->deleteNext();
tok->deleteNext(); tok->deleteNext();
tok->deleteNext(); }
} }
} }

View File

@ -75,6 +75,7 @@ private:
TEST_CASE(sizeof4); TEST_CASE(sizeof4);
TEST_CASE(sizeof5); TEST_CASE(sizeof5);
TEST_CASE(sizeof6); TEST_CASE(sizeof6);
TEST_CASE(sizeof7);
TEST_CASE(casting); TEST_CASE(casting);
TEST_CASE(template1); TEST_CASE(template1);
@ -448,6 +449,13 @@ private:
ASSERT_EQUALS(expected.str(), sizeof_(code)); ASSERT_EQUALS(expected.str(), sizeof_(code));
} }
void sizeof7()
{
const char code[] = ";INT32 i[10];\n"
"sizeof(i[0]);\n";
ASSERT_EQUALS(" ; INT32 i [ 10 ] ; sizeof ( i [ 0 ] ) ;", sizeof_(code));
}
void casting() void casting()
{ {
const char code[] = "void f()\n" const char code[] = "void f()\n"