From: John McCall Date: Fri, 12 Nov 2010 07:35:56 +0000 (+0000) Subject: API enhancements to TypeLocBuilder. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=41bafb1b62dfb2577c5aa7ba7fbd6ba5bebdbfee;p=clang API enhancements to TypeLocBuilder. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@118886 91177308-0d34-0410-b5e6-96231b3b80d8 --- 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]); + } }; }