From: Argyrios Kyrtzidis Date: Tue, 13 Mar 2012 01:09:41 +0000 (+0000) Subject: [Sema] Prefer to use ObjCInterfaceDecl's protocol_begin()/protocol_end() iterators... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a5f4441de7890953460d95f4e88b9fa432b48dc2;p=clang [Sema] Prefer to use ObjCInterfaceDecl's protocol_begin()/protocol_end() iterators instead of ObjCInterfaceDecl::getReferencedProtocols(), because the iterators are safe to use even if the caller did not check that the interface is a definition. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152597 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/DeclObjC.h b/include/clang/AST/DeclObjC.h index 6aad5d0823..37a2e9ff8b 100644 --- a/include/clang/AST/DeclObjC.h +++ b/include/clang/AST/DeclObjC.h @@ -651,6 +651,7 @@ public: void setExternallyCompleted(); const ObjCProtocolList &getReferencedProtocols() const { + assert(hasDefinition() && "Caller did not check for forward reference!"); if (data().ExternallyCompleted) LoadExternalDefinition(); diff --git a/lib/AST/DeclObjC.cpp b/lib/AST/DeclObjC.cpp index 3d1fc84660..a92c624b4c 100644 --- a/lib/AST/DeclObjC.cpp +++ b/lib/AST/DeclObjC.cpp @@ -334,10 +334,9 @@ ObjCMethodDecl *ObjCInterfaceDecl::lookupMethod(Selector Sel, return MethodDecl; // Didn't find one yet - look through protocols. - const ObjCList &Protocols = - ClassDecl->getReferencedProtocols(); - for (ObjCList::iterator I = Protocols.begin(), - E = Protocols.end(); I != E; ++I) + for (ObjCInterfaceDecl::protocol_iterator I = ClassDecl->protocol_begin(), + E = ClassDecl->protocol_end(); + I != E; ++I) if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance))) return MethodDecl; if (!noCategoryLookup) { @@ -850,11 +849,8 @@ bool ObjCInterfaceDecl::ClassImplementsProtocol(ObjCProtocolDecl *lProto, ObjCInterfaceDecl *IDecl = this; // 1st, look up the class. - const ObjCList &Protocols = - IDecl->getReferencedProtocols(); - - for (ObjCList::iterator PI = Protocols.begin(), - E = Protocols.end(); PI != E; ++PI) { + for (ObjCInterfaceDecl::protocol_iterator + PI = IDecl->protocol_begin(), E = IDecl->protocol_end(); PI != E; ++PI){ if (getASTContext().ProtocolCompatibleWithProtocol(lProto, *PI)) return true; // This is dubious and is added to be compatible with gcc. In gcc, it is diff --git a/lib/CodeGen/CGObjCGNU.cpp b/lib/CodeGen/CGObjCGNU.cpp index 3e5c4a2a93..4dedc9de28 100644 --- a/lib/CodeGen/CGObjCGNU.cpp +++ b/lib/CodeGen/CGObjCGNU.cpp @@ -2070,9 +2070,9 @@ void CGObjCGNU::GenerateClass(const ObjCImplementationDecl *OID) { } // Collect the names of referenced protocols SmallVector Protocols; - const ObjCList &Protos =ClassDecl->getReferencedProtocols(); - for (ObjCList::iterator I = Protos.begin(), - E = Protos.end(); I != E; ++I) + for (ObjCInterfaceDecl::protocol_iterator + I = ClassDecl->protocol_begin(), + E = ClassDecl->protocol_end(); I != E; ++I) Protocols.push_back((*I)->getNameAsString()); diff --git a/lib/Rewrite/RewriteModernObjC.cpp b/lib/Rewrite/RewriteModernObjC.cpp index 2023f18691..786139c035 100644 --- a/lib/Rewrite/RewriteModernObjC.cpp +++ b/lib/Rewrite/RewriteModernObjC.cpp @@ -6283,10 +6283,10 @@ void RewriteModernObjC::RewriteObjCCategoryImplDecl(ObjCCategoryImplDecl *IDecl, // Protocols referenced in class declaration? // Protocol's super protocol list std::vector RefedProtocols; - const ObjCList &Protocols = CDecl->getReferencedProtocols(); - for (ObjCList::iterator I = Protocols.begin(), - E = Protocols.end(); - I != E; ++I) { + for (ObjCInterfaceDecl::protocol_iterator I = CDecl->protocol_begin(), + E = CDecl->protocol_end(); + + I != E; ++I) { RefedProtocols.push_back(*I); // Must write out all protocol definitions in current qualifier list, // and in their nested qualifiers before writing out current definition. diff --git a/lib/Sema/SemaCodeComplete.cpp b/lib/Sema/SemaCodeComplete.cpp index 21a5cfa79d..7ee2bcba82 100644 --- a/lib/Sema/SemaCodeComplete.cpp +++ b/lib/Sema/SemaCodeComplete.cpp @@ -4708,9 +4708,8 @@ static void AddObjCMethods(ObjCContainerDecl *Container, return; // Add methods in protocols. - const ObjCList &Protocols= IFace->getReferencedProtocols(); - for (ObjCList::iterator I = Protocols.begin(), - E = Protocols.end(); + for (ObjCInterfaceDecl::protocol_iterator I = IFace->protocol_begin(), + E = IFace->protocol_end(); I != E; ++I) AddObjCMethods(*I, WantInstanceMethods, WantKind, SelIdents, NumSelIdents, CurContext, Selectors, AllowSameLength, Results, false);