27 this->visitProgramElement(funcDef);
30 bool visitExpression(
const Expression& expr)
override {
35 bool visitStatement(
const Statement& stmt)
override {
36 switch (stmt.
kind()) {
37 case Statement::Kind::kBlock: {
39 const auto& block = stmt.
as<
Block>();
41 this->visitStatement(*block.children().back());
43 case Statement::Kind::kSwitch:
44 case Statement::Kind::kDo:
45 case Statement::Kind::kFor:
49 case Statement::Kind::kReturn:
54 return INHERITED::visitStatement(stmt);
62 return CountReturnsAtEndOfControlFlow{funcDef}.fNumReturns;
77 switch (stmt.
kind()) {
78 case Statement::Kind::kReturn: {
83 case Statement::Kind::kVarDeclaration: {
89 case Statement::Kind::kBlock: {
90 int depthIncrement = stmt.
as<
Block>().isScope() ? 1 : 0;
119 if (counter.fNumReturns > returnsAtEndOfControlFlow) {
120 return ReturnComplexity::kEarlyReturns;
122 if (counter.fNumReturns > 1) {
123 return ReturnComplexity::kScopedReturns;
125 if (counter.fVariablesInBlocks && counter.fDeepestReturn > 1) {
126 return ReturnComplexity::kScopedReturns;
128 return ReturnComplexity::kSingleSafeReturn;
#define INHERITED(method,...)
const StatementArray & children() const
bool visitExpression(const Expression &expr) override
CountReturnsWithLimit(const FunctionDefinition &funcDef, int limit)
bool visitStatement(const Statement &stmt) override
virtual bool visitStatement(typename T::Statement &statement)
virtual bool visitProgramElement(typename T::ProgramElement &programElement)
static float max(float r, float g, float b)
ReturnComplexity GetReturnComplexity(const FunctionDefinition &funcDef)
static int count_returns_at_end_of_control_flow(const FunctionDefinition &funcDef)