[PATCH] D62035: [AST] const-ify ObjC inherited class search

Brian Gesiak via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu May 16 14:47:32 PDT 2019


modocache created this revision.
modocache added a reviewer: rjmccall.
Herald added a project: clang.

When writing an AST matcher to find inherited Objective-C classes, I
noticed the returned `ObjCInterfaceDecl*` was mutable. It doesn't seem
like it needs to be mutable, so this patch makes it const.

Patch by Adam Ernst.


Repository:
  rC Clang

https://reviews.llvm.org/D62035

Files:
  include/clang/AST/DeclObjC.h
  lib/AST/DeclObjC.cpp
  lib/Sema/SemaDeclObjC.cpp


Index: lib/Sema/SemaDeclObjC.cpp
===================================================================
--- lib/Sema/SemaDeclObjC.cpp
+++ lib/Sema/SemaDeclObjC.cpp
@@ -2685,7 +2685,7 @@
   assert (IDecl && "CheckProtocolMethodDefs - IDecl is null");
 
   ObjCInterfaceDecl *Super = IDecl->getSuperClass();
-  ObjCInterfaceDecl *NSIDecl = nullptr;
+  const ObjCInterfaceDecl *NSIDecl = nullptr;
 
   // If this protocol is marked 'objc_protocol_requires_explicit_implementation'
   // then we should check if any class in the super class hierarchy also
Index: lib/AST/DeclObjC.cpp
===================================================================
--- lib/AST/DeclObjC.cpp
+++ lib/AST/DeclObjC.cpp
@@ -646,10 +646,10 @@
 }
 
 /// lookupInheritedClass - This method returns ObjCInterfaceDecl * of the super
-/// class whose name is passed as argument. If it is not one of the super classes
-/// the it returns NULL.
-ObjCInterfaceDecl *ObjCInterfaceDecl::lookupInheritedClass(
-                                        const IdentifierInfo*ICName) {
+/// class whose name is passed as argument. If it is not one of the super
+/// classes then it returns NULL.
+const ObjCInterfaceDecl *
+ObjCInterfaceDecl::lookupInheritedClass(const IdentifierInfo *ICName) const {
   // FIXME: Should make sure no callers ever do this.
   if (!hasDefinition())
     return nullptr;
@@ -657,7 +657,7 @@
   if (data().ExternallyCompleted)
     LoadExternalDefinition();
 
-  ObjCInterfaceDecl* ClassDecl = this;
+  auto *ClassDecl = this;
   while (ClassDecl != nullptr) {
     if (ClassDecl->getIdentifier() == ICName)
       return ClassDecl;
Index: include/clang/AST/DeclObjC.h
===================================================================
--- include/clang/AST/DeclObjC.h
+++ include/clang/AST/DeclObjC.h
@@ -1852,7 +1852,8 @@
     return lookupMethod(Sel, false/*isInstance*/);
   }
 
-  ObjCInterfaceDecl *lookupInheritedClass(const IdentifierInfo *ICName);
+  const ObjCInterfaceDecl *
+  lookupInheritedClass(const IdentifierInfo *ICName) const;
 
   /// Lookup a method in the classes implementation hierarchy.
   ObjCMethodDecl *lookupPrivateMethod(const Selector &Sel,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62035.199911.patch
Type: text/x-patch
Size: 2164 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190516/d45644bc/attachment.bin>


More information about the cfe-commits mailing list