11 #include "clang/AST/ASTContext.h" 12 #include "clang/ASTMatchers/ASTMatchFinder.h" 21 void AvoidThrowingObjCExceptionCheck::registerMatchers(MatchFinder *Finder) {
23 if (!getLangOpts().ObjC1 && !getLangOpts().ObjC2) {
27 Finder->addMatcher(objcThrowStmt().bind(
"throwStmt"),
this);
29 objcMessageExpr(anyOf(hasSelector(
"raise:format:"),
30 hasSelector(
"raise:format:arguments:")),
31 hasReceiverType(asString(
"NSException")))
32 .bind(
"raiseException"),
36 void AvoidThrowingObjCExceptionCheck::check(
37 const MatchFinder::MatchResult &Result) {
38 const auto *MatchedStmt =
39 Result.Nodes.getNodeAs<ObjCAtThrowStmt>(
"throwStmt");
40 const auto *MatchedExpr =
41 Result.Nodes.getNodeAs<ObjCMessageExpr>(
"raiseException");
42 auto SourceLoc = MatchedStmt ==
nullptr ? MatchedExpr->getSelectorStartLoc()
43 : MatchedStmt->getThrowLoc();
45 "pass in NSError ** instead of throwing exception to indicate " 46 "Objective-C errors");
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//