The ivars in an ObjCImplementationDecl are now stored in the
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
diff --git a/include/clang/AST/DeclObjC.h b/include/clang/AST/DeclObjC.h
index 0e1de5e..1672aaa 100644
--- a/include/clang/AST/DeclObjC.h
+++ b/include/clang/AST/DeclObjC.h
@@ -946,9 +946,6 @@
   /// 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 @@
                                         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 @@
   
   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;
diff --git a/lib/AST/DeclObjC.cpp b/lib/AST/DeclObjC.cpp
index 49ff6d5..bcd2e08 100644
--- a/lib/AST/DeclObjC.cpp
+++ b/lib/AST/DeclObjC.cpp
@@ -637,12 +637,6 @@
   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
 //===----------------------------------------------------------------------===//
diff --git a/lib/Frontend/PCHReader.cpp b/lib/Frontend/PCHReader.cpp
index 0ad93dc..481f148 100644
--- a/lib/Frontend/PCHReader.cpp
+++ b/lib/Frontend/PCHReader.cpp
@@ -334,7 +334,8 @@
 
 void PCHDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
   VisitObjCImplDecl(D);
-  // FIXME: Implement.
+  D->setSuperClass(
+              cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
 }
 
 
@@ -2270,7 +2271,7 @@
   }
   
   case pch::DECL_OBJC_IMPLEMENTATION: {
-    // FIXME: Implement.
+    D = ObjCImplementationDecl::Create(Context, 0, SourceLocation(), 0, 0);
     break;
   }
   
diff --git a/lib/Frontend/PCHWriter.cpp b/lib/Frontend/PCHWriter.cpp
index 0a0a38d..6961eb6 100644
--- a/lib/Frontend/PCHWriter.cpp
+++ b/lib/Frontend/PCHWriter.cpp
@@ -506,7 +506,7 @@
 
 void PCHDeclWriter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
   VisitObjCImplDecl(D);
-  // FIXME: Implement.
+  Writer.AddDeclRef(D->getSuperClass(), Record);
   Code = pch::DECL_OBJC_IMPLEMENTATION;
 }
 
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 040c546..c7a45dc 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -3952,7 +3952,12 @@
     } 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);
     }
   }
diff --git a/tools/clang-cc/RewriteObjC.cpp b/tools/clang-cc/RewriteObjC.cpp
index f31e5cc..5b8fd52 100644
--- a/tools/clang-cc/RewriteObjC.cpp
+++ b/tools/clang-cc/RewriteObjC.cpp
@@ -3185,8 +3185,8 @@
   }
   
   // 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 @@
     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();