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,
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,
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits