]> granicus.if.org Git - clang/commitdiff
[Sema] Prefer to use ObjCInterfaceDecl's protocol_begin()/protocol_end() iterators...
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 13 Mar 2012 01:09:41 +0000 (01:09 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 13 Mar 2012 01:09:41 +0000 (01:09 +0000)
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

include/clang/AST/DeclObjC.h
lib/AST/DeclObjC.cpp
lib/CodeGen/CGObjCGNU.cpp
lib/Rewrite/RewriteModernObjC.cpp
lib/Sema/SemaCodeComplete.cpp

index 6aad5d0823a3e652453cbc0326dbf7746b5d0009..37a2e9ff8bd1a76a854cceb00157e083d2789099 100644 (file)
@@ -651,6 +651,7 @@ public:
   void setExternallyCompleted();
 
   const ObjCProtocolList &getReferencedProtocols() const {
+    assert(hasDefinition() && "Caller did not check for forward reference!");
     if (data().ExternallyCompleted)
       LoadExternalDefinition();
 
index 3d1fc8466008f6079c1a7c0800e162eebfe384db..a92c624b4ca2dd5ea8f29b83b9e088dea955bf3c 100644 (file)
@@ -334,10 +334,9 @@ ObjCMethodDecl *ObjCInterfaceDecl::lookupMethod(Selector Sel,
       return MethodDecl;
 
     // Didn't find one yet - look through protocols.
-    const ObjCList<ObjCProtocolDecl> &Protocols =
-      ClassDecl->getReferencedProtocols();
-    for (ObjCList<ObjCProtocolDecl>::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<ObjCProtocolDecl> &Protocols =
-  IDecl->getReferencedProtocols();
-
-  for (ObjCList<ObjCProtocolDecl>::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
index 3e5c4a2a93a12333e915991469c07510c402dcb3..4dedc9de28f3348b1c407a5ca13501c0a67b1aa4 100644 (file)
@@ -2070,9 +2070,9 @@ void CGObjCGNU::GenerateClass(const ObjCImplementationDecl *OID) {
   }
   // Collect the names of referenced protocols
   SmallVector<std::string, 16> Protocols;
-  const ObjCList<ObjCProtocolDecl> &Protos =ClassDecl->getReferencedProtocols();
-  for (ObjCList<ObjCProtocolDecl>::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());
 
 
index 2023f1869162597900813440e87675cda8e02d3c..786139c0358de851e5778fdfc4adc9621f37ef39 100644 (file)
@@ -6283,10 +6283,10 @@ void RewriteModernObjC::RewriteObjCCategoryImplDecl(ObjCCategoryImplDecl *IDecl,
   // Protocols referenced in class declaration?
   // Protocol's super protocol list
   std::vector<ObjCProtocolDecl *> RefedProtocols;
-  const ObjCList<ObjCProtocolDecl> &Protocols = CDecl->getReferencedProtocols();
-  for (ObjCList<ObjCProtocolDecl>::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.
index 21a5cfa79d1bd3aec46c917d7a596b81d70c8840..7ee2bcba824f494f84dd409f0e5d09801e8dcfa4 100644 (file)
@@ -4708,9 +4708,8 @@ static void AddObjCMethods(ObjCContainerDecl *Container,
     return;
   
   // Add methods in protocols.
-  const ObjCList<ObjCProtocolDecl> &Protocols= IFace->getReferencedProtocols();
-  for (ObjCList<ObjCProtocolDecl>::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);