]> granicus.if.org Git - clang/commitdiff
The ivars in an ObjCImplementationDecl are now stored in the
authorDouglas Gregor <dgregor@apple.com>
Thu, 23 Apr 2009 03:23:08 +0000 (03:23 +0000)
committerDouglas Gregor <dgregor@apple.com>
Thu, 23 Apr 2009 03:23:08 +0000 (03:23 +0000)
DeclContext rather than in a separate list. This makes PCH
(de-)serialization trivial, so that ivars can be loaded lazily.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69857 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/DeclObjC.h
lib/AST/DeclObjC.cpp
lib/Frontend/PCHReader.cpp
lib/Frontend/PCHWriter.cpp
lib/Sema/SemaDecl.cpp
tools/clang-cc/RewriteObjC.cpp

index 0e1de5e8aa5ed1bcb01d11fbb9340ebf538b5614..1672aaa51f7189d3b1ea567194d050d71841e3d9 100644 (file)
@@ -946,9 +946,6 @@ class ObjCImplementationDecl : public ObjCImplDecl {
   /// Implementation Class's super class.
   ObjCInterfaceDecl *SuperClass;
     
-  /// Instance variables declared in the @implementation.
-  ObjCList<ObjCIvarDecl> IVars;
-
   ObjCImplementationDecl(DeclContext *DC, SourceLocation L, 
                          ObjCInterfaceDecl *classInterface,
                          ObjCInterfaceDecl *superDecl)
@@ -960,13 +957,6 @@ public:
                                         ObjCInterfaceDecl *classInterface,
                                         ObjCInterfaceDecl *superDecl);
   
-  /// Destroy - Call destructors and release memory.
-  virtual void Destroy(ASTContext& C);
-
-  void setIVarList(ObjCIvarDecl *const *InArray, unsigned Num, ASTContext &C) {
-    IVars.set(InArray, Num, C);
-  }
-  
   /// getIdentifier - Get the identifier that names the class
   /// interface associated with this implementation.
   IdentifierInfo *getIdentifier() const { 
@@ -991,11 +981,19 @@ public:
   
   void setSuperClass(ObjCInterfaceDecl * superCls) { SuperClass = superCls; }
     
-  typedef ObjCList<ObjCIvarDecl>::iterator ivar_iterator;
-  ivar_iterator ivar_begin() const { return IVars.begin(); }
-  ivar_iterator ivar_end() const { return IVars.end(); }
-  unsigned ivar_size() const { return IVars.size(); }
-  bool ivar_empty() const { return IVars.empty(); }
+  typedef specific_decl_iterator<ObjCIvarDecl> ivar_iterator;
+  ivar_iterator ivar_begin(ASTContext &Context) const { 
+    return ivar_iterator(decls_begin(Context)); 
+  }
+  ivar_iterator ivar_end(ASTContext &Context) const { 
+    return ivar_iterator(decls_end(Context));
+  }
+  unsigned ivar_size(ASTContext &Context) const { 
+    return std::distance(ivar_begin(Context), ivar_end(Context));
+  }
+  bool ivar_empty(ASTContext &Context) const { 
+    return ivar_begin(Context) == ivar_end(Context);
+  }
   
   static bool classof(const Decl *D) {
     return D->getKind() == ObjCImplementation;
index 49ff6d53c00851b0acbe54245078ceac386a3de1..bcd2e08f6d6b48176e98d70fb8bf4d432f7ea4f1 100644 (file)
@@ -637,12 +637,6 @@ ObjCImplementationDecl::Create(ASTContext &C, DeclContext *DC,
   return new (C) ObjCImplementationDecl(DC, L, ClassInterface, SuperDecl);
 }
 
-/// Destroy - Call destructors and release memory.
-void ObjCImplementationDecl::Destroy(ASTContext &C) {
-  IVars.Destroy(C);
-  Decl::Destroy(C);
-}
-
 //===----------------------------------------------------------------------===//
 // ObjCCompatibleAliasDecl
 //===----------------------------------------------------------------------===//
index 0ad93dc65ccd05c45ca0f3168e569cb552928b7c..481f14855cbfdeb5f68af3d71f789b84dd348d1f 100644 (file)
@@ -334,7 +334,8 @@ void PCHDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
 
 void PCHDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
   VisitObjCImplDecl(D);
-  // FIXME: Implement.
+  D->setSuperClass(
+              cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
 }
 
 
@@ -2270,7 +2271,7 @@ Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) {
   }
   
   case pch::DECL_OBJC_IMPLEMENTATION: {
-    // FIXME: Implement.
+    D = ObjCImplementationDecl::Create(Context, 0, SourceLocation(), 0, 0);
     break;
   }
   
index 0a0a38d874013a599cb77eda79a4082ab7a16276..6961eb6a13d76201c0c03b2b0f09e42cb2e94d4e 100644 (file)
@@ -506,7 +506,7 @@ void PCHDeclWriter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
 
 void PCHDeclWriter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
   VisitObjCImplDecl(D);
-  // FIXME: Implement.
+  Writer.AddDeclRef(D->getSuperClass(), Record);
   Code = pch::DECL_OBJC_IMPLEMENTATION;
 }
 
index 040c5467ac589253a56f43cf4d0ae8d17df795f2..c7a45dc9d70cc75129a19874667d9eda854dfead 100644 (file)
@@ -3952,7 +3952,12 @@ void Sema::ActOnFields(Scope* S,
     } else if (ObjCImplementationDecl *IMPDecl = 
                   dyn_cast<ObjCImplementationDecl>(EnclosingDecl)) {
       assert(IMPDecl && "ActOnFields - missing ObjCImplementationDecl");
-      IMPDecl->setIVarList(ClsFields, RecFields.size(), Context);
+      for (unsigned I = 0, N = RecFields.size(); I != N; ++I) {
+        // FIXME: Set the DeclContext correctly when we build the
+        // declarations.
+        ClsFields[I]->setLexicalDeclContext(IMPDecl);
+        IMPDecl->addDecl(Context, ClsFields[I]);
+      }
       CheckImplementationIvars(IMPDecl, ClsFields, RecFields.size(), RBrac);
     }
   }
index f31e5ccf5f9e0e520e0b73725359144fc4b4e256..5b8fd5268cd48315c11e012571d2987c79fb599c 100644 (file)
@@ -3185,8 +3185,8 @@ void RewriteObjC::RewriteObjCClassMetaData(ObjCImplementationDecl *IDecl,
   }
   
   // Build _objc_ivar_list metadata for classes ivars if needed
-  unsigned NumIvars = !IDecl->ivar_empty()
-                      ? IDecl->ivar_size() 
+  unsigned NumIvars = !IDecl->ivar_empty(*Context)
+                      ? IDecl->ivar_size(*Context
                       : (CDecl ? CDecl->ivar_size() : 0);
   if (NumIvars > 0) {
     static bool objc_ivar = false;
@@ -3223,9 +3223,15 @@ void RewriteObjC::RewriteObjCClassMetaData(ObjCImplementationDecl *IDecl,
     Result += "\n";
     
     ObjCInterfaceDecl::ivar_iterator IVI, IVE;
-    if (!IDecl->ivar_empty()) {
-      IVI = IDecl->ivar_begin();
-      IVE = IDecl->ivar_end();
+    llvm::SmallVector<ObjCIvarDecl *, 8> IVars;
+    if (!IDecl->ivar_empty(*Context)) {
+      for (ObjCImplementationDecl::ivar_iterator 
+             IV = IDecl->ivar_begin(*Context),
+             IVEnd = IDecl->ivar_end(*Context);
+           IV != IVEnd; ++IV)
+        IVars.push_back(*IV);
+      IVI = IVars.begin();
+      IVE = IVars.end();
     } else {
       IVI = CDecl->ivar_begin();
       IVE = CDecl->ivar_end();