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