[PATCH] D60543: [clang] Update isDerivedFrom to support Objective-C classes 🔍

Stephane Moore via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 7 17:12:36 PDT 2019


stephanemoore added a comment.

I spent some time becoming familiar with how `isDerivedFrom` behaves for C++ classes. I //think// that I have managed to get the behavior for Objective-C classes to mirror that of C++ classes. Please let me know if I overlooked anything.



================
Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:2642-2649
+  if (const auto *InterfaceDecl = dyn_cast<ObjCInterfaceDecl>(&Node)) {
+    // Check if any of the superclasses of the class match.
+    for (const ObjCInterfaceDecl *SuperClass = InterfaceDecl->getSuperClass();
+         SuperClass != nullptr; SuperClass = SuperClass->getSuperClass()) {
+      if (Base.matches(*SuperClass, Finder, Builder))
+        return true;
+    }
----------------
stephanemoore wrote:
> aaron.ballman wrote:
> > This should probably be done similar to how `classIsDerivedFrom()` works. For instance, there's some type alias matching logic that this does not replicate, but we probably want.
> Upon first glance I had determined that the type aliasing logic in `classIsDerivedFrom()` was particular to C++. On second consideration, we will probably want to make sure that compatibility aliases are handled correctly for Objective-C. I will take a look into making sure that works as expected.
Done.


================
Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:2667-2672
+  if (const auto *InterfaceDecl = dyn_cast<ObjCInterfaceDecl>(&Node)) {
+    return Matcher<ObjCInterfaceDecl>(M).matches(*InterfaceDecl, Finder,
+                                                 Builder);
+  }
+
+  llvm_unreachable("Not a valid polymorphic type");
----------------
aaron.ballman wrote:
> How about:
> ```
> const auto *InterfaceDecl = cast<ObjCInterfaceDecl>(&Node);
> return Matcher...
> ```
> We can rely on `cast<>` to assert if the node is of an unexpected type. Same suggestions below.
Good call. Done.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60543/new/

https://reviews.llvm.org/D60543





More information about the cfe-commits mailing list