Refactorizations for executionpath.cpp (rearranged code, added some else before if)

This commit is contained in:
PKEuS 2011-12-17 11:26:20 +01:00 committed by Daniel Marjamäki
parent 2fa0168e55
commit 009471f4ee
1 changed files with 27 additions and 30 deletions

View File

@ -172,7 +172,7 @@ void ExecutionPath::checkScope(const Token *tok, std::list<ExecutionPath *> &che
} }
// goto/setjmp/longjmp => bailout // goto/setjmp/longjmp => bailout
if (Token::Match(tok, "goto|setjmp|longjmp")) { else if (Token::Match(tok, "goto|setjmp|longjmp")) {
ExecutionPath::bailOut(checks); ExecutionPath::bailOut(checks);
return; return;
} }
@ -185,6 +185,19 @@ void ExecutionPath::checkScope(const Token *tok, std::list<ExecutionPath *> &che
} }
} }
// for/while/switch/do .. bail out
else if (Token::Match(tok, "for|while|switch|do")) {
// goto {
const Token *tok2 = tok->next();
if (tok2 && tok2->str() == "(")
tok2 = tok2->link();
if (tok2 && tok2->str() == ")")
tok2 = tok2->next();
if (!tok2 || tok2->str() != "{") {
ExecutionPath::bailOut(checks);
return;
}
if (tok->str() == "switch") { if (tok->str() == "switch") {
// parse condition // parse condition
if (checks.size() > 10 || check->parseCondition(*tok->next(), checks)) { if (checks.size() > 10 || check->parseCondition(*tok->next(), checks)) {
@ -192,21 +205,19 @@ void ExecutionPath::checkScope(const Token *tok, std::list<ExecutionPath *> &che
return; return;
} }
const Token *tok2 = tok->next()->link();
if (Token::simpleMatch(tok2, ") { case")) {
// what variable ids should the if be counted for? // what variable ids should the if be counted for?
std::set<unsigned int> countif; std::set<unsigned int> countif;
std::list<ExecutionPath *> newchecks; std::list<ExecutionPath *> newchecks;
for (tok2 = tok2->tokAt(2); tok2; tok2 = tok2->next()) { for (const Token* tok3 = tok2->next(); tok3; tok3 = tok3->next()) {
if (tok2->str() == "{") if (tok3->str() == "{")
tok2 = tok2->link(); tok3 = tok3->link();
else if (tok2->str() == "}") else if (tok3->str() == "}")
break; break;
else if (tok2->str() == "case" && else if (tok3->str() == "case" &&
!Token::Match(tok2, "case %num% : ; case")) { !Token::Match(tok3, "case %num% : ; case")) {
parseIfSwitchBody(tok2, checks, newchecks, countif); parseIfSwitchBody(tok3, checks, newchecks, countif);
} }
} }
@ -220,22 +231,8 @@ void ExecutionPath::checkScope(const Token *tok, std::list<ExecutionPath *> &che
(*it)->numberOfIf++; (*it)->numberOfIf++;
} }
} }
} // no switch
else {
// for/while/switch/do .. bail out
if (Token::Match(tok, "for|while|switch|do")) {
// goto {
const Token *tok2 = tok->next();
if (tok2 && tok2->str() == "(")
tok2 = tok2->link();
if (tok2 && tok2->str() == ")")
tok2 = tok2->next();
if (!tok2 || tok2->str() != "{") {
ExecutionPath::bailOut(checks);
return;
}
if (tok->str() != "switch") {
for (const Token *tok3 = tok; tok3 && tok3 != tok2; tok3 = tok3->next()) { for (const Token *tok3 = tok; tok3 && tok3 != tok2; tok3 = tok3->next()) {
if (tok3->varId()) if (tok3->varId())
ExecutionPath::bailOutVar(checks, tok3->varId()); ExecutionPath::bailOutVar(checks, tok3->varId());
@ -357,7 +354,7 @@ void ExecutionPath::checkScope(const Token *tok, std::list<ExecutionPath *> &che
} }
// ; { ... } // ; { ... }
if (Token::Match(tok->previous(), "[;{}] {")) { if (Token::Match(tok->previous(), "[;{}:] {")) {
ExecutionPath::checkScope(tok->next(), checks); ExecutionPath::checkScope(tok->next(), checks);
tok = tok->link(); tok = tok->link();
continue; continue;