blob: fc73e6f412521fc1fd76ab895c2a9c40bc9d97fd [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
Douglas Gregoraaba5e32009-02-04 19:02:06 +000014#include "clang/AST/DeclTemplate.h"
Chandler Carruth55fc8732012-12-04 09:13:33 +000015#include "clang/AST/ASTContext.h"
16#include "clang/AST/ASTMutationListener.h"
17#include "clang/AST/DeclCXX.h"
Douglas Gregor55f6b142009-02-09 18:46:07 +000018#include "clang/AST/Expr.h"
Douglas Gregorb95cc972011-01-04 02:33:52 +000019#include "clang/AST/ExprCXX.h"
John McCall833ca992009-10-29 08:12:44 +000020#include "clang/AST/TypeLoc.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),
Richard Smith6964b3f2012-09-07 02:06:42 +000035 NumParams(NumParams), ContainsUnexpandedParameterPack(false) {
36 assert(this->NumParams == NumParams && "Too many template parameters");
37 for (unsigned Idx = 0; Idx < NumParams; ++Idx) {
38 NamedDecl *P = Params[Idx];
39 begin()[Idx] = P;
40
41 if (!P->isTemplateParameterPack()) {
42 if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(P))
43 if (NTTP->getType()->containsUnexpandedParameterPack())
44 ContainsUnexpandedParameterPack = true;
45
46 if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(P))
47 if (TTP->getTemplateParameters()->containsUnexpandedParameterPack())
48 ContainsUnexpandedParameterPack = true;
49
50 // FIXME: If a default argument contains an unexpanded parameter pack, the
51 // template parameter list does too.
52 }
53 }
Douglas Gregoraaba5e32009-02-04 19:02:06 +000054}
55
56TemplateParameterList *
Jay Foad4ba2a172011-01-12 09:06:06 +000057TemplateParameterList::Create(const ASTContext &C, SourceLocation TemplateLoc,
Douglas Gregorbf4ea562009-09-15 16:23:51 +000058 SourceLocation LAngleLoc, NamedDecl **Params,
Douglas Gregorddc29e12009-02-06 22:42:48 +000059 unsigned NumParams, SourceLocation RAngleLoc) {
Douglas Gregorbf4ea562009-09-15 16:23:51 +000060 unsigned Size = sizeof(TemplateParameterList)
61 + sizeof(NamedDecl *) * NumParams;
Richard Smith1a30edb2012-08-16 22:51:34 +000062 unsigned Align = std::max(llvm::alignOf<TemplateParameterList>(),
63 llvm::alignOf<NamedDecl*>());
Douglas Gregoraaba5e32009-02-04 19:02:06 +000064 void *Mem = C.Allocate(Size, Align);
Mike Stump1eb44332009-09-09 15:08:12 +000065 return new (Mem) TemplateParameterList(TemplateLoc, LAngleLoc, Params,
Douglas Gregorddc29e12009-02-06 22:42:48 +000066 NumParams, RAngleLoc);
Douglas Gregoraaba5e32009-02-04 19:02:06 +000067}
68
Douglas Gregor62cb18d2009-02-11 18:16:40 +000069unsigned TemplateParameterList::getMinRequiredArguments() const {
Douglas Gregor6952f1e2011-01-19 20:10:05 +000070 unsigned NumRequiredArgs = 0;
71 for (iterator P = const_cast<TemplateParameterList *>(this)->begin(),
72 PEnd = const_cast<TemplateParameterList *>(this)->end();
73 P != PEnd; ++P) {
74 if ((*P)->isTemplateParameterPack()) {
75 if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(*P))
76 if (NTTP->isExpandedParameterPack()) {
77 NumRequiredArgs += NTTP->getNumExpansionTypes();
78 continue;
79 }
80
Douglas Gregor62cb18d2009-02-11 18:16:40 +000081 break;
Douglas Gregor6952f1e2011-01-19 20:10:05 +000082 }
83
84 if (TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(*P)) {
85 if (TTP->hasDefaultArgument())
86 break;
87 } else if (NonTypeTemplateParmDecl *NTTP
88 = dyn_cast<NonTypeTemplateParmDecl>(*P)) {
89 if (NTTP->hasDefaultArgument())
90 break;
91 } else if (cast<TemplateTemplateParmDecl>(*P)->hasDefaultArgument())
92 break;
93
94 ++NumRequiredArgs;
Douglas Gregor62cb18d2009-02-11 18:16:40 +000095 }
Douglas Gregor6952f1e2011-01-19 20:10:05 +000096
Douglas Gregor62cb18d2009-02-11 18:16:40 +000097 return NumRequiredArgs;
98}
99
Douglas Gregored9c0f92009-10-29 00:04:11 +0000100unsigned TemplateParameterList::getDepth() const {
101 if (size() == 0)
102 return 0;
103
104 const NamedDecl *FirstParm = getParam(0);
105 if (const TemplateTypeParmDecl *TTP
106 = dyn_cast<TemplateTypeParmDecl>(FirstParm))
107 return TTP->getDepth();
108 else if (const NonTypeTemplateParmDecl *NTTP
109 = dyn_cast<NonTypeTemplateParmDecl>(FirstParm))
110 return NTTP->getDepth();
111 else
112 return cast<TemplateTemplateParmDecl>(FirstParm)->getDepth();
113}
114
Douglas Gregor787a40d2011-03-04 18:32:38 +0000115static void AdoptTemplateParameterList(TemplateParameterList *Params,
116 DeclContext *Owner) {
117 for (TemplateParameterList::iterator P = Params->begin(),
118 PEnd = Params->end();
119 P != PEnd; ++P) {
120 (*P)->setDeclContext(Owner);
121
122 if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(*P))
123 AdoptTemplateParameterList(TTP->getTemplateParameters(), Owner);
124 }
125}
126
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000127//===----------------------------------------------------------------------===//
Peter Collingbourne9eabeba2010-07-29 16:11:51 +0000128// RedeclarableTemplateDecl Implementation
129//===----------------------------------------------------------------------===//
130
Dmitri Gribenkob76d9712013-01-23 16:52:57 +0000131RedeclarableTemplateDecl::CommonBase *RedeclarableTemplateDecl::getCommonPtr() const {
Rafael Espindola92975352013-10-19 02:28:17 +0000132 if (Common)
133 return Common;
134
135 // Walk the previous-declaration chain until we either find a declaration
136 // with a common pointer or we run out of previous declarations.
137 SmallVector<const RedeclarableTemplateDecl *, 2> PrevDecls;
138 for (const RedeclarableTemplateDecl *Prev = getPreviousDecl(); Prev;
139 Prev = Prev->getPreviousDecl()) {
140 if (Prev->Common) {
141 Common = Prev->Common;
142 break;
Douglas Gregor7c99bb5c2012-01-14 15:13:49 +0000143 }
Peter Collingbourne9eabeba2010-07-29 16:11:51 +0000144
Rafael Espindola92975352013-10-19 02:28:17 +0000145 PrevDecls.push_back(Prev);
Peter Collingbourne9eabeba2010-07-29 16:11:51 +0000146 }
Peter Collingbourne9eabeba2010-07-29 16:11:51 +0000147
Rafael Espindola92975352013-10-19 02:28:17 +0000148 // If we never found a common pointer, allocate one now.
149 if (!Common) {
150 // FIXME: If any of the declarations is from an AST file, we probably
151 // need an update record to add the common data.
152
153 Common = newCommon(getASTContext());
154 }
155
156 // Update any previous declarations we saw with the common pointer.
157 for (unsigned I = 0, N = PrevDecls.size(); I != N; ++I)
158 PrevDecls[I]->Common = Common;
159
Douglas Gregor7c99bb5c2012-01-14 15:13:49 +0000160 return Common;
Peter Collingbournef88718e2010-07-29 16:12:09 +0000161}
162
Peter Collingbourne40485902010-07-30 17:09:04 +0000163template <class EntryType>
164typename RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::DeclType*
165RedeclarableTemplateDecl::findSpecializationImpl(
Chandler Carruthd964d632012-05-03 23:49:05 +0000166 llvm::FoldingSetVector<EntryType> &Specs,
Peter Collingbourne40485902010-07-30 17:09:04 +0000167 const TemplateArgument *Args, unsigned NumArgs,
168 void *&InsertPos) {
169 typedef SpecEntryTraits<EntryType> SETraits;
170 llvm::FoldingSetNodeID ID;
171 EntryType::Profile(ID,Args,NumArgs, getASTContext());
172 EntryType *Entry = Specs.FindNodeOrInsertPos(ID, InsertPos);
Douglas Gregoref96ee02012-01-14 16:38:05 +0000173 return Entry ? SETraits::getMostRecentDecl(Entry) : 0;
Peter Collingbourne40485902010-07-30 17:09:04 +0000174}
175
Douglas Gregorc494f772011-03-05 17:54:25 +0000176/// \brief Generate the injected template arguments for the given template
177/// parameter list, e.g., for the injected-class-name of a class template.
178static void GenerateInjectedTemplateArgs(ASTContext &Context,
179 TemplateParameterList *Params,
180 TemplateArgument *Args) {
181 for (TemplateParameterList::iterator Param = Params->begin(),
182 ParamEnd = Params->end();
183 Param != ParamEnd; ++Param) {
184 TemplateArgument Arg;
185 if (TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(*Param)) {
186 QualType ArgType = Context.getTypeDeclType(TTP);
187 if (TTP->isParameterPack())
David Blaikie66874fb2013-02-21 01:47:18 +0000188 ArgType = Context.getPackExpansionType(ArgType, None);
David Blaikiedc84cd52013-02-20 22:23:23 +0000189
Douglas Gregorc494f772011-03-05 17:54:25 +0000190 Arg = TemplateArgument(ArgType);
191 } else if (NonTypeTemplateParmDecl *NTTP =
192 dyn_cast<NonTypeTemplateParmDecl>(*Param)) {
John McCallf4b88a42012-03-10 09:33:50 +0000193 Expr *E = new (Context) DeclRefExpr(NTTP, /*enclosing*/ false,
Douglas Gregorc494f772011-03-05 17:54:25 +0000194 NTTP->getType().getNonLValueExprType(Context),
195 Expr::getValueKindForType(NTTP->getType()),
196 NTTP->getLocation());
197
198 if (NTTP->isParameterPack())
David Blaikie66874fb2013-02-21 01:47:18 +0000199 E = new (Context) PackExpansionExpr(Context.DependentTy, E,
200 NTTP->getLocation(), None);
Douglas Gregorc494f772011-03-05 17:54:25 +0000201 Arg = TemplateArgument(E);
202 } else {
203 TemplateTemplateParmDecl *TTP = cast<TemplateTemplateParmDecl>(*Param);
204 if (TTP->isParameterPack())
David Blaikiedc84cd52013-02-20 22:23:23 +0000205 Arg = TemplateArgument(TemplateName(TTP), Optional<unsigned>());
Douglas Gregorc494f772011-03-05 17:54:25 +0000206 else
207 Arg = TemplateArgument(TemplateName(TTP));
208 }
209
210 if ((*Param)->isTemplateParameterPack())
211 Arg = TemplateArgument::CreatePackCopy(Context, &Arg, 1);
212
213 *Args++ = Arg;
214 }
215}
216
Peter Collingbourne9eabeba2010-07-29 16:11:51 +0000217//===----------------------------------------------------------------------===//
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000218// FunctionTemplateDecl Implementation
219//===----------------------------------------------------------------------===//
220
Douglas Gregor00545312010-05-23 18:26:36 +0000221void FunctionTemplateDecl::DeallocateCommon(void *Ptr) {
222 static_cast<Common *>(Ptr)->~Common();
223}
224
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000225FunctionTemplateDecl *FunctionTemplateDecl::Create(ASTContext &C,
226 DeclContext *DC,
227 SourceLocation L,
228 DeclarationName Name,
Douglas Gregor127102b2009-06-29 20:59:39 +0000229 TemplateParameterList *Params,
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000230 NamedDecl *Decl) {
Douglas Gregor787a40d2011-03-04 18:32:38 +0000231 AdoptTemplateParameterList(Params, cast<DeclContext>(Decl));
Stephen Hines651f13c2014-04-23 16:59:28 -0700232 return new (C, DC) FunctionTemplateDecl(DC, L, Name, Params, Decl);
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000233}
234
Douglas Gregor1e68ecc2012-01-05 21:55:30 +0000235FunctionTemplateDecl *FunctionTemplateDecl::CreateDeserialized(ASTContext &C,
236 unsigned ID) {
Stephen Hines651f13c2014-04-23 16:59:28 -0700237 return new (C, ID) FunctionTemplateDecl(0, SourceLocation(), DeclarationName(),
238 0, 0);
Douglas Gregor9a299e02011-03-04 17:52:15 +0000239}
240
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +0000241RedeclarableTemplateDecl::CommonBase *
Dmitri Gribenkob76d9712013-01-23 16:52:57 +0000242FunctionTemplateDecl::newCommon(ASTContext &C) const {
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +0000243 Common *CommonPtr = new (C) Common;
244 C.AddDeallocation(DeallocateCommon, CommonPtr);
Peter Collingbourne9eabeba2010-07-29 16:11:51 +0000245 return CommonPtr;
246}
247
Richard Smith6982bf42013-06-28 04:37:53 +0000248void FunctionTemplateDecl::LoadLazySpecializations() const {
249 Common *CommonPtr = getCommonPtr();
250 if (CommonPtr->LazySpecializations) {
251 ASTContext &Context = getASTContext();
252 uint32_t *Specs = CommonPtr->LazySpecializations;
253 CommonPtr->LazySpecializations = 0;
254 for (uint32_t I = 0, N = *Specs++; I != N; ++I)
255 (void)Context.getExternalSource()->GetExternalDecl(Specs[I]);
256 }
257}
258
259llvm::FoldingSetVector<FunctionTemplateSpecializationInfo> &
260FunctionTemplateDecl::getSpecializations() const {
261 LoadLazySpecializations();
262 return getCommonPtr()->Specializations;
263}
264
Argyrios Kyrtzidis2c853e42010-07-20 13:59:58 +0000265FunctionDecl *
266FunctionTemplateDecl::findSpecialization(const TemplateArgument *Args,
267 unsigned NumArgs, void *&InsertPos) {
Peter Collingbourne40485902010-07-30 17:09:04 +0000268 return findSpecializationImpl(getSpecializations(), Args, NumArgs, InsertPos);
Argyrios Kyrtzidis2c853e42010-07-20 13:59:58 +0000269}
270
Sebastian Redl5bbcdbf2011-04-14 14:07:59 +0000271void FunctionTemplateDecl::addSpecialization(
272 FunctionTemplateSpecializationInfo *Info, void *InsertPos) {
Douglas Gregor1e1e9722012-03-28 14:34:23 +0000273 if (InsertPos)
274 getSpecializations().InsertNode(Info, InsertPos);
275 else
276 getSpecializations().GetOrInsertNode(Info);
Sebastian Redl5bbcdbf2011-04-14 14:07:59 +0000277 if (ASTMutationListener *L = getASTMutationListener())
278 L->AddedCXXTemplateSpecialization(this, Info->Function);
279}
280
Richard Smith7a9f7c72013-05-17 03:04:50 +0000281ArrayRef<TemplateArgument> FunctionTemplateDecl::getInjectedTemplateArgs() {
Douglas Gregorc494f772011-03-05 17:54:25 +0000282 TemplateParameterList *Params = getTemplateParameters();
283 Common *CommonPtr = getCommonPtr();
284 if (!CommonPtr->InjectedArgs) {
285 CommonPtr->InjectedArgs
Richard Smith7a9f7c72013-05-17 03:04:50 +0000286 = new (getASTContext()) TemplateArgument[Params->size()];
287 GenerateInjectedTemplateArgs(getASTContext(), Params,
Douglas Gregorc494f772011-03-05 17:54:25 +0000288 CommonPtr->InjectedArgs);
289 }
Richard Smith7a9f7c72013-05-17 03:04:50 +0000290
291 return llvm::makeArrayRef(CommonPtr->InjectedArgs, Params->size());
Douglas Gregorc494f772011-03-05 17:54:25 +0000292}
293
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000294//===----------------------------------------------------------------------===//
295// ClassTemplateDecl Implementation
296//===----------------------------------------------------------------------===//
297
Douglas Gregor00545312010-05-23 18:26:36 +0000298void ClassTemplateDecl::DeallocateCommon(void *Ptr) {
299 static_cast<Common *>(Ptr)->~Common();
300}
301
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000302ClassTemplateDecl *ClassTemplateDecl::Create(ASTContext &C,
303 DeclContext *DC,
304 SourceLocation L,
305 DeclarationName Name,
306 TemplateParameterList *Params,
Douglas Gregor5953d8b2009-03-19 17:26:29 +0000307 NamedDecl *Decl,
308 ClassTemplateDecl *PrevDecl) {
Douglas Gregor787a40d2011-03-04 18:32:38 +0000309 AdoptTemplateParameterList(Params, cast<DeclContext>(Decl));
Stephen Hines651f13c2014-04-23 16:59:28 -0700310 ClassTemplateDecl *New =
311 new (C, DC) ClassTemplateDecl(DC, L, Name, Params, Decl);
Rafael Espindolabc650912013-10-17 15:37:26 +0000312 New->setPreviousDecl(PrevDecl);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000313 return New;
Douglas Gregor5953d8b2009-03-19 17:26:29 +0000314}
315
Douglas Gregor1e68ecc2012-01-05 21:55:30 +0000316ClassTemplateDecl *ClassTemplateDecl::CreateDeserialized(ASTContext &C,
317 unsigned ID) {
Stephen Hines651f13c2014-04-23 16:59:28 -0700318 return new (C, ID) ClassTemplateDecl(EmptyShell());
Douglas Gregor9a299e02011-03-04 17:52:15 +0000319}
320
Dmitri Gribenkoe252a892013-02-14 13:20:36 +0000321void ClassTemplateDecl::LoadLazySpecializations() const {
Douglas Gregorc8e5cf82010-10-27 22:21:36 +0000322 Common *CommonPtr = getCommonPtr();
323 if (CommonPtr->LazySpecializations) {
324 ASTContext &Context = getASTContext();
325 uint32_t *Specs = CommonPtr->LazySpecializations;
326 CommonPtr->LazySpecializations = 0;
327 for (uint32_t I = 0, N = *Specs++; I != N; ++I)
328 (void)Context.getExternalSource()->GetExternalDecl(Specs[I]);
329 }
330}
331
Chandler Carruthd964d632012-05-03 23:49:05 +0000332llvm::FoldingSetVector<ClassTemplateSpecializationDecl> &
Dmitri Gribenkoe252a892013-02-14 13:20:36 +0000333ClassTemplateDecl::getSpecializations() const {
Douglas Gregorc8e5cf82010-10-27 22:21:36 +0000334 LoadLazySpecializations();
335 return getCommonPtr()->Specializations;
336}
337
Chandler Carruthd964d632012-05-03 23:49:05 +0000338llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> &
Douglas Gregorc8e5cf82010-10-27 22:21:36 +0000339ClassTemplateDecl::getPartialSpecializations() {
340 LoadLazySpecializations();
341 return getCommonPtr()->PartialSpecializations;
342}
343
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +0000344RedeclarableTemplateDecl::CommonBase *
Dmitri Gribenkob76d9712013-01-23 16:52:57 +0000345ClassTemplateDecl::newCommon(ASTContext &C) const {
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +0000346 Common *CommonPtr = new (C) Common;
347 C.AddDeallocation(DeallocateCommon, CommonPtr);
Peter Collingbourne9eabeba2010-07-29 16:11:51 +0000348 return CommonPtr;
349}
350
Argyrios Kyrtzidiscc0b1bc2010-07-20 13:59:28 +0000351ClassTemplateSpecializationDecl *
352ClassTemplateDecl::findSpecialization(const TemplateArgument *Args,
353 unsigned NumArgs, void *&InsertPos) {
Peter Collingbourne40485902010-07-30 17:09:04 +0000354 return findSpecializationImpl(getSpecializations(), Args, NumArgs, InsertPos);
Argyrios Kyrtzidiscc0b1bc2010-07-20 13:59:28 +0000355}
356
Argyrios Kyrtzidisbef1a7b2010-10-28 07:38:42 +0000357void ClassTemplateDecl::AddSpecialization(ClassTemplateSpecializationDecl *D,
358 void *InsertPos) {
Douglas Gregor1e1e9722012-03-28 14:34:23 +0000359 if (InsertPos)
360 getSpecializations().InsertNode(D, InsertPos);
361 else {
362 ClassTemplateSpecializationDecl *Existing
363 = getSpecializations().GetOrInsertNode(D);
364 (void)Existing;
365 assert(Existing->isCanonicalDecl() && "Non-canonical specialization?");
366 }
Argyrios Kyrtzidisbef1a7b2010-10-28 07:38:42 +0000367 if (ASTMutationListener *L = getASTMutationListener())
368 L->AddedCXXTemplateSpecialization(this, D);
369}
370
Argyrios Kyrtzidiscc0b1bc2010-07-20 13:59:28 +0000371ClassTemplatePartialSpecializationDecl *
372ClassTemplateDecl::findPartialSpecialization(const TemplateArgument *Args,
373 unsigned NumArgs,
374 void *&InsertPos) {
Peter Collingbourne40485902010-07-30 17:09:04 +0000375 return findSpecializationImpl(getPartialSpecializations(), Args, NumArgs,
376 InsertPos);
Argyrios Kyrtzidiscc0b1bc2010-07-20 13:59:28 +0000377}
378
Argyrios Kyrtzidisbef1a7b2010-10-28 07:38:42 +0000379void ClassTemplateDecl::AddPartialSpecialization(
380 ClassTemplatePartialSpecializationDecl *D,
381 void *InsertPos) {
Douglas Gregor1e1e9722012-03-28 14:34:23 +0000382 if (InsertPos)
383 getPartialSpecializations().InsertNode(D, InsertPos);
384 else {
385 ClassTemplatePartialSpecializationDecl *Existing
386 = getPartialSpecializations().GetOrInsertNode(D);
387 (void)Existing;
388 assert(Existing->isCanonicalDecl() && "Non-canonical specialization?");
389 }
390
Argyrios Kyrtzidisbef1a7b2010-10-28 07:38:42 +0000391 if (ASTMutationListener *L = getASTMutationListener())
392 L->AddedCXXTemplateSpecialization(this, D);
393}
394
Douglas Gregordc60c1e2010-04-30 05:56:50 +0000395void ClassTemplateDecl::getPartialSpecializations(
Chris Lattner5f9e2722011-07-23 10:55:15 +0000396 SmallVectorImpl<ClassTemplatePartialSpecializationDecl *> &PS) {
Chandler Carruthd964d632012-05-03 23:49:05 +0000397 llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> &PartialSpecs
Argyrios Kyrtzidis5bf1bdc2010-06-21 10:57:41 +0000398 = getPartialSpecializations();
Douglas Gregordc60c1e2010-04-30 05:56:50 +0000399 PS.clear();
Richard Smith37fd27d2013-08-22 23:27:37 +0000400 PS.reserve(PartialSpecs.size());
Chandler Carruthd964d632012-05-03 23:49:05 +0000401 for (llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl>::iterator
Douglas Gregordc60c1e2010-04-30 05:56:50 +0000402 P = PartialSpecs.begin(), PEnd = PartialSpecs.end();
Richard Smith37fd27d2013-08-22 23:27:37 +0000403 P != PEnd; ++P)
404 PS.push_back(P->getMostRecentDecl());
Douglas Gregordc60c1e2010-04-30 05:56:50 +0000405}
406
Douglas Gregorb88e8882009-07-30 17:40:51 +0000407ClassTemplatePartialSpecializationDecl *
408ClassTemplateDecl::findPartialSpecialization(QualType T) {
409 ASTContext &Context = getASTContext();
Chandler Carruthd964d632012-05-03 23:49:05 +0000410 using llvm::FoldingSetVector;
411 typedef FoldingSetVector<ClassTemplatePartialSpecializationDecl>::iterator
Douglas Gregorb88e8882009-07-30 17:40:51 +0000412 partial_spec_iterator;
413 for (partial_spec_iterator P = getPartialSpecializations().begin(),
414 PEnd = getPartialSpecializations().end();
415 P != PEnd; ++P) {
John McCall31f17ec2010-04-27 00:57:59 +0000416 if (Context.hasSameType(P->getInjectedSpecializationType(), T))
Douglas Gregoref96ee02012-01-14 16:38:05 +0000417 return P->getMostRecentDecl();
Argyrios Kyrtzidiscc0b1bc2010-07-20 13:59:28 +0000418 }
419
420 return 0;
421}
422
423ClassTemplatePartialSpecializationDecl *
424ClassTemplateDecl::findPartialSpecInstantiatedFromMember(
425 ClassTemplatePartialSpecializationDecl *D) {
426 Decl *DCanon = D->getCanonicalDecl();
Chandler Carruthd964d632012-05-03 23:49:05 +0000427 for (llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl>::iterator
Argyrios Kyrtzidiscc0b1bc2010-07-20 13:59:28 +0000428 P = getPartialSpecializations().begin(),
429 PEnd = getPartialSpecializations().end();
430 P != PEnd; ++P) {
431 if (P->getInstantiatedFromMember()->getCanonicalDecl() == DCanon)
Douglas Gregoref96ee02012-01-14 16:38:05 +0000432 return P->getMostRecentDecl();
Douglas Gregorb88e8882009-07-30 17:40:51 +0000433 }
Mike Stump1eb44332009-09-09 15:08:12 +0000434
Douglas Gregorb88e8882009-07-30 17:40:51 +0000435 return 0;
436}
437
John McCall3cb0ebd2010-03-10 03:28:59 +0000438QualType
Douglas Gregor24bae922010-07-08 18:37:38 +0000439ClassTemplateDecl::getInjectedClassNameSpecialization() {
Argyrios Kyrtzidis5bf1bdc2010-06-21 10:57:41 +0000440 Common *CommonPtr = getCommonPtr();
Douglas Gregor7da97d02009-05-10 22:57:19 +0000441 if (!CommonPtr->InjectedClassNameType.isNull())
442 return CommonPtr->InjectedClassNameType;
443
Douglas Gregorb7d09d62010-12-23 16:00:30 +0000444 // C++0x [temp.dep.type]p2:
445 // The template argument list of a primary template is a template argument
446 // list in which the nth template argument has the value of the nth template
447 // parameter of the class template. If the nth template parameter is a
448 // template parameter pack (14.5.3), the nth template argument is a pack
449 // expansion (14.5.3) whose pattern is the name of the template parameter
450 // pack.
Douglas Gregor24bae922010-07-08 18:37:38 +0000451 ASTContext &Context = getASTContext();
Douglas Gregor7da97d02009-05-10 22:57:19 +0000452 TemplateParameterList *Params = getTemplateParameters();
Chris Lattner5f9e2722011-07-23 10:55:15 +0000453 SmallVector<TemplateArgument, 16> TemplateArgs;
Douglas Gregorc494f772011-03-05 17:54:25 +0000454 TemplateArgs.resize(Params->size());
455 GenerateInjectedTemplateArgs(getASTContext(), Params, TemplateArgs.data());
Douglas Gregor7da97d02009-05-10 22:57:19 +0000456 CommonPtr->InjectedClassNameType
Douglas Gregor1275ae02009-07-28 23:00:59 +0000457 = Context.getTemplateSpecializationType(TemplateName(this),
Douglas Gregor7da97d02009-05-10 22:57:19 +0000458 &TemplateArgs[0],
Douglas Gregor1275ae02009-07-28 23:00:59 +0000459 TemplateArgs.size());
Douglas Gregor7da97d02009-05-10 22:57:19 +0000460 return CommonPtr->InjectedClassNameType;
461}
462
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000463//===----------------------------------------------------------------------===//
464// TemplateTypeParm Allocation/Deallocation Method Implementations
465//===----------------------------------------------------------------------===//
466
467TemplateTypeParmDecl *
Jay Foad4ba2a172011-01-12 09:06:06 +0000468TemplateTypeParmDecl::Create(const ASTContext &C, DeclContext *DC,
Abramo Bagnara344577e2011-03-06 15:48:19 +0000469 SourceLocation KeyLoc, SourceLocation NameLoc,
470 unsigned D, unsigned P, IdentifierInfo *Id,
471 bool Typename, bool ParameterPack) {
Chandler Carruth4fb86f82011-05-01 00:51:33 +0000472 TemplateTypeParmDecl *TTPDecl =
Stephen Hines651f13c2014-04-23 16:59:28 -0700473 new (C, DC) TemplateTypeParmDecl(DC, KeyLoc, NameLoc, Id, Typename);
Chandler Carruth4fb86f82011-05-01 00:51:33 +0000474 QualType TTPType = C.getTemplateTypeParmType(D, P, ParameterPack, TTPDecl);
475 TTPDecl->TypeForDecl = TTPType.getTypePtr();
476 return TTPDecl;
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000477}
478
Argyrios Kyrtzidisb8b03e62010-07-02 11:54:55 +0000479TemplateTypeParmDecl *
Douglas Gregor1e68ecc2012-01-05 21:55:30 +0000480TemplateTypeParmDecl::CreateDeserialized(const ASTContext &C, unsigned ID) {
Stephen Hines651f13c2014-04-23 16:59:28 -0700481 return new (C, ID) TemplateTypeParmDecl(0, SourceLocation(), SourceLocation(),
482 0, false);
Argyrios Kyrtzidisb8b03e62010-07-02 11:54:55 +0000483}
484
John McCall833ca992009-10-29 08:12:44 +0000485SourceLocation TemplateTypeParmDecl::getDefaultArgumentLoc() const {
Abramo Bagnara77d4ee22011-03-04 12:42:03 +0000486 return hasDefaultArgument()
487 ? DefaultArgument->getTypeLoc().getBeginLoc()
488 : SourceLocation();
489}
490
491SourceRange TemplateTypeParmDecl::getSourceRange() const {
492 if (hasDefaultArgument() && !defaultArgumentWasInherited())
Abramo Bagnara344577e2011-03-06 15:48:19 +0000493 return SourceRange(getLocStart(),
Abramo Bagnara77d4ee22011-03-04 12:42:03 +0000494 DefaultArgument->getTypeLoc().getEndLoc());
495 else
Abramo Bagnara344577e2011-03-06 15:48:19 +0000496 return TypeDecl::getSourceRange();
John McCall833ca992009-10-29 08:12:44 +0000497}
498
Douglas Gregored9c0f92009-10-29 00:04:11 +0000499unsigned TemplateTypeParmDecl::getDepth() const {
500 return TypeForDecl->getAs<TemplateTypeParmType>()->getDepth();
501}
502
503unsigned TemplateTypeParmDecl::getIndex() const {
504 return TypeForDecl->getAs<TemplateTypeParmType>()->getIndex();
505}
506
Chandler Carruth4fb86f82011-05-01 00:51:33 +0000507bool TemplateTypeParmDecl::isParameterPack() const {
508 return TypeForDecl->getAs<TemplateTypeParmType>()->isParameterPack();
509}
510
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000511//===----------------------------------------------------------------------===//
512// NonTypeTemplateParmDecl Method Implementations
513//===----------------------------------------------------------------------===//
514
Douglas Gregor6952f1e2011-01-19 20:10:05 +0000515NonTypeTemplateParmDecl::NonTypeTemplateParmDecl(DeclContext *DC,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +0000516 SourceLocation StartLoc,
517 SourceLocation IdLoc,
518 unsigned D, unsigned P,
519 IdentifierInfo *Id,
Douglas Gregor6952f1e2011-01-19 20:10:05 +0000520 QualType T,
521 TypeSourceInfo *TInfo,
522 const QualType *ExpandedTypes,
523 unsigned NumExpandedTypes,
524 TypeSourceInfo **ExpandedTInfos)
Abramo Bagnaraff676cb2011-03-08 08:55:46 +0000525 : DeclaratorDecl(NonTypeTemplateParm, DC, IdLoc, Id, T, TInfo, StartLoc),
Douglas Gregor6952f1e2011-01-19 20:10:05 +0000526 TemplateParmPosition(D, P), DefaultArgumentAndInherited(0, false),
527 ParameterPack(true), ExpandedParameterPack(true),
528 NumExpandedTypes(NumExpandedTypes)
529{
530 if (ExpandedTypes && ExpandedTInfos) {
531 void **TypesAndInfos = reinterpret_cast<void **>(this + 1);
532 for (unsigned I = 0; I != NumExpandedTypes; ++I) {
533 TypesAndInfos[2*I] = ExpandedTypes[I].getAsOpaquePtr();
534 TypesAndInfos[2*I + 1] = ExpandedTInfos[I];
535 }
536 }
537}
538
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000539NonTypeTemplateParmDecl *
Jay Foad4ba2a172011-01-12 09:06:06 +0000540NonTypeTemplateParmDecl::Create(const ASTContext &C, DeclContext *DC,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +0000541 SourceLocation StartLoc, SourceLocation IdLoc,
542 unsigned D, unsigned P, IdentifierInfo *Id,
543 QualType T, bool ParameterPack,
544 TypeSourceInfo *TInfo) {
Stephen Hines651f13c2014-04-23 16:59:28 -0700545 return new (C, DC) NonTypeTemplateParmDecl(DC, StartLoc, IdLoc, D, P, Id,
546 T, ParameterPack, TInfo);
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000547}
548
Douglas Gregor6952f1e2011-01-19 20:10:05 +0000549NonTypeTemplateParmDecl *
550NonTypeTemplateParmDecl::Create(const ASTContext &C, DeclContext *DC,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +0000551 SourceLocation StartLoc, SourceLocation IdLoc,
552 unsigned D, unsigned P,
Douglas Gregor6952f1e2011-01-19 20:10:05 +0000553 IdentifierInfo *Id, QualType T,
554 TypeSourceInfo *TInfo,
555 const QualType *ExpandedTypes,
556 unsigned NumExpandedTypes,
557 TypeSourceInfo **ExpandedTInfos) {
Stephen Hines651f13c2014-04-23 16:59:28 -0700558 unsigned Extra = NumExpandedTypes * 2 * sizeof(void*);
559 return new (C, DC, Extra) NonTypeTemplateParmDecl(
560 DC, StartLoc, IdLoc, D, P, Id, T, TInfo,
561 ExpandedTypes, NumExpandedTypes, ExpandedTInfos);
Douglas Gregor6952f1e2011-01-19 20:10:05 +0000562}
563
Douglas Gregor1e68ecc2012-01-05 21:55:30 +0000564NonTypeTemplateParmDecl *
565NonTypeTemplateParmDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
Stephen Hines651f13c2014-04-23 16:59:28 -0700566 return new (C, ID) NonTypeTemplateParmDecl(0, SourceLocation(),
567 SourceLocation(), 0, 0, 0,
568 QualType(), false, 0);
Douglas Gregor1e68ecc2012-01-05 21:55:30 +0000569}
570
571NonTypeTemplateParmDecl *
572NonTypeTemplateParmDecl::CreateDeserialized(ASTContext &C, unsigned ID,
573 unsigned NumExpandedTypes) {
Stephen Hines651f13c2014-04-23 16:59:28 -0700574 unsigned Extra = NumExpandedTypes * 2 * sizeof(void*);
575 return new (C, ID, Extra) NonTypeTemplateParmDecl(
576 0, SourceLocation(), SourceLocation(), 0, 0, 0, QualType(), 0,
577 0, NumExpandedTypes, 0);
Douglas Gregor1e68ecc2012-01-05 21:55:30 +0000578}
579
John McCall76a40212011-02-09 01:13:10 +0000580SourceRange NonTypeTemplateParmDecl::getSourceRange() const {
Abramo Bagnaraee4bfd42011-03-04 11:03:48 +0000581 if (hasDefaultArgument() && !defaultArgumentWasInherited())
Abramo Bagnaraa2026c92011-03-08 16:41:52 +0000582 return SourceRange(getOuterLocStart(),
583 getDefaultArgument()->getSourceRange().getEnd());
584 return DeclaratorDecl::getSourceRange();
John McCall76a40212011-02-09 01:13:10 +0000585}
586
Douglas Gregord684b002009-02-10 19:49:53 +0000587SourceLocation NonTypeTemplateParmDecl::getDefaultArgumentLoc() const {
Abramo Bagnarad92f7a22010-06-09 09:26:05 +0000588 return hasDefaultArgument()
589 ? getDefaultArgument()->getSourceRange().getBegin()
590 : SourceLocation();
Douglas Gregord684b002009-02-10 19:49:53 +0000591}
592
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000593//===----------------------------------------------------------------------===//
594// TemplateTemplateParmDecl Method Implementations
595//===----------------------------------------------------------------------===//
596
David Blaikie99ba9e32011-12-20 02:48:34 +0000597void TemplateTemplateParmDecl::anchor() { }
598
Richard Smith6964b3f2012-09-07 02:06:42 +0000599TemplateTemplateParmDecl::TemplateTemplateParmDecl(
600 DeclContext *DC, SourceLocation L, unsigned D, unsigned P,
601 IdentifierInfo *Id, TemplateParameterList *Params,
602 unsigned NumExpansions, TemplateParameterList * const *Expansions)
603 : TemplateDecl(TemplateTemplateParm, DC, L, Id, Params),
604 TemplateParmPosition(D, P), DefaultArgument(),
605 DefaultArgumentWasInherited(false), ParameterPack(true),
606 ExpandedParameterPack(true), NumExpandedParams(NumExpansions) {
607 if (Expansions)
608 std::memcpy(reinterpret_cast<void*>(this + 1), Expansions,
609 sizeof(TemplateParameterList*) * NumExpandedParams);
610}
611
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000612TemplateTemplateParmDecl *
Jay Foad4ba2a172011-01-12 09:06:06 +0000613TemplateTemplateParmDecl::Create(const ASTContext &C, DeclContext *DC,
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000614 SourceLocation L, unsigned D, unsigned P,
Douglas Gregor61c4d282011-01-05 15:48:55 +0000615 bool ParameterPack, IdentifierInfo *Id,
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000616 TemplateParameterList *Params) {
Stephen Hines651f13c2014-04-23 16:59:28 -0700617 return new (C, DC) TemplateTemplateParmDecl(DC, L, D, P, ParameterPack, Id,
618 Params);
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000619}
620
Douglas Gregor1e68ecc2012-01-05 21:55:30 +0000621TemplateTemplateParmDecl *
Richard Smith6964b3f2012-09-07 02:06:42 +0000622TemplateTemplateParmDecl::Create(const ASTContext &C, DeclContext *DC,
623 SourceLocation L, unsigned D, unsigned P,
624 IdentifierInfo *Id,
625 TemplateParameterList *Params,
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +0000626 ArrayRef<TemplateParameterList *> Expansions) {
Stephen Hines651f13c2014-04-23 16:59:28 -0700627 return new (C, DC, sizeof(TemplateParameterList*) * Expansions.size())
628 TemplateTemplateParmDecl(DC, L, D, P, Id, Params,
629 Expansions.size(), Expansions.data());
Richard Smith6964b3f2012-09-07 02:06:42 +0000630}
631
632TemplateTemplateParmDecl *
Douglas Gregor1e68ecc2012-01-05 21:55:30 +0000633TemplateTemplateParmDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
Stephen Hines651f13c2014-04-23 16:59:28 -0700634 return new (C, ID) TemplateTemplateParmDecl(0, SourceLocation(), 0, 0, false,
635 0, 0);
Douglas Gregor1e68ecc2012-01-05 21:55:30 +0000636}
637
Richard Smith6964b3f2012-09-07 02:06:42 +0000638TemplateTemplateParmDecl *
639TemplateTemplateParmDecl::CreateDeserialized(ASTContext &C, unsigned ID,
640 unsigned NumExpansions) {
Stephen Hines651f13c2014-04-23 16:59:28 -0700641 return new (C, ID, sizeof(TemplateParameterList*) * NumExpansions)
642 TemplateTemplateParmDecl(0, SourceLocation(), 0, 0, 0, 0,
643 NumExpansions, 0);
Richard Smith6964b3f2012-09-07 02:06:42 +0000644}
645
Douglas Gregor3e00bad2009-02-17 01:05:43 +0000646//===----------------------------------------------------------------------===//
Douglas Gregor7e063902009-05-11 23:53:27 +0000647// TemplateArgumentList Implementation
648//===----------------------------------------------------------------------===//
Douglas Gregor910f8002010-11-07 23:05:16 +0000649TemplateArgumentList *
650TemplateArgumentList::CreateCopy(ASTContext &Context,
651 const TemplateArgument *Args,
652 unsigned NumArgs) {
653 std::size_t Size = sizeof(TemplateArgumentList)
654 + NumArgs * sizeof(TemplateArgument);
655 void *Mem = Context.Allocate(Size);
656 TemplateArgument *StoredArgs
657 = reinterpret_cast<TemplateArgument *>(
658 static_cast<TemplateArgumentList *>(Mem) + 1);
659 std::uninitialized_copy(Args, Args + NumArgs, StoredArgs);
660 return new (Mem) TemplateArgumentList(StoredArgs, NumArgs, true);
Argyrios Kyrtzidis94d228d2010-06-23 13:48:23 +0000661}
662
Argyrios Kyrtzidis71a76052011-09-22 20:07:09 +0000663FunctionTemplateSpecializationInfo *
664FunctionTemplateSpecializationInfo::Create(ASTContext &C, FunctionDecl *FD,
665 FunctionTemplateDecl *Template,
666 TemplateSpecializationKind TSK,
667 const TemplateArgumentList *TemplateArgs,
668 const TemplateArgumentListInfo *TemplateArgsAsWritten,
669 SourceLocation POI) {
670 const ASTTemplateArgumentListInfo *ArgsAsWritten = 0;
671 if (TemplateArgsAsWritten)
672 ArgsAsWritten = ASTTemplateArgumentListInfo::Create(C,
673 *TemplateArgsAsWritten);
674
675 return new (C) FunctionTemplateSpecializationInfo(FD, Template, TSK,
676 TemplateArgs,
677 ArgsAsWritten,
678 POI);
679}
680
Douglas Gregor7e063902009-05-11 23:53:27 +0000681//===----------------------------------------------------------------------===//
David Blaikie99ba9e32011-12-20 02:48:34 +0000682// TemplateDecl Implementation
683//===----------------------------------------------------------------------===//
684
685void TemplateDecl::anchor() { }
686
687//===----------------------------------------------------------------------===//
Douglas Gregor3e00bad2009-02-17 01:05:43 +0000688// ClassTemplateSpecializationDecl Implementation
689//===----------------------------------------------------------------------===//
690ClassTemplateSpecializationDecl::
Douglas Gregor13c85772010-05-06 00:28:52 +0000691ClassTemplateSpecializationDecl(ASTContext &Context, Kind DK, TagKind TK,
Abramo Bagnaraba877ad2011-03-09 14:09:51 +0000692 DeclContext *DC, SourceLocation StartLoc,
693 SourceLocation IdLoc,
Douglas Gregor3e00bad2009-02-17 01:05:43 +0000694 ClassTemplateDecl *SpecializedTemplate,
Douglas Gregor910f8002010-11-07 23:05:16 +0000695 const TemplateArgument *Args,
696 unsigned NumArgs,
Douglas Gregor8e9e9ef2009-07-29 23:36:44 +0000697 ClassTemplateSpecializationDecl *PrevDecl)
Abramo Bagnaraba877ad2011-03-09 14:09:51 +0000698 : CXXRecordDecl(DK, TK, DC, StartLoc, IdLoc,
Douglas Gregor8e9e9ef2009-07-29 23:36:44 +0000699 SpecializedTemplate->getIdentifier(),
700 PrevDecl),
Douglas Gregor3e00bad2009-02-17 01:05:43 +0000701 SpecializedTemplate(SpecializedTemplate),
Abramo Bagnarac98971d2010-06-12 07:44:57 +0000702 ExplicitInfo(0),
Douglas Gregor910f8002010-11-07 23:05:16 +0000703 TemplateArgs(TemplateArgumentList::CreateCopy(Context, Args, NumArgs)),
Douglas Gregor7e063902009-05-11 23:53:27 +0000704 SpecializationKind(TSK_Undeclared) {
Douglas Gregor3e00bad2009-02-17 01:05:43 +0000705}
Mike Stump1eb44332009-09-09 15:08:12 +0000706
Argyrios Kyrtzidis94d228d2010-06-23 13:48:23 +0000707ClassTemplateSpecializationDecl::ClassTemplateSpecializationDecl(Kind DK)
Abramo Bagnaraba877ad2011-03-09 14:09:51 +0000708 : CXXRecordDecl(DK, TTK_Struct, 0, SourceLocation(), SourceLocation(), 0, 0),
Argyrios Kyrtzidis94d228d2010-06-23 13:48:23 +0000709 ExplicitInfo(0),
710 SpecializationKind(TSK_Undeclared) {
711}
712
Douglas Gregor3e00bad2009-02-17 01:05:43 +0000713ClassTemplateSpecializationDecl *
Douglas Gregor13c85772010-05-06 00:28:52 +0000714ClassTemplateSpecializationDecl::Create(ASTContext &Context, TagKind TK,
Abramo Bagnaraba877ad2011-03-09 14:09:51 +0000715 DeclContext *DC,
716 SourceLocation StartLoc,
717 SourceLocation IdLoc,
Douglas Gregor3e00bad2009-02-17 01:05:43 +0000718 ClassTemplateDecl *SpecializedTemplate,
Douglas Gregor910f8002010-11-07 23:05:16 +0000719 const TemplateArgument *Args,
720 unsigned NumArgs,
Douglas Gregorcc636682009-02-17 23:15:12 +0000721 ClassTemplateSpecializationDecl *PrevDecl) {
Stephen Hines651f13c2014-04-23 16:59:28 -0700722 ClassTemplateSpecializationDecl *Result =
723 new (Context, DC) ClassTemplateSpecializationDecl(
724 Context, ClassTemplateSpecialization, TK, DC, StartLoc, IdLoc,
725 SpecializedTemplate, Args, NumArgs, PrevDecl);
Douglas Gregor6bd99292013-02-09 01:35:03 +0000726 Result->MayHaveOutOfDateDef = false;
727
Douglas Gregorcc636682009-02-17 23:15:12 +0000728 Context.getTypeDeclType(Result, PrevDecl);
729 return Result;
Douglas Gregor3e00bad2009-02-17 01:05:43 +0000730}
Douglas Gregorc8ab2562009-05-31 09:31:02 +0000731
Argyrios Kyrtzidis94d228d2010-06-23 13:48:23 +0000732ClassTemplateSpecializationDecl *
Stephen Hines651f13c2014-04-23 16:59:28 -0700733ClassTemplateSpecializationDecl::CreateDeserialized(ASTContext &C,
Douglas Gregor1e68ecc2012-01-05 21:55:30 +0000734 unsigned ID) {
Douglas Gregor6bd99292013-02-09 01:35:03 +0000735 ClassTemplateSpecializationDecl *Result =
Stephen Hines651f13c2014-04-23 16:59:28 -0700736 new (C, ID) ClassTemplateSpecializationDecl(ClassTemplateSpecialization);
Douglas Gregor6bd99292013-02-09 01:35:03 +0000737 Result->MayHaveOutOfDateDef = false;
738 return Result;
Argyrios Kyrtzidis94d228d2010-06-23 13:48:23 +0000739}
740
Benjamin Kramer5eada842013-02-22 15:46:01 +0000741void ClassTemplateSpecializationDecl::getNameForDiagnostic(
742 raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const {
743 NamedDecl::getNameForDiagnostic(OS, Policy, Qualified);
Douglas Gregorda2142f2011-02-19 18:51:44 +0000744
745 const TemplateArgumentList &TemplateArgs = getTemplateArgs();
Benjamin Kramer5eada842013-02-22 15:46:01 +0000746 TemplateSpecializationType::PrintTemplateArgumentList(
747 OS, TemplateArgs.data(), TemplateArgs.size(), Policy);
Douglas Gregorda2142f2011-02-19 18:51:44 +0000748}
749
Douglas Gregor37d93e92009-08-02 23:24:31 +0000750ClassTemplateDecl *
Mike Stump1eb44332009-09-09 15:08:12 +0000751ClassTemplateSpecializationDecl::getSpecializedTemplate() const {
752 if (SpecializedPartialSpecialization *PartialSpec
Douglas Gregor37d93e92009-08-02 23:24:31 +0000753 = SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization*>())
754 return PartialSpec->PartialSpecialization->getSpecializedTemplate();
755 return SpecializedTemplate.get<ClassTemplateDecl*>();
756}
757
Abramo Bagnara4a85a732011-03-04 14:20:30 +0000758SourceRange
759ClassTemplateSpecializationDecl::getSourceRange() const {
Abramo Bagnara09d82122011-10-03 20:34:03 +0000760 if (ExplicitInfo) {
Abramo Bagnarab2e80012012-10-15 21:06:42 +0000761 SourceLocation Begin = getTemplateKeywordLoc();
762 if (Begin.isValid()) {
763 // Here we have an explicit (partial) specialization or instantiation.
764 assert(getSpecializationKind() == TSK_ExplicitSpecialization ||
765 getSpecializationKind() == TSK_ExplicitInstantiationDeclaration ||
766 getSpecializationKind() == TSK_ExplicitInstantiationDefinition);
767 if (getExternLoc().isValid())
768 Begin = getExternLoc();
769 SourceLocation End = getRBraceLoc();
770 if (End.isInvalid())
771 End = getTypeAsWritten()->getTypeLoc().getEndLoc();
772 return SourceRange(Begin, End);
773 }
774 // An implicit instantiation of a class template partial specialization
775 // uses ExplicitInfo to record the TypeAsWritten, but the source
776 // locations should be retrieved from the instantiation pattern.
777 typedef ClassTemplatePartialSpecializationDecl CTPSDecl;
778 CTPSDecl *ctpsd = const_cast<CTPSDecl*>(cast<CTPSDecl>(this));
779 CTPSDecl *inst_from = ctpsd->getInstantiatedFromMember();
780 assert(inst_from != 0);
781 return inst_from->getSourceRange();
Abramo Bagnara09d82122011-10-03 20:34:03 +0000782 }
783 else {
784 // No explicit info available.
785 llvm::PointerUnion<ClassTemplateDecl *,
786 ClassTemplatePartialSpecializationDecl *>
787 inst_from = getInstantiatedFrom();
788 if (inst_from.isNull())
789 return getSpecializedTemplate()->getSourceRange();
790 if (ClassTemplateDecl *ctd = inst_from.dyn_cast<ClassTemplateDecl*>())
791 return ctd->getSourceRange();
792 return inst_from.get<ClassTemplatePartialSpecializationDecl*>()
793 ->getSourceRange();
794 }
Abramo Bagnara4a85a732011-03-04 14:20:30 +0000795}
796
Douglas Gregorc8ab2562009-05-31 09:31:02 +0000797//===----------------------------------------------------------------------===//
798// ClassTemplatePartialSpecializationDecl Implementation
799//===----------------------------------------------------------------------===//
David Blaikie99ba9e32011-12-20 02:48:34 +0000800void ClassTemplatePartialSpecializationDecl::anchor() { }
801
Douglas Gregor9a299e02011-03-04 17:52:15 +0000802ClassTemplatePartialSpecializationDecl::
803ClassTemplatePartialSpecializationDecl(ASTContext &Context, TagKind TK,
Abramo Bagnaraba877ad2011-03-09 14:09:51 +0000804 DeclContext *DC,
805 SourceLocation StartLoc,
806 SourceLocation IdLoc,
Douglas Gregor9a299e02011-03-04 17:52:15 +0000807 TemplateParameterList *Params,
808 ClassTemplateDecl *SpecializedTemplate,
809 const TemplateArgument *Args,
810 unsigned NumArgs,
Enea Zaffanellac1cef082013-08-10 07:24:53 +0000811 const ASTTemplateArgumentListInfo *ArgInfos,
Richard Smith37fd27d2013-08-22 23:27:37 +0000812 ClassTemplatePartialSpecializationDecl *PrevDecl)
Douglas Gregor9a299e02011-03-04 17:52:15 +0000813 : ClassTemplateSpecializationDecl(Context,
814 ClassTemplatePartialSpecialization,
Abramo Bagnaraba877ad2011-03-09 14:09:51 +0000815 TK, DC, StartLoc, IdLoc,
816 SpecializedTemplate,
Douglas Gregor9a299e02011-03-04 17:52:15 +0000817 Args, NumArgs, PrevDecl),
818 TemplateParams(Params), ArgsAsWritten(ArgInfos),
Richard Smith37fd27d2013-08-22 23:27:37 +0000819 InstantiatedFromMember(0, false)
Enea Zaffanellac1cef082013-08-10 07:24:53 +0000820{
Douglas Gregor787a40d2011-03-04 18:32:38 +0000821 AdoptTemplateParameterList(Params, this);
Douglas Gregor9a299e02011-03-04 17:52:15 +0000822}
823
Douglas Gregorc8ab2562009-05-31 09:31:02 +0000824ClassTemplatePartialSpecializationDecl *
825ClassTemplatePartialSpecializationDecl::
Abramo Bagnaraba877ad2011-03-09 14:09:51 +0000826Create(ASTContext &Context, TagKind TK,DeclContext *DC,
827 SourceLocation StartLoc, SourceLocation IdLoc,
Douglas Gregorc8ab2562009-05-31 09:31:02 +0000828 TemplateParameterList *Params,
829 ClassTemplateDecl *SpecializedTemplate,
Douglas Gregor910f8002010-11-07 23:05:16 +0000830 const TemplateArgument *Args,
831 unsigned NumArgs,
John McCalld5532b62009-11-23 01:53:49 +0000832 const TemplateArgumentListInfo &ArgInfos,
John McCall3cb0ebd2010-03-10 03:28:59 +0000833 QualType CanonInjectedType,
Richard Smith37fd27d2013-08-22 23:27:37 +0000834 ClassTemplatePartialSpecializationDecl *PrevDecl) {
Enea Zaffanellac1cef082013-08-10 07:24:53 +0000835 const ASTTemplateArgumentListInfo *ASTArgInfos =
836 ASTTemplateArgumentListInfo::Create(Context, ArgInfos);
John McCall833ca992009-10-29 08:12:44 +0000837
Stephen Hines651f13c2014-04-23 16:59:28 -0700838 ClassTemplatePartialSpecializationDecl *Result = new (Context, DC)
839 ClassTemplatePartialSpecializationDecl(Context, TK, DC, StartLoc, IdLoc,
840 Params, SpecializedTemplate, Args,
841 NumArgs, ASTArgInfos, PrevDecl);
Douglas Gregorc8ab2562009-05-31 09:31:02 +0000842 Result->setSpecializationKind(TSK_ExplicitSpecialization);
Douglas Gregor6bd99292013-02-09 01:35:03 +0000843 Result->MayHaveOutOfDateDef = false;
John McCall3cb0ebd2010-03-10 03:28:59 +0000844
845 Context.getInjectedClassNameType(Result, CanonInjectedType);
Douglas Gregorc8ab2562009-05-31 09:31:02 +0000846 return Result;
847}
John McCalldd4a3b02009-09-16 22:47:08 +0000848
Argyrios Kyrtzidis94d228d2010-06-23 13:48:23 +0000849ClassTemplatePartialSpecializationDecl *
Douglas Gregor1e68ecc2012-01-05 21:55:30 +0000850ClassTemplatePartialSpecializationDecl::CreateDeserialized(ASTContext &C,
851 unsigned ID) {
Stephen Hines651f13c2014-04-23 16:59:28 -0700852 ClassTemplatePartialSpecializationDecl *Result =
853 new (C, ID) ClassTemplatePartialSpecializationDecl();
Douglas Gregor6bd99292013-02-09 01:35:03 +0000854 Result->MayHaveOutOfDateDef = false;
855 return Result;
Argyrios Kyrtzidis94d228d2010-06-23 13:48:23 +0000856}
857
John McCalldd4a3b02009-09-16 22:47:08 +0000858//===----------------------------------------------------------------------===//
859// FriendTemplateDecl Implementation
860//===----------------------------------------------------------------------===//
861
David Blaikie99ba9e32011-12-20 02:48:34 +0000862void FriendTemplateDecl::anchor() { }
863
John McCalldd4a3b02009-09-16 22:47:08 +0000864FriendTemplateDecl *FriendTemplateDecl::Create(ASTContext &Context,
865 DeclContext *DC,
866 SourceLocation L,
867 unsigned NParams,
868 TemplateParameterList **Params,
869 FriendUnion Friend,
870 SourceLocation FLoc) {
Stephen Hines651f13c2014-04-23 16:59:28 -0700871 return new (Context, DC) FriendTemplateDecl(DC, L, NParams, Params,
872 Friend, FLoc);
John McCalldd4a3b02009-09-16 22:47:08 +0000873}
Argyrios Kyrtzidis554e6aa2010-07-22 16:04:10 +0000874
Douglas Gregor1e68ecc2012-01-05 21:55:30 +0000875FriendTemplateDecl *FriendTemplateDecl::CreateDeserialized(ASTContext &C,
876 unsigned ID) {
Stephen Hines651f13c2014-04-23 16:59:28 -0700877 return new (C, ID) FriendTemplateDecl(EmptyShell());
Argyrios Kyrtzidis554e6aa2010-07-22 16:04:10 +0000878}
Richard Smith3e4c6c42011-05-05 21:57:07 +0000879
880//===----------------------------------------------------------------------===//
881// TypeAliasTemplateDecl Implementation
882//===----------------------------------------------------------------------===//
883
884TypeAliasTemplateDecl *TypeAliasTemplateDecl::Create(ASTContext &C,
885 DeclContext *DC,
886 SourceLocation L,
887 DeclarationName Name,
888 TemplateParameterList *Params,
889 NamedDecl *Decl) {
890 AdoptTemplateParameterList(Params, DC);
Stephen Hines651f13c2014-04-23 16:59:28 -0700891 return new (C, DC) TypeAliasTemplateDecl(DC, L, Name, Params, Decl);
Richard Smith3e4c6c42011-05-05 21:57:07 +0000892}
893
Douglas Gregor1e68ecc2012-01-05 21:55:30 +0000894TypeAliasTemplateDecl *TypeAliasTemplateDecl::CreateDeserialized(ASTContext &C,
895 unsigned ID) {
Stephen Hines651f13c2014-04-23 16:59:28 -0700896 return new (C, ID) TypeAliasTemplateDecl(0, SourceLocation(), DeclarationName(),
897 0, 0);
Richard Smith3e4c6c42011-05-05 21:57:07 +0000898}
899
900void TypeAliasTemplateDecl::DeallocateCommon(void *Ptr) {
901 static_cast<Common *>(Ptr)->~Common();
902}
903RedeclarableTemplateDecl::CommonBase *
Dmitri Gribenkob76d9712013-01-23 16:52:57 +0000904TypeAliasTemplateDecl::newCommon(ASTContext &C) const {
Richard Smith3e4c6c42011-05-05 21:57:07 +0000905 Common *CommonPtr = new (C) Common;
906 C.AddDeallocation(DeallocateCommon, CommonPtr);
907 return CommonPtr;
908}
909
David Blaikie99ba9e32011-12-20 02:48:34 +0000910//===----------------------------------------------------------------------===//
911// ClassScopeFunctionSpecializationDecl Implementation
912//===----------------------------------------------------------------------===//
913
914void ClassScopeFunctionSpecializationDecl::anchor() { }
Douglas Gregor1e68ecc2012-01-05 21:55:30 +0000915
916ClassScopeFunctionSpecializationDecl *
917ClassScopeFunctionSpecializationDecl::CreateDeserialized(ASTContext &C,
918 unsigned ID) {
Stephen Hines651f13c2014-04-23 16:59:28 -0700919 return new (C, ID) ClassScopeFunctionSpecializationDecl(
920 0, SourceLocation(), 0, false, TemplateArgumentListInfo());
Douglas Gregor1e68ecc2012-01-05 21:55:30 +0000921}
Larisse Voufoef4579c2013-08-06 01:03:05 +0000922
923//===----------------------------------------------------------------------===//
924// VarTemplateDecl Implementation
925//===----------------------------------------------------------------------===//
926
927void VarTemplateDecl::DeallocateCommon(void *Ptr) {
928 static_cast<Common *>(Ptr)->~Common();
929}
930
Larisse Voufo439d6652013-08-13 02:02:26 +0000931VarTemplateDecl *VarTemplateDecl::getDefinition() {
932 VarTemplateDecl *CurD = this;
933 while (CurD) {
934 if (CurD->isThisDeclarationADefinition())
935 return CurD;
936 CurD = CurD->getPreviousDecl();
937 }
938 return 0;
939}
940
Larisse Voufoef4579c2013-08-06 01:03:05 +0000941VarTemplateDecl *VarTemplateDecl::Create(ASTContext &C, DeclContext *DC,
942 SourceLocation L, DeclarationName Name,
943 TemplateParameterList *Params,
Stephen Hines651f13c2014-04-23 16:59:28 -0700944 VarDecl *Decl) {
945 return new (C, DC) VarTemplateDecl(DC, L, Name, Params, Decl);
Larisse Voufoef4579c2013-08-06 01:03:05 +0000946}
947
948VarTemplateDecl *VarTemplateDecl::CreateDeserialized(ASTContext &C,
949 unsigned ID) {
Stephen Hines651f13c2014-04-23 16:59:28 -0700950 return new (C, ID) VarTemplateDecl(EmptyShell());
Larisse Voufoef4579c2013-08-06 01:03:05 +0000951}
952
Stephen Hines651f13c2014-04-23 16:59:28 -0700953// TODO: Unify across class, function and variable templates?
Larisse Voufo8d2a5ea2013-08-23 22:21:36 +0000954// May require moving this and Common to RedeclarableTemplateDecl.
Larisse Voufoef4579c2013-08-06 01:03:05 +0000955void VarTemplateDecl::LoadLazySpecializations() const {
956 Common *CommonPtr = getCommonPtr();
957 if (CommonPtr->LazySpecializations) {
958 ASTContext &Context = getASTContext();
959 uint32_t *Specs = CommonPtr->LazySpecializations;
960 CommonPtr->LazySpecializations = 0;
961 for (uint32_t I = 0, N = *Specs++; I != N; ++I)
962 (void)Context.getExternalSource()->GetExternalDecl(Specs[I]);
963 }
964}
965
966llvm::FoldingSetVector<VarTemplateSpecializationDecl> &
967VarTemplateDecl::getSpecializations() const {
968 LoadLazySpecializations();
969 return getCommonPtr()->Specializations;
970}
971
972llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl> &
973VarTemplateDecl::getPartialSpecializations() {
974 LoadLazySpecializations();
975 return getCommonPtr()->PartialSpecializations;
976}
977
978RedeclarableTemplateDecl::CommonBase *
979VarTemplateDecl::newCommon(ASTContext &C) const {
980 Common *CommonPtr = new (C) Common;
981 C.AddDeallocation(DeallocateCommon, CommonPtr);
982 return CommonPtr;
983}
984
985VarTemplateSpecializationDecl *
986VarTemplateDecl::findSpecialization(const TemplateArgument *Args,
987 unsigned NumArgs, void *&InsertPos) {
988 return findSpecializationImpl(getSpecializations(), Args, NumArgs, InsertPos);
989}
990
991void VarTemplateDecl::AddSpecialization(VarTemplateSpecializationDecl *D,
992 void *InsertPos) {
993 if (InsertPos)
994 getSpecializations().InsertNode(D, InsertPos);
995 else {
996 VarTemplateSpecializationDecl *Existing =
997 getSpecializations().GetOrInsertNode(D);
998 (void)Existing;
999 assert(Existing->isCanonicalDecl() && "Non-canonical specialization?");
1000 }
1001 if (ASTMutationListener *L = getASTMutationListener())
1002 L->AddedCXXTemplateSpecialization(this, D);
1003}
1004
1005VarTemplatePartialSpecializationDecl *
1006VarTemplateDecl::findPartialSpecialization(const TemplateArgument *Args,
1007 unsigned NumArgs, void *&InsertPos) {
1008 return findSpecializationImpl(getPartialSpecializations(), Args, NumArgs,
1009 InsertPos);
1010}
1011
1012void VarTemplateDecl::AddPartialSpecialization(
1013 VarTemplatePartialSpecializationDecl *D, void *InsertPos) {
1014 if (InsertPos)
1015 getPartialSpecializations().InsertNode(D, InsertPos);
1016 else {
1017 VarTemplatePartialSpecializationDecl *Existing =
1018 getPartialSpecializations().GetOrInsertNode(D);
1019 (void)Existing;
1020 assert(Existing->isCanonicalDecl() && "Non-canonical specialization?");
1021 }
1022
1023 if (ASTMutationListener *L = getASTMutationListener())
1024 L->AddedCXXTemplateSpecialization(this, D);
1025}
1026
1027void VarTemplateDecl::getPartialSpecializations(
1028 SmallVectorImpl<VarTemplatePartialSpecializationDecl *> &PS) {
1029 llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl> &PartialSpecs =
1030 getPartialSpecializations();
1031 PS.clear();
Richard Smith37fd27d2013-08-22 23:27:37 +00001032 PS.reserve(PartialSpecs.size());
Larisse Voufoef4579c2013-08-06 01:03:05 +00001033 for (llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl>::iterator
1034 P = PartialSpecs.begin(),
1035 PEnd = PartialSpecs.end();
Richard Smith37fd27d2013-08-22 23:27:37 +00001036 P != PEnd; ++P)
1037 PS.push_back(P->getMostRecentDecl());
Larisse Voufoef4579c2013-08-06 01:03:05 +00001038}
1039
1040VarTemplatePartialSpecializationDecl *
1041VarTemplateDecl::findPartialSpecInstantiatedFromMember(
1042 VarTemplatePartialSpecializationDecl *D) {
1043 Decl *DCanon = D->getCanonicalDecl();
1044 for (llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl>::iterator
1045 P = getPartialSpecializations().begin(),
1046 PEnd = getPartialSpecializations().end();
1047 P != PEnd; ++P) {
1048 if (P->getInstantiatedFromMember()->getCanonicalDecl() == DCanon)
1049 return P->getMostRecentDecl();
1050 }
1051
1052 return 0;
1053}
1054
1055//===----------------------------------------------------------------------===//
1056// VarTemplateSpecializationDecl Implementation
1057//===----------------------------------------------------------------------===//
1058VarTemplateSpecializationDecl::VarTemplateSpecializationDecl(
1059 ASTContext &Context, Kind DK, DeclContext *DC, SourceLocation StartLoc,
1060 SourceLocation IdLoc, VarTemplateDecl *SpecializedTemplate, QualType T,
1061 TypeSourceInfo *TInfo, StorageClass S, const TemplateArgument *Args,
1062 unsigned NumArgs)
1063 : VarDecl(DK, DC, StartLoc, IdLoc, SpecializedTemplate->getIdentifier(), T,
1064 TInfo, S),
1065 SpecializedTemplate(SpecializedTemplate), ExplicitInfo(0),
1066 TemplateArgs(TemplateArgumentList::CreateCopy(Context, Args, NumArgs)),
1067 SpecializationKind(TSK_Undeclared) {}
1068
1069VarTemplateSpecializationDecl::VarTemplateSpecializationDecl(Kind DK)
1070 : VarDecl(DK, 0, SourceLocation(), SourceLocation(), 0, QualType(), 0,
1071 SC_None),
1072 ExplicitInfo(0), SpecializationKind(TSK_Undeclared) {}
1073
1074VarTemplateSpecializationDecl *VarTemplateSpecializationDecl::Create(
1075 ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
1076 SourceLocation IdLoc, VarTemplateDecl *SpecializedTemplate, QualType T,
1077 TypeSourceInfo *TInfo, StorageClass S, const TemplateArgument *Args,
1078 unsigned NumArgs) {
Stephen Hines651f13c2014-04-23 16:59:28 -07001079 return new (Context, DC) VarTemplateSpecializationDecl(
1080 Context, VarTemplateSpecialization, DC, StartLoc, IdLoc,
1081 SpecializedTemplate, T, TInfo, S, Args, NumArgs);
Larisse Voufoef4579c2013-08-06 01:03:05 +00001082}
1083
1084VarTemplateSpecializationDecl *
1085VarTemplateSpecializationDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
Stephen Hines651f13c2014-04-23 16:59:28 -07001086 return new (C, ID) VarTemplateSpecializationDecl(VarTemplateSpecialization);
Larisse Voufoef4579c2013-08-06 01:03:05 +00001087}
1088
1089void VarTemplateSpecializationDecl::getNameForDiagnostic(
1090 raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const {
1091 NamedDecl::getNameForDiagnostic(OS, Policy, Qualified);
1092
1093 const TemplateArgumentList &TemplateArgs = getTemplateArgs();
1094 TemplateSpecializationType::PrintTemplateArgumentList(
1095 OS, TemplateArgs.data(), TemplateArgs.size(), Policy);
1096}
1097
1098VarTemplateDecl *VarTemplateSpecializationDecl::getSpecializedTemplate() const {
1099 if (SpecializedPartialSpecialization *PartialSpec =
1100 SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>())
1101 return PartialSpec->PartialSpecialization->getSpecializedTemplate();
1102 return SpecializedTemplate.get<VarTemplateDecl *>();
1103}
1104
1105void VarTemplateSpecializationDecl::setTemplateArgsInfo(
1106 const TemplateArgumentListInfo &ArgsInfo) {
1107 unsigned N = ArgsInfo.size();
1108 TemplateArgsInfo.setLAngleLoc(ArgsInfo.getLAngleLoc());
1109 TemplateArgsInfo.setRAngleLoc(ArgsInfo.getRAngleLoc());
1110 for (unsigned I = 0; I != N; ++I)
1111 TemplateArgsInfo.addArgument(ArgsInfo[I]);
1112}
1113
1114//===----------------------------------------------------------------------===//
1115// VarTemplatePartialSpecializationDecl Implementation
1116//===----------------------------------------------------------------------===//
1117void VarTemplatePartialSpecializationDecl::anchor() {}
1118
1119VarTemplatePartialSpecializationDecl::VarTemplatePartialSpecializationDecl(
1120 ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
1121 SourceLocation IdLoc, TemplateParameterList *Params,
1122 VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo,
1123 StorageClass S, const TemplateArgument *Args, unsigned NumArgs,
Richard Smith37fd27d2013-08-22 23:27:37 +00001124 const ASTTemplateArgumentListInfo *ArgInfos)
Larisse Voufoef4579c2013-08-06 01:03:05 +00001125 : VarTemplateSpecializationDecl(Context, VarTemplatePartialSpecialization,
1126 DC, StartLoc, IdLoc, SpecializedTemplate, T,
1127 TInfo, S, Args, NumArgs),
1128 TemplateParams(Params), ArgsAsWritten(ArgInfos),
Richard Smith37fd27d2013-08-22 23:27:37 +00001129 InstantiatedFromMember(0, false) {
Larisse Voufoef4579c2013-08-06 01:03:05 +00001130 // TODO: The template parameters should be in DC by now. Verify.
1131 // AdoptTemplateParameterList(Params, DC);
1132}
1133
1134VarTemplatePartialSpecializationDecl *
1135VarTemplatePartialSpecializationDecl::Create(
1136 ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
1137 SourceLocation IdLoc, TemplateParameterList *Params,
1138 VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo,
1139 StorageClass S, const TemplateArgument *Args, unsigned NumArgs,
Richard Smith37fd27d2013-08-22 23:27:37 +00001140 const TemplateArgumentListInfo &ArgInfos) {
Enea Zaffanellac1cef082013-08-10 07:24:53 +00001141 const ASTTemplateArgumentListInfo *ASTArgInfos
1142 = ASTTemplateArgumentListInfo::Create(Context, ArgInfos);
Larisse Voufoef4579c2013-08-06 01:03:05 +00001143
1144 VarTemplatePartialSpecializationDecl *Result =
Stephen Hines651f13c2014-04-23 16:59:28 -07001145 new (Context, DC) VarTemplatePartialSpecializationDecl(
Larisse Voufoef4579c2013-08-06 01:03:05 +00001146 Context, DC, StartLoc, IdLoc, Params, SpecializedTemplate, T, TInfo,
Richard Smith37fd27d2013-08-22 23:27:37 +00001147 S, Args, NumArgs, ASTArgInfos);
Larisse Voufoef4579c2013-08-06 01:03:05 +00001148 Result->setSpecializationKind(TSK_ExplicitSpecialization);
1149 return Result;
1150}
1151
1152VarTemplatePartialSpecializationDecl *
1153VarTemplatePartialSpecializationDecl::CreateDeserialized(ASTContext &C,
1154 unsigned ID) {
Stephen Hines651f13c2014-04-23 16:59:28 -07001155 return new (C, ID) VarTemplatePartialSpecializationDecl();
Larisse Voufoef4579c2013-08-06 01:03:05 +00001156}