void MisleadingIndentationCheck::registerMatchers(MatchFinder *Finder) { Finder->addMatcher(ifStmt(hasElse(stmt())).bind("if"), this); Finder->addMatcher( compoundStmt(has(stmt(anyOf(ifStmt(), forStmt(), whileStmt())))) .bind("compound"), this); }
void MultiwayPathsCoveredCheck::registerMatchers(MatchFinder *Finder) { Finder->addMatcher( switchStmt( hasCondition(allOf( // Match on switch statements that have either a bit-field or // an integer condition. The ordering in 'anyOf()' is // important because the last condition is the most general. anyOf(ignoringImpCasts(memberExpr(hasDeclaration( fieldDecl(isBitField()).bind("bitfield")))), ignoringImpCasts(declRefExpr().bind("non-enum-condition"))), // 'unless()' must be the last match here and must be bound, // otherwise the matcher does not work correctly, because it // will not explicitly ignore enum conditions. unless(ignoringImpCasts( declRefExpr(hasType(enumType())).bind("enum-condition")))))) .bind("switch"), this); // This option is noisy, therefore matching is configurable. if (WarnOnMissingElse) { Finder->addMatcher( ifStmt(allOf(hasParent(ifStmt()), unless(hasElse(anything())))) .bind("else-if"), this); } }
void ElseAfterReturnCheck::registerMatchers(MatchFinder *Finder) { // FIXME: Support continue, break and throw. Finder->addMatcher( ifStmt( hasThen(stmt(anyOf(returnStmt(), compoundStmt(has(returnStmt()))))), hasElse(stmt().bind("else"))).bind("if"), this); }
void ElseAfterReturnCheck::registerMatchers(MatchFinder *Finder) { const auto ControlFlowInterruptorMatcher = stmt(anyOf(returnStmt().bind("return"), continueStmt().bind("continue"), breakStmt().bind("break"), cxxThrowExpr().bind("throw"))); Finder->addMatcher( stmt(forEach( ifStmt(hasThen(stmt( anyOf(ControlFlowInterruptorMatcher, compoundStmt(has(ControlFlowInterruptorMatcher))))), hasElse(stmt().bind("else"))) .bind("if"))), this); }
void ASTIf::analyse(SemanticAnalyser *analyser) { for (size_t i = 0; i < conditions_.size(); i++) { analyser->pathAnalyser().beginBranch(); analyser->scoper().pushScope(); analyser->expectType(Type::boolean(), &conditions_[i]); analyser->popTemporaryScope(conditions_[i]); blocks_[i].analyse(analyser); analyser->scoper().popScope(analyser->app()); analyser->pathAnalyser().beginBranch(); } if (hasElse()) { analyser->pathAnalyser().beginBranch(); analyser->scoper().pushScope(); blocks_.back().analyse(analyser); analyser->scoper().popScope(analyser->app()); analyser->pathAnalyser().endBranch(); analyser->pathAnalyser().endMutualExclusiveBranches(); } else { analyser->pathAnalyser().endUncertainBranches(); } }
void Rule_6_4_2::registerMatchers(ast_matchers::MatchFinder *Finder) { Finder->addMatcher( ifStmt(hasElse(ifStmt(unless(hasElse(stmt()))).bind("if"))), this); }