10#include "clang/AST/ASTContext.h"
11#include "clang/ASTMatchers/ASTMatchFinder.h"
19 Finder->addMatcher(objcThrowStmt().bind(
"throwStmt"),
this);
21 objcMessageExpr(anyOf(hasSelector(
"raise:format:"),
22 hasSelector(
"raise:format:arguments:")),
23 hasReceiverType(asString(
"NSException")))
24 .bind(
"raiseException"),
29 const MatchFinder::MatchResult &Result) {
30 const auto *MatchedStmt =
31 Result.Nodes.getNodeAs<ObjCAtThrowStmt>(
"throwStmt");
32 const auto *MatchedExpr =
33 Result.Nodes.getNodeAs<ObjCMessageExpr>(
"raiseException");
34 auto SourceLoc = MatchedStmt ==
nullptr ? MatchedExpr->getSelectorStartLoc()
35 : MatchedStmt->getThrowLoc();
38 if (SourceLoc.isInvalid())
43 if (SourceLoc.isMacroID()) {
44 SourceManager &SM = *Result.SourceManager;
45 auto MacroLoc = SM.getImmediateMacroCallerLoc(SourceLoc);
48 if (SM.isInSystemHeader(MacroLoc))
53 "pass in NSError ** instead of throwing exception to indicate "
54 "Objective-C errors");
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.