[PATCH] D66270: [clang-tidy] Migrate objc-super-self to use isDerivedFrom
gribozavr added a comment. LGTM, thanks! Repository: rL LLVM CHANGES SINCE LAST ACTION https://reviews.llvm.org/D66270/new/ https://reviews.llvm.org/D66270 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D66270: [clang-tidy] Migrate objc-super-self to use isDerivedFrom
This revision was automatically updated to reflect the committed changes. Closed by commit rL369081: [clang-tidy] Migrate objc-super-self to use isDerivedFrom (authored by stephanemoore, committed by ). Herald added a project: LLVM. Herald added a subscriber: llvm-commits. Changed prior to commit: https://reviews.llvm.org/D66270?vs=215311=215528#toc Repository: rL LLVM CHANGES SINCE LAST ACTION https://reviews.llvm.org/D66270/new/ https://reviews.llvm.org/D66270 Files: clang-tools-extra/trunk/clang-tidy/objc/SuperSelfCheck.cpp Index: clang-tools-extra/trunk/clang-tidy/objc/SuperSelfCheck.cpp === --- clang-tools-extra/trunk/clang-tidy/objc/SuperSelfCheck.cpp +++ clang-tools-extra/trunk/clang-tidy/objc/SuperSelfCheck.cpp @@ -35,38 +35,25 @@ return Node.getMethodFamily() == OMF_init; } -/// \brief Matches Objective-C implementations of classes that directly or -/// indirectly have a superclass matching \c InterfaceDecl. +/// \brief Matches Objective-C implementations with interfaces that match +/// \c Base. /// -/// Note that a class is not considered to be a subclass of itself. -/// -/// Example matches implementation declarations for Y and Z. -/// (matcher = objcInterfaceDecl(isSubclassOf(hasName("X" +/// Example matches implementation declarations for X. +/// (matcher = objcImplementationDecl(hasInterface(hasName("X" /// \code /// @interface X /// @end -/// @interface Y : X -/// @end -/// @implementation Y // directly derived +/// @implementation X /// @end -/// @interface Z : Y -/// @end -/// @implementation Z // indirectly derived +/// @interface Y +//@end +/// @implementation Y /// @end /// \endcode -AST_MATCHER_P(ObjCImplementationDecl, isSubclassOf, - ast_matchers::internal::Matcher, - InterfaceDecl) { - // Check if any of the superclasses of the class match. - for (const ObjCInterfaceDecl *SuperClass = - Node.getClassInterface()->getSuperClass(); - SuperClass != nullptr; SuperClass = SuperClass->getSuperClass()) { -if (InterfaceDecl.matches(*SuperClass, Finder, Builder)) - return true; - } - - // No matches found. - return false; +AST_MATCHER_P(ObjCImplementationDecl, hasInterface, + ast_matchers::internal::Matcher, Base) { + const ObjCInterfaceDecl *InterfaceDecl = Node.getClassInterface(); + return Base.matches(*InterfaceDecl, Finder, Builder); } /// \brief Matches Objective-C message expressions where the receiver is the @@ -93,11 +80,11 @@ return; Finder->addMatcher( - objcMessageExpr( - hasSelector("self"), isMessagingSuperInstance(), - hasAncestor(objcMethodDecl(isInitializer(), - hasDeclContext(objcImplementationDecl( - isSubclassOf(hasName("NSObject"))) + objcMessageExpr(hasSelector("self"), isMessagingSuperInstance(), + hasAncestor(objcMethodDecl( + isInitializer(), + hasDeclContext(objcImplementationDecl(hasInterface( + isDerivedFrom(hasName("NSObject" .bind("message"), this); } Index: clang-tools-extra/trunk/clang-tidy/objc/SuperSelfCheck.cpp === --- clang-tools-extra/trunk/clang-tidy/objc/SuperSelfCheck.cpp +++ clang-tools-extra/trunk/clang-tidy/objc/SuperSelfCheck.cpp @@ -35,38 +35,25 @@ return Node.getMethodFamily() == OMF_init; } -/// \brief Matches Objective-C implementations of classes that directly or -/// indirectly have a superclass matching \c InterfaceDecl. +/// \brief Matches Objective-C implementations with interfaces that match +/// \c Base. /// -/// Note that a class is not considered to be a subclass of itself. -/// -/// Example matches implementation declarations for Y and Z. -/// (matcher = objcInterfaceDecl(isSubclassOf(hasName("X" +/// Example matches implementation declarations for X. +/// (matcher = objcImplementationDecl(hasInterface(hasName("X" /// \code /// @interface X /// @end -/// @interface Y : X -/// @end -/// @implementation Y // directly derived +/// @implementation X /// @end -/// @interface Z : Y -/// @end -/// @implementation Z // indirectly derived +/// @interface Y +//@end +/// @implementation Y /// @end /// \endcode -AST_MATCHER_P(ObjCImplementationDecl, isSubclassOf, - ast_matchers::internal::Matcher, - InterfaceDecl) { - // Check if any of the superclasses of the class match. - for (const ObjCInterfaceDecl *SuperClass = - Node.getClassInterface()->getSuperClass(); - SuperClass != nullptr; SuperClass = SuperClass->getSuperClass()) { -if (InterfaceDecl.matches(*SuperClass, Finder, Builder)) - return true; - } - - // No matches
[PATCH] D66270: [clang-tidy] Migrate objc-super-self to use isDerivedFrom
aaron.ballman accepted this revision. aaron.ballman added a comment. This revision is now accepted and ready to land. LGTM! Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D66270/new/ https://reviews.llvm.org/D66270 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D66270: [clang-tidy] Migrate objc-super-self to use isDerivedFrom
stephanemoore updated this revision to Diff 215311. stephanemoore added a comment. Fix example matches in comment. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D66270/new/ https://reviews.llvm.org/D66270 Files: clang-tools-extra/clang-tidy/objc/SuperSelfCheck.cpp Index: clang-tools-extra/clang-tidy/objc/SuperSelfCheck.cpp === --- clang-tools-extra/clang-tidy/objc/SuperSelfCheck.cpp +++ clang-tools-extra/clang-tidy/objc/SuperSelfCheck.cpp @@ -35,38 +35,25 @@ return Node.getMethodFamily() == OMF_init; } -/// \brief Matches Objective-C implementations of classes that directly or -/// indirectly have a superclass matching \c InterfaceDecl. +/// \brief Matches Objective-C implementations with interfaces that match +/// \c Base. /// -/// Note that a class is not considered to be a subclass of itself. -/// -/// Example matches implementation declarations for Y and Z. -/// (matcher = objcInterfaceDecl(isSubclassOf(hasName("X" +/// Example matches implementation declarations for X. +/// (matcher = objcImplementationDecl(hasInterface(hasName("X" /// \code /// @interface X /// @end -/// @interface Y : X -/// @end -/// @implementation Y // directly derived -/// @end -/// @interface Z : Y +/// @implementation X /// @end -/// @implementation Z // indirectly derived +/// @interface Y +//@end +/// @implementation Y /// @end /// \endcode -AST_MATCHER_P(ObjCImplementationDecl, isSubclassOf, - ast_matchers::internal::Matcher, - InterfaceDecl) { - // Check if any of the superclasses of the class match. - for (const ObjCInterfaceDecl *SuperClass = - Node.getClassInterface()->getSuperClass(); - SuperClass != nullptr; SuperClass = SuperClass->getSuperClass()) { -if (InterfaceDecl.matches(*SuperClass, Finder, Builder)) - return true; - } - - // No matches found. - return false; +AST_MATCHER_P(ObjCImplementationDecl, hasInterface, + ast_matchers::internal::Matcher, Base) { + const ObjCInterfaceDecl *InterfaceDecl = Node.getClassInterface(); + return Base.matches(*InterfaceDecl, Finder, Builder); } /// \brief Matches Objective-C message expressions where the receiver is the @@ -93,11 +80,11 @@ return; Finder->addMatcher( - objcMessageExpr( - hasSelector("self"), isMessagingSuperInstance(), - hasAncestor(objcMethodDecl(isInitializer(), - hasDeclContext(objcImplementationDecl( - isSubclassOf(hasName("NSObject"))) + objcMessageExpr(hasSelector("self"), isMessagingSuperInstance(), + hasAncestor(objcMethodDecl( + isInitializer(), + hasDeclContext(objcImplementationDecl(hasInterface( + isDerivedFrom(hasName("NSObject" .bind("message"), this); } Index: clang-tools-extra/clang-tidy/objc/SuperSelfCheck.cpp === --- clang-tools-extra/clang-tidy/objc/SuperSelfCheck.cpp +++ clang-tools-extra/clang-tidy/objc/SuperSelfCheck.cpp @@ -35,38 +35,25 @@ return Node.getMethodFamily() == OMF_init; } -/// \brief Matches Objective-C implementations of classes that directly or -/// indirectly have a superclass matching \c InterfaceDecl. +/// \brief Matches Objective-C implementations with interfaces that match +/// \c Base. /// -/// Note that a class is not considered to be a subclass of itself. -/// -/// Example matches implementation declarations for Y and Z. -/// (matcher = objcInterfaceDecl(isSubclassOf(hasName("X" +/// Example matches implementation declarations for X. +/// (matcher = objcImplementationDecl(hasInterface(hasName("X" /// \code /// @interface X /// @end -/// @interface Y : X -/// @end -/// @implementation Y // directly derived -/// @end -/// @interface Z : Y +/// @implementation X /// @end -/// @implementation Z // indirectly derived +/// @interface Y +//@end +/// @implementation Y /// @end /// \endcode -AST_MATCHER_P(ObjCImplementationDecl, isSubclassOf, - ast_matchers::internal::Matcher, - InterfaceDecl) { - // Check if any of the superclasses of the class match. - for (const ObjCInterfaceDecl *SuperClass = - Node.getClassInterface()->getSuperClass(); - SuperClass != nullptr; SuperClass = SuperClass->getSuperClass()) { -if (InterfaceDecl.matches(*SuperClass, Finder, Builder)) - return true; - } - - // No matches found. - return false; +AST_MATCHER_P(ObjCImplementationDecl, hasInterface, + ast_matchers::internal::Matcher, Base) { + const ObjCInterfaceDecl *InterfaceDecl = Node.getClassInterface(); + return Base.matches(*InterfaceDecl, Finder, Builder); }
[PATCH] D66270: [clang-tidy] Migrate objc-super-self to use isDerivedFrom
stephanemoore created this revision. stephanemoore added reviewers: aaron.ballman, gribozavr. Herald added subscribers: cfe-commits, xazax.hun. Herald added a project: clang. This migrates objc-super-self to `isDerivedFrom` as it now supports matching Objective-C interface declarations. Test Notes: Ran clang tools tests. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D66270 Files: clang-tools-extra/clang-tidy/objc/SuperSelfCheck.cpp Index: clang-tools-extra/clang-tidy/objc/SuperSelfCheck.cpp === --- clang-tools-extra/clang-tidy/objc/SuperSelfCheck.cpp +++ clang-tools-extra/clang-tidy/objc/SuperSelfCheck.cpp @@ -35,38 +35,25 @@ return Node.getMethodFamily() == OMF_init; } -/// \brief Matches Objective-C implementations of classes that directly or -/// indirectly have a superclass matching \c InterfaceDecl. -/// -/// Note that a class is not considered to be a subclass of itself. +/// \brief Matches Objective-C implementations with interfaces that match +/// \c Base. /// /// Example matches implementation declarations for Y and Z. -/// (matcher = objcInterfaceDecl(isSubclassOf(hasName("X" +/// (matcher = objcImplementationDecl(hasInterface(hasName("X" /// \code /// @interface X /// @end -/// @interface Y : X -/// @end -/// @implementation Y // directly derived -/// @end -/// @interface Z : Y +/// @implementation X /// @end -/// @implementation Z // indirectly derived +/// @interface Y +//@end +/// @implementation Y /// @end /// \endcode -AST_MATCHER_P(ObjCImplementationDecl, isSubclassOf, - ast_matchers::internal::Matcher, - InterfaceDecl) { - // Check if any of the superclasses of the class match. - for (const ObjCInterfaceDecl *SuperClass = - Node.getClassInterface()->getSuperClass(); - SuperClass != nullptr; SuperClass = SuperClass->getSuperClass()) { -if (InterfaceDecl.matches(*SuperClass, Finder, Builder)) - return true; - } - - // No matches found. - return false; +AST_MATCHER_P(ObjCImplementationDecl, hasInterface, + ast_matchers::internal::Matcher, Base) { + const ObjCInterfaceDecl *InterfaceDecl = Node.getClassInterface(); + return Base.matches(*InterfaceDecl, Finder, Builder); } /// \brief Matches Objective-C message expressions where the receiver is the @@ -93,11 +80,11 @@ return; Finder->addMatcher( - objcMessageExpr( - hasSelector("self"), isMessagingSuperInstance(), - hasAncestor(objcMethodDecl(isInitializer(), - hasDeclContext(objcImplementationDecl( - isSubclassOf(hasName("NSObject"))) + objcMessageExpr(hasSelector("self"), isMessagingSuperInstance(), + hasAncestor(objcMethodDecl( + isInitializer(), + hasDeclContext(objcImplementationDecl(hasInterface( + isDerivedFrom(hasName("NSObject" .bind("message"), this); } Index: clang-tools-extra/clang-tidy/objc/SuperSelfCheck.cpp === --- clang-tools-extra/clang-tidy/objc/SuperSelfCheck.cpp +++ clang-tools-extra/clang-tidy/objc/SuperSelfCheck.cpp @@ -35,38 +35,25 @@ return Node.getMethodFamily() == OMF_init; } -/// \brief Matches Objective-C implementations of classes that directly or -/// indirectly have a superclass matching \c InterfaceDecl. -/// -/// Note that a class is not considered to be a subclass of itself. +/// \brief Matches Objective-C implementations with interfaces that match +/// \c Base. /// /// Example matches implementation declarations for Y and Z. -/// (matcher = objcInterfaceDecl(isSubclassOf(hasName("X" +/// (matcher = objcImplementationDecl(hasInterface(hasName("X" /// \code /// @interface X /// @end -/// @interface Y : X -/// @end -/// @implementation Y // directly derived -/// @end -/// @interface Z : Y +/// @implementation X /// @end -/// @implementation Z // indirectly derived +/// @interface Y +//@end +/// @implementation Y /// @end /// \endcode -AST_MATCHER_P(ObjCImplementationDecl, isSubclassOf, - ast_matchers::internal::Matcher, - InterfaceDecl) { - // Check if any of the superclasses of the class match. - for (const ObjCInterfaceDecl *SuperClass = - Node.getClassInterface()->getSuperClass(); - SuperClass != nullptr; SuperClass = SuperClass->getSuperClass()) { -if (InterfaceDecl.matches(*SuperClass, Finder, Builder)) - return true; - } - - // No matches found. - return false; +AST_MATCHER_P(ObjCImplementationDecl, hasInterface, + ast_matchers::internal::Matcher, Base) { + const ObjCInterfaceDecl *InterfaceDecl = Node.getClassInterface(); + return