Author: mattd Date: Mon Apr 22 09:04:44 2019 New Revision: 358898 URL: http://llvm.org/viewvc/llvm-project?rev=358898&view=rev Log: [sema][objc] Minor refactor to OverrideSearch. NFCI.
Summary: * Removed a member that was only used during construction. * Use range-based for iteration when accessing the result of the search. * Require an `ObjCMethodDecl` reference upon construction of an * Constify. Reviewers: rjmccall Reviewed By: rjmccall Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D60850 Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=358898&r1=358897&r2=358898&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original) +++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Mon Apr 22 09:04:44 2019 @@ -4166,13 +4166,12 @@ namespace { /// overrides. class OverrideSearch { public: - Sema &S; - ObjCMethodDecl *Method; + const ObjCMethodDecl *Method; llvm::SmallSetVector<ObjCMethodDecl*, 4> Overridden; bool Recursive; public: - OverrideSearch(Sema &S, ObjCMethodDecl *method) : S(S), Method(method) { + OverrideSearch(Sema &S, const ObjCMethodDecl *method) : Method(method) { Selector selector = method->getSelector(); // Bypass this search if we've never seen an instance/class method @@ -4186,19 +4185,20 @@ public: if (it == S.MethodPool.end()) return; } - ObjCMethodList &list = + const ObjCMethodList &list = method->isInstanceMethod() ? it->second.first : it->second.second; if (!list.getMethod()) return; - ObjCContainerDecl *container + const ObjCContainerDecl *container = cast<ObjCContainerDecl>(method->getDeclContext()); // Prevent the search from reaching this container again. This is // important with categories, which override methods from the // interface and each other. - if (ObjCCategoryDecl *Category = dyn_cast<ObjCCategoryDecl>(container)) { + if (const ObjCCategoryDecl *Category = + dyn_cast<ObjCCategoryDecl>(container)) { searchFromContainer(container); - if (ObjCInterfaceDecl *Interface = Category->getClassInterface()) + if (const ObjCInterfaceDecl *Interface = Category->getClassInterface()) searchFromContainer(Interface); } else { searchFromContainer(container); @@ -4210,7 +4210,7 @@ public: iterator end() const { return Overridden.end(); } private: - void searchFromContainer(ObjCContainerDecl *container) { + void searchFromContainer(const ObjCContainerDecl *container) { if (container->isInvalidDecl()) return; switch (container->getDeclKind()) { @@ -4226,7 +4226,7 @@ private: } } - void searchFrom(ObjCProtocolDecl *protocol) { + void searchFrom(const ObjCProtocolDecl *protocol) { if (!protocol->hasDefinition()) return; @@ -4235,14 +4235,14 @@ private: search(protocol->getReferencedProtocols()); } - void searchFrom(ObjCCategoryDecl *category) { + void searchFrom(const ObjCCategoryDecl *category) { // A method in a category declaration overrides declarations from // the main class and from protocols the category references. // The main class is handled in the constructor. search(category->getReferencedProtocols()); } - void searchFrom(ObjCCategoryImplDecl *impl) { + void searchFrom(const ObjCCategoryImplDecl *impl) { // A method in a category definition that has a category // declaration overrides declarations from the category // declaration. @@ -4252,12 +4252,12 @@ private: search(Interface); // Otherwise it overrides declarations from the class. - } else if (ObjCInterfaceDecl *Interface = impl->getClassInterface()) { + } else if (const auto *Interface = impl->getClassInterface()) { search(Interface); } } - void searchFrom(ObjCInterfaceDecl *iface) { + void searchFrom(const ObjCInterfaceDecl *iface) { // A method in a class declaration overrides declarations from if (!iface->hasDefinition()) return; @@ -4274,20 +4274,19 @@ private: search(iface->getReferencedProtocols()); } - void searchFrom(ObjCImplementationDecl *impl) { + void searchFrom(const ObjCImplementationDecl *impl) { // A method in a class implementation overrides declarations from // the class interface. - if (ObjCInterfaceDecl *Interface = impl->getClassInterface()) + if (const auto *Interface = impl->getClassInterface()) search(Interface); } void search(const ObjCProtocolList &protocols) { - for (ObjCProtocolList::iterator i = protocols.begin(), e = protocols.end(); - i != e; ++i) - search(*i); + for (const auto *Proto : protocols) + search(Proto); } - void search(ObjCContainerDecl *container) { + void search(const ObjCContainerDecl *container) { // Check for a method in this container which matches this selector. ObjCMethodDecl *meth = container->getMethod(Method->getSelector(), Method->isInstanceMethod(), @@ -4313,6 +4312,8 @@ private: void Sema::CheckObjCMethodOverrides(ObjCMethodDecl *ObjCMethod, ObjCInterfaceDecl *CurrentClass, ResultTypeCompatibilityKind RTC) { + if (!ObjCMethod) + return; // Search for overridden methods and merge information down from them. OverrideSearch overrides(*this, ObjCMethod); // Keep track if the method overrides any method in the class's base classes, @@ -4321,10 +4322,7 @@ void Sema::CheckObjCMethodOverrides(ObjC // For this info, a method in an implementation is not considered as // overriding the same method in the interface or its categories. bool hasOverriddenMethodsInBaseOrProtocol = false; - for (OverrideSearch::iterator - i = overrides.begin(), e = overrides.end(); i != e; ++i) { - ObjCMethodDecl *overridden = *i; - + for (ObjCMethodDecl *overridden : overrides) { if (!hasOverriddenMethodsInBaseOrProtocol) { if (isa<ObjCProtocolDecl>(overridden->getDeclContext()) || CurrentClass != overridden->getClassInterface() || @@ -4351,9 +4349,7 @@ void Sema::CheckObjCMethodOverrides(ObjC if (CategCount > 1 || !isa<ObjCCategoryImplDecl>(overridden->getDeclContext())) { OverrideSearch overrides(*this, overridden); - for (OverrideSearch::iterator - OI= overrides.begin(), OE= overrides.end(); OI!=OE; ++OI) { - ObjCMethodDecl *SuperOverridden = *OI; + for (ObjCMethodDecl *SuperOverridden : overrides) { if (isa<ObjCProtocolDecl>(SuperOverridden->getDeclContext()) || CurrentClass != SuperOverridden->getClassInterface()) { hasOverriddenMethodsInBaseOrProtocol = true; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits