Fix ticket #100 (Simplify constants simplifies leaks out from variable scope and simplifies whole file)
This commit is contained in:
parent
4f121daca4
commit
5d3574bb03
|
@ -597,10 +597,20 @@ void Tokenizer::simplifyTokenList()
|
||||||
{
|
{
|
||||||
const char *sym = tok->strAt(2);
|
const char *sym = tok->strAt(2);
|
||||||
const char *num = tok->strAt(4);
|
const char *num = tok->strAt(4);
|
||||||
|
int indent = 1;
|
||||||
for (Token *tok2 = tok->tokAt(6); tok2; tok2 = tok2->next())
|
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);
|
tok2->str(num);
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,7 +110,7 @@ private:
|
||||||
TEST_CASE(simplify_numeric_condition);
|
TEST_CASE(simplify_numeric_condition);
|
||||||
TEST_CASE(tokenize_double);
|
TEST_CASE(tokenize_double);
|
||||||
TEST_CASE(tokenize_strings);
|
TEST_CASE(tokenize_strings);
|
||||||
// TODO TEST_CASE(simplify_constants);
|
TEST_CASE(simplify_constants);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1044,6 +1044,8 @@ private:
|
||||||
"void f()\n"
|
"void f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
"const int a = 45;\n"
|
"const int a = 45;\n"
|
||||||
|
"if( a )\n"
|
||||||
|
"{ int b = a; }\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"void g()\n"
|
"void g()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -1061,7 +1063,7 @@ private:
|
||||||
std::ostringstream ostr;
|
std::ostringstream ostr;
|
||||||
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
|
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
|
||||||
ostr << " " << tok->str();
|
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());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue