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