]> granicus.if.org Git - clang/commitdiff
simplify the interface for creating ObjcForwardProtocolDecl
authorChris Lattner <sabre@nondot.org>
Sat, 6 Oct 2007 20:05:59 +0000 (20:05 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 6 Oct 2007 20:05:59 +0000 (20:05 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42705 91177308-0d34-0410-b5e6-96231b3b80d8

Sema/SemaDecl.cpp
include/clang/AST/DeclObjC.h
include/clang/AST/Type.h

index 8f743789e841038652ba8573db3da178f399f09c..5916f4cccbed06624f11e63dc9499e8b109e32a6 100644 (file)
@@ -1036,13 +1036,12 @@ Sema::ActOnFindProtocolDeclaration(Scope *S,
 Action::DeclTy *
 Sema::ActOnForwardProtocolDeclaration(Scope *S, SourceLocation AtProtocolLoc,
         IdentifierInfo **IdentList, unsigned NumElts) {
-  ObjcForwardProtocolDecl *FDecl = new ObjcForwardProtocolDecl(AtProtocolLoc, 
-                                                               NumElts);
+  llvm::SmallVector<ObjcProtocolDecl*, 32> Protocols;
   
   for (unsigned i = 0; i != NumElts; ++i) {
-    ObjcProtocolDecl *PDecl;
-    PDecl = getObjCProtocolDecl(S, IdentList[i], AtProtocolLoc);
-    if (!PDecl)  {// Already seen?
+    ObjcProtocolDecl *PDecl = getObjCProtocolDecl(S, IdentList[i],
+                                                  AtProtocolLoc);
+    if (!PDecl)  { // Already seen?
       PDecl = new ObjcProtocolDecl(SourceLocation(), 0, IdentList[i], true);
       // Chain & install the protocol decl into the identifier.
       PDecl->setNext(IdentList[i]->getFETokenInfo<ScopedDecl>());
@@ -1051,9 +1050,10 @@ Sema::ActOnForwardProtocolDeclaration(Scope *S, SourceLocation AtProtocolLoc,
     // Remember that this needs to be removed when the scope is popped.
     S->AddDecl(IdentList[i]);
     
-    FDecl->setForwardProtocolDecl((int)i, PDecl);
+    Protocols.push_back(PDecl);
   }
-  return FDecl;
+  return new ObjcForwardProtocolDecl(AtProtocolLoc,
+                                     &Protocols[0], Protocols.size());
 }
 
 Sema::DeclTy *Sema::ActOnStartCategoryInterface(Scope* S,
index 0d1bc7fb6d08f03c1a45ac166a9c61418df7d069..0f4e8d76b50dd46717e9538e7e95f469c169f254 100644 (file)
@@ -381,12 +381,13 @@ class ObjcForwardProtocolDecl : public TypeDecl {
   ObjcProtocolDecl **ReferencedProtocols;
   unsigned NumReferencedProtocols;
 public:
-  ObjcForwardProtocolDecl(SourceLocation L, unsigned nElts)
+  ObjcForwardProtocolDecl(SourceLocation L, 
+                          ObjcProtocolDecl **Elts, unsigned nElts)
   : TypeDecl(ObjcForwardProtocol, L, 0, 0) { 
+    NumReferencedProtocols = nElts;
     if (nElts) {
       ReferencedProtocols = new ObjcProtocolDecl*[nElts];
-      memset(ReferencedProtocols, '\0', nElts*sizeof(ObjcProtocolDecl*));
-      NumReferencedProtocols = nElts;
+      memcpy(ReferencedProtocols, Elts, nElts*sizeof(ObjcProtocolDecl*));
     } else {
       ReferencedProtocols = 0;
     }
@@ -407,7 +408,6 @@ public:
     return ReferencedProtocols[idx];
   }
   
-  
   static bool classof(const Decl *D) {
     return D->getKind() == ObjcForwardProtocol;
   }
index 7abc62e0ecfefbb40691060f15ab6770c7c41f0f..f2c49473123b4f65a95a6046b8883fbb8ca1b54a 100644 (file)
@@ -326,7 +326,6 @@ private:
   friend class QualType;
 public:
   virtual void getAsStringInternal(std::string &InnerString) const = 0;
-  
   static bool classof(const Type *) { return true; }
 };