[cfe-commits] r70692 - /cfe/trunk/lib/AST/ASTContext.cpp

Daniel Dunbar daniel at zuster.org
Sun May 3 04:16:47 PDT 2009


Author: ddunbar
Date: Sun May  3 06:16:44 2009
New Revision: 70692

URL: http://llvm.org/viewvc/llvm-project?rev=70692&view=rev
Log:
Implement the interface/implementation layout distinction.
 - These routines should now be independent of the Sema state.

 - This is nearly zero functionality change, the distinction only
   matters in the non-fragile ABI, and the consumers that care about
   this distinction should be using getASTObjCImplementationLayout.

Modified:
    cfe/trunk/lib/AST/ASTContext.cpp

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=70692&r1=70691&r2=70692&view=diff

==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Sun May  3 06:16:44 2009
@@ -745,16 +745,29 @@
 ASTContext::getObjCLayout(const ObjCInterfaceDecl *D,
                           const ObjCImplementationDecl *Impl) {
   // Look up this layout, if already laid out, return what we have.
-  const ASTRecordLayout *&Entry = ObjCLayouts[D];
+  const ASTRecordLayout *&Entry = 
+    ObjCLayouts[Impl ? (ObjCContainerDecl*) Impl : (ObjCContainerDecl*) D];
   if (Entry) return *Entry;
 
+  unsigned FieldCount = D->ivar_size();
+  // Add in synthesized ivar count if laying out an implementation.
+  if (Impl) {
+    for (ObjCInterfaceDecl::prop_iterator I = D->prop_begin(*this),
+           E = D->prop_end(*this); I != E; ++I)
+      if ((*I)->getPropertyIvarDecl())
+        ++FieldCount;
+
+    // If there aren't any sythesized ivar's then reuse the interface
+    // entry. Note we can't cache this because we simply free all
+    // entries later; however we shouldn't look up implementations
+    // frequently.
+    if (FieldCount == D->ivar_size())
+      return getObjCLayout(D, 0);
+  }
+
   // Allocate and assign into ASTRecordLayouts here.  The "Entry" reference can
   // be invalidated (dangle) if the ASTRecordLayouts hashtable is inserted into.
   ASTRecordLayout *NewEntry = NULL;
-  // FIXME. Add actual count of synthesized ivars, instead of count
-  // of properties which is the upper bound, but is safe.
-  unsigned FieldCount = 
-    D->ivar_size() + std::distance(D->prop_begin(*this), D->prop_end(*this));
   if (ObjCInterfaceDecl *SD = D->getSuperClass()) {
     FieldCount++;
     const ASTRecordLayout &SL = getASTObjCInterfaceLayout(SD);
@@ -785,11 +798,13 @@
     const ObjCIvarDecl* Ivar = (*IVI);
     NewEntry->LayoutField(Ivar, i++, false, StructPacking, *this);
   }
-  // Also synthesized ivars
-  for (ObjCInterfaceDecl::prop_iterator I = D->prop_begin(*this),
-       E = D->prop_end(*this); I != E; ++I) {
-    if (ObjCIvarDecl *Ivar = (*I)->getPropertyIvarDecl())
-      NewEntry->LayoutField(Ivar, i++, false, StructPacking, *this);
+  // And synthesized ivars, if this is an implementation.
+  if (Impl) {
+    for (ObjCInterfaceDecl::prop_iterator I = D->prop_begin(*this),
+           E = D->prop_end(*this); I != E; ++I) {
+      if (ObjCIvarDecl *Ivar = (*I)->getPropertyIvarDecl())
+        NewEntry->LayoutField(Ivar, i++, false, StructPacking, *this);
+    }
   }
   
   // Finally, round the size of the total struct up to the alignment of the





More information about the cfe-commits mailing list