Tokenizer::simplifyFlowControl: 1) remove consecutive 'break' or 'continue', since they don't influence the CheckOther results; 2) improve the code speed where possible;
Tokenizer::eraseDeadCode: Ditto.
This commit is contained in:
parent
fcb6759f43
commit
f47ac539d6
|
@ -4476,7 +4476,7 @@ void Tokenizer::simplifyFlowControl()
|
||||||
unsigned int indentlevel = 0;
|
unsigned int indentlevel = 0;
|
||||||
Token *beginindent = 0;
|
Token *beginindent = 0;
|
||||||
for (Token *tok = _tokens; tok; tok = tok->next()) {
|
for (Token *tok = _tokens; tok; tok = tok->next()) {
|
||||||
if (tok->str() == "(") {
|
if (tok->str() == "(" || tok->str() == "[") {
|
||||||
tok = tok->link();
|
tok = tok->link();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -4498,13 +4498,7 @@ void Tokenizer::simplifyFlowControl()
|
||||||
eraseDeadCode(tok, beginindent->link());
|
eraseDeadCode(tok, beginindent->link());
|
||||||
|
|
||||||
} else if (Token::Match(tok,"continue|break ;")) {
|
} else if (Token::Match(tok,"continue|break ;")) {
|
||||||
if (Token::simpleMatch(tok, "continue ; continue ;")
|
|
||||||
|| Token::simpleMatch(tok, "break ; break ;")) {
|
|
||||||
//save the 'double break|continue' message
|
|
||||||
tok = tok->tokAt(3);
|
|
||||||
} else {
|
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
}
|
|
||||||
eraseDeadCode(tok, beginindent->link());
|
eraseDeadCode(tok, beginindent->link());
|
||||||
|
|
||||||
} else if (tok->str() == "return" || tok->str() == "throw") {
|
} else if (tok->str() == "return" || tok->str() == "throw") {
|
||||||
|
@ -8351,12 +8345,11 @@ void Tokenizer::eraseDeadCode(Token *begin, const Token *end)
|
||||||
if (Token::Match(tok2->next(), "{|[|(")) {
|
if (Token::Match(tok2->next(), "{|[|(")) {
|
||||||
tok2 = tok2->next()->link();
|
tok2 = tok2->next()->link();
|
||||||
} else if (Token::Match(tok2, "[{};] case %any% : ;") || Token::Match(tok2, "[{};] default : ;")) {
|
} else if (Token::Match(tok2, "[{};] case %any% : ;") || Token::Match(tok2, "[{};] default : ;")) {
|
||||||
const Token *end3 = tok2->tokAt(4 + (tok2->next()->str() == "case"));
|
if (tok2->next()->str() == "case")
|
||||||
Token::eraseTokens(tok2, end3);
|
tok2->deleteNext();
|
||||||
if (Token::simpleMatch(tok2->previous(), "break ; break ;")) {
|
tok2->deleteNext();
|
||||||
tok2->deleteNext();
|
tok2->deleteNext();
|
||||||
tok2->deleteNext();
|
tok2->deleteNext();
|
||||||
}
|
|
||||||
} else if (tok2->next()->str() == "}") {
|
} else if (tok2->next()->str() == "}") {
|
||||||
--indentlevel2;
|
--indentlevel2;
|
||||||
if (indentlevel2 <= indentcase)
|
if (indentlevel2 <= indentcase)
|
||||||
|
|
|
@ -3096,8 +3096,6 @@ private:
|
||||||
beforedead.push_back("goto labels");
|
beforedead.push_back("goto labels");
|
||||||
beforedead.push_back("break");
|
beforedead.push_back("break");
|
||||||
beforedead.push_back("continue");
|
beforedead.push_back("continue");
|
||||||
beforedead.push_back("break ; break");
|
|
||||||
beforedead.push_back("continue ; continue");
|
|
||||||
|
|
||||||
for (std::list<std::string>::iterator it = beforedead.begin(); it != beforedead.end(); ++it) {
|
for (std::list<std::string>::iterator it = beforedead.begin(); it != beforedead.end(); ++it) {
|
||||||
{
|
{
|
||||||
|
@ -3175,7 +3173,7 @@ private:
|
||||||
" break; break;"
|
" break; break;"
|
||||||
" }"
|
" }"
|
||||||
"}";
|
"}";
|
||||||
std::string expected = "void foo ( ) { " + *it + " ; { label : ; foo ( ) ; break ; break ; } }";
|
std::string expected = "void foo ( ) { " + *it + " ; { label : ; foo ( ) ; break ; } }";
|
||||||
ASSERT_EQUALS(expected, tok(code));
|
ASSERT_EQUALS(expected, tok(code));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3190,7 +3188,7 @@ private:
|
||||||
" break;"
|
" break;"
|
||||||
" }"
|
" }"
|
||||||
"}";
|
"}";
|
||||||
std::string expected = "void foo ( ) { " + *it + " ; { label : ; foo ( ) ; break ; break ; } }";
|
std::string expected = "void foo ( ) { " + *it + " ; { label : ; foo ( ) ; break ; } }";
|
||||||
ASSERT_EQUALS(expected, tok(code));
|
ASSERT_EQUALS(expected, tok(code));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3205,7 +3203,7 @@ private:
|
||||||
" break; break;"
|
" break; break;"
|
||||||
" }"
|
" }"
|
||||||
"}";
|
"}";
|
||||||
std::string expected = "void foo ( ) { " + *it + " ; { label : ; foo ( ) ; break ; break ; } }";
|
std::string expected = "void foo ( ) { " + *it + " ; { label : ; foo ( ) ; break ; } }";
|
||||||
ASSERT_EQUALS(expected, tok(code));
|
ASSERT_EQUALS(expected, tok(code));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue