Fix ticket #100 (Simplify constants simplifies leaks out from variable scope and simplifies whole file)

This commit is contained in:
Reijo Tomperi 2009-02-12 19:26:42 +00:00
parent 4f121daca4
commit 5d3574bb03
2 changed files with 16 additions and 4 deletions

View File

@ -597,10 +597,20 @@ void Tokenizer::simplifyTokenList()
{
const char *sym = tok->strAt(2);
const char *num = tok->strAt(4);
int indent = 1;
for (Token *tok2 = tok->tokAt(6); tok2; tok2 = tok2->next())
{
if (tok2->str() == sym)
if (tok2->str() == "{")
{
++indent;
}
else if (tok2->str() == "}")
{
--indent;
if (indent == 0)
break;
}
else if (tok2->str() == sym)
{
tok2->str(num);
}

View File

@ -110,7 +110,7 @@ private:
TEST_CASE(simplify_numeric_condition);
TEST_CASE(tokenize_double);
TEST_CASE(tokenize_strings);
// TODO TEST_CASE(simplify_constants);
TEST_CASE(simplify_constants);
}
@ -1044,6 +1044,8 @@ private:
"void f()\n"
"{\n"
"const int a = 45;\n"
"if( a )\n"
"{ int b = a; }\n"
"}\n"
"void g()\n"
"{\n"
@ -1061,7 +1063,7 @@ private:
std::ostringstream ostr;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str();
ASSERT_EQUALS(std::string(" void f ( ) { const int a = 45 ; } void g ( ) { int a ; a = 2 ; }"), ostr.str());
ASSERT_EQUALS(std::string(" void f ( ) { const int a = 45 ; { int b ; b = 45 ; } } void g ( ) { int a ; a = 2 ; }"), ostr.str());
}
};