Tokenizer: better bailout in simplifyKnownVariables when there is loop

This commit is contained in:
Daniel Marjamäki 2010-11-07 10:42:08 +01:00
parent fb068a4e71
commit b881718d9f
2 changed files with 19 additions and 3 deletions

View File

@ -5961,9 +5961,11 @@ bool Tokenizer::simplifyKnownVariables()
break;
// Stop if something like 'while (--var)' is found
if (tok3->str() == "while" || tok3->str() == "do")
if (tok3->str() == "for" || tok3->str() == "while" || tok3->str() == "do")
{
const Token *endpar = tok3->next()->link();
if (Token::simpleMatch(endpar, ") {"))
endpar = endpar->next()->link();
bool bailout = false;
for (const Token *tok4 = tok3; tok4 && tok4 != endpar; tok4 = tok4->next())
{

View File

@ -123,7 +123,8 @@ private:
TEST_CASE(simplifyKnownVariables30);
TEST_CASE(simplifyKnownVariables31);
TEST_CASE(simplifyKnownVariables32); // const
TEST_CASE(simplifyKnownVariablesBailOutFor);
TEST_CASE(simplifyKnownVariablesBailOutFor1);
TEST_CASE(simplifyKnownVariablesBailOutFor2);
TEST_CASE(simplifyKnownVariablesBailOutMemberFunction);
TEST_CASE(varid1);
@ -1870,7 +1871,7 @@ private:
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true));
}
void simplifyKnownVariablesBailOutFor()
void simplifyKnownVariablesBailOutFor1()
{
const char code[] = "void foo() {\n"
" for (int i = 0; i < 10; ++i) { }\n"
@ -1881,6 +1882,19 @@ private:
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true));
}
void simplifyKnownVariablesBailOutFor2()
{
const char code[] = "void foo() {\n"
" int i = 0;\n"
" while (i < 10) { ++i; }\n"
"}\n";
const char expected[] = "void foo ( ) {\n"
"int i ; i = 0 ;\n"
"while ( i < 10 ) { ++ i ; }\n"
"}";
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true));
}
void simplifyKnownVariablesBailOutMemberFunction()
{
const char code[] = "void foo(obj a) {\n"