aboutsummaryrefslogtreecommitdiff
path: root/lib/AST
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-02-17 01:05:43 +0000
committerDouglas Gregor <dgregor@apple.com>2009-02-17 01:05:43 +0000
commit3e00bad490f1bae8a2c60f934e7eb5dbb9752c5d (patch)
treecd116f187b667c5f88dd380a317592ad5ccdb287 /lib/AST
parentf50adff9997578a021c5fb1689852949e8e4d9b4 (diff)
Added ClassTemplateSpecializationDecl, which is a subclass of
CXXRecordDecl that is used to represent class template specializations. These are canonical declarations that can refer to either an actual class template specialization in the code, e.g., template<> class vector<bool> { }; or to a template instantiation. However, neither of these features is actually implemented yet, so really we're just using (and uniqing) the declarations to make sure that, e.g., A<int> is a different type from A<float>. Note that we carefully distinguish between what the user wrote in the source code (e.g., "A<FLOAT>") and the semantic entity it represents (e.g., "A<float, int>"); the former is in the sugared Type, the latter is an actual Decl. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64716 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST')
-rw-r--r--lib/AST/DeclCXX.cpp6
-rw-r--r--lib/AST/DeclTemplate.cpp36
2 files changed, 39 insertions, 3 deletions
diff --git a/lib/AST/DeclCXX.cpp b/lib/AST/DeclCXX.cpp
index 6de575411b..294e94f5f4 100644
--- a/lib/AST/DeclCXX.cpp
+++ b/lib/AST/DeclCXX.cpp
@@ -21,9 +21,9 @@ using namespace clang;
// Decl Allocation/Deallocation Method Implementations
//===----------------------------------------------------------------------===//
-CXXRecordDecl::CXXRecordDecl(TagKind TK, DeclContext *DC,
+CXXRecordDecl::CXXRecordDecl(Kind K, TagKind TK, DeclContext *DC,
SourceLocation L, IdentifierInfo *Id)
- : RecordDecl(CXXRecord, TK, DC, L, Id),
+ : RecordDecl(K, TK, DC, L, Id),
UserDeclaredConstructor(false), UserDeclaredCopyConstructor(false),
UserDeclaredCopyAssignment(false), UserDeclaredDestructor(false),
Aggregate(true), PlainOldData(true), Polymorphic(false), Bases(0),
@@ -32,7 +32,7 @@ CXXRecordDecl::CXXRecordDecl(TagKind TK, DeclContext *DC,
CXXRecordDecl *CXXRecordDecl::Create(ASTContext &C, TagKind TK, DeclContext *DC,
SourceLocation L, IdentifierInfo *Id,
CXXRecordDecl* PrevDecl) {
- CXXRecordDecl* R = new (C) CXXRecordDecl(TK, DC, L, Id);
+ CXXRecordDecl* R = new (C) CXXRecordDecl(CXXRecord, TK, DC, L, Id);
C.getTypeDeclType(R, PrevDecl);
return R;
}
diff --git a/lib/AST/DeclTemplate.cpp b/lib/AST/DeclTemplate.cpp
index dccb8df075..81ef3ab70e 100644
--- a/lib/AST/DeclTemplate.cpp
+++ b/lib/AST/DeclTemplate.cpp
@@ -143,3 +143,39 @@ SourceLocation TemplateTemplateParmDecl::getDefaultArgumentLoc() const {
return DefaultArgument? DefaultArgument->getSourceRange().getBegin()
: SourceLocation();
}
+
+//===----------------------------------------------------------------------===//
+// ClassTemplateSpecializationDecl Implementation
+//===----------------------------------------------------------------------===//
+ClassTemplateSpecializationDecl::
+ClassTemplateSpecializationDecl(DeclContext *DC, SourceLocation L,
+ ClassTemplateDecl *SpecializedTemplate,
+ TemplateArgument *TemplateArgs,
+ unsigned NumTemplateArgs)
+ : CXXRecordDecl(ClassTemplateSpecialization,
+ SpecializedTemplate->getTemplatedDecl()->getTagKind(),
+ DC, L,
+ // FIXME: Should we use DeclarationName for the name of
+ // class template specializations?
+ SpecializedTemplate->getIdentifier()),
+ SpecializedTemplate(SpecializedTemplate),
+ NumTemplateArgs(NumTemplateArgs) {
+ TemplateArgument *Arg = reinterpret_cast<TemplateArgument *>(this + 1);
+ for (unsigned ArgIdx = 0; ArgIdx < NumTemplateArgs; ++ArgIdx, ++Arg)
+ *Arg = TemplateArgs[ArgIdx];
+}
+
+ClassTemplateSpecializationDecl *
+ClassTemplateSpecializationDecl::Create(ASTContext &Context,
+ DeclContext *DC, SourceLocation L,
+ ClassTemplateDecl *SpecializedTemplate,
+ TemplateArgument *TemplateArgs,
+ unsigned NumTemplateArgs) {
+ unsigned Size = sizeof(ClassTemplateSpecializationDecl) +
+ sizeof(TemplateArgument) * NumTemplateArgs;
+ unsigned Align = llvm::AlignOf<ClassTemplateSpecializationDecl>::Alignment;
+ void *Mem = Context.Allocate(Size, Align);
+ return new (Mem) ClassTemplateSpecializationDecl(DC, L, SpecializedTemplate,
+ TemplateArgs,
+ NumTemplateArgs);
+}