Fixed #1452 (Simplify goto better)

This commit is contained in:
Daniel Marjamäki 2010-02-25 20:03:39 +01:00
parent 0da133f8a0
commit 377d3091a9
2 changed files with 19 additions and 10 deletions

View File

@ -5087,7 +5087,7 @@ void Tokenizer::simplifyGoto()
++lev;
}
if (Token::Match(tok2, "%var% :"))
if (Token::Match(tok2, "%var% :") || tok2->str() == "goto")
{
break;
}
@ -5115,7 +5115,8 @@ void Tokenizer::simplifyGoto()
token->deleteNext();
// Insert the statements..
bool ret = false;
bool ret = false; // is there return
bool ret2 = false; // is there return in indentlevel 0
std::list<Token*> links;
std::list<Token*> links2;
std::list<Token*> links3;
@ -5133,11 +5134,19 @@ void Tokenizer::simplifyGoto()
++lev;
}
else if (tok2->str() == "return")
{
ret = true;
if (indentlevel == 1 && lev == 0)
ret2 = true;
}
token->insertToken(tok2->str().c_str());
token = token->next();
token->linenr(tok2->linenr());
token->varId(tok2->varId());
if (ret2 && tok2->str() == ";")
{
break;
}
if (token->str() == "(")
{
links.push_back(token);

View File

@ -2156,21 +2156,21 @@ private:
{
const char code[] = "void foo(int x)\n"
"{\n"
" goto A;\n"
" goto A;\n"
"A:\n"
" fooA();\n"
" goto B;\n"
" fooNever();\n"
" fooA();\n"
" goto B;\n"
" fooNever();\n"
"B:\n"
" fooB();\n"
" return 3;\n"
" fooB();\n"
" return 3;\n"
"}";
const char expect[] = "void foo ( int x ) "
"{ "
"fooA ( ) ; "
"fooB ( ) ; "
"return 3; "
"return 3 ; "
"fooA ( ) ; "
"fooB ( ) ; "
"return 3 ; "
@ -2179,7 +2179,7 @@ private:
"return 3 ; "
"}";
TODO_ASSERT_EQUALS(expect, tok(code));
ASSERT_EQUALS(expect, tok(code));
}
{