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

Anders Carlsson andersca at mac.com
Mon Sep 21 17:04:45 PDT 2009


Author: andersca
Date: Mon Sep 21 19:04:45 2009
New Revision: 82502

URL: http://llvm.org/viewvc/llvm-project?rev=82502&view=rev
Log:
Record layout builder cleanup.

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=82502&r1=82501&r2=82502&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/RecordLayout.h (original)
+++ cfe/trunk/include/clang/AST/RecordLayout.h Mon Sep 21 19:04:45 2009
@@ -91,9 +91,10 @@
                   const uint64_t *fieldoffsets, unsigned fieldcount,
                   uint64_t nonvirtualsize, unsigned nonvirtualalign,
                   const CXXRecordDecl *PB, bool PBVirtual,
-                  const CXXRecordDecl **bases, const uint64_t *baseoffsets,
-                  unsigned basecount, const CXXRecordDecl **vbases,
-                  const uint64_t *vbaseoffsets,unsigned vbasecount)
+                  const std::pair<const CXXRecordDecl *, uint64_t> *bases,
+                  unsigned numbases,
+                  const std::pair<const CXXRecordDecl *, uint64_t> *vbases,
+                  unsigned numvbases)
   : Size(size), DataSize(datasize), FieldOffsets(0), Alignment(alignment),
   FieldCount(fieldcount), CXXInfo(new CXXRecordLayoutInfo) {
     if (FieldCount > 0)  {
@@ -106,10 +107,10 @@
     CXXInfo->PrimaryBaseWasVirtual = PBVirtual;
     CXXInfo->NonVirtualSize = nonvirtualsize;
     CXXInfo->NonVirtualAlign = nonvirtualalign;
-    for (unsigned i = 0; i != basecount; ++i)
-      CXXInfo->BaseOffsets[bases[i]] = baseoffsets[i];
-    for (unsigned i = 0; i != vbasecount; ++i)
-      CXXInfo->VBaseOffsets[vbases[i]] = vbaseoffsets[i];
+    for (unsigned i = 0; i != numbases; ++i)
+      CXXInfo->BaseOffsets[bases[i].first] = bases[i].second;
+    for (unsigned i = 0; i != numvbases; ++i)
+      CXXInfo->VBaseOffsets[vbases[i].first] = vbases[i].second;
   }
 
   ~ASTRecordLayout() {

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

==============================================================================
--- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Mon Sep 21 19:04:45 2009
@@ -198,8 +198,7 @@
         // Mark it so we don't lay it out twice.
         mark.insert(Base);
         assert (IndirectPrimary.count(Base) && "IndirectPrimary was wrong");
-        VBases.push_back(Base);
-        VBaseOffsets.push_back(Offset);
+        VBases.push_back(std::make_pair(Base, Offset));
       } else if (IndirectPrimary.count(Base)) {
         // Someone else will eventually lay this out.
         ;
@@ -210,7 +209,7 @@
         // Mark it so we don't lay it out twice.
         mark.insert(Base);
         LayoutVirtualBase(Base);
-        BaseOffset = *(VBaseOffsets.end()-1);
+        BaseOffset = VBases.back().second;
       }
     }
     if (Base->getNumVBases()) {
@@ -236,13 +235,10 @@
   Size = (Size + (BaseAlign-1)) & ~(BaseAlign-1);
 
   // Add base class offsets.
-  if (IsVirtualBase) {
-    VBases.push_back(RD);
-    VBaseOffsets.push_back(Size);
-  } else {
-    Bases.push_back(RD);
-    BaseOffsets.push_back(Size);
-  }
+  if (IsVirtualBase) 
+    VBases.push_back(std::make_pair(RD, Size));
+  else
+    Bases.push_back(std::make_pair(RD, Size));
 
 #if 0
   // And now add offsets for all our primary virtual bases as well, so
@@ -469,11 +465,6 @@
   // FIXME: IsPODForThePurposeOfLayout should be stored in the record layout.
   bool IsPODForThePurposeOfLayout = cast<CXXRecordDecl>(D)->isPOD();
 
-  assert(Builder.Bases.size() == Builder.BaseOffsets.size() &&
-         "Base offsets vector must be same size as bases vector!");
-  assert(Builder.VBases.size() == Builder.VBaseOffsets.size() &&
-         "Base offsets vector must be same size as bases vector!");
-
   // FIXME: This should be done in FinalizeLayout.
   uint64_t DataSize =
     IsPODForThePurposeOfLayout ? Builder.Size : Builder.NextOffset;
@@ -488,10 +479,8 @@
                              Builder.PrimaryBase,
                              Builder.PrimaryBaseWasVirtual,
                              Builder.Bases.data(),
-                             Builder.BaseOffsets.data(),
                              Builder.Bases.size(),
                              Builder.VBases.data(),
-                             Builder.VBaseOffsets.data(),
                              Builder.VBases.size());
 }
 

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

==============================================================================
--- cfe/trunk/lib/AST/RecordLayoutBuilder.h (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.h Mon Sep 21 19:04:45 2009
@@ -40,11 +40,11 @@
   const CXXRecordDecl *PrimaryBase;
   bool PrimaryBaseWasVirtual;
 
-  llvm::SmallVector<const CXXRecordDecl *, 4> Bases;
-  llvm::SmallVector<uint64_t, 4> BaseOffsets;
-
-  llvm::SmallVector<const CXXRecordDecl *, 4> VBases;
-  llvm::SmallVector<uint64_t, 4> VBaseOffsets;
+  typedef llvm::SmallVector<std::pair<const CXXRecordDecl *, 
+                                      uint64_t>, 4> BaseOffsetsTy;
+  
+  BaseOffsetsTy Bases;
+  BaseOffsetsTy VBases;
 
   ASTRecordLayoutBuilder(ASTContext &Ctx);
 





More information about the cfe-commits mailing list