Tokenizer: it's possible to set null lower bound for eraseDeadCode when used inside simplifyFlowControl.

Remove now unused 'beginindent' and moved 'goto' simplification together with 'return' group.
This commit is contained in:
Edoardo Prezioso 2012-01-28 21:35:16 +01:00
parent bb703f4d0b
commit fa77f98b1c
1 changed files with 4 additions and 10 deletions

View File

@ -3894,7 +3894,6 @@ void Tokenizer::simplifyRealloc()
void Tokenizer::simplifyFlowControl() void Tokenizer::simplifyFlowControl()
{ {
unsigned int indentlevel = 0; unsigned int indentlevel = 0;
Token *beginindent = 0;
for (Token *tok = _tokens; tok; tok = tok->next()) { for (Token *tok = _tokens; tok; tok = tok->next()) {
if (tok->str() == "(" || tok->str() == "[") { if (tok->str() == "(" || tok->str() == "[") {
tok = tok->link(); tok = tok->link();
@ -3906,7 +3905,6 @@ void Tokenizer::simplifyFlowControl()
tok = tok->link(); tok = tok->link();
continue; continue;
} }
beginindent = tok;
++indentlevel; ++indentlevel;
} else if (tok->str() == "}") { } else if (tok->str() == "}") {
if (!indentlevel) if (!indentlevel)
@ -3917,22 +3915,18 @@ void Tokenizer::simplifyFlowControl()
if (!indentlevel) if (!indentlevel)
continue; continue;
if (Token::Match(tok, "goto %var% ;")) { if (Token::Match(tok,"continue|break ;")) {
tok = tok->tokAt(2);
eraseDeadCode(tok, beginindent->link());
} else if (Token::Match(tok,"continue|break ;")) {
tok = tok->next(); tok = tok->next();
eraseDeadCode(tok, beginindent->link()); eraseDeadCode(tok, 0);
} else if (Token::Match(tok,"return|throw|exit|abort")) { } else if (Token::Match(tok,"return|throw|exit|abort|goto")) {
//catch the first ';' //catch the first ';'
for (Token *tok2 = tok->next(); tok2; tok2 = tok2->next()) { for (Token *tok2 = tok->next(); tok2; tok2 = tok2->next()) {
if (tok2->str() == "(" || tok2->str() == "[") { if (tok2->str() == "(" || tok2->str() == "[") {
tok2 = tok2->link(); tok2 = tok2->link();
} else if (tok2->str() == ";") { } else if (tok2->str() == ";") {
tok = tok2; tok = tok2;
eraseDeadCode(tok, beginindent->link()); eraseDeadCode(tok, 0);
break; break;
} else if (Token::Match(tok2, "[{}]")) } else if (Token::Match(tok2, "[{}]"))
break; //Wrong code. break; //Wrong code.