Tokenizer: Bailout simplifyKnownVariables for loop variables

This commit is contained in:
Daniel Marjamäki 2010-11-07 08:10:09 +01:00
parent 662cd27f87
commit 25391cb562
2 changed files with 20 additions and 3 deletions

View File

@ -5773,7 +5773,6 @@ bool Tokenizer::simplifyKnownVariables()
Token *tok2 = tok;
for (; tok2; tok2 = tok2->next())
{
if (tok2->str() == "{")
++indentlevel;
@ -5798,6 +5797,12 @@ bool Tokenizer::simplifyKnownVariables()
if (varid == 0)
continue;
if (Token::Match(tok2->tokAt(-3), "for ( %type% %var% = %num% ;"))
{
// skip loop variable
continue;
}
if (tok2->str() == tok2->strAt(2))
continue;

View File

@ -122,7 +122,8 @@ private:
TEST_CASE(simplifyKnownVariables29); // ticket #1811
TEST_CASE(simplifyKnownVariables30);
TEST_CASE(simplifyKnownVariables31);
TEST_CASE(simplifyKnownVariablesBailOut1);
TEST_CASE(simplifyKnownVariablesBailOutFor);
TEST_CASE(simplifyKnownVariablesBailOutMemberFunction);
TEST_CASE(varid1);
TEST_CASE(varid2);
@ -1855,7 +1856,18 @@ private:
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true));
}
void simplifyKnownVariablesBailOut1()
void simplifyKnownVariablesBailOutFor()
{
const char code[] = "void foo() {\n"
" for (int i = 0; i < 10; ++i) { }\n"
"}\n";
const char expected[] = "void foo ( ) {\n"
"for ( int i = 0 ; i < 10 ; ++ i ) { }\n"
"}";
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true));
}
void simplifyKnownVariablesBailOutMemberFunction()
{
const char code[] = "void foo(obj a) {\n"
" obj b = a;\n"