[cfe-commits] r76333 - in /cfe/trunk: include/clang/AST/RecordLayout.h lib/AST/RecordLayoutBuilder.cpp lib/AST/RecordLayoutBuilder.h

Anders Carlsson andersca at mac.com
Sat Jul 18 13:51:35 PDT 2009


Author: andersca
Date: Sat Jul 18 15:50:59 2009
New Revision: 76333

URL: http://llvm.org/viewvc/llvm-project?rev=76333&view=rev
Log:
More layout builder work.

Modified:
    cfe/trunk/include/clang/AST/RecordLayout.h
    cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
    cfe/trunk/lib/AST/RecordLayoutBuilder.h

Modified: cfe/trunk/include/clang/AST/RecordLayout.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecordLayout.h?rev=76333&r1=76332&r2=76333&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/RecordLayout.h (original)
+++ cfe/trunk/include/clang/AST/RecordLayout.h Sat Jul 18 15:50:59 2009
@@ -44,8 +44,10 @@
   }
 
   ASTRecordLayout(uint64_t Size, unsigned Alignment,
+                  unsigned nextoffset,
                   const uint64_t *fieldoffsets, unsigned fieldcount) 
-  : Size(Size), FieldOffsets(0), Alignment(Alignment), FieldCount(fieldcount) {
+  : Size(Size), NextOffset(nextoffset), FieldOffsets(0), Alignment(Alignment), 
+    FieldCount(fieldcount) {
     if (FieldCount > 0)  {
       FieldOffsets = new uint64_t[FieldCount];
       for (unsigned i = 0; i < FieldCount; ++i)

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

==============================================================================
--- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Sat Jul 18 15:50:59 2009
@@ -11,6 +11,7 @@
 
 #include "clang/AST/Attr.h"
 #include "clang/AST/Decl.h"
+#include "clang/AST/DeclObjC.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/RecordLayout.h"
 #include "clang/Basic/TargetInfo.h"
@@ -42,6 +43,36 @@
   FinishLayout();
 }
 
+void ASTRecordLayoutBuilder::Layout(const ObjCInterfaceDecl *D,
+                                    const ObjCImplementationDecl *Impl) {
+  if (ObjCInterfaceDecl *SD = D->getSuperClass()) {
+    const ASTRecordLayout &SL = Ctx.getASTObjCInterfaceLayout(SD);
+
+    UpdateAlignment(SL.getAlignment());
+    
+    // We start laying out ivars not at the end of the superclass
+    // structure, but at the next byte following the last field.
+    Size = llvm::RoundUpToAlignment(SL.NextOffset, 8);
+    NextOffset = Size;
+  }
+  
+  if (const PackedAttr *PA = D->getAttr<PackedAttr>())
+    StructPacking = PA->getAlignment();
+  
+  if (const AlignedAttr *AA = D->getAttr<AlignedAttr>())
+    UpdateAlignment(AA->getAlignment());
+  
+  // Layout each ivar sequentially.
+  llvm::SmallVector<ObjCIvarDecl*, 16> Ivars;
+  Ctx.ShallowCollectObjCIvars(D, Ivars, Impl);
+  for (unsigned i = 0, e = Ivars.size(); i != e; ++i)
+    LayoutField(Ivars[i]);
+  
+  // Finally, round the size of the total struct up to the alignment of the
+  // struct itself.
+  FinishLayout();
+}
+
 void ASTRecordLayoutBuilder::LayoutField(const FieldDecl *D) {
   unsigned FieldPacking = StructPacking;
   uint64_t FieldOffset = IsUnion ? 0 : Size;
@@ -157,6 +188,21 @@
   Builder.Layout(D);
 
   return new ASTRecordLayout(Builder.Size, Builder.Alignment,
+                             Builder.NextOffset,
+                             Builder.FieldOffsets.data(), 
+                             Builder.FieldOffsets.size());
+}
+
+const ASTRecordLayout *
+ASTRecordLayoutBuilder::ComputeLayout(ASTContext &Ctx,
+                                      const ObjCInterfaceDecl *D,
+                                      const ObjCImplementationDecl *Impl) {
+  ASTRecordLayoutBuilder Builder(Ctx);
+  
+  Builder.Layout(D, Impl);
+  
+  return new ASTRecordLayout(Builder.Size, Builder.Alignment,
+                             Builder.NextOffset,
                              Builder.FieldOffsets.data(), 
                              Builder.FieldOffsets.size());
 }

Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.h?rev=76333&r1=76332&r2=76333&view=diff

==============================================================================
--- cfe/trunk/lib/AST/RecordLayoutBuilder.h (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.h Sat Jul 18 15:50:59 2009
@@ -16,6 +16,8 @@
   class ASTContext;
   class ASTRecordLayout;
   class FieldDecl;
+  class ObjCImplementationDecl;
+  class ObjCInterfaceDecl;
   class RecordDecl;
   
 class ASTRecordLayoutBuilder {
@@ -32,6 +34,9 @@
   ASTRecordLayoutBuilder(ASTContext &Ctx);
   
   void Layout(const RecordDecl *D);
+  void Layout(const ObjCInterfaceDecl *D,
+              const ObjCImplementationDecl *Impl);
+
   void LayoutField(const FieldDecl *D);
   void FinishLayout();
   
@@ -42,7 +47,9 @@
 public:
   static const ASTRecordLayout *ComputeLayout(ASTContext &Ctx, 
                                               const RecordDecl *RD);
-  
+  static const ASTRecordLayout *ComputeLayout(ASTContext &Ctx,
+                                              const ObjCInterfaceDecl *D,
+                                            const ObjCImplementationDecl *Impl);
 };
   
 } // end namespace clang





More information about the cfe-commits mailing list