aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2010-11-12 07:35:56 +0000
committerJohn McCall <rjmccall@apple.com>2010-11-12 07:35:56 +0000
commit41bafb1b62dfb2577c5aa7ba7fbd6ba5bebdbfee (patch)
tree10c033845992858f2f420b3caa48917e9fda6b1d
parentcb7b1e17b63967317ab5cc55682168cf0380519a (diff)
API enhancements to TypeLocBuilder.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@118886 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/AST/TypeLocBuilder.h43
1 files changed, 34 insertions, 9 deletions
diff --git a/include/clang/AST/TypeLocBuilder.h b/include/clang/AST/TypeLocBuilder.h
index 880af267f3..90a46c7546 100644
--- a/include/clang/AST/TypeLocBuilder.h
+++ b/include/clang/AST/TypeLocBuilder.h
@@ -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]);
+ }
};
}