]> granicus.if.org Git - clang/commitdiff
API enhancements to TypeLocBuilder.
authorJohn McCall <rjmccall@apple.com>
Fri, 12 Nov 2010 07:35:56 +0000 (07:35 +0000)
committerJohn McCall <rjmccall@apple.com>
Fri, 12 Nov 2010 07:35:56 +0000 (07:35 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@118886 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/TypeLocBuilder.h

index 880af267f324636794a7e7e4a69d30708073f4c8..90a46c7546dcfdc83edc316a0995e030b9ba15e7 100644 (file)
@@ -62,17 +62,17 @@ class TypeLocBuilder {
   /// 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 @@ private:
 
     Index -= LocalSize;
 
-    return TypeLoc(T, &Buffer[Index]);
+    return getTypeLoc(T);
   }
 
   /// Grow to the given capacity.
@@ -148,6 +148,31 @@ private:
     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]);
+  }
 };
 
 }