]> granicus.if.org Git - clang/commitdiff
simplify the interface to create ObjcClassDecl's.
authorChris Lattner <sabre@nondot.org>
Sat, 6 Oct 2007 20:08:36 +0000 (20:08 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 6 Oct 2007 20:08:36 +0000 (20:08 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42706 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 5916f4cccbed06624f11e63dc9499e8b109e32a6..71ba023dcf081604807b8e12e659db79c57058db 100644 (file)
@@ -1372,12 +1372,11 @@ Action::DeclTy *
 Sema::ActOnForwardClassDeclaration(Scope *S, SourceLocation AtClassLoc,
                                    IdentifierInfo **IdentList, unsigned NumElts) 
 {
-  ObjcClassDecl *CDecl = new ObjcClassDecl(AtClassLoc, NumElts);
-
+  llvm::SmallVector<ObjcInterfaceDecl*, 32> Interfaces;
+  
   for (unsigned i = 0; i != NumElts; ++i) {
-    ObjcInterfaceDecl *IDecl;
-    IDecl = getObjCInterfaceDecl(IdentList[i]); 
-    if (!IDecl)  {// Already seen?
+    ObjcInterfaceDecl *IDecl = getObjCInterfaceDecl(IdentList[i]); 
+    if (!IDecl) {  // Not already seen?  Make a forward decl.
       IDecl = new ObjcInterfaceDecl(SourceLocation(), 0, IdentList[i], true);
       // Chain & install the interface decl into the identifier.
       IDecl->setNext(IdentList[i]->getFETokenInfo<ScopedDecl>());
@@ -1385,10 +1384,11 @@ Sema::ActOnForwardClassDeclaration(Scope *S, SourceLocation AtClassLoc,
     }
     // Remember that this needs to be removed when the scope is popped.
     S->AddDecl(IdentList[i]);
-    
-    CDecl->setInterfaceDecl((int)i, IDecl);
+
+    Interfaces.push_back(IDecl);
   }
-  return CDecl;
+  
+  return new ObjcClassDecl(AtClassLoc, &Interfaces[0], Interfaces.size());
 }
 
 
index 0f4e8d76b50dd46717e9538e7e95f469c169f254..17b7adc00a39491b62b9fa3f8847dbee6648b909 100644 (file)
@@ -351,19 +351,21 @@ public:
 /// @class NSCursor, NSImage, NSPasteboard, NSWindow;
 ///
 class ObjcClassDecl : public TypeDecl {
-  ObjcInterfaceDecl **ForwardDecls;   // Null if not defined.
-  int NumForwardDecls;               // -1 if not defined.
+  ObjcInterfaceDecl **ForwardDecls;
+  unsigned NumForwardDecls;
 public:
-  ObjcClassDecl(SourceLocation L, unsigned nElts)
+  ObjcClassDecl(SourceLocation L, ObjcInterfaceDecl **Elts, unsigned nElts)
     : TypeDecl(ObjcClass, L, 0, 0) { 
     if (nElts) {
       ForwardDecls = new ObjcInterfaceDecl*[nElts];
-      memset(ForwardDecls, '\0', nElts*sizeof(ObjcInterfaceDecl*));
+      memcpy(ForwardDecls, Elts, nElts*sizeof(ObjcInterfaceDecl*));
+    } else {
+      ForwardDecls = 0;
     }
     NumForwardDecls = nElts;
   }
-  void setInterfaceDecl(int idx, ObjcInterfaceDecl *OID) {
-    assert((idx < NumForwardDecls) && "index out of range");
+  void setInterfaceDecl(unsigned idx, ObjcInterfaceDecl *OID) {
+    assert(idx < NumForwardDecls && "index out of range");
     ForwardDecls[idx] = OID;
   }
   static bool classof(const Decl *D) {