Encapsulate template arguments lists in a new class,
TemplateArgumentList. This avoids the need to pass around
pointer/length pairs of template arguments lists, and will eventually
make it easier to introduce member templates and variadic templates.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71517 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/DeclTemplate.cpp b/lib/AST/DeclTemplate.cpp
index 4f64f8b..f1979c4 100644
--- a/lib/AST/DeclTemplate.cpp
+++ b/lib/AST/DeclTemplate.cpp
@@ -236,12 +236,42 @@
}
//===----------------------------------------------------------------------===//
+// TemplateArgumentList Implementation
+//===----------------------------------------------------------------------===//
+TemplateArgumentList::TemplateArgumentList(ASTContext &Context,
+ TemplateArgument *TemplateArgs,
+ unsigned NumTemplateArgs,
+ bool CopyArgs)
+ : NumArguments(NumTemplateArgs) {
+ if (!CopyArgs) {
+ Arguments.setPointer(TemplateArgs);
+ Arguments.setInt(1);
+ return;
+ }
+
+ unsigned Size = sizeof(TemplateArgument) * NumTemplateArgs;
+ unsigned Align = llvm::AlignOf<TemplateArgument>::Alignment;
+ void *Mem = Context.Allocate(Size, Align);
+ Arguments.setPointer((TemplateArgument *)Mem);
+ Arguments.setInt(0);
+
+ TemplateArgument *Args = (TemplateArgument *)Mem;
+ for (unsigned I = 0; I != NumTemplateArgs; ++I)
+ new (Args + I) TemplateArgument(TemplateArgs[I]);
+}
+
+TemplateArgumentList::~TemplateArgumentList() {
+ // FIXME: Deallocate template arguments
+}
+
+//===----------------------------------------------------------------------===//
// ClassTemplateSpecializationDecl Implementation
//===----------------------------------------------------------------------===//
ClassTemplateSpecializationDecl::
-ClassTemplateSpecializationDecl(DeclContext *DC, SourceLocation L,
+ClassTemplateSpecializationDecl(ASTContext &Context,
+ DeclContext *DC, SourceLocation L,
ClassTemplateDecl *SpecializedTemplate,
- TemplateArgument *TemplateArgs,
+ TemplateArgument *TemplateArgs,
unsigned NumTemplateArgs)
: CXXRecordDecl(ClassTemplateSpecialization,
SpecializedTemplate->getTemplatedDecl()->getTagKind(),
@@ -250,10 +280,8 @@
// class template specializations?
SpecializedTemplate->getIdentifier()),
SpecializedTemplate(SpecializedTemplate),
- NumTemplateArgs(NumTemplateArgs), SpecializationKind(TSK_Undeclared) {
- TemplateArgument *Arg = reinterpret_cast<TemplateArgument *>(this + 1);
- for (unsigned ArgIdx = 0; ArgIdx < NumTemplateArgs; ++ArgIdx, ++Arg)
- new (Arg) TemplateArgument(TemplateArgs[ArgIdx]);
+ TemplateArgs(Context, TemplateArgs, NumTemplateArgs, /*CopyArgs=*/true),
+ SpecializationKind(TSK_Undeclared) {
}
ClassTemplateSpecializationDecl *
@@ -263,13 +291,11 @@
TemplateArgument *TemplateArgs,
unsigned NumTemplateArgs,
ClassTemplateSpecializationDecl *PrevDecl) {
- unsigned Size = sizeof(ClassTemplateSpecializationDecl) +
- sizeof(TemplateArgument) * NumTemplateArgs;
- unsigned Align = llvm::AlignOf<ClassTemplateSpecializationDecl>::Alignment;
- void *Mem = Context.Allocate(Size, Align);
ClassTemplateSpecializationDecl *Result
- = new (Mem) ClassTemplateSpecializationDecl(DC, L, SpecializedTemplate,
- TemplateArgs, NumTemplateArgs);
+ = new (Context)ClassTemplateSpecializationDecl(Context, DC, L,
+ SpecializedTemplate,
+ TemplateArgs,
+ NumTemplateArgs);
Context.getTypeDeclType(Result, PrevDecl);
return Result;
}