This revision was automatically updated to reflect the committed changes. stephanemoore marked an inline comment as done. Closed by commit rL368632: [clang] Update isDerivedFrom to support Objective-C classes 🔍 (authored by stephanemoore, committed by ). Herald added a project: LLVM. Herald added a subscriber: llvm-commits.
Changed prior to commit: https://reviews.llvm.org/D60543?vs=214272&id=214735#toc Repository: rL LLVM CHANGES SINCE LAST ACTION https://reviews.llvm.org/D60543/new/ https://reviews.llvm.org/D60543 Files: cfe/trunk/docs/LibASTMatchersReference.html cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h cfe/trunk/lib/ASTMatchers/ASTMatchFinder.cpp cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp cfe/trunk/unittests/ASTMatchers/Dynamic/RegistryTest.cpp
Index: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h =================================================================== --- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h @@ -2611,8 +2611,9 @@ AST_POLYMORPHIC_SUPPORTED_TYPES(CXXOperatorCallExpr, FunctionDecl)>(Name); } -/// Matches C++ classes that are directly or indirectly derived from -/// a class matching \c Base. +/// Matches C++ classes that are directly or indirectly derived from a class +/// matching \c Base, or Objective-C classes that directly or indirectly +/// subclass a class matching \c Base. /// /// Note that a class is not considered to be derived from itself. /// @@ -2632,36 +2633,80 @@ /// typedef Foo X; /// class Bar : public Foo {}; // derived from a type that X is a typedef of /// \endcode -AST_MATCHER_P(CXXRecordDecl, isDerivedFrom, - internal::Matcher<NamedDecl>, Base) { - return Finder->classIsDerivedFrom(&Node, Base, Builder, /*Directly=*/false); +/// +/// In the following example, Bar matches isDerivedFrom(hasName("NSObject")) +/// \code +/// @interface NSObject @end +/// @interface Bar : NSObject @end +/// \endcode +/// +/// Usable as: Matcher<CXXRecordDecl>, Matcher<ObjCInterfaceDecl> +AST_POLYMORPHIC_MATCHER_P( + isDerivedFrom, + AST_POLYMORPHIC_SUPPORTED_TYPES(CXXRecordDecl, ObjCInterfaceDecl), + internal::Matcher<NamedDecl>, Base) { + // Check if the node is a C++ struct/union/class. + if (const auto *RD = dyn_cast<CXXRecordDecl>(&Node)) + return Finder->classIsDerivedFrom(RD, Base, Builder, /*Directly=*/false); + + // The node must be an Objective-C class. + const auto *InterfaceDecl = cast<ObjCInterfaceDecl>(&Node); + return Finder->objcClassIsDerivedFrom(InterfaceDecl, Base, Builder, + /*Directly=*/false); } /// Overloaded method as shortcut for \c isDerivedFrom(hasName(...)). -AST_MATCHER_P_OVERLOAD(CXXRecordDecl, isDerivedFrom, std::string, BaseName, 1) { +AST_POLYMORPHIC_MATCHER_P_OVERLOAD( + isDerivedFrom, + AST_POLYMORPHIC_SUPPORTED_TYPES(CXXRecordDecl, ObjCInterfaceDecl), + std::string, BaseName, 1) { if (BaseName.empty()) return false; - return isDerivedFrom(hasName(BaseName)).matches(Node, Finder, Builder); + + const auto M = isDerivedFrom(hasName(BaseName)); + + if (const auto *RD = dyn_cast<CXXRecordDecl>(&Node)) + return Matcher<CXXRecordDecl>(M).matches(*RD, Finder, Builder); + + const auto *InterfaceDecl = cast<ObjCInterfaceDecl>(&Node); + return Matcher<ObjCInterfaceDecl>(M).matches(*InterfaceDecl, Finder, Builder); } /// Similar to \c isDerivedFrom(), but also matches classes that directly /// match \c Base. -AST_MATCHER_P_OVERLOAD(CXXRecordDecl, isSameOrDerivedFrom, - internal::Matcher<NamedDecl>, Base, 0) { - return Matcher<CXXRecordDecl>(anyOf(Base, isDerivedFrom(Base))) - .matches(Node, Finder, Builder); +AST_POLYMORPHIC_MATCHER_P_OVERLOAD( + isSameOrDerivedFrom, + AST_POLYMORPHIC_SUPPORTED_TYPES(CXXRecordDecl, ObjCInterfaceDecl), + internal::Matcher<NamedDecl>, Base, 0) { + const auto M = anyOf(Base, isDerivedFrom(Base)); + + if (const auto *RD = dyn_cast<CXXRecordDecl>(&Node)) + return Matcher<CXXRecordDecl>(M).matches(*RD, Finder, Builder); + + const auto *InterfaceDecl = cast<ObjCInterfaceDecl>(&Node); + return Matcher<ObjCInterfaceDecl>(M).matches(*InterfaceDecl, Finder, Builder); } /// Overloaded method as shortcut for /// \c isSameOrDerivedFrom(hasName(...)). -AST_MATCHER_P_OVERLOAD(CXXRecordDecl, isSameOrDerivedFrom, std::string, - BaseName, 1) { +AST_POLYMORPHIC_MATCHER_P_OVERLOAD( + isSameOrDerivedFrom, + AST_POLYMORPHIC_SUPPORTED_TYPES(CXXRecordDecl, ObjCInterfaceDecl), + std::string, BaseName, 1) { if (BaseName.empty()) return false; - return isSameOrDerivedFrom(hasName(BaseName)).matches(Node, Finder, Builder); + + const auto M = isSameOrDerivedFrom(hasName(BaseName)); + + if (const auto *RD = dyn_cast<CXXRecordDecl>(&Node)) + return Matcher<CXXRecordDecl>(M).matches(*RD, Finder, Builder); + + const auto *InterfaceDecl = cast<ObjCInterfaceDecl>(&Node); + return Matcher<ObjCInterfaceDecl>(M).matches(*InterfaceDecl, Finder, Builder); } -/// Matches C++ classes that are directly derived from a class matching \c Base. +/// Matches C++ or Objective-C classes that are directly derived from a class +/// matching \c Base. /// /// Note that a class is not considered to be derived from itself. /// @@ -2681,18 +2726,34 @@ /// typedef Foo X; /// class Bar : public Foo {}; // derived from a type that X is a typedef of /// \endcode -AST_MATCHER_P_OVERLOAD(CXXRecordDecl, isDirectlyDerivedFrom, - internal::Matcher<NamedDecl>, Base, 0) { - return Finder->classIsDerivedFrom(&Node, Base, Builder, /*Directly=*/true); +AST_POLYMORPHIC_MATCHER_P_OVERLOAD( + isDirectlyDerivedFrom, + AST_POLYMORPHIC_SUPPORTED_TYPES(CXXRecordDecl, ObjCInterfaceDecl), + internal::Matcher<NamedDecl>, Base, 0) { + // Check if the node is a C++ struct/union/class. + if (const auto *RD = dyn_cast<CXXRecordDecl>(&Node)) + return Finder->classIsDerivedFrom(RD, Base, Builder, /*Directly=*/true); + + // The node must be an Objective-C class. + const auto *InterfaceDecl = cast<ObjCInterfaceDecl>(&Node); + return Finder->objcClassIsDerivedFrom(InterfaceDecl, Base, Builder, + /*Directly=*/true); } /// Overloaded method as shortcut for \c isDirectlyDerivedFrom(hasName(...)). -AST_MATCHER_P_OVERLOAD(CXXRecordDecl, isDirectlyDerivedFrom, std::string, - BaseName, 1) { +AST_POLYMORPHIC_MATCHER_P_OVERLOAD( + isDirectlyDerivedFrom, + AST_POLYMORPHIC_SUPPORTED_TYPES(CXXRecordDecl, ObjCInterfaceDecl), + std::string, BaseName, 1) { if (BaseName.empty()) return false; - return isDirectlyDerivedFrom(hasName(BaseName)) - .matches(Node, Finder, Builder); + const auto M = isDirectlyDerivedFrom(hasName(BaseName)); + + if (const auto *RD = dyn_cast<CXXRecordDecl>(&Node)) + return Matcher<CXXRecordDecl>(M).matches(*RD, Finder, Builder); + + const auto *InterfaceDecl = cast<ObjCInterfaceDecl>(&Node); + return Matcher<ObjCInterfaceDecl>(M).matches(*InterfaceDecl, Finder, Builder); } /// Matches the first method of a class or struct that satisfies \c /// InnerMatcher. Index: cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h =================================================================== --- cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h @@ -971,7 +971,7 @@ virtual ~ASTMatchFinder() = default; - /// Returns true if the given class is directly or indirectly derived + /// Returns true if the given C++ class is directly or indirectly derived /// from a base type matching \c base. /// /// A class is not considered to be derived from itself. @@ -980,6 +980,15 @@ BoundNodesTreeBuilder *Builder, bool Directly) = 0; + /// Returns true if the given Objective-C class is directly or indirectly + /// derived from a base class matching \c base. + /// + /// A class is not considered to be derived from itself. + virtual bool objcClassIsDerivedFrom(const ObjCInterfaceDecl *Declaration, + const Matcher<NamedDecl> &Base, + BoundNodesTreeBuilder *Builder, + bool Directly) = 0; + template <typename T> bool matchesChildOf(const T &Node, const DynTypedMatcher &Matcher, BoundNodesTreeBuilder *Builder, Index: cfe/trunk/lib/ASTMatchers/ASTMatchFinder.cpp =================================================================== --- cfe/trunk/lib/ASTMatchers/ASTMatchFinder.cpp +++ cfe/trunk/lib/ASTMatchers/ASTMatchFinder.cpp @@ -374,6 +374,12 @@ return true; } + bool VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) { + const ObjCInterfaceDecl *InterfaceDecl = CAD->getClassInterface(); + CompatibleAliases[InterfaceDecl].insert(CAD); + return true; + } + bool TraverseDecl(Decl *DeclNode); bool TraverseStmt(Stmt *StmtNode, DataRecursionQueue *Queue = nullptr); bool TraverseType(QualType TypeNode); @@ -433,6 +439,11 @@ BoundNodesTreeBuilder *Builder, bool Directly) override; + bool objcClassIsDerivedFrom(const ObjCInterfaceDecl *Declaration, + const Matcher<NamedDecl> &Base, + BoundNodesTreeBuilder *Builder, + bool Directly) override; + // Implements ASTMatchFinder::matchesChildOf. bool matchesChildOf(const ast_type_traits::DynTypedNode &Node, const DynTypedMatcher &Matcher, @@ -763,6 +774,23 @@ return false; } + bool + objcClassHasMatchingCompatibilityAlias(const ObjCInterfaceDecl *InterfaceDecl, + const Matcher<NamedDecl> &Matcher, + BoundNodesTreeBuilder *Builder) { + auto Aliases = CompatibleAliases.find(InterfaceDecl); + if (Aliases == CompatibleAliases.end()) + return false; + for (const ObjCCompatibleAliasDecl *Alias : Aliases->second) { + BoundNodesTreeBuilder Result(*Builder); + if (Matcher.matches(*Alias, this, &Result)) { + *Builder = std::move(Result); + return true; + } + } + return false; + } + /// Bucket to record map. /// /// Used to get the appropriate bucket for each matcher. @@ -787,6 +815,11 @@ // Maps a canonical type to its TypedefDecls. llvm::DenseMap<const Type*, std::set<const TypedefNameDecl*> > TypeAliases; + // Maps an Objective-C interface to its ObjCCompatibleAliasDecls. + llvm::DenseMap<const ObjCInterfaceDecl *, + llvm::SmallPtrSet<const ObjCCompatibleAliasDecl *, 2>> + CompatibleAliases; + // Maps (matcher, node) -> the match result for memoization. typedef std::map<MatchKey, MemoizedMatchResult> MemoizationMap; MemoizationMap ResultCache; @@ -813,7 +846,7 @@ return nullptr; } -// Returns true if the given class is directly or indirectly derived +// Returns true if the given C++ class is directly or indirectly derived // from a base type with the given name. A class is not considered to be // derived from itself. bool MatchASTVisitor::classIsDerivedFrom(const CXXRecordDecl *Declaration, @@ -850,6 +883,34 @@ return false; } +// Returns true if the given Objective-C class is directly or indirectly +// derived from a matching base class. A class is not considered to be derived +// from itself. +bool MatchASTVisitor::objcClassIsDerivedFrom( + const ObjCInterfaceDecl *Declaration, const Matcher<NamedDecl> &Base, + BoundNodesTreeBuilder *Builder, bool Directly) { + // Check if any of the superclasses of the class match. + for (const ObjCInterfaceDecl *ClassDecl = Declaration->getSuperClass(); + ClassDecl != nullptr; ClassDecl = ClassDecl->getSuperClass()) { + // Check if there are any matching compatibility aliases. + if (objcClassHasMatchingCompatibilityAlias(ClassDecl, Base, Builder)) + return true; + + // Check if there are any matching type aliases. + const Type *TypeNode = ClassDecl->getTypeForDecl(); + if (typeHasMatchingAlias(TypeNode, Base, Builder)) + return true; + + if (Base.matches(*ClassDecl, this, Builder)) + return true; + + if (Directly) + return false; + } + + return false; +} + bool MatchASTVisitor::TraverseDecl(Decl *DeclNode) { if (!DeclNode) { return true; Index: cfe/trunk/unittests/ASTMatchers/Dynamic/RegistryTest.cpp =================================================================== --- cfe/trunk/unittests/ASTMatchers/Dynamic/RegistryTest.cpp +++ cfe/trunk/unittests/ASTMatchers/Dynamic/RegistryTest.cpp @@ -439,7 +439,7 @@ Error.get()).isNull()); EXPECT_EQ("Incorrect type for arg 1. " "(Expected = Matcher<CXXRecordDecl>) != " - "(Actual = Matcher<CXXRecordDecl>&Matcher" + "(Actual = Matcher<CXXRecordDecl|ObjCInterfaceDecl>&Matcher" "<MemberExpr|UnresolvedMemberExpr|CXXDependentScopeMemberExpr>)", Error->toString()); } Index: cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp =================================================================== --- cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp +++ cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp @@ -573,6 +573,111 @@ EXPECT_TRUE(notMatches(Code, cxxRecordDecl(isSameOrDerivedFrom("")))); } +TEST(DeclarationMatcher, ObjCClassIsDerived) { + DeclarationMatcher IsDerivedFromX = objcInterfaceDecl(isDerivedFrom("X")); + EXPECT_TRUE( + matchesObjC("@interface X @end @interface Y : X @end", IsDerivedFromX)); + EXPECT_TRUE(matchesObjC( + "@interface X @end @interface Y<__covariant ObjectType> : X @end", + IsDerivedFromX)); + EXPECT_TRUE(matchesObjC( + "@interface X @end @compatibility_alias Y X; @interface Z : Y @end", + IsDerivedFromX)); + EXPECT_TRUE(matchesObjC( + "@interface X @end typedef X Y; @interface Z : Y @end", IsDerivedFromX)); + EXPECT_TRUE(notMatchesObjC("@interface X @end", IsDerivedFromX)); + EXPECT_TRUE(notMatchesObjC("@class X;", IsDerivedFromX)); + EXPECT_TRUE(notMatchesObjC("@class Y;", IsDerivedFromX)); + EXPECT_TRUE(notMatchesObjC("@interface X @end @compatibility_alias Y X;", + IsDerivedFromX)); + EXPECT_TRUE(notMatchesObjC("@interface X @end typedef X Y;", IsDerivedFromX)); + + DeclarationMatcher IsDirectlyDerivedFromX = + objcInterfaceDecl(isDirectlyDerivedFrom("X")); + EXPECT_TRUE( + matchesObjC("@interface X @end @interface Y : X @end", IsDirectlyDerivedFromX)); + EXPECT_TRUE(matchesObjC( + "@interface X @end @interface Y<__covariant ObjectType> : X @end", + IsDirectlyDerivedFromX)); + EXPECT_TRUE(matchesObjC( + "@interface X @end @compatibility_alias Y X; @interface Z : Y @end", + IsDirectlyDerivedFromX)); + EXPECT_TRUE(matchesObjC( + "@interface X @end typedef X Y; @interface Z : Y @end", + IsDirectlyDerivedFromX)); + EXPECT_TRUE(notMatchesObjC("@interface X @end", IsDirectlyDerivedFromX)); + EXPECT_TRUE(notMatchesObjC("@class X;", IsDirectlyDerivedFromX)); + EXPECT_TRUE(notMatchesObjC("@class Y;", IsDirectlyDerivedFromX)); + EXPECT_TRUE(notMatchesObjC("@interface X @end @compatibility_alias Y X;", + IsDirectlyDerivedFromX)); + EXPECT_TRUE(notMatchesObjC("@interface X @end typedef X Y;", + IsDirectlyDerivedFromX)); + + DeclarationMatcher IsAX = objcInterfaceDecl(isSameOrDerivedFrom("X")); + EXPECT_TRUE(matchesObjC("@interface X @end @interface Y : X @end", IsAX)); + EXPECT_TRUE(matchesObjC("@interface X @end", IsAX)); + EXPECT_TRUE(matchesObjC("@class X;", IsAX)); + EXPECT_TRUE(notMatchesObjC("@interface Y @end", IsAX)); + EXPECT_TRUE(notMatchesObjC("@class Y;", IsAX)); + + DeclarationMatcher ZIsDerivedFromX = + objcInterfaceDecl(hasName("Z"), isDerivedFrom("X")); + DeclarationMatcher ZIsDirectlyDerivedFromX = + objcInterfaceDecl(hasName("Z"), isDirectlyDerivedFrom("X")); + EXPECT_TRUE(matchesObjC( + "@interface X @end @interface Y : X @end @interface Z : Y @end", + ZIsDerivedFromX)); + EXPECT_TRUE(matchesObjC("@interface X @end @interface Y : X @end typedef Y " + "V; typedef V W; @interface Z : W @end", + ZIsDerivedFromX)); + EXPECT_TRUE(matchesObjC( + "@interface X @end typedef X Y; @interface Z : Y @end", ZIsDerivedFromX)); + EXPECT_TRUE(matchesObjC( + "@interface X @end typedef X Y; @interface Z : Y @end", + ZIsDirectlyDerivedFromX)); + EXPECT_TRUE(matchesObjC( + "@interface A @end typedef A X; typedef A Y; @interface Z : Y @end", + ZIsDerivedFromX)); + EXPECT_TRUE(matchesObjC( + "@interface A @end typedef A X; typedef A Y; @interface Z : Y @end", + ZIsDirectlyDerivedFromX)); + EXPECT_TRUE(matchesObjC( + "@interface X @end @compatibility_alias Y X; @interface Z : Y @end", + ZIsDerivedFromX)); + EXPECT_TRUE(matchesObjC( + "@interface X @end @compatibility_alias Y X; @interface Z : Y @end", + ZIsDirectlyDerivedFromX)); + EXPECT_TRUE(matchesObjC( + "@interface Y @end @compatibility_alias X Y; @interface Z : Y @end", + ZIsDerivedFromX)); + EXPECT_TRUE(matchesObjC( + "@interface Y @end @compatibility_alias X Y; @interface Z : Y @end", + ZIsDirectlyDerivedFromX)); + EXPECT_TRUE(matchesObjC( + "@interface A @end @compatibility_alias X A; @compatibility_alias Y A;" + "@interface Z : Y @end", ZIsDerivedFromX)); + EXPECT_TRUE(matchesObjC( + "@interface A @end @compatibility_alias X A; @compatibility_alias Y A;" + "@interface Z : Y @end", ZIsDirectlyDerivedFromX)); + EXPECT_TRUE(matchesObjC( + "@interface Y @end typedef Y X; @interface Z : X @end", ZIsDerivedFromX)); + EXPECT_TRUE(matchesObjC( + "@interface Y @end typedef Y X; @interface Z : X @end", + ZIsDirectlyDerivedFromX)); + EXPECT_TRUE(matchesObjC( + "@interface A @end @compatibility_alias Y A; typedef Y X;" + "@interface Z : A @end", ZIsDerivedFromX)); + EXPECT_TRUE(matchesObjC( + "@interface A @end @compatibility_alias Y A; typedef Y X;" + "@interface Z : A @end", ZIsDirectlyDerivedFromX)); + EXPECT_TRUE(matchesObjC( + "@interface A @end typedef A Y; @compatibility_alias X Y;" + "@interface Z : A @end", ZIsDerivedFromX)); + EXPECT_TRUE(matchesObjC( + "@interface A @end typedef A Y; @compatibility_alias X Y;" + "@interface Z : A @end", ZIsDirectlyDerivedFromX)); +} + TEST(DeclarationMatcher, IsLambda) { const auto IsLambda = cxxMethodDecl(ofClass(cxxRecordDecl(isLambda()))); EXPECT_TRUE(matches("auto x = []{};", IsLambda)); Index: cfe/trunk/docs/LibASTMatchersReference.html =================================================================== --- cfe/trunk/docs/LibASTMatchersReference.html +++ cfe/trunk/docs/LibASTMatchersReference.html @@ -2576,13 +2576,13 @@ </pre></td></tr> -<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>></td><td class="name" onclick="toggle('isDerivedFrom1')"><a name="isDerivedFrom1Anchor">isDerivedFrom</a></td><td>std::string BaseName</td></tr> -<tr><td colspan="4" class="doc" id="isDerivedFrom1"><pre>Overloaded method as shortcut for isDerivedFrom(hasName(...)). +<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>></td><td class="name" onclick="toggle('isDerivedFrom2')"><a name="isDerivedFrom2Anchor">isDerivedFrom</a></td><td>std::string BaseName</td></tr> +<tr><td colspan="4" class="doc" id="isDerivedFrom2"><pre>Overloaded method as shortcut for isDerivedFrom(hasName(...)). </pre></td></tr> -<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>></td><td class="name" onclick="toggle('isDirectlyDerivedFrom1')"><a name="isDirectlyDerivedFrom1Anchor">isDirectlyDerivedFrom</a></td><td>std::string BaseName</td></tr> -<tr><td colspan="4" class="doc" id="isDirectlyDerivedFrom1"><pre>Overloaded method as shortcut for isDirectlyDerivedFrom(hasName(...)). +<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>></td><td class="name" onclick="toggle('isDirectlyDerivedFrom2')"><a name="isDirectlyDerivedFrom2Anchor">isDirectlyDerivedFrom</a></td><td>std::string BaseName</td></tr> +<tr><td colspan="4" class="doc" id="isDirectlyDerivedFrom2"><pre>Overloaded method as shortcut for isDirectlyDerivedFrom(hasName(...)). </pre></td></tr> @@ -2628,8 +2628,8 @@ </pre></td></tr> -<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>></td><td class="name" onclick="toggle('isSameOrDerivedFrom1')"><a name="isSameOrDerivedFrom1Anchor">isSameOrDerivedFrom</a></td><td>std::string BaseName</td></tr> -<tr><td colspan="4" class="doc" id="isSameOrDerivedFrom1"><pre>Overloaded method as shortcut for +<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>></td><td class="name" onclick="toggle('isSameOrDerivedFrom2')"><a name="isSameOrDerivedFrom2Anchor">isSameOrDerivedFrom</a></td><td>std::string BaseName</td></tr> +<tr><td colspan="4" class="doc" id="isSameOrDerivedFrom2"><pre>Overloaded method as shortcut for isSameOrDerivedFrom(hasName(...)). </pre></td></tr> @@ -3593,6 +3593,22 @@ </pre></td></tr> +<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCInterfaceDecl.html">ObjCInterfaceDecl</a>></td><td class="name" onclick="toggle('isDerivedFrom3')"><a name="isDerivedFrom3Anchor">isDerivedFrom</a></td><td>std::string BaseName</td></tr> +<tr><td colspan="4" class="doc" id="isDerivedFrom3"><pre>Overloaded method as shortcut for isDerivedFrom(hasName(...)). +</pre></td></tr> + + +<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCInterfaceDecl.html">ObjCInterfaceDecl</a>></td><td class="name" onclick="toggle('isDirectlyDerivedFrom3')"><a name="isDirectlyDerivedFrom3Anchor">isDirectlyDerivedFrom</a></td><td>std::string BaseName</td></tr> +<tr><td colspan="4" class="doc" id="isDirectlyDerivedFrom3"><pre>Overloaded method as shortcut for isDirectlyDerivedFrom(hasName(...)). +</pre></td></tr> + + +<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCInterfaceDecl.html">ObjCInterfaceDecl</a>></td><td class="name" onclick="toggle('isSameOrDerivedFrom3')"><a name="isSameOrDerivedFrom3Anchor">isSameOrDerivedFrom</a></td><td>std::string BaseName</td></tr> +<tr><td colspan="4" class="doc" id="isSameOrDerivedFrom3"><pre>Overloaded method as shortcut for +isSameOrDerivedFrom(hasName(...)). +</pre></td></tr> + + <tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMessageExpr.html">ObjCMessageExpr</a>></td><td class="name" onclick="toggle('argumentCountIs2')"><a name="argumentCountIs2Anchor">argumentCountIs</a></td><td>unsigned N</td></tr> <tr><td colspan="4" class="doc" id="argumentCountIs2"><pre>Checks that a call expression or a constructor call expression has a specific number of arguments (including absent default arguments). @@ -5248,8 +5264,9 @@ <tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>></td><td class="name" onclick="toggle('isDerivedFrom0')"><a name="isDerivedFrom0Anchor">isDerivedFrom</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html">NamedDecl</a>> Base</td></tr> -<tr><td colspan="4" class="doc" id="isDerivedFrom0"><pre>Matches C++ classes that are directly or indirectly derived from -a class matching Base. +<tr><td colspan="4" class="doc" id="isDerivedFrom0"><pre>Matches C++ classes that are directly or indirectly derived from a class +matching Base, or Objective-C classes that directly or indirectly +subclass a class matching Base. Note that a class is not considered to be derived from itself. @@ -5265,11 +5282,18 @@ class Foo; typedef Foo X; class Bar : public Foo {}; // derived from a type that X is a typedef of + +In the following example, Bar matches isDerivedFrom(hasName("NSObject")) + @interface NSObject @end + @interface Bar : NSObject @end + +Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCInterfaceDecl.html">ObjCInterfaceDecl</a>> </pre></td></tr> <tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>></td><td class="name" onclick="toggle('isDirectlyDerivedFrom0')"><a name="isDirectlyDerivedFrom0Anchor">isDirectlyDerivedFrom</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html">NamedDecl</a>> Base</td></tr> -<tr><td colspan="4" class="doc" id="isDirectlyDerivedFrom0"><pre>Matches C++ classes that are directly derived from a class matching Base. +<tr><td colspan="4" class="doc" id="isDirectlyDerivedFrom0"><pre>Matches C++ or Objective-C classes that are directly derived from a class +matching Base. Note that a class is not considered to be derived from itself. @@ -6468,6 +6492,61 @@ </pre></td></tr> +<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCInterfaceDecl.html">ObjCInterfaceDecl</a>></td><td class="name" onclick="toggle('isDerivedFrom1')"><a name="isDerivedFrom1Anchor">isDerivedFrom</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html">NamedDecl</a>> Base</td></tr> +<tr><td colspan="4" class="doc" id="isDerivedFrom1"><pre>Matches C++ classes that are directly or indirectly derived from a class +matching Base, or Objective-C classes that directly or indirectly +subclass a class matching Base. + +Note that a class is not considered to be derived from itself. + +Example matches Y, Z, C (Base == hasName("X")) + class X; + class Y : public X {}; // directly derived + class Z : public Y {}; // indirectly derived + typedef X A; + typedef A B; + class C : public B {}; // derived from a typedef of X + +In the following example, Bar matches isDerivedFrom(hasName("X")): + class Foo; + typedef Foo X; + class Bar : public Foo {}; // derived from a type that X is a typedef of + +In the following example, Bar matches isDerivedFrom(hasName("NSObject")) + @interface NSObject @end + @interface Bar : NSObject @end + +Usable as: Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>>, Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCInterfaceDecl.html">ObjCInterfaceDecl</a>> +</pre></td></tr> + + +<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCInterfaceDecl.html">ObjCInterfaceDecl</a>></td><td class="name" onclick="toggle('isDirectlyDerivedFrom1')"><a name="isDirectlyDerivedFrom1Anchor">isDirectlyDerivedFrom</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html">NamedDecl</a>> Base</td></tr> +<tr><td colspan="4" class="doc" id="isDirectlyDerivedFrom1"><pre>Matches C++ or Objective-C classes that are directly derived from a class +matching Base. + +Note that a class is not considered to be derived from itself. + +Example matches Y, C (Base == hasName("X")) + class X; + class Y : public X {}; // directly derived + class Z : public Y {}; // indirectly derived + typedef X A; + typedef A B; + class C : public B {}; // derived from a typedef of X + +In the following example, Bar matches isDerivedFrom(hasName("X")): + class Foo; + typedef Foo X; + class Bar : public Foo {}; // derived from a type that X is a typedef of +</pre></td></tr> + + +<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCInterfaceDecl.html">ObjCInterfaceDecl</a>></td><td class="name" onclick="toggle('isSameOrDerivedFrom1')"><a name="isSameOrDerivedFrom1Anchor">isSameOrDerivedFrom</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html">NamedDecl</a>> Base</td></tr> +<tr><td colspan="4" class="doc" id="isSameOrDerivedFrom1"><pre>Similar to isDerivedFrom(), but also matches classes that directly +match Base. +</pre></td></tr> + + <tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1ObjCMessageExpr.html">ObjCMessageExpr</a>></td><td class="name" onclick="toggle('hasAnyArgument3')"><a name="hasAnyArgument3Anchor">hasAnyArgument</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> <tr><td colspan="4" class="doc" id="hasAnyArgument3"><pre>Matches any argument of a call expression or a constructor call expression, or an ObjC-message-send expression.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits