blob: a74552621970acf7a6f2fb3669e082c7fe62d5bf [file] [log] [blame]
Sebastian Redl06a59bb2009-10-23 22:13:42 +00001//===--- DeclTemplate.cpp - Template Declaration AST Node Implementation --===//
Douglas Gregoraaba5e32009-02-04 19:02:06 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the C++ related Decl classes for templates.
11//
12//===----------------------------------------------------------------------===//
13
14#include "clang/AST/DeclCXX.h"
15#include "clang/AST/DeclTemplate.h"
Douglas Gregor55f6b142009-02-09 18:46:07 +000016#include "clang/AST/Expr.h"
Douglas Gregorb95cc972011-01-04 02:33:52 +000017#include "clang/AST/ExprCXX.h"
Douglas Gregoraaba5e32009-02-04 19:02:06 +000018#include "clang/AST/ASTContext.h"
John McCall833ca992009-10-29 08:12:44 +000019#include "clang/AST/TypeLoc.h"
Argyrios Kyrtzidisbef1a7b2010-10-28 07:38:42 +000020#include "clang/AST/ASTMutationListener.h"
Douglas Gregoraaba5e32009-02-04 19:02:06 +000021#include "clang/Basic/IdentifierTable.h"
22#include "llvm/ADT/STLExtras.h"
Douglas Gregor910f8002010-11-07 23:05:16 +000023#include <memory>
Douglas Gregoraaba5e32009-02-04 19:02:06 +000024using namespace clang;
25
26//===----------------------------------------------------------------------===//
27// TemplateParameterList Implementation
28//===----------------------------------------------------------------------===//
29
Douglas Gregorddc29e12009-02-06 22:42:48 +000030TemplateParameterList::TemplateParameterList(SourceLocation TemplateLoc,
31 SourceLocation LAngleLoc,
Douglas Gregorbf4ea562009-09-15 16:23:51 +000032 NamedDecl **Params, unsigned NumParams,
Douglas Gregorddc29e12009-02-06 22:42:48 +000033 SourceLocation RAngleLoc)
34 : TemplateLoc(TemplateLoc), LAngleLoc(LAngleLoc), RAngleLoc(RAngleLoc),
35 NumParams(NumParams) {
Douglas Gregoraaba5e32009-02-04 19:02:06 +000036 for (unsigned Idx = 0; Idx < NumParams; ++Idx)
37 begin()[Idx] = Params[Idx];
38}
39
40TemplateParameterList *
Jay Foad4ba2a172011-01-12 09:06:06 +000041TemplateParameterList::Create(const ASTContext &C, SourceLocation TemplateLoc,
Douglas Gregorbf4ea562009-09-15 16:23:51 +000042 SourceLocation LAngleLoc, NamedDecl **Params,
Douglas Gregorddc29e12009-02-06 22:42:48 +000043 unsigned NumParams, SourceLocation RAngleLoc) {
Douglas Gregorbf4ea562009-09-15 16:23:51 +000044 unsigned Size = sizeof(TemplateParameterList)
45 + sizeof(NamedDecl *) * NumParams;
Douglas Gregoraaba5e32009-02-04 19:02:06 +000046 unsigned Align = llvm::AlignOf<TemplateParameterList>::Alignment;
47 void *Mem = C.Allocate(Size, Align);
Mike Stump1eb44332009-09-09 15:08:12 +000048 return new (Mem) TemplateParameterList(TemplateLoc, LAngleLoc, Params,
Douglas Gregorddc29e12009-02-06 22:42:48 +000049 NumParams, RAngleLoc);
Douglas Gregoraaba5e32009-02-04 19:02:06 +000050}
51
Douglas Gregor62cb18d2009-02-11 18:16:40 +000052unsigned TemplateParameterList::getMinRequiredArguments() const {
Douglas Gregor6952f1e2011-01-19 20:10:05 +000053 unsigned NumRequiredArgs = 0;
54 for (iterator P = const_cast<TemplateParameterList *>(this)->begin(),
55 PEnd = const_cast<TemplateParameterList *>(this)->end();
56 P != PEnd; ++P) {
57 if ((*P)->isTemplateParameterPack()) {
58 if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(*P))
59 if (NTTP->isExpandedParameterPack()) {
60 NumRequiredArgs += NTTP->getNumExpansionTypes();
61 continue;
62 }
63
Douglas Gregor62cb18d2009-02-11 18:16:40 +000064 break;
Douglas Gregor6952f1e2011-01-19 20:10:05 +000065 }
66
67 if (TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(*P)) {
68 if (TTP->hasDefaultArgument())
69 break;
70 } else if (NonTypeTemplateParmDecl *NTTP
71 = dyn_cast<NonTypeTemplateParmDecl>(*P)) {
72 if (NTTP->hasDefaultArgument())
73 break;
74 } else if (cast<TemplateTemplateParmDecl>(*P)->hasDefaultArgument())
75 break;
76
77 ++NumRequiredArgs;
Douglas Gregor62cb18d2009-02-11 18:16:40 +000078 }
Douglas Gregor6952f1e2011-01-19 20:10:05 +000079
Douglas Gregor62cb18d2009-02-11 18:16:40 +000080 return NumRequiredArgs;
81}
82
Douglas Gregored9c0f92009-10-29 00:04:11 +000083unsigned TemplateParameterList::getDepth() const {
84 if (size() == 0)
85 return 0;
86
87 const NamedDecl *FirstParm = getParam(0);
88 if (const TemplateTypeParmDecl *TTP
89 = dyn_cast<TemplateTypeParmDecl>(FirstParm))
90 return TTP->getDepth();
91 else if (const NonTypeTemplateParmDecl *NTTP
92 = dyn_cast<NonTypeTemplateParmDecl>(FirstParm))
93 return NTTP->getDepth();
94 else
95 return cast<TemplateTemplateParmDecl>(FirstParm)->getDepth();
96}
97
Douglas Gregor787a40d2011-03-04 18:32:38 +000098static void AdoptTemplateParameterList(TemplateParameterList *Params,
99 DeclContext *Owner) {
100 for (TemplateParameterList::iterator P = Params->begin(),
101 PEnd = Params->end();
102 P != PEnd; ++P) {
103 (*P)->setDeclContext(Owner);
104
105 if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(*P))
106 AdoptTemplateParameterList(TTP->getTemplateParameters(), Owner);
107 }
108}
109
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000110//===----------------------------------------------------------------------===//
Peter Collingbourne9eabeba2010-07-29 16:11:51 +0000111// RedeclarableTemplateDecl Implementation
112//===----------------------------------------------------------------------===//
113
114RedeclarableTemplateDecl::CommonBase *RedeclarableTemplateDecl::getCommonPtr() {
Douglas Gregor7c99bb5c2012-01-14 15:13:49 +0000115 if (!Common) {
116 // Walk the previous-declaration chain until we either find a declaration
117 // with a common pointer or we run out of previous declarations.
118 llvm::SmallVector<RedeclarableTemplateDecl *, 2> PrevDecls;
119 for (RedeclarableTemplateDecl *Prev = getPreviousDeclaration(); Prev;
120 Prev = Prev->getPreviousDeclaration()) {
121 if (Prev->Common) {
122 Common = Prev->Common;
123 break;
124 }
125
126 PrevDecls.push_back(Prev);
127 }
Peter Collingbourne9eabeba2010-07-29 16:11:51 +0000128
Douglas Gregor7c99bb5c2012-01-14 15:13:49 +0000129 // If we never found a common pointer, allocate one now.
130 if (!Common)
131 Common = newCommon(getASTContext());
132
133 // Update any previous declarations we saw with the common pointer.
134 for (unsigned I = 0, N = PrevDecls.size(); I != N; ++I)
135 PrevDecls[I]->Common = Common;
Peter Collingbourne9eabeba2010-07-29 16:11:51 +0000136 }
Peter Collingbourne9eabeba2010-07-29 16:11:51 +0000137
Douglas Gregor7c99bb5c2012-01-14 15:13:49 +0000138 return Common;
Peter Collingbournef88718e2010-07-29 16:12:09 +0000139}
140
Peter Collingbourne40485902010-07-30 17:09:04 +0000141template <class EntryType>
142typename RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::DeclType*
143RedeclarableTemplateDecl::findSpecializationImpl(
144 llvm::FoldingSet<EntryType> &Specs,
145 const TemplateArgument *Args, unsigned NumArgs,
146 void *&InsertPos) {
147 typedef SpecEntryTraits<EntryType> SETraits;
148 llvm::FoldingSetNodeID ID;
149 EntryType::Profile(ID,Args,NumArgs, getASTContext());
150 EntryType *Entry = Specs.FindNodeOrInsertPos(ID, InsertPos);
151 return Entry ? SETraits::getMostRecentDeclaration(Entry) : 0;
152}
153
Douglas Gregorc494f772011-03-05 17:54:25 +0000154/// \brief Generate the injected template arguments for the given template
155/// parameter list, e.g., for the injected-class-name of a class template.
156static void GenerateInjectedTemplateArgs(ASTContext &Context,
157 TemplateParameterList *Params,
158 TemplateArgument *Args) {
159 for (TemplateParameterList::iterator Param = Params->begin(),
160 ParamEnd = Params->end();
161 Param != ParamEnd; ++Param) {
162 TemplateArgument Arg;
163 if (TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(*Param)) {
164 QualType ArgType = Context.getTypeDeclType(TTP);
165 if (TTP->isParameterPack())
166 ArgType = Context.getPackExpansionType(ArgType,
167 llvm::Optional<unsigned>());
168
169 Arg = TemplateArgument(ArgType);
170 } else if (NonTypeTemplateParmDecl *NTTP =
171 dyn_cast<NonTypeTemplateParmDecl>(*Param)) {
172 Expr *E = new (Context) DeclRefExpr(NTTP,
173 NTTP->getType().getNonLValueExprType(Context),
174 Expr::getValueKindForType(NTTP->getType()),
175 NTTP->getLocation());
176
177 if (NTTP->isParameterPack())
178 E = new (Context) PackExpansionExpr(Context.DependentTy, E,
179 NTTP->getLocation(),
180 llvm::Optional<unsigned>());
181 Arg = TemplateArgument(E);
182 } else {
183 TemplateTemplateParmDecl *TTP = cast<TemplateTemplateParmDecl>(*Param);
184 if (TTP->isParameterPack())
185 Arg = TemplateArgument(TemplateName(TTP), llvm::Optional<unsigned>());
186 else
187 Arg = TemplateArgument(TemplateName(TTP));
188 }
189
190 if ((*Param)->isTemplateParameterPack())
191 Arg = TemplateArgument::CreatePackCopy(Context, &Arg, 1);
192
193 *Args++ = Arg;
194 }
195}
196
Peter Collingbourne9eabeba2010-07-29 16:11:51 +0000197//===----------------------------------------------------------------------===//
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000198// FunctionTemplateDecl Implementation
199//===----------------------------------------------------------------------===//
200
Douglas Gregor00545312010-05-23 18:26:36 +0000201void FunctionTemplateDecl::DeallocateCommon(void *Ptr) {
202 static_cast<Common *>(Ptr)->~Common();
203}
204
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000205FunctionTemplateDecl *FunctionTemplateDecl::Create(ASTContext &C,
206 DeclContext *DC,
207 SourceLocation L,
208 DeclarationName Name,
Douglas Gregor127102b2009-06-29 20:59:39 +0000209 TemplateParameterList *Params,
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000210 NamedDecl *Decl) {
Douglas Gregor787a40d2011-03-04 18:32:38 +0000211 AdoptTemplateParameterList(Params, cast<DeclContext>(Decl));
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000212 return new (C) FunctionTemplateDecl(DC, L, Name, Params, Decl);
213}
214
Douglas Gregor1e68ecc2012-01-05 21:55:30 +0000215FunctionTemplateDecl *FunctionTemplateDecl::CreateDeserialized(ASTContext &C,
216 unsigned ID) {
217 void *Mem = AllocateDeserializedDecl(C, ID, sizeof(FunctionTemplateDecl));
218 return new (Mem) FunctionTemplateDecl(0, SourceLocation(), DeclarationName(),
219 0, 0);
Douglas Gregor9a299e02011-03-04 17:52:15 +0000220}
221
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +0000222RedeclarableTemplateDecl::CommonBase *
223FunctionTemplateDecl::newCommon(ASTContext &C) {
224 Common *CommonPtr = new (C) Common;
225 C.AddDeallocation(DeallocateCommon, CommonPtr);
Peter Collingbourne9eabeba2010-07-29 16:11:51 +0000226 return CommonPtr;
227}
228
Argyrios Kyrtzidis2c853e42010-07-20 13:59:58 +0000229FunctionDecl *
230FunctionTemplateDecl::findSpecialization(const TemplateArgument *Args,
231 unsigned NumArgs, void *&InsertPos) {
Peter Collingbourne40485902010-07-30 17:09:04 +0000232 return findSpecializationImpl(getSpecializations(), Args, NumArgs, InsertPos);
Argyrios Kyrtzidis2c853e42010-07-20 13:59:58 +0000233}
234
Sebastian Redl5bbcdbf2011-04-14 14:07:59 +0000235void FunctionTemplateDecl::addSpecialization(
236 FunctionTemplateSpecializationInfo *Info, void *InsertPos) {
237 getSpecializations().InsertNode(Info, InsertPos);
238 if (ASTMutationListener *L = getASTMutationListener())
239 L->AddedCXXTemplateSpecialization(this, Info->Function);
240}
241
Douglas Gregorc494f772011-03-05 17:54:25 +0000242std::pair<const TemplateArgument *, unsigned>
243FunctionTemplateDecl::getInjectedTemplateArgs() {
244 TemplateParameterList *Params = getTemplateParameters();
245 Common *CommonPtr = getCommonPtr();
246 if (!CommonPtr->InjectedArgs) {
247 CommonPtr->InjectedArgs
248 = new (getASTContext()) TemplateArgument [Params->size()];
249 GenerateInjectedTemplateArgs(getASTContext(), Params,
250 CommonPtr->InjectedArgs);
251 }
252
253 return std::make_pair(CommonPtr->InjectedArgs, Params->size());
254}
255
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000256//===----------------------------------------------------------------------===//
257// ClassTemplateDecl Implementation
258//===----------------------------------------------------------------------===//
259
Douglas Gregor00545312010-05-23 18:26:36 +0000260void ClassTemplateDecl::DeallocateCommon(void *Ptr) {
261 static_cast<Common *>(Ptr)->~Common();
262}
263
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000264ClassTemplateDecl *ClassTemplateDecl::Create(ASTContext &C,
265 DeclContext *DC,
266 SourceLocation L,
267 DeclarationName Name,
268 TemplateParameterList *Params,
Douglas Gregor5953d8b2009-03-19 17:26:29 +0000269 NamedDecl *Decl,
270 ClassTemplateDecl *PrevDecl) {
Douglas Gregor787a40d2011-03-04 18:32:38 +0000271 AdoptTemplateParameterList(Params, cast<DeclContext>(Decl));
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000272 ClassTemplateDecl *New = new (C) ClassTemplateDecl(DC, L, Name, Params, Decl);
Argyrios Kyrtzidis5bf1bdc2010-06-21 10:57:41 +0000273 New->setPreviousDeclaration(PrevDecl);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000274 return New;
Douglas Gregor5953d8b2009-03-19 17:26:29 +0000275}
276
Douglas Gregor1e68ecc2012-01-05 21:55:30 +0000277ClassTemplateDecl *ClassTemplateDecl::CreateDeserialized(ASTContext &C,
278 unsigned ID) {
279 void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ClassTemplateDecl));
280 return new (Mem) ClassTemplateDecl(EmptyShell());
Douglas Gregor9a299e02011-03-04 17:52:15 +0000281}
282
Douglas Gregorc8e5cf82010-10-27 22:21:36 +0000283void ClassTemplateDecl::LoadLazySpecializations() {
284 Common *CommonPtr = getCommonPtr();
285 if (CommonPtr->LazySpecializations) {
286 ASTContext &Context = getASTContext();
287 uint32_t *Specs = CommonPtr->LazySpecializations;
288 CommonPtr->LazySpecializations = 0;
289 for (uint32_t I = 0, N = *Specs++; I != N; ++I)
290 (void)Context.getExternalSource()->GetExternalDecl(Specs[I]);
291 }
292}
293
294llvm::FoldingSet<ClassTemplateSpecializationDecl> &
295ClassTemplateDecl::getSpecializations() {
296 LoadLazySpecializations();
297 return getCommonPtr()->Specializations;
298}
299
300llvm::FoldingSet<ClassTemplatePartialSpecializationDecl> &
301ClassTemplateDecl::getPartialSpecializations() {
302 LoadLazySpecializations();
303 return getCommonPtr()->PartialSpecializations;
304}
305
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +0000306RedeclarableTemplateDecl::CommonBase *
307ClassTemplateDecl::newCommon(ASTContext &C) {
308 Common *CommonPtr = new (C) Common;
309 C.AddDeallocation(DeallocateCommon, CommonPtr);
Peter Collingbourne9eabeba2010-07-29 16:11:51 +0000310 return CommonPtr;
311}
312
Argyrios Kyrtzidiscc0b1bc2010-07-20 13:59:28 +0000313ClassTemplateSpecializationDecl *
314ClassTemplateDecl::findSpecialization(const TemplateArgument *Args,
315 unsigned NumArgs, void *&InsertPos) {
Peter Collingbourne40485902010-07-30 17:09:04 +0000316 return findSpecializationImpl(getSpecializations(), Args, NumArgs, InsertPos);
Argyrios Kyrtzidiscc0b1bc2010-07-20 13:59:28 +0000317}
318
Argyrios Kyrtzidisbef1a7b2010-10-28 07:38:42 +0000319void ClassTemplateDecl::AddSpecialization(ClassTemplateSpecializationDecl *D,
320 void *InsertPos) {
321 getSpecializations().InsertNode(D, InsertPos);
322 if (ASTMutationListener *L = getASTMutationListener())
323 L->AddedCXXTemplateSpecialization(this, D);
324}
325
Argyrios Kyrtzidiscc0b1bc2010-07-20 13:59:28 +0000326ClassTemplatePartialSpecializationDecl *
327ClassTemplateDecl::findPartialSpecialization(const TemplateArgument *Args,
328 unsigned NumArgs,
329 void *&InsertPos) {
Peter Collingbourne40485902010-07-30 17:09:04 +0000330 return findSpecializationImpl(getPartialSpecializations(), Args, NumArgs,
331 InsertPos);
Argyrios Kyrtzidiscc0b1bc2010-07-20 13:59:28 +0000332}
333
Argyrios Kyrtzidisbef1a7b2010-10-28 07:38:42 +0000334void ClassTemplateDecl::AddPartialSpecialization(
335 ClassTemplatePartialSpecializationDecl *D,
336 void *InsertPos) {
337 getPartialSpecializations().InsertNode(D, InsertPos);
338 if (ASTMutationListener *L = getASTMutationListener())
339 L->AddedCXXTemplateSpecialization(this, D);
340}
341
Douglas Gregordc60c1e2010-04-30 05:56:50 +0000342void ClassTemplateDecl::getPartialSpecializations(
Chris Lattner5f9e2722011-07-23 10:55:15 +0000343 SmallVectorImpl<ClassTemplatePartialSpecializationDecl *> &PS) {
Douglas Gregordc60c1e2010-04-30 05:56:50 +0000344 llvm::FoldingSet<ClassTemplatePartialSpecializationDecl> &PartialSpecs
Argyrios Kyrtzidis5bf1bdc2010-06-21 10:57:41 +0000345 = getPartialSpecializations();
Douglas Gregordc60c1e2010-04-30 05:56:50 +0000346 PS.clear();
347 PS.resize(PartialSpecs.size());
348 for (llvm::FoldingSet<ClassTemplatePartialSpecializationDecl>::iterator
349 P = PartialSpecs.begin(), PEnd = PartialSpecs.end();
350 P != PEnd; ++P) {
351 assert(!PS[P->getSequenceNumber()]);
Argyrios Kyrtzidiscc0b1bc2010-07-20 13:59:28 +0000352 PS[P->getSequenceNumber()] = P->getMostRecentDeclaration();
Douglas Gregordc60c1e2010-04-30 05:56:50 +0000353 }
354}
355
Douglas Gregorb88e8882009-07-30 17:40:51 +0000356ClassTemplatePartialSpecializationDecl *
357ClassTemplateDecl::findPartialSpecialization(QualType T) {
358 ASTContext &Context = getASTContext();
359 typedef llvm::FoldingSet<ClassTemplatePartialSpecializationDecl>::iterator
360 partial_spec_iterator;
361 for (partial_spec_iterator P = getPartialSpecializations().begin(),
362 PEnd = getPartialSpecializations().end();
363 P != PEnd; ++P) {
John McCall31f17ec2010-04-27 00:57:59 +0000364 if (Context.hasSameType(P->getInjectedSpecializationType(), T))
Argyrios Kyrtzidiscc0b1bc2010-07-20 13:59:28 +0000365 return P->getMostRecentDeclaration();
366 }
367
368 return 0;
369}
370
371ClassTemplatePartialSpecializationDecl *
372ClassTemplateDecl::findPartialSpecInstantiatedFromMember(
373 ClassTemplatePartialSpecializationDecl *D) {
374 Decl *DCanon = D->getCanonicalDecl();
375 for (llvm::FoldingSet<ClassTemplatePartialSpecializationDecl>::iterator
376 P = getPartialSpecializations().begin(),
377 PEnd = getPartialSpecializations().end();
378 P != PEnd; ++P) {
379 if (P->getInstantiatedFromMember()->getCanonicalDecl() == DCanon)
380 return P->getMostRecentDeclaration();
Douglas Gregorb88e8882009-07-30 17:40:51 +0000381 }
Mike Stump1eb44332009-09-09 15:08:12 +0000382
Douglas Gregorb88e8882009-07-30 17:40:51 +0000383 return 0;
384}
385
John McCall3cb0ebd2010-03-10 03:28:59 +0000386QualType
Douglas Gregor24bae922010-07-08 18:37:38 +0000387ClassTemplateDecl::getInjectedClassNameSpecialization() {
Argyrios Kyrtzidis5bf1bdc2010-06-21 10:57:41 +0000388 Common *CommonPtr = getCommonPtr();
Douglas Gregor7da97d02009-05-10 22:57:19 +0000389 if (!CommonPtr->InjectedClassNameType.isNull())
390 return CommonPtr->InjectedClassNameType;
391
Douglas Gregorb7d09d62010-12-23 16:00:30 +0000392 // C++0x [temp.dep.type]p2:
393 // The template argument list of a primary template is a template argument
394 // list in which the nth template argument has the value of the nth template
395 // parameter of the class template. If the nth template parameter is a
396 // template parameter pack (14.5.3), the nth template argument is a pack
397 // expansion (14.5.3) whose pattern is the name of the template parameter
398 // pack.
Douglas Gregor24bae922010-07-08 18:37:38 +0000399 ASTContext &Context = getASTContext();
Douglas Gregor7da97d02009-05-10 22:57:19 +0000400 TemplateParameterList *Params = getTemplateParameters();
Chris Lattner5f9e2722011-07-23 10:55:15 +0000401 SmallVector<TemplateArgument, 16> TemplateArgs;
Douglas Gregorc494f772011-03-05 17:54:25 +0000402 TemplateArgs.resize(Params->size());
403 GenerateInjectedTemplateArgs(getASTContext(), Params, TemplateArgs.data());
Douglas Gregor7da97d02009-05-10 22:57:19 +0000404 CommonPtr->InjectedClassNameType
Douglas Gregor1275ae02009-07-28 23:00:59 +0000405 = Context.getTemplateSpecializationType(TemplateName(this),
Douglas Gregor7da97d02009-05-10 22:57:19 +0000406 &TemplateArgs[0],
Douglas Gregor1275ae02009-07-28 23:00:59 +0000407 TemplateArgs.size());
Douglas Gregor7da97d02009-05-10 22:57:19 +0000408 return CommonPtr->InjectedClassNameType;
409}
410
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000411//===----------------------------------------------------------------------===//
412// TemplateTypeParm Allocation/Deallocation Method Implementations
413//===----------------------------------------------------------------------===//
414
415TemplateTypeParmDecl *
Jay Foad4ba2a172011-01-12 09:06:06 +0000416TemplateTypeParmDecl::Create(const ASTContext &C, DeclContext *DC,
Abramo Bagnara344577e2011-03-06 15:48:19 +0000417 SourceLocation KeyLoc, SourceLocation NameLoc,
418 unsigned D, unsigned P, IdentifierInfo *Id,
419 bool Typename, bool ParameterPack) {
Chandler Carruth4fb86f82011-05-01 00:51:33 +0000420 TemplateTypeParmDecl *TTPDecl =
421 new (C) TemplateTypeParmDecl(DC, KeyLoc, NameLoc, Id, Typename);
422 QualType TTPType = C.getTemplateTypeParmType(D, P, ParameterPack, TTPDecl);
423 TTPDecl->TypeForDecl = TTPType.getTypePtr();
424 return TTPDecl;
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000425}
426
Argyrios Kyrtzidisb8b03e62010-07-02 11:54:55 +0000427TemplateTypeParmDecl *
Douglas Gregor1e68ecc2012-01-05 21:55:30 +0000428TemplateTypeParmDecl::CreateDeserialized(const ASTContext &C, unsigned ID) {
429 void *Mem = AllocateDeserializedDecl(C, ID, sizeof(TemplateTypeParmDecl));
430 return new (Mem) TemplateTypeParmDecl(0, SourceLocation(), SourceLocation(),
431 0, false);
Argyrios Kyrtzidisb8b03e62010-07-02 11:54:55 +0000432}
433
John McCall833ca992009-10-29 08:12:44 +0000434SourceLocation TemplateTypeParmDecl::getDefaultArgumentLoc() const {
Abramo Bagnara77d4ee22011-03-04 12:42:03 +0000435 return hasDefaultArgument()
436 ? DefaultArgument->getTypeLoc().getBeginLoc()
437 : SourceLocation();
438}
439
440SourceRange TemplateTypeParmDecl::getSourceRange() const {
441 if (hasDefaultArgument() && !defaultArgumentWasInherited())
Abramo Bagnara344577e2011-03-06 15:48:19 +0000442 return SourceRange(getLocStart(),
Abramo Bagnara77d4ee22011-03-04 12:42:03 +0000443 DefaultArgument->getTypeLoc().getEndLoc());
444 else
Abramo Bagnara344577e2011-03-06 15:48:19 +0000445 return TypeDecl::getSourceRange();
John McCall833ca992009-10-29 08:12:44 +0000446}
447
Douglas Gregored9c0f92009-10-29 00:04:11 +0000448unsigned TemplateTypeParmDecl::getDepth() const {
449 return TypeForDecl->getAs<TemplateTypeParmType>()->getDepth();
450}
451
452unsigned TemplateTypeParmDecl::getIndex() const {
453 return TypeForDecl->getAs<TemplateTypeParmType>()->getIndex();
454}
455
Chandler Carruth4fb86f82011-05-01 00:51:33 +0000456bool TemplateTypeParmDecl::isParameterPack() const {
457 return TypeForDecl->getAs<TemplateTypeParmType>()->isParameterPack();
458}
459
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000460//===----------------------------------------------------------------------===//
461// NonTypeTemplateParmDecl Method Implementations
462//===----------------------------------------------------------------------===//
463
Douglas Gregor6952f1e2011-01-19 20:10:05 +0000464NonTypeTemplateParmDecl::NonTypeTemplateParmDecl(DeclContext *DC,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +0000465 SourceLocation StartLoc,
466 SourceLocation IdLoc,
467 unsigned D, unsigned P,
468 IdentifierInfo *Id,
Douglas Gregor6952f1e2011-01-19 20:10:05 +0000469 QualType T,
470 TypeSourceInfo *TInfo,
471 const QualType *ExpandedTypes,
472 unsigned NumExpandedTypes,
473 TypeSourceInfo **ExpandedTInfos)
Abramo Bagnaraff676cb2011-03-08 08:55:46 +0000474 : DeclaratorDecl(NonTypeTemplateParm, DC, IdLoc, Id, T, TInfo, StartLoc),
Douglas Gregor6952f1e2011-01-19 20:10:05 +0000475 TemplateParmPosition(D, P), DefaultArgumentAndInherited(0, false),
476 ParameterPack(true), ExpandedParameterPack(true),
477 NumExpandedTypes(NumExpandedTypes)
478{
479 if (ExpandedTypes && ExpandedTInfos) {
480 void **TypesAndInfos = reinterpret_cast<void **>(this + 1);
481 for (unsigned I = 0; I != NumExpandedTypes; ++I) {
482 TypesAndInfos[2*I] = ExpandedTypes[I].getAsOpaquePtr();
483 TypesAndInfos[2*I + 1] = ExpandedTInfos[I];
484 }
485 }
486}
487
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000488NonTypeTemplateParmDecl *
Jay Foad4ba2a172011-01-12 09:06:06 +0000489NonTypeTemplateParmDecl::Create(const ASTContext &C, DeclContext *DC,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +0000490 SourceLocation StartLoc, SourceLocation IdLoc,
491 unsigned D, unsigned P, IdentifierInfo *Id,
492 QualType T, bool ParameterPack,
493 TypeSourceInfo *TInfo) {
494 return new (C) NonTypeTemplateParmDecl(DC, StartLoc, IdLoc, D, P, Id,
495 T, ParameterPack, TInfo);
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000496}
497
Douglas Gregor6952f1e2011-01-19 20:10:05 +0000498NonTypeTemplateParmDecl *
499NonTypeTemplateParmDecl::Create(const ASTContext &C, DeclContext *DC,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +0000500 SourceLocation StartLoc, SourceLocation IdLoc,
501 unsigned D, unsigned P,
Douglas Gregor6952f1e2011-01-19 20:10:05 +0000502 IdentifierInfo *Id, QualType T,
503 TypeSourceInfo *TInfo,
504 const QualType *ExpandedTypes,
505 unsigned NumExpandedTypes,
506 TypeSourceInfo **ExpandedTInfos) {
507 unsigned Size = sizeof(NonTypeTemplateParmDecl)
508 + NumExpandedTypes * 2 * sizeof(void*);
509 void *Mem = C.Allocate(Size);
Abramo Bagnaraff676cb2011-03-08 08:55:46 +0000510 return new (Mem) NonTypeTemplateParmDecl(DC, StartLoc, IdLoc,
511 D, P, Id, T, TInfo,
Douglas Gregor6952f1e2011-01-19 20:10:05 +0000512 ExpandedTypes, NumExpandedTypes,
513 ExpandedTInfos);
514}
515
Douglas Gregor1e68ecc2012-01-05 21:55:30 +0000516NonTypeTemplateParmDecl *
517NonTypeTemplateParmDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
518 void *Mem = AllocateDeserializedDecl(C, ID, sizeof(NonTypeTemplateParmDecl));
519 return new (Mem) NonTypeTemplateParmDecl(0, SourceLocation(),
520 SourceLocation(), 0, 0, 0,
521 QualType(), false, 0);
522}
523
524NonTypeTemplateParmDecl *
525NonTypeTemplateParmDecl::CreateDeserialized(ASTContext &C, unsigned ID,
526 unsigned NumExpandedTypes) {
527 unsigned Size = sizeof(NonTypeTemplateParmDecl)
528 + NumExpandedTypes * 2 * sizeof(void*);
529
530 void *Mem = AllocateDeserializedDecl(C, ID, Size);
531 return new (Mem) NonTypeTemplateParmDecl(0, SourceLocation(),
532 SourceLocation(), 0, 0, 0,
533 QualType(), 0, 0, NumExpandedTypes,
534 0);
535}
536
John McCall76a40212011-02-09 01:13:10 +0000537SourceRange NonTypeTemplateParmDecl::getSourceRange() const {
Abramo Bagnaraee4bfd42011-03-04 11:03:48 +0000538 if (hasDefaultArgument() && !defaultArgumentWasInherited())
Abramo Bagnaraa2026c92011-03-08 16:41:52 +0000539 return SourceRange(getOuterLocStart(),
540 getDefaultArgument()->getSourceRange().getEnd());
541 return DeclaratorDecl::getSourceRange();
John McCall76a40212011-02-09 01:13:10 +0000542}
543
Douglas Gregord684b002009-02-10 19:49:53 +0000544SourceLocation NonTypeTemplateParmDecl::getDefaultArgumentLoc() const {
Abramo Bagnarad92f7a22010-06-09 09:26:05 +0000545 return hasDefaultArgument()
546 ? getDefaultArgument()->getSourceRange().getBegin()
547 : SourceLocation();
Douglas Gregord684b002009-02-10 19:49:53 +0000548}
549
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000550//===----------------------------------------------------------------------===//
551// TemplateTemplateParmDecl Method Implementations
552//===----------------------------------------------------------------------===//
553
David Blaikie99ba9e32011-12-20 02:48:34 +0000554void TemplateTemplateParmDecl::anchor() { }
555
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000556TemplateTemplateParmDecl *
Jay Foad4ba2a172011-01-12 09:06:06 +0000557TemplateTemplateParmDecl::Create(const ASTContext &C, DeclContext *DC,
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000558 SourceLocation L, unsigned D, unsigned P,
Douglas Gregor61c4d282011-01-05 15:48:55 +0000559 bool ParameterPack, IdentifierInfo *Id,
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000560 TemplateParameterList *Params) {
Douglas Gregor61c4d282011-01-05 15:48:55 +0000561 return new (C) TemplateTemplateParmDecl(DC, L, D, P, ParameterPack, Id,
562 Params);
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000563}
564
Douglas Gregor1e68ecc2012-01-05 21:55:30 +0000565TemplateTemplateParmDecl *
566TemplateTemplateParmDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
567 void *Mem = AllocateDeserializedDecl(C, ID, sizeof(TemplateTemplateParmDecl));
568 return new (Mem) TemplateTemplateParmDecl(0, SourceLocation(), 0, 0, false,
569 0, 0);
570}
571
Douglas Gregor3e00bad2009-02-17 01:05:43 +0000572//===----------------------------------------------------------------------===//
Douglas Gregor7e063902009-05-11 23:53:27 +0000573// TemplateArgumentList Implementation
574//===----------------------------------------------------------------------===//
Douglas Gregor910f8002010-11-07 23:05:16 +0000575TemplateArgumentList *
576TemplateArgumentList::CreateCopy(ASTContext &Context,
577 const TemplateArgument *Args,
578 unsigned NumArgs) {
579 std::size_t Size = sizeof(TemplateArgumentList)
580 + NumArgs * sizeof(TemplateArgument);
581 void *Mem = Context.Allocate(Size);
582 TemplateArgument *StoredArgs
583 = reinterpret_cast<TemplateArgument *>(
584 static_cast<TemplateArgumentList *>(Mem) + 1);
585 std::uninitialized_copy(Args, Args + NumArgs, StoredArgs);
586 return new (Mem) TemplateArgumentList(StoredArgs, NumArgs, true);
Argyrios Kyrtzidis94d228d2010-06-23 13:48:23 +0000587}
588
Argyrios Kyrtzidis71a76052011-09-22 20:07:09 +0000589FunctionTemplateSpecializationInfo *
590FunctionTemplateSpecializationInfo::Create(ASTContext &C, FunctionDecl *FD,
591 FunctionTemplateDecl *Template,
592 TemplateSpecializationKind TSK,
593 const TemplateArgumentList *TemplateArgs,
594 const TemplateArgumentListInfo *TemplateArgsAsWritten,
595 SourceLocation POI) {
596 const ASTTemplateArgumentListInfo *ArgsAsWritten = 0;
597 if (TemplateArgsAsWritten)
598 ArgsAsWritten = ASTTemplateArgumentListInfo::Create(C,
599 *TemplateArgsAsWritten);
600
601 return new (C) FunctionTemplateSpecializationInfo(FD, Template, TSK,
602 TemplateArgs,
603 ArgsAsWritten,
604 POI);
605}
606
Douglas Gregor7e063902009-05-11 23:53:27 +0000607//===----------------------------------------------------------------------===//
David Blaikie99ba9e32011-12-20 02:48:34 +0000608// TemplateDecl Implementation
609//===----------------------------------------------------------------------===//
610
611void TemplateDecl::anchor() { }
612
613//===----------------------------------------------------------------------===//
Douglas Gregor3e00bad2009-02-17 01:05:43 +0000614// ClassTemplateSpecializationDecl Implementation
615//===----------------------------------------------------------------------===//
616ClassTemplateSpecializationDecl::
Douglas Gregor13c85772010-05-06 00:28:52 +0000617ClassTemplateSpecializationDecl(ASTContext &Context, Kind DK, TagKind TK,
Abramo Bagnaraba877ad2011-03-09 14:09:51 +0000618 DeclContext *DC, SourceLocation StartLoc,
619 SourceLocation IdLoc,
Douglas Gregor3e00bad2009-02-17 01:05:43 +0000620 ClassTemplateDecl *SpecializedTemplate,
Douglas Gregor910f8002010-11-07 23:05:16 +0000621 const TemplateArgument *Args,
622 unsigned NumArgs,
Douglas Gregor8e9e9ef2009-07-29 23:36:44 +0000623 ClassTemplateSpecializationDecl *PrevDecl)
Abramo Bagnaraba877ad2011-03-09 14:09:51 +0000624 : CXXRecordDecl(DK, TK, DC, StartLoc, IdLoc,
Douglas Gregor8e9e9ef2009-07-29 23:36:44 +0000625 SpecializedTemplate->getIdentifier(),
626 PrevDecl),
Douglas Gregor3e00bad2009-02-17 01:05:43 +0000627 SpecializedTemplate(SpecializedTemplate),
Abramo Bagnarac98971d2010-06-12 07:44:57 +0000628 ExplicitInfo(0),
Douglas Gregor910f8002010-11-07 23:05:16 +0000629 TemplateArgs(TemplateArgumentList::CreateCopy(Context, Args, NumArgs)),
Douglas Gregor7e063902009-05-11 23:53:27 +0000630 SpecializationKind(TSK_Undeclared) {
Douglas Gregor3e00bad2009-02-17 01:05:43 +0000631}
Mike Stump1eb44332009-09-09 15:08:12 +0000632
Argyrios Kyrtzidis94d228d2010-06-23 13:48:23 +0000633ClassTemplateSpecializationDecl::ClassTemplateSpecializationDecl(Kind DK)
Abramo Bagnaraba877ad2011-03-09 14:09:51 +0000634 : CXXRecordDecl(DK, TTK_Struct, 0, SourceLocation(), SourceLocation(), 0, 0),
Argyrios Kyrtzidis94d228d2010-06-23 13:48:23 +0000635 ExplicitInfo(0),
636 SpecializationKind(TSK_Undeclared) {
637}
638
Douglas Gregor3e00bad2009-02-17 01:05:43 +0000639ClassTemplateSpecializationDecl *
Douglas Gregor13c85772010-05-06 00:28:52 +0000640ClassTemplateSpecializationDecl::Create(ASTContext &Context, TagKind TK,
Abramo Bagnaraba877ad2011-03-09 14:09:51 +0000641 DeclContext *DC,
642 SourceLocation StartLoc,
643 SourceLocation IdLoc,
Douglas Gregor3e00bad2009-02-17 01:05:43 +0000644 ClassTemplateDecl *SpecializedTemplate,
Douglas Gregor910f8002010-11-07 23:05:16 +0000645 const TemplateArgument *Args,
646 unsigned NumArgs,
Douglas Gregorcc636682009-02-17 23:15:12 +0000647 ClassTemplateSpecializationDecl *PrevDecl) {
Douglas Gregorcc636682009-02-17 23:15:12 +0000648 ClassTemplateSpecializationDecl *Result
Mike Stump1eb44332009-09-09 15:08:12 +0000649 = new (Context)ClassTemplateSpecializationDecl(Context,
Douglas Gregorc8ab2562009-05-31 09:31:02 +0000650 ClassTemplateSpecialization,
Abramo Bagnaraba877ad2011-03-09 14:09:51 +0000651 TK, DC, StartLoc, IdLoc,
Douglas Gregor7e063902009-05-11 23:53:27 +0000652 SpecializedTemplate,
Douglas Gregor910f8002010-11-07 23:05:16 +0000653 Args, NumArgs,
Douglas Gregor8e9e9ef2009-07-29 23:36:44 +0000654 PrevDecl);
Douglas Gregorcc636682009-02-17 23:15:12 +0000655 Context.getTypeDeclType(Result, PrevDecl);
656 return Result;
Douglas Gregor3e00bad2009-02-17 01:05:43 +0000657}
Douglas Gregorc8ab2562009-05-31 09:31:02 +0000658
Argyrios Kyrtzidis94d228d2010-06-23 13:48:23 +0000659ClassTemplateSpecializationDecl *
Douglas Gregor1e68ecc2012-01-05 21:55:30 +0000660ClassTemplateSpecializationDecl::CreateDeserialized(ASTContext &C,
661 unsigned ID) {
662 void *Mem = AllocateDeserializedDecl(C, ID,
663 sizeof(ClassTemplateSpecializationDecl));
664 return new (Mem) ClassTemplateSpecializationDecl(ClassTemplateSpecialization);
Argyrios Kyrtzidis94d228d2010-06-23 13:48:23 +0000665}
666
Douglas Gregorda2142f2011-02-19 18:51:44 +0000667void
668ClassTemplateSpecializationDecl::getNameForDiagnostic(std::string &S,
669 const PrintingPolicy &Policy,
670 bool Qualified) const {
671 NamedDecl::getNameForDiagnostic(S, Policy, Qualified);
672
673 const TemplateArgumentList &TemplateArgs = getTemplateArgs();
674 S += TemplateSpecializationType::PrintTemplateArgumentList(
675 TemplateArgs.data(),
676 TemplateArgs.size(),
677 Policy);
678}
679
Douglas Gregor37d93e92009-08-02 23:24:31 +0000680ClassTemplateDecl *
Mike Stump1eb44332009-09-09 15:08:12 +0000681ClassTemplateSpecializationDecl::getSpecializedTemplate() const {
682 if (SpecializedPartialSpecialization *PartialSpec
Douglas Gregor37d93e92009-08-02 23:24:31 +0000683 = SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization*>())
684 return PartialSpec->PartialSpecialization->getSpecializedTemplate();
685 return SpecializedTemplate.get<ClassTemplateDecl*>();
686}
687
Abramo Bagnara4a85a732011-03-04 14:20:30 +0000688SourceRange
689ClassTemplateSpecializationDecl::getSourceRange() const {
Abramo Bagnara09d82122011-10-03 20:34:03 +0000690 if (ExplicitInfo) {
691 SourceLocation Begin = getExternLoc();
692 if (Begin.isInvalid())
693 Begin = getTemplateKeywordLoc();
694 SourceLocation End = getRBraceLoc();
695 if (End.isInvalid())
696 End = getTypeAsWritten()->getTypeLoc().getEndLoc();
697 return SourceRange(Begin, End);
698 }
699 else {
700 // No explicit info available.
701 llvm::PointerUnion<ClassTemplateDecl *,
702 ClassTemplatePartialSpecializationDecl *>
703 inst_from = getInstantiatedFrom();
704 if (inst_from.isNull())
705 return getSpecializedTemplate()->getSourceRange();
706 if (ClassTemplateDecl *ctd = inst_from.dyn_cast<ClassTemplateDecl*>())
707 return ctd->getSourceRange();
708 return inst_from.get<ClassTemplatePartialSpecializationDecl*>()
709 ->getSourceRange();
710 }
Abramo Bagnara4a85a732011-03-04 14:20:30 +0000711}
712
Douglas Gregorc8ab2562009-05-31 09:31:02 +0000713//===----------------------------------------------------------------------===//
714// ClassTemplatePartialSpecializationDecl Implementation
715//===----------------------------------------------------------------------===//
David Blaikie99ba9e32011-12-20 02:48:34 +0000716void ClassTemplatePartialSpecializationDecl::anchor() { }
717
Douglas Gregor9a299e02011-03-04 17:52:15 +0000718ClassTemplatePartialSpecializationDecl::
719ClassTemplatePartialSpecializationDecl(ASTContext &Context, TagKind TK,
Abramo Bagnaraba877ad2011-03-09 14:09:51 +0000720 DeclContext *DC,
721 SourceLocation StartLoc,
722 SourceLocation IdLoc,
Douglas Gregor9a299e02011-03-04 17:52:15 +0000723 TemplateParameterList *Params,
724 ClassTemplateDecl *SpecializedTemplate,
725 const TemplateArgument *Args,
726 unsigned NumArgs,
727 TemplateArgumentLoc *ArgInfos,
728 unsigned NumArgInfos,
729 ClassTemplatePartialSpecializationDecl *PrevDecl,
730 unsigned SequenceNumber)
731 : ClassTemplateSpecializationDecl(Context,
732 ClassTemplatePartialSpecialization,
Abramo Bagnaraba877ad2011-03-09 14:09:51 +0000733 TK, DC, StartLoc, IdLoc,
734 SpecializedTemplate,
Douglas Gregor9a299e02011-03-04 17:52:15 +0000735 Args, NumArgs, PrevDecl),
736 TemplateParams(Params), ArgsAsWritten(ArgInfos),
737 NumArgsAsWritten(NumArgInfos), SequenceNumber(SequenceNumber),
738 InstantiatedFromMember(0, false)
739{
Douglas Gregor787a40d2011-03-04 18:32:38 +0000740 AdoptTemplateParameterList(Params, this);
Douglas Gregor9a299e02011-03-04 17:52:15 +0000741}
742
Douglas Gregorc8ab2562009-05-31 09:31:02 +0000743ClassTemplatePartialSpecializationDecl *
744ClassTemplatePartialSpecializationDecl::
Abramo Bagnaraba877ad2011-03-09 14:09:51 +0000745Create(ASTContext &Context, TagKind TK,DeclContext *DC,
746 SourceLocation StartLoc, SourceLocation IdLoc,
Douglas Gregorc8ab2562009-05-31 09:31:02 +0000747 TemplateParameterList *Params,
748 ClassTemplateDecl *SpecializedTemplate,
Douglas Gregor910f8002010-11-07 23:05:16 +0000749 const TemplateArgument *Args,
750 unsigned NumArgs,
John McCalld5532b62009-11-23 01:53:49 +0000751 const TemplateArgumentListInfo &ArgInfos,
John McCall3cb0ebd2010-03-10 03:28:59 +0000752 QualType CanonInjectedType,
Douglas Gregordc60c1e2010-04-30 05:56:50 +0000753 ClassTemplatePartialSpecializationDecl *PrevDecl,
754 unsigned SequenceNumber) {
John McCalld5532b62009-11-23 01:53:49 +0000755 unsigned N = ArgInfos.size();
John McCall833ca992009-10-29 08:12:44 +0000756 TemplateArgumentLoc *ClonedArgs = new (Context) TemplateArgumentLoc[N];
757 for (unsigned I = 0; I != N; ++I)
758 ClonedArgs[I] = ArgInfos[I];
759
Douglas Gregorc8ab2562009-05-31 09:31:02 +0000760 ClassTemplatePartialSpecializationDecl *Result
Abramo Bagnaraba877ad2011-03-09 14:09:51 +0000761 = new (Context)ClassTemplatePartialSpecializationDecl(Context, TK, DC,
762 StartLoc, IdLoc,
763 Params,
Douglas Gregorc8ab2562009-05-31 09:31:02 +0000764 SpecializedTemplate,
Douglas Gregor910f8002010-11-07 23:05:16 +0000765 Args, NumArgs,
John McCall833ca992009-10-29 08:12:44 +0000766 ClonedArgs, N,
Douglas Gregordc60c1e2010-04-30 05:56:50 +0000767 PrevDecl,
768 SequenceNumber);
Douglas Gregorc8ab2562009-05-31 09:31:02 +0000769 Result->setSpecializationKind(TSK_ExplicitSpecialization);
John McCall3cb0ebd2010-03-10 03:28:59 +0000770
771 Context.getInjectedClassNameType(Result, CanonInjectedType);
Douglas Gregorc8ab2562009-05-31 09:31:02 +0000772 return Result;
773}
John McCalldd4a3b02009-09-16 22:47:08 +0000774
Argyrios Kyrtzidis94d228d2010-06-23 13:48:23 +0000775ClassTemplatePartialSpecializationDecl *
Douglas Gregor1e68ecc2012-01-05 21:55:30 +0000776ClassTemplatePartialSpecializationDecl::CreateDeserialized(ASTContext &C,
777 unsigned ID) {
778 void *Mem = AllocateDeserializedDecl(C, ID,
779 sizeof(ClassTemplatePartialSpecializationDecl));
780 return new (Mem) ClassTemplatePartialSpecializationDecl();
Argyrios Kyrtzidis94d228d2010-06-23 13:48:23 +0000781}
782
John McCalldd4a3b02009-09-16 22:47:08 +0000783//===----------------------------------------------------------------------===//
784// FriendTemplateDecl Implementation
785//===----------------------------------------------------------------------===//
786
David Blaikie99ba9e32011-12-20 02:48:34 +0000787void FriendTemplateDecl::anchor() { }
788
John McCalldd4a3b02009-09-16 22:47:08 +0000789FriendTemplateDecl *FriendTemplateDecl::Create(ASTContext &Context,
790 DeclContext *DC,
791 SourceLocation L,
792 unsigned NParams,
793 TemplateParameterList **Params,
794 FriendUnion Friend,
795 SourceLocation FLoc) {
796 FriendTemplateDecl *Result
797 = new (Context) FriendTemplateDecl(DC, L, NParams, Params, Friend, FLoc);
798 return Result;
799}
Argyrios Kyrtzidis554e6aa2010-07-22 16:04:10 +0000800
Douglas Gregor1e68ecc2012-01-05 21:55:30 +0000801FriendTemplateDecl *FriendTemplateDecl::CreateDeserialized(ASTContext &C,
802 unsigned ID) {
803 void *Mem = AllocateDeserializedDecl(C, ID, sizeof(FriendTemplateDecl));
804 return new (Mem) FriendTemplateDecl(EmptyShell());
Argyrios Kyrtzidis554e6aa2010-07-22 16:04:10 +0000805}
Richard Smith3e4c6c42011-05-05 21:57:07 +0000806
807//===----------------------------------------------------------------------===//
808// TypeAliasTemplateDecl Implementation
809//===----------------------------------------------------------------------===//
810
811TypeAliasTemplateDecl *TypeAliasTemplateDecl::Create(ASTContext &C,
812 DeclContext *DC,
813 SourceLocation L,
814 DeclarationName Name,
815 TemplateParameterList *Params,
816 NamedDecl *Decl) {
817 AdoptTemplateParameterList(Params, DC);
818 return new (C) TypeAliasTemplateDecl(DC, L, Name, Params, Decl);
819}
820
Douglas Gregor1e68ecc2012-01-05 21:55:30 +0000821TypeAliasTemplateDecl *TypeAliasTemplateDecl::CreateDeserialized(ASTContext &C,
822 unsigned ID) {
823 void *Mem = AllocateDeserializedDecl(C, ID, sizeof(TypeAliasTemplateDecl));
824 return new (Mem) TypeAliasTemplateDecl(0, SourceLocation(), DeclarationName(),
825 0, 0);
Richard Smith3e4c6c42011-05-05 21:57:07 +0000826}
827
828void TypeAliasTemplateDecl::DeallocateCommon(void *Ptr) {
829 static_cast<Common *>(Ptr)->~Common();
830}
831RedeclarableTemplateDecl::CommonBase *
832TypeAliasTemplateDecl::newCommon(ASTContext &C) {
833 Common *CommonPtr = new (C) Common;
834 C.AddDeallocation(DeallocateCommon, CommonPtr);
835 return CommonPtr;
836}
837
David Blaikie99ba9e32011-12-20 02:48:34 +0000838//===----------------------------------------------------------------------===//
839// ClassScopeFunctionSpecializationDecl Implementation
840//===----------------------------------------------------------------------===//
841
842void ClassScopeFunctionSpecializationDecl::anchor() { }
Douglas Gregor1e68ecc2012-01-05 21:55:30 +0000843
844ClassScopeFunctionSpecializationDecl *
845ClassScopeFunctionSpecializationDecl::CreateDeserialized(ASTContext &C,
846 unsigned ID) {
847 void *Mem = AllocateDeserializedDecl(C, ID,
848 sizeof(ClassScopeFunctionSpecializationDecl));
849 return new (Mem) ClassScopeFunctionSpecializationDecl(0, SourceLocation(), 0);
850}