[cfe-commits] r118886 - /cfe/trunk/include/clang/AST/TypeLocBuilder.h

John McCall rjmccall at apple.com
Thu Nov 11 23:35:56 PST 2010


Author: rjmccall
Date: Fri Nov 12 01:35:56 2010
New Revision: 118886

URL: http://llvm.org/viewvc/llvm-project?rev=118886&view=rev
Log:
API enhancements to TypeLocBuilder.


Modified:
    cfe/trunk/include/clang/AST/TypeLocBuilder.h

Modified: cfe/trunk/include/clang/AST/TypeLocBuilder.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/TypeLocBuilder.h?rev=118886&r1=118885&r2=118886&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/TypeLocBuilder.h (original)
+++ cfe/trunk/include/clang/AST/TypeLocBuilder.h Fri Nov 12 01:35:56 2010
@@ -62,17 +62,17 @@
   /// Pushes a copy of the given TypeLoc onto this builder.  The builder
   /// must be empty for this to work.
   void pushFullCopy(TypeLoc L) {
-#ifndef NDEBUG
-    assert(LastTy.isNull() && "pushing copy on non-empty TypeLocBuilder");
-    LastTy = L.getNextTypeLoc().getType();
-#endif
-    assert(Index == Capacity && "pushing copy on non-empty TypeLocBuilder");
-
-    unsigned Size = L.getFullDataSize();
-    TypeLoc Copy = pushImpl(L.getType(), Size);
+    size_t Size = L.getFullDataSize();
+    TypeLoc Copy = pushFullUninitializedImpl(L.getType(), Size);
     memcpy(Copy.getOpaqueData(), L.getOpaqueData(), Size);
   }
 
+  /// Pushes uninitialized space for the given type.  The builder must
+  /// be empty.
+  TypeLoc pushFullUninitialized(QualType T) {
+    return pushFullUninitializedImpl(T, TypeLoc::getFullDataSizeForType(T));
+  }
+
   /// Pushes space for a typespec TypeLoc.  Invalidates any TypeLocs
   /// previously retrieved from this builder.
   TypeSpecTypeLoc pushTypeSpec(QualType T) {
@@ -127,7 +127,7 @@
 
     Index -= LocalSize;
 
-    return TypeLoc(T, &Buffer[Index]);
+    return getTypeLoc(T);
   }
 
   /// Grow to the given capacity.
@@ -148,6 +148,31 @@
     Capacity = NewCapacity;
     Index = NewIndex;
   }
+
+  TypeLoc pushFullUninitializedImpl(QualType T, size_t Size) {
+#ifndef NDEBUG
+    assert(LastTy.isNull() && "pushing full on non-empty TypeLocBuilder");
+    LastTy = T;
+#endif
+    assert(Index == Capacity && "pushing full on non-empty TypeLocBuilder");
+
+    reserve(Size);
+    Index -= Size;
+
+    return getTypeLoc(T);
+  }
+
+
+  // This is private because, when we kill off TypeSourceInfo in favor
+  // of TypeLoc, we'll want an interface that creates a TypeLoc given
+  // an ASTContext, and we don't want people to think they can just
+  // use this as an equivalent.
+  TypeLoc getTypeLoc(QualType T) {
+#ifndef NDEBUG
+    assert(LastTy == T && "type doesn't match last type pushed!");
+#endif
+    return TypeLoc(T, &Buffer[Index]);
+  }
 };
 
 }





More information about the cfe-commits mailing list