20class SwitchCaseContainsExit :
public ProgramVisitor {
22 SwitchCaseContainsExit(
bool conditionalExits) : fConditionalExits(conditionalExits) {}
24 bool visitExpression(
const Expression& expr)
override {
29 bool visitStatement(
const Statement& stmt)
override {
30 switch (stmt.kind()) {
31 case Statement::Kind::kBlock:
32 case Statement::Kind::kSwitchCase:
33 return INHERITED::visitStatement(stmt);
35 case Statement::Kind::kReturn:
37 return fConditionalExits ? fInConditional : !fInConditional;
42 (fConditionalExits ? fInConditional : !fInConditional);
44 case Statement::Kind::kBreak:
46 return !fInLoop && !fInSwitch &&
47 (fConditionalExits ? fInConditional : !fInConditional);
49 case Statement::Kind::kIf: {
51 bool result = INHERITED::visitStatement(stmt);
56 case Statement::Kind::kFor:
57 case Statement::Kind::kDo: {
63 bool result = INHERITED::visitStatement(stmt);
69 case Statement::Kind::kSwitch: {
71 bool result = INHERITED::visitStatement(stmt);
81 bool fConditionalExits =
false;
82 int fInConditional = 0;
91 return SwitchCaseContainsExit{
false}.visitStatement(stmt);
95 return SwitchCaseContainsExit{
true}.visitStatement(stmt);
#define INHERITED(method,...)
Expression(Position pos, Kind kind, const Type *type)
bool SwitchCaseContainsUnconditionalExit(const Statement &stmt)
bool SwitchCaseContainsConditionalExit(const Statement &stmt)