10#include "clang/AST/ASTContext.h"
11#include "clang/ASTMatchers/ASTMatchFinder.h"
32 return Node.getMethodFamily() == OMF_init;
51 ast_matchers::internal::Matcher<ObjCInterfaceDecl>, Base) {
52 const ObjCInterfaceDecl *InterfaceDecl = Node.getClassInterface();
53 return Base.matches(*InterfaceDecl, Finder, Builder);
68AST_MATCHER(ObjCMessageExpr, isMessagingSuperInstance) {
69 return Node.getReceiverKind() == ObjCMessageExpr::SuperInstance;
76 objcMessageExpr(hasSelector(
"self"), isMessagingSuperInstance(),
77 hasAncestor(objcMethodDecl(
79 hasDeclContext(objcImplementationDecl(hasInterface(
80 isDerivedFrom(hasName(
"NSObject"))))))))
86 const auto *Message = Result.Nodes.getNodeAs<ObjCMessageExpr>(
"message");
89 diag(Message->getExprLoc(),
"suspicious invocation of %0 in "
90 "initializer; did you mean to "
91 "invoke a superclass initializer?")
92 << Message->getMethodDecl();
94 const SourceLocation ReceiverLoc = Message->getReceiverRange().getBegin();
95 if (ReceiverLoc.isMacroID() || ReceiverLoc.isInvalid())
98 const SourceLocation SelectorLoc = Message->getSelectorStartLoc();
99 if (SelectorLoc.isMacroID() || SelectorLoc.isInvalid())
102 Diag << FixItHint::CreateReplacement(Message->getSourceRange(),
103 StringRef(
"[super init]"));
void registerMatchers(ast_matchers::MatchFinder *Finder) override
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
AST_MATCHER_P(Stmt, isStatementIdenticalToBoundNode, std::string, ID)
AST_MATCHER(BinaryOperator, isRelationalOperator)