Tokenizer: better bailout in simplifyKnownVariables when there is loop
This commit is contained in:
parent
fb068a4e71
commit
b881718d9f
|
@ -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())
|
||||
{
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue