1f4a2713aSLionel Sambuc //===--- DeclTemplate.cpp - Template Declaration AST Node Implementation --===//
2f4a2713aSLionel Sambuc //
3f4a2713aSLionel Sambuc // The LLVM Compiler Infrastructure
4f4a2713aSLionel Sambuc //
5f4a2713aSLionel Sambuc // This file is distributed under the University of Illinois Open Source
6f4a2713aSLionel Sambuc // License. See LICENSE.TXT for details.
7f4a2713aSLionel Sambuc //
8f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
9f4a2713aSLionel Sambuc //
10f4a2713aSLionel Sambuc // This file implements the C++ related Decl classes for templates.
11f4a2713aSLionel Sambuc //
12f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
13f4a2713aSLionel Sambuc
14f4a2713aSLionel Sambuc #include "clang/AST/DeclTemplate.h"
15f4a2713aSLionel Sambuc #include "clang/AST/ASTContext.h"
16f4a2713aSLionel Sambuc #include "clang/AST/ASTMutationListener.h"
17f4a2713aSLionel Sambuc #include "clang/AST/DeclCXX.h"
18f4a2713aSLionel Sambuc #include "clang/AST/Expr.h"
19f4a2713aSLionel Sambuc #include "clang/AST/ExprCXX.h"
20f4a2713aSLionel Sambuc #include "clang/AST/TypeLoc.h"
21f4a2713aSLionel Sambuc #include "clang/Basic/IdentifierTable.h"
22f4a2713aSLionel Sambuc #include "llvm/ADT/STLExtras.h"
23f4a2713aSLionel Sambuc #include <memory>
24f4a2713aSLionel Sambuc using namespace clang;
25f4a2713aSLionel Sambuc
26f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
27f4a2713aSLionel Sambuc // TemplateParameterList Implementation
28f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
29f4a2713aSLionel Sambuc
TemplateParameterList(SourceLocation TemplateLoc,SourceLocation LAngleLoc,NamedDecl ** Params,unsigned NumParams,SourceLocation RAngleLoc)30f4a2713aSLionel Sambuc TemplateParameterList::TemplateParameterList(SourceLocation TemplateLoc,
31f4a2713aSLionel Sambuc SourceLocation LAngleLoc,
32f4a2713aSLionel Sambuc NamedDecl **Params, unsigned NumParams,
33f4a2713aSLionel Sambuc SourceLocation RAngleLoc)
34f4a2713aSLionel Sambuc : TemplateLoc(TemplateLoc), LAngleLoc(LAngleLoc), RAngleLoc(RAngleLoc),
35f4a2713aSLionel Sambuc NumParams(NumParams), ContainsUnexpandedParameterPack(false) {
36f4a2713aSLionel Sambuc assert(this->NumParams == NumParams && "Too many template parameters");
37f4a2713aSLionel Sambuc for (unsigned Idx = 0; Idx < NumParams; ++Idx) {
38f4a2713aSLionel Sambuc NamedDecl *P = Params[Idx];
39f4a2713aSLionel Sambuc begin()[Idx] = P;
40f4a2713aSLionel Sambuc
41f4a2713aSLionel Sambuc if (!P->isTemplateParameterPack()) {
42f4a2713aSLionel Sambuc if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(P))
43f4a2713aSLionel Sambuc if (NTTP->getType()->containsUnexpandedParameterPack())
44f4a2713aSLionel Sambuc ContainsUnexpandedParameterPack = true;
45f4a2713aSLionel Sambuc
46f4a2713aSLionel Sambuc if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(P))
47f4a2713aSLionel Sambuc if (TTP->getTemplateParameters()->containsUnexpandedParameterPack())
48f4a2713aSLionel Sambuc ContainsUnexpandedParameterPack = true;
49f4a2713aSLionel Sambuc
50f4a2713aSLionel Sambuc // FIXME: If a default argument contains an unexpanded parameter pack, the
51f4a2713aSLionel Sambuc // template parameter list does too.
52f4a2713aSLionel Sambuc }
53f4a2713aSLionel Sambuc }
54f4a2713aSLionel Sambuc }
55f4a2713aSLionel Sambuc
56f4a2713aSLionel Sambuc TemplateParameterList *
Create(const ASTContext & C,SourceLocation TemplateLoc,SourceLocation LAngleLoc,NamedDecl ** Params,unsigned NumParams,SourceLocation RAngleLoc)57f4a2713aSLionel Sambuc TemplateParameterList::Create(const ASTContext &C, SourceLocation TemplateLoc,
58f4a2713aSLionel Sambuc SourceLocation LAngleLoc, NamedDecl **Params,
59f4a2713aSLionel Sambuc unsigned NumParams, SourceLocation RAngleLoc) {
60f4a2713aSLionel Sambuc unsigned Size = sizeof(TemplateParameterList)
61f4a2713aSLionel Sambuc + sizeof(NamedDecl *) * NumParams;
62f4a2713aSLionel Sambuc unsigned Align = std::max(llvm::alignOf<TemplateParameterList>(),
63f4a2713aSLionel Sambuc llvm::alignOf<NamedDecl*>());
64f4a2713aSLionel Sambuc void *Mem = C.Allocate(Size, Align);
65f4a2713aSLionel Sambuc return new (Mem) TemplateParameterList(TemplateLoc, LAngleLoc, Params,
66f4a2713aSLionel Sambuc NumParams, RAngleLoc);
67f4a2713aSLionel Sambuc }
68f4a2713aSLionel Sambuc
getMinRequiredArguments() const69f4a2713aSLionel Sambuc unsigned TemplateParameterList::getMinRequiredArguments() const {
70f4a2713aSLionel Sambuc unsigned NumRequiredArgs = 0;
71f4a2713aSLionel Sambuc for (iterator P = const_cast<TemplateParameterList *>(this)->begin(),
72f4a2713aSLionel Sambuc PEnd = const_cast<TemplateParameterList *>(this)->end();
73f4a2713aSLionel Sambuc P != PEnd; ++P) {
74f4a2713aSLionel Sambuc if ((*P)->isTemplateParameterPack()) {
75f4a2713aSLionel Sambuc if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(*P))
76f4a2713aSLionel Sambuc if (NTTP->isExpandedParameterPack()) {
77f4a2713aSLionel Sambuc NumRequiredArgs += NTTP->getNumExpansionTypes();
78f4a2713aSLionel Sambuc continue;
79f4a2713aSLionel Sambuc }
80f4a2713aSLionel Sambuc
81f4a2713aSLionel Sambuc break;
82f4a2713aSLionel Sambuc }
83f4a2713aSLionel Sambuc
84f4a2713aSLionel Sambuc if (TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(*P)) {
85f4a2713aSLionel Sambuc if (TTP->hasDefaultArgument())
86f4a2713aSLionel Sambuc break;
87f4a2713aSLionel Sambuc } else if (NonTypeTemplateParmDecl *NTTP
88f4a2713aSLionel Sambuc = dyn_cast<NonTypeTemplateParmDecl>(*P)) {
89f4a2713aSLionel Sambuc if (NTTP->hasDefaultArgument())
90f4a2713aSLionel Sambuc break;
91f4a2713aSLionel Sambuc } else if (cast<TemplateTemplateParmDecl>(*P)->hasDefaultArgument())
92f4a2713aSLionel Sambuc break;
93f4a2713aSLionel Sambuc
94f4a2713aSLionel Sambuc ++NumRequiredArgs;
95f4a2713aSLionel Sambuc }
96f4a2713aSLionel Sambuc
97f4a2713aSLionel Sambuc return NumRequiredArgs;
98f4a2713aSLionel Sambuc }
99f4a2713aSLionel Sambuc
getDepth() const100f4a2713aSLionel Sambuc unsigned TemplateParameterList::getDepth() const {
101f4a2713aSLionel Sambuc if (size() == 0)
102f4a2713aSLionel Sambuc return 0;
103f4a2713aSLionel Sambuc
104f4a2713aSLionel Sambuc const NamedDecl *FirstParm = getParam(0);
105f4a2713aSLionel Sambuc if (const TemplateTypeParmDecl *TTP
106f4a2713aSLionel Sambuc = dyn_cast<TemplateTypeParmDecl>(FirstParm))
107f4a2713aSLionel Sambuc return TTP->getDepth();
108f4a2713aSLionel Sambuc else if (const NonTypeTemplateParmDecl *NTTP
109f4a2713aSLionel Sambuc = dyn_cast<NonTypeTemplateParmDecl>(FirstParm))
110f4a2713aSLionel Sambuc return NTTP->getDepth();
111f4a2713aSLionel Sambuc else
112f4a2713aSLionel Sambuc return cast<TemplateTemplateParmDecl>(FirstParm)->getDepth();
113f4a2713aSLionel Sambuc }
114f4a2713aSLionel Sambuc
AdoptTemplateParameterList(TemplateParameterList * Params,DeclContext * Owner)115f4a2713aSLionel Sambuc static void AdoptTemplateParameterList(TemplateParameterList *Params,
116f4a2713aSLionel Sambuc DeclContext *Owner) {
117f4a2713aSLionel Sambuc for (TemplateParameterList::iterator P = Params->begin(),
118f4a2713aSLionel Sambuc PEnd = Params->end();
119f4a2713aSLionel Sambuc P != PEnd; ++P) {
120f4a2713aSLionel Sambuc (*P)->setDeclContext(Owner);
121f4a2713aSLionel Sambuc
122f4a2713aSLionel Sambuc if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(*P))
123f4a2713aSLionel Sambuc AdoptTemplateParameterList(TTP->getTemplateParameters(), Owner);
124f4a2713aSLionel Sambuc }
125f4a2713aSLionel Sambuc }
126f4a2713aSLionel Sambuc
127f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
128f4a2713aSLionel Sambuc // RedeclarableTemplateDecl Implementation
129f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
130f4a2713aSLionel Sambuc
getCommonPtr() const131f4a2713aSLionel Sambuc RedeclarableTemplateDecl::CommonBase *RedeclarableTemplateDecl::getCommonPtr() const {
132f4a2713aSLionel Sambuc if (Common)
133f4a2713aSLionel Sambuc return Common;
134f4a2713aSLionel Sambuc
135f4a2713aSLionel Sambuc // Walk the previous-declaration chain until we either find a declaration
136f4a2713aSLionel Sambuc // with a common pointer or we run out of previous declarations.
137f4a2713aSLionel Sambuc SmallVector<const RedeclarableTemplateDecl *, 2> PrevDecls;
138f4a2713aSLionel Sambuc for (const RedeclarableTemplateDecl *Prev = getPreviousDecl(); Prev;
139f4a2713aSLionel Sambuc Prev = Prev->getPreviousDecl()) {
140f4a2713aSLionel Sambuc if (Prev->Common) {
141f4a2713aSLionel Sambuc Common = Prev->Common;
142f4a2713aSLionel Sambuc break;
143f4a2713aSLionel Sambuc }
144f4a2713aSLionel Sambuc
145f4a2713aSLionel Sambuc PrevDecls.push_back(Prev);
146f4a2713aSLionel Sambuc }
147f4a2713aSLionel Sambuc
148f4a2713aSLionel Sambuc // If we never found a common pointer, allocate one now.
149f4a2713aSLionel Sambuc if (!Common) {
150f4a2713aSLionel Sambuc // FIXME: If any of the declarations is from an AST file, we probably
151f4a2713aSLionel Sambuc // need an update record to add the common data.
152f4a2713aSLionel Sambuc
153f4a2713aSLionel Sambuc Common = newCommon(getASTContext());
154f4a2713aSLionel Sambuc }
155f4a2713aSLionel Sambuc
156f4a2713aSLionel Sambuc // Update any previous declarations we saw with the common pointer.
157f4a2713aSLionel Sambuc for (unsigned I = 0, N = PrevDecls.size(); I != N; ++I)
158f4a2713aSLionel Sambuc PrevDecls[I]->Common = Common;
159f4a2713aSLionel Sambuc
160f4a2713aSLionel Sambuc return Common;
161f4a2713aSLionel Sambuc }
162f4a2713aSLionel Sambuc
163f4a2713aSLionel Sambuc template <class EntryType>
164f4a2713aSLionel Sambuc typename RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::DeclType*
findSpecializationImpl(llvm::FoldingSetVector<EntryType> & Specs,ArrayRef<TemplateArgument> Args,void * & InsertPos)165f4a2713aSLionel Sambuc RedeclarableTemplateDecl::findSpecializationImpl(
166f4a2713aSLionel Sambuc llvm::FoldingSetVector<EntryType> &Specs,
167*0a6a1f1dSLionel Sambuc ArrayRef<TemplateArgument> Args,
168f4a2713aSLionel Sambuc void *&InsertPos) {
169f4a2713aSLionel Sambuc typedef SpecEntryTraits<EntryType> SETraits;
170f4a2713aSLionel Sambuc llvm::FoldingSetNodeID ID;
171*0a6a1f1dSLionel Sambuc EntryType::Profile(ID,Args, getASTContext());
172f4a2713aSLionel Sambuc EntryType *Entry = Specs.FindNodeOrInsertPos(ID, InsertPos);
173*0a6a1f1dSLionel Sambuc return Entry ? SETraits::getMostRecentDecl(Entry) : nullptr;
174f4a2713aSLionel Sambuc }
175f4a2713aSLionel Sambuc
176f4a2713aSLionel Sambuc /// \brief Generate the injected template arguments for the given template
177f4a2713aSLionel Sambuc /// parameter list, e.g., for the injected-class-name of a class template.
GenerateInjectedTemplateArgs(ASTContext & Context,TemplateParameterList * Params,TemplateArgument * Args)178f4a2713aSLionel Sambuc static void GenerateInjectedTemplateArgs(ASTContext &Context,
179f4a2713aSLionel Sambuc TemplateParameterList *Params,
180f4a2713aSLionel Sambuc TemplateArgument *Args) {
181f4a2713aSLionel Sambuc for (TemplateParameterList::iterator Param = Params->begin(),
182f4a2713aSLionel Sambuc ParamEnd = Params->end();
183f4a2713aSLionel Sambuc Param != ParamEnd; ++Param) {
184f4a2713aSLionel Sambuc TemplateArgument Arg;
185f4a2713aSLionel Sambuc if (TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(*Param)) {
186f4a2713aSLionel Sambuc QualType ArgType = Context.getTypeDeclType(TTP);
187f4a2713aSLionel Sambuc if (TTP->isParameterPack())
188f4a2713aSLionel Sambuc ArgType = Context.getPackExpansionType(ArgType, None);
189f4a2713aSLionel Sambuc
190f4a2713aSLionel Sambuc Arg = TemplateArgument(ArgType);
191f4a2713aSLionel Sambuc } else if (NonTypeTemplateParmDecl *NTTP =
192f4a2713aSLionel Sambuc dyn_cast<NonTypeTemplateParmDecl>(*Param)) {
193f4a2713aSLionel Sambuc Expr *E = new (Context) DeclRefExpr(NTTP, /*enclosing*/ false,
194f4a2713aSLionel Sambuc NTTP->getType().getNonLValueExprType(Context),
195f4a2713aSLionel Sambuc Expr::getValueKindForType(NTTP->getType()),
196f4a2713aSLionel Sambuc NTTP->getLocation());
197f4a2713aSLionel Sambuc
198f4a2713aSLionel Sambuc if (NTTP->isParameterPack())
199f4a2713aSLionel Sambuc E = new (Context) PackExpansionExpr(Context.DependentTy, E,
200f4a2713aSLionel Sambuc NTTP->getLocation(), None);
201f4a2713aSLionel Sambuc Arg = TemplateArgument(E);
202f4a2713aSLionel Sambuc } else {
203f4a2713aSLionel Sambuc TemplateTemplateParmDecl *TTP = cast<TemplateTemplateParmDecl>(*Param);
204f4a2713aSLionel Sambuc if (TTP->isParameterPack())
205f4a2713aSLionel Sambuc Arg = TemplateArgument(TemplateName(TTP), Optional<unsigned>());
206f4a2713aSLionel Sambuc else
207f4a2713aSLionel Sambuc Arg = TemplateArgument(TemplateName(TTP));
208f4a2713aSLionel Sambuc }
209f4a2713aSLionel Sambuc
210f4a2713aSLionel Sambuc if ((*Param)->isTemplateParameterPack())
211f4a2713aSLionel Sambuc Arg = TemplateArgument::CreatePackCopy(Context, &Arg, 1);
212f4a2713aSLionel Sambuc
213f4a2713aSLionel Sambuc *Args++ = Arg;
214f4a2713aSLionel Sambuc }
215f4a2713aSLionel Sambuc }
216f4a2713aSLionel Sambuc
217f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
218f4a2713aSLionel Sambuc // FunctionTemplateDecl Implementation
219f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
220f4a2713aSLionel Sambuc
DeallocateCommon(void * Ptr)221f4a2713aSLionel Sambuc void FunctionTemplateDecl::DeallocateCommon(void *Ptr) {
222f4a2713aSLionel Sambuc static_cast<Common *>(Ptr)->~Common();
223f4a2713aSLionel Sambuc }
224f4a2713aSLionel Sambuc
Create(ASTContext & C,DeclContext * DC,SourceLocation L,DeclarationName Name,TemplateParameterList * Params,NamedDecl * Decl)225f4a2713aSLionel Sambuc FunctionTemplateDecl *FunctionTemplateDecl::Create(ASTContext &C,
226f4a2713aSLionel Sambuc DeclContext *DC,
227f4a2713aSLionel Sambuc SourceLocation L,
228f4a2713aSLionel Sambuc DeclarationName Name,
229f4a2713aSLionel Sambuc TemplateParameterList *Params,
230f4a2713aSLionel Sambuc NamedDecl *Decl) {
231f4a2713aSLionel Sambuc AdoptTemplateParameterList(Params, cast<DeclContext>(Decl));
232*0a6a1f1dSLionel Sambuc return new (C, DC) FunctionTemplateDecl(C, DC, L, Name, Params, Decl);
233f4a2713aSLionel Sambuc }
234f4a2713aSLionel Sambuc
CreateDeserialized(ASTContext & C,unsigned ID)235f4a2713aSLionel Sambuc FunctionTemplateDecl *FunctionTemplateDecl::CreateDeserialized(ASTContext &C,
236f4a2713aSLionel Sambuc unsigned ID) {
237*0a6a1f1dSLionel Sambuc return new (C, ID) FunctionTemplateDecl(C, nullptr, SourceLocation(),
238*0a6a1f1dSLionel Sambuc DeclarationName(), nullptr, nullptr);
239f4a2713aSLionel Sambuc }
240f4a2713aSLionel Sambuc
241f4a2713aSLionel Sambuc RedeclarableTemplateDecl::CommonBase *
newCommon(ASTContext & C) const242f4a2713aSLionel Sambuc FunctionTemplateDecl::newCommon(ASTContext &C) const {
243f4a2713aSLionel Sambuc Common *CommonPtr = new (C) Common;
244f4a2713aSLionel Sambuc C.AddDeallocation(DeallocateCommon, CommonPtr);
245f4a2713aSLionel Sambuc return CommonPtr;
246f4a2713aSLionel Sambuc }
247f4a2713aSLionel Sambuc
LoadLazySpecializations() const248f4a2713aSLionel Sambuc void FunctionTemplateDecl::LoadLazySpecializations() const {
249f4a2713aSLionel Sambuc Common *CommonPtr = getCommonPtr();
250f4a2713aSLionel Sambuc if (CommonPtr->LazySpecializations) {
251f4a2713aSLionel Sambuc ASTContext &Context = getASTContext();
252f4a2713aSLionel Sambuc uint32_t *Specs = CommonPtr->LazySpecializations;
253*0a6a1f1dSLionel Sambuc CommonPtr->LazySpecializations = nullptr;
254f4a2713aSLionel Sambuc for (uint32_t I = 0, N = *Specs++; I != N; ++I)
255f4a2713aSLionel Sambuc (void)Context.getExternalSource()->GetExternalDecl(Specs[I]);
256f4a2713aSLionel Sambuc }
257f4a2713aSLionel Sambuc }
258f4a2713aSLionel Sambuc
259f4a2713aSLionel Sambuc llvm::FoldingSetVector<FunctionTemplateSpecializationInfo> &
getSpecializations() const260f4a2713aSLionel Sambuc FunctionTemplateDecl::getSpecializations() const {
261f4a2713aSLionel Sambuc LoadLazySpecializations();
262f4a2713aSLionel Sambuc return getCommonPtr()->Specializations;
263f4a2713aSLionel Sambuc }
264f4a2713aSLionel Sambuc
265f4a2713aSLionel Sambuc FunctionDecl *
findSpecialization(ArrayRef<TemplateArgument> Args,void * & InsertPos)266*0a6a1f1dSLionel Sambuc FunctionTemplateDecl::findSpecialization(ArrayRef<TemplateArgument> Args,
267*0a6a1f1dSLionel Sambuc void *&InsertPos) {
268*0a6a1f1dSLionel Sambuc return findSpecializationImpl(getSpecializations(), Args, InsertPos);
269f4a2713aSLionel Sambuc }
270f4a2713aSLionel Sambuc
addSpecialization(FunctionTemplateSpecializationInfo * Info,void * InsertPos)271f4a2713aSLionel Sambuc void FunctionTemplateDecl::addSpecialization(
272f4a2713aSLionel Sambuc FunctionTemplateSpecializationInfo *Info, void *InsertPos) {
273f4a2713aSLionel Sambuc if (InsertPos)
274f4a2713aSLionel Sambuc getSpecializations().InsertNode(Info, InsertPos);
275f4a2713aSLionel Sambuc else
276f4a2713aSLionel Sambuc getSpecializations().GetOrInsertNode(Info);
277f4a2713aSLionel Sambuc if (ASTMutationListener *L = getASTMutationListener())
278f4a2713aSLionel Sambuc L->AddedCXXTemplateSpecialization(this, Info->Function);
279f4a2713aSLionel Sambuc }
280f4a2713aSLionel Sambuc
getInjectedTemplateArgs()281f4a2713aSLionel Sambuc ArrayRef<TemplateArgument> FunctionTemplateDecl::getInjectedTemplateArgs() {
282f4a2713aSLionel Sambuc TemplateParameterList *Params = getTemplateParameters();
283f4a2713aSLionel Sambuc Common *CommonPtr = getCommonPtr();
284f4a2713aSLionel Sambuc if (!CommonPtr->InjectedArgs) {
285f4a2713aSLionel Sambuc CommonPtr->InjectedArgs
286f4a2713aSLionel Sambuc = new (getASTContext()) TemplateArgument[Params->size()];
287f4a2713aSLionel Sambuc GenerateInjectedTemplateArgs(getASTContext(), Params,
288f4a2713aSLionel Sambuc CommonPtr->InjectedArgs);
289f4a2713aSLionel Sambuc }
290f4a2713aSLionel Sambuc
291f4a2713aSLionel Sambuc return llvm::makeArrayRef(CommonPtr->InjectedArgs, Params->size());
292f4a2713aSLionel Sambuc }
293f4a2713aSLionel Sambuc
294f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
295f4a2713aSLionel Sambuc // ClassTemplateDecl Implementation
296f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
297f4a2713aSLionel Sambuc
DeallocateCommon(void * Ptr)298f4a2713aSLionel Sambuc void ClassTemplateDecl::DeallocateCommon(void *Ptr) {
299f4a2713aSLionel Sambuc static_cast<Common *>(Ptr)->~Common();
300f4a2713aSLionel Sambuc }
301f4a2713aSLionel Sambuc
Create(ASTContext & C,DeclContext * DC,SourceLocation L,DeclarationName Name,TemplateParameterList * Params,NamedDecl * Decl,ClassTemplateDecl * PrevDecl)302f4a2713aSLionel Sambuc ClassTemplateDecl *ClassTemplateDecl::Create(ASTContext &C,
303f4a2713aSLionel Sambuc DeclContext *DC,
304f4a2713aSLionel Sambuc SourceLocation L,
305f4a2713aSLionel Sambuc DeclarationName Name,
306f4a2713aSLionel Sambuc TemplateParameterList *Params,
307f4a2713aSLionel Sambuc NamedDecl *Decl,
308f4a2713aSLionel Sambuc ClassTemplateDecl *PrevDecl) {
309f4a2713aSLionel Sambuc AdoptTemplateParameterList(Params, cast<DeclContext>(Decl));
310*0a6a1f1dSLionel Sambuc ClassTemplateDecl *New = new (C, DC) ClassTemplateDecl(C, DC, L, Name,
311*0a6a1f1dSLionel Sambuc Params, Decl);
312f4a2713aSLionel Sambuc New->setPreviousDecl(PrevDecl);
313f4a2713aSLionel Sambuc return New;
314f4a2713aSLionel Sambuc }
315f4a2713aSLionel Sambuc
CreateDeserialized(ASTContext & C,unsigned ID)316f4a2713aSLionel Sambuc ClassTemplateDecl *ClassTemplateDecl::CreateDeserialized(ASTContext &C,
317f4a2713aSLionel Sambuc unsigned ID) {
318*0a6a1f1dSLionel Sambuc return new (C, ID) ClassTemplateDecl(C, nullptr, SourceLocation(),
319*0a6a1f1dSLionel Sambuc DeclarationName(), nullptr, nullptr);
320f4a2713aSLionel Sambuc }
321f4a2713aSLionel Sambuc
LoadLazySpecializations() const322f4a2713aSLionel Sambuc void ClassTemplateDecl::LoadLazySpecializations() const {
323f4a2713aSLionel Sambuc Common *CommonPtr = getCommonPtr();
324f4a2713aSLionel Sambuc if (CommonPtr->LazySpecializations) {
325f4a2713aSLionel Sambuc ASTContext &Context = getASTContext();
326f4a2713aSLionel Sambuc uint32_t *Specs = CommonPtr->LazySpecializations;
327*0a6a1f1dSLionel Sambuc CommonPtr->LazySpecializations = nullptr;
328f4a2713aSLionel Sambuc for (uint32_t I = 0, N = *Specs++; I != N; ++I)
329f4a2713aSLionel Sambuc (void)Context.getExternalSource()->GetExternalDecl(Specs[I]);
330f4a2713aSLionel Sambuc }
331f4a2713aSLionel Sambuc }
332f4a2713aSLionel Sambuc
333f4a2713aSLionel Sambuc llvm::FoldingSetVector<ClassTemplateSpecializationDecl> &
getSpecializations() const334f4a2713aSLionel Sambuc ClassTemplateDecl::getSpecializations() const {
335f4a2713aSLionel Sambuc LoadLazySpecializations();
336f4a2713aSLionel Sambuc return getCommonPtr()->Specializations;
337f4a2713aSLionel Sambuc }
338f4a2713aSLionel Sambuc
339f4a2713aSLionel Sambuc llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> &
getPartialSpecializations()340f4a2713aSLionel Sambuc ClassTemplateDecl::getPartialSpecializations() {
341f4a2713aSLionel Sambuc LoadLazySpecializations();
342f4a2713aSLionel Sambuc return getCommonPtr()->PartialSpecializations;
343f4a2713aSLionel Sambuc }
344f4a2713aSLionel Sambuc
345f4a2713aSLionel Sambuc RedeclarableTemplateDecl::CommonBase *
newCommon(ASTContext & C) const346f4a2713aSLionel Sambuc ClassTemplateDecl::newCommon(ASTContext &C) const {
347f4a2713aSLionel Sambuc Common *CommonPtr = new (C) Common;
348f4a2713aSLionel Sambuc C.AddDeallocation(DeallocateCommon, CommonPtr);
349f4a2713aSLionel Sambuc return CommonPtr;
350f4a2713aSLionel Sambuc }
351f4a2713aSLionel Sambuc
352f4a2713aSLionel Sambuc ClassTemplateSpecializationDecl *
findSpecialization(ArrayRef<TemplateArgument> Args,void * & InsertPos)353*0a6a1f1dSLionel Sambuc ClassTemplateDecl::findSpecialization(ArrayRef<TemplateArgument> Args,
354*0a6a1f1dSLionel Sambuc void *&InsertPos) {
355*0a6a1f1dSLionel Sambuc return findSpecializationImpl(getSpecializations(), Args, InsertPos);
356f4a2713aSLionel Sambuc }
357f4a2713aSLionel Sambuc
AddSpecialization(ClassTemplateSpecializationDecl * D,void * InsertPos)358f4a2713aSLionel Sambuc void ClassTemplateDecl::AddSpecialization(ClassTemplateSpecializationDecl *D,
359f4a2713aSLionel Sambuc void *InsertPos) {
360f4a2713aSLionel Sambuc if (InsertPos)
361f4a2713aSLionel Sambuc getSpecializations().InsertNode(D, InsertPos);
362f4a2713aSLionel Sambuc else {
363f4a2713aSLionel Sambuc ClassTemplateSpecializationDecl *Existing
364f4a2713aSLionel Sambuc = getSpecializations().GetOrInsertNode(D);
365f4a2713aSLionel Sambuc (void)Existing;
366f4a2713aSLionel Sambuc assert(Existing->isCanonicalDecl() && "Non-canonical specialization?");
367f4a2713aSLionel Sambuc }
368f4a2713aSLionel Sambuc if (ASTMutationListener *L = getASTMutationListener())
369f4a2713aSLionel Sambuc L->AddedCXXTemplateSpecialization(this, D);
370f4a2713aSLionel Sambuc }
371f4a2713aSLionel Sambuc
372f4a2713aSLionel Sambuc ClassTemplatePartialSpecializationDecl *
findPartialSpecialization(ArrayRef<TemplateArgument> Args,void * & InsertPos)373*0a6a1f1dSLionel Sambuc ClassTemplateDecl::findPartialSpecialization(ArrayRef<TemplateArgument> Args,
374f4a2713aSLionel Sambuc void *&InsertPos) {
375*0a6a1f1dSLionel Sambuc return findSpecializationImpl(getPartialSpecializations(), Args, InsertPos);
376f4a2713aSLionel Sambuc }
377f4a2713aSLionel Sambuc
AddPartialSpecialization(ClassTemplatePartialSpecializationDecl * D,void * InsertPos)378f4a2713aSLionel Sambuc void ClassTemplateDecl::AddPartialSpecialization(
379f4a2713aSLionel Sambuc ClassTemplatePartialSpecializationDecl *D,
380f4a2713aSLionel Sambuc void *InsertPos) {
381f4a2713aSLionel Sambuc if (InsertPos)
382f4a2713aSLionel Sambuc getPartialSpecializations().InsertNode(D, InsertPos);
383f4a2713aSLionel Sambuc else {
384f4a2713aSLionel Sambuc ClassTemplatePartialSpecializationDecl *Existing
385f4a2713aSLionel Sambuc = getPartialSpecializations().GetOrInsertNode(D);
386f4a2713aSLionel Sambuc (void)Existing;
387f4a2713aSLionel Sambuc assert(Existing->isCanonicalDecl() && "Non-canonical specialization?");
388f4a2713aSLionel Sambuc }
389f4a2713aSLionel Sambuc
390f4a2713aSLionel Sambuc if (ASTMutationListener *L = getASTMutationListener())
391f4a2713aSLionel Sambuc L->AddedCXXTemplateSpecialization(this, D);
392f4a2713aSLionel Sambuc }
393f4a2713aSLionel Sambuc
getPartialSpecializations(SmallVectorImpl<ClassTemplatePartialSpecializationDecl * > & PS)394f4a2713aSLionel Sambuc void ClassTemplateDecl::getPartialSpecializations(
395f4a2713aSLionel Sambuc SmallVectorImpl<ClassTemplatePartialSpecializationDecl *> &PS) {
396f4a2713aSLionel Sambuc llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> &PartialSpecs
397f4a2713aSLionel Sambuc = getPartialSpecializations();
398f4a2713aSLionel Sambuc PS.clear();
399f4a2713aSLionel Sambuc PS.reserve(PartialSpecs.size());
400f4a2713aSLionel Sambuc for (llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl>::iterator
401f4a2713aSLionel Sambuc P = PartialSpecs.begin(), PEnd = PartialSpecs.end();
402f4a2713aSLionel Sambuc P != PEnd; ++P)
403f4a2713aSLionel Sambuc PS.push_back(P->getMostRecentDecl());
404f4a2713aSLionel Sambuc }
405f4a2713aSLionel Sambuc
406f4a2713aSLionel Sambuc ClassTemplatePartialSpecializationDecl *
findPartialSpecialization(QualType T)407f4a2713aSLionel Sambuc ClassTemplateDecl::findPartialSpecialization(QualType T) {
408f4a2713aSLionel Sambuc ASTContext &Context = getASTContext();
409f4a2713aSLionel Sambuc using llvm::FoldingSetVector;
410f4a2713aSLionel Sambuc typedef FoldingSetVector<ClassTemplatePartialSpecializationDecl>::iterator
411f4a2713aSLionel Sambuc partial_spec_iterator;
412f4a2713aSLionel Sambuc for (partial_spec_iterator P = getPartialSpecializations().begin(),
413f4a2713aSLionel Sambuc PEnd = getPartialSpecializations().end();
414f4a2713aSLionel Sambuc P != PEnd; ++P) {
415f4a2713aSLionel Sambuc if (Context.hasSameType(P->getInjectedSpecializationType(), T))
416f4a2713aSLionel Sambuc return P->getMostRecentDecl();
417f4a2713aSLionel Sambuc }
418f4a2713aSLionel Sambuc
419*0a6a1f1dSLionel Sambuc return nullptr;
420f4a2713aSLionel Sambuc }
421f4a2713aSLionel Sambuc
422f4a2713aSLionel Sambuc ClassTemplatePartialSpecializationDecl *
findPartialSpecInstantiatedFromMember(ClassTemplatePartialSpecializationDecl * D)423f4a2713aSLionel Sambuc ClassTemplateDecl::findPartialSpecInstantiatedFromMember(
424f4a2713aSLionel Sambuc ClassTemplatePartialSpecializationDecl *D) {
425f4a2713aSLionel Sambuc Decl *DCanon = D->getCanonicalDecl();
426f4a2713aSLionel Sambuc for (llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl>::iterator
427f4a2713aSLionel Sambuc P = getPartialSpecializations().begin(),
428f4a2713aSLionel Sambuc PEnd = getPartialSpecializations().end();
429f4a2713aSLionel Sambuc P != PEnd; ++P) {
430f4a2713aSLionel Sambuc if (P->getInstantiatedFromMember()->getCanonicalDecl() == DCanon)
431f4a2713aSLionel Sambuc return P->getMostRecentDecl();
432f4a2713aSLionel Sambuc }
433f4a2713aSLionel Sambuc
434*0a6a1f1dSLionel Sambuc return nullptr;
435f4a2713aSLionel Sambuc }
436f4a2713aSLionel Sambuc
437f4a2713aSLionel Sambuc QualType
getInjectedClassNameSpecialization()438f4a2713aSLionel Sambuc ClassTemplateDecl::getInjectedClassNameSpecialization() {
439f4a2713aSLionel Sambuc Common *CommonPtr = getCommonPtr();
440f4a2713aSLionel Sambuc if (!CommonPtr->InjectedClassNameType.isNull())
441f4a2713aSLionel Sambuc return CommonPtr->InjectedClassNameType;
442f4a2713aSLionel Sambuc
443f4a2713aSLionel Sambuc // C++0x [temp.dep.type]p2:
444f4a2713aSLionel Sambuc // The template argument list of a primary template is a template argument
445f4a2713aSLionel Sambuc // list in which the nth template argument has the value of the nth template
446f4a2713aSLionel Sambuc // parameter of the class template. If the nth template parameter is a
447f4a2713aSLionel Sambuc // template parameter pack (14.5.3), the nth template argument is a pack
448f4a2713aSLionel Sambuc // expansion (14.5.3) whose pattern is the name of the template parameter
449f4a2713aSLionel Sambuc // pack.
450f4a2713aSLionel Sambuc ASTContext &Context = getASTContext();
451f4a2713aSLionel Sambuc TemplateParameterList *Params = getTemplateParameters();
452f4a2713aSLionel Sambuc SmallVector<TemplateArgument, 16> TemplateArgs;
453f4a2713aSLionel Sambuc TemplateArgs.resize(Params->size());
454f4a2713aSLionel Sambuc GenerateInjectedTemplateArgs(getASTContext(), Params, TemplateArgs.data());
455f4a2713aSLionel Sambuc CommonPtr->InjectedClassNameType
456f4a2713aSLionel Sambuc = Context.getTemplateSpecializationType(TemplateName(this),
457f4a2713aSLionel Sambuc &TemplateArgs[0],
458f4a2713aSLionel Sambuc TemplateArgs.size());
459f4a2713aSLionel Sambuc return CommonPtr->InjectedClassNameType;
460f4a2713aSLionel Sambuc }
461f4a2713aSLionel Sambuc
462f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
463f4a2713aSLionel Sambuc // TemplateTypeParm Allocation/Deallocation Method Implementations
464f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
465f4a2713aSLionel Sambuc
466f4a2713aSLionel Sambuc TemplateTypeParmDecl *
Create(const ASTContext & C,DeclContext * DC,SourceLocation KeyLoc,SourceLocation NameLoc,unsigned D,unsigned P,IdentifierInfo * Id,bool Typename,bool ParameterPack)467f4a2713aSLionel Sambuc TemplateTypeParmDecl::Create(const ASTContext &C, DeclContext *DC,
468f4a2713aSLionel Sambuc SourceLocation KeyLoc, SourceLocation NameLoc,
469f4a2713aSLionel Sambuc unsigned D, unsigned P, IdentifierInfo *Id,
470f4a2713aSLionel Sambuc bool Typename, bool ParameterPack) {
471f4a2713aSLionel Sambuc TemplateTypeParmDecl *TTPDecl =
472*0a6a1f1dSLionel Sambuc new (C, DC) TemplateTypeParmDecl(DC, KeyLoc, NameLoc, Id, Typename);
473f4a2713aSLionel Sambuc QualType TTPType = C.getTemplateTypeParmType(D, P, ParameterPack, TTPDecl);
474*0a6a1f1dSLionel Sambuc TTPDecl->setTypeForDecl(TTPType.getTypePtr());
475f4a2713aSLionel Sambuc return TTPDecl;
476f4a2713aSLionel Sambuc }
477f4a2713aSLionel Sambuc
478f4a2713aSLionel Sambuc TemplateTypeParmDecl *
CreateDeserialized(const ASTContext & C,unsigned ID)479f4a2713aSLionel Sambuc TemplateTypeParmDecl::CreateDeserialized(const ASTContext &C, unsigned ID) {
480*0a6a1f1dSLionel Sambuc return new (C, ID) TemplateTypeParmDecl(nullptr, SourceLocation(),
481*0a6a1f1dSLionel Sambuc SourceLocation(), nullptr, false);
482f4a2713aSLionel Sambuc }
483f4a2713aSLionel Sambuc
getDefaultArgumentLoc() const484f4a2713aSLionel Sambuc SourceLocation TemplateTypeParmDecl::getDefaultArgumentLoc() const {
485f4a2713aSLionel Sambuc return hasDefaultArgument()
486f4a2713aSLionel Sambuc ? DefaultArgument->getTypeLoc().getBeginLoc()
487f4a2713aSLionel Sambuc : SourceLocation();
488f4a2713aSLionel Sambuc }
489f4a2713aSLionel Sambuc
getSourceRange() const490f4a2713aSLionel Sambuc SourceRange TemplateTypeParmDecl::getSourceRange() const {
491f4a2713aSLionel Sambuc if (hasDefaultArgument() && !defaultArgumentWasInherited())
492f4a2713aSLionel Sambuc return SourceRange(getLocStart(),
493f4a2713aSLionel Sambuc DefaultArgument->getTypeLoc().getEndLoc());
494f4a2713aSLionel Sambuc else
495f4a2713aSLionel Sambuc return TypeDecl::getSourceRange();
496f4a2713aSLionel Sambuc }
497f4a2713aSLionel Sambuc
getDepth() const498f4a2713aSLionel Sambuc unsigned TemplateTypeParmDecl::getDepth() const {
499*0a6a1f1dSLionel Sambuc return getTypeForDecl()->getAs<TemplateTypeParmType>()->getDepth();
500f4a2713aSLionel Sambuc }
501f4a2713aSLionel Sambuc
getIndex() const502f4a2713aSLionel Sambuc unsigned TemplateTypeParmDecl::getIndex() const {
503*0a6a1f1dSLionel Sambuc return getTypeForDecl()->getAs<TemplateTypeParmType>()->getIndex();
504f4a2713aSLionel Sambuc }
505f4a2713aSLionel Sambuc
isParameterPack() const506f4a2713aSLionel Sambuc bool TemplateTypeParmDecl::isParameterPack() const {
507*0a6a1f1dSLionel Sambuc return getTypeForDecl()->getAs<TemplateTypeParmType>()->isParameterPack();
508f4a2713aSLionel Sambuc }
509f4a2713aSLionel Sambuc
510f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
511f4a2713aSLionel Sambuc // NonTypeTemplateParmDecl Method Implementations
512f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
513f4a2713aSLionel Sambuc
NonTypeTemplateParmDecl(DeclContext * DC,SourceLocation StartLoc,SourceLocation IdLoc,unsigned D,unsigned P,IdentifierInfo * Id,QualType T,TypeSourceInfo * TInfo,const QualType * ExpandedTypes,unsigned NumExpandedTypes,TypeSourceInfo ** ExpandedTInfos)514f4a2713aSLionel Sambuc NonTypeTemplateParmDecl::NonTypeTemplateParmDecl(DeclContext *DC,
515f4a2713aSLionel Sambuc SourceLocation StartLoc,
516f4a2713aSLionel Sambuc SourceLocation IdLoc,
517f4a2713aSLionel Sambuc unsigned D, unsigned P,
518f4a2713aSLionel Sambuc IdentifierInfo *Id,
519f4a2713aSLionel Sambuc QualType T,
520f4a2713aSLionel Sambuc TypeSourceInfo *TInfo,
521f4a2713aSLionel Sambuc const QualType *ExpandedTypes,
522f4a2713aSLionel Sambuc unsigned NumExpandedTypes,
523f4a2713aSLionel Sambuc TypeSourceInfo **ExpandedTInfos)
524f4a2713aSLionel Sambuc : DeclaratorDecl(NonTypeTemplateParm, DC, IdLoc, Id, T, TInfo, StartLoc),
525*0a6a1f1dSLionel Sambuc TemplateParmPosition(D, P), DefaultArgumentAndInherited(nullptr, false),
526f4a2713aSLionel Sambuc ParameterPack(true), ExpandedParameterPack(true),
527f4a2713aSLionel Sambuc NumExpandedTypes(NumExpandedTypes)
528f4a2713aSLionel Sambuc {
529f4a2713aSLionel Sambuc if (ExpandedTypes && ExpandedTInfos) {
530f4a2713aSLionel Sambuc void **TypesAndInfos = reinterpret_cast<void **>(this + 1);
531f4a2713aSLionel Sambuc for (unsigned I = 0; I != NumExpandedTypes; ++I) {
532f4a2713aSLionel Sambuc TypesAndInfos[2*I] = ExpandedTypes[I].getAsOpaquePtr();
533f4a2713aSLionel Sambuc TypesAndInfos[2*I + 1] = ExpandedTInfos[I];
534f4a2713aSLionel Sambuc }
535f4a2713aSLionel Sambuc }
536f4a2713aSLionel Sambuc }
537f4a2713aSLionel Sambuc
538f4a2713aSLionel Sambuc NonTypeTemplateParmDecl *
Create(const ASTContext & C,DeclContext * DC,SourceLocation StartLoc,SourceLocation IdLoc,unsigned D,unsigned P,IdentifierInfo * Id,QualType T,bool ParameterPack,TypeSourceInfo * TInfo)539f4a2713aSLionel Sambuc NonTypeTemplateParmDecl::Create(const ASTContext &C, DeclContext *DC,
540f4a2713aSLionel Sambuc SourceLocation StartLoc, SourceLocation IdLoc,
541f4a2713aSLionel Sambuc unsigned D, unsigned P, IdentifierInfo *Id,
542f4a2713aSLionel Sambuc QualType T, bool ParameterPack,
543f4a2713aSLionel Sambuc TypeSourceInfo *TInfo) {
544*0a6a1f1dSLionel Sambuc return new (C, DC) NonTypeTemplateParmDecl(DC, StartLoc, IdLoc, D, P, Id,
545f4a2713aSLionel Sambuc T, ParameterPack, TInfo);
546f4a2713aSLionel Sambuc }
547f4a2713aSLionel Sambuc
548f4a2713aSLionel Sambuc NonTypeTemplateParmDecl *
Create(const ASTContext & C,DeclContext * DC,SourceLocation StartLoc,SourceLocation IdLoc,unsigned D,unsigned P,IdentifierInfo * Id,QualType T,TypeSourceInfo * TInfo,const QualType * ExpandedTypes,unsigned NumExpandedTypes,TypeSourceInfo ** ExpandedTInfos)549f4a2713aSLionel Sambuc NonTypeTemplateParmDecl::Create(const ASTContext &C, DeclContext *DC,
550f4a2713aSLionel Sambuc SourceLocation StartLoc, SourceLocation IdLoc,
551f4a2713aSLionel Sambuc unsigned D, unsigned P,
552f4a2713aSLionel Sambuc IdentifierInfo *Id, QualType T,
553f4a2713aSLionel Sambuc TypeSourceInfo *TInfo,
554f4a2713aSLionel Sambuc const QualType *ExpandedTypes,
555f4a2713aSLionel Sambuc unsigned NumExpandedTypes,
556f4a2713aSLionel Sambuc TypeSourceInfo **ExpandedTInfos) {
557*0a6a1f1dSLionel Sambuc unsigned Extra = NumExpandedTypes * 2 * sizeof(void*);
558*0a6a1f1dSLionel Sambuc return new (C, DC, Extra) NonTypeTemplateParmDecl(
559*0a6a1f1dSLionel Sambuc DC, StartLoc, IdLoc, D, P, Id, T, TInfo,
560*0a6a1f1dSLionel Sambuc ExpandedTypes, NumExpandedTypes, ExpandedTInfos);
561f4a2713aSLionel Sambuc }
562f4a2713aSLionel Sambuc
563f4a2713aSLionel Sambuc NonTypeTemplateParmDecl *
CreateDeserialized(ASTContext & C,unsigned ID)564f4a2713aSLionel Sambuc NonTypeTemplateParmDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
565*0a6a1f1dSLionel Sambuc return new (C, ID) NonTypeTemplateParmDecl(nullptr, SourceLocation(),
566*0a6a1f1dSLionel Sambuc SourceLocation(), 0, 0, nullptr,
567*0a6a1f1dSLionel Sambuc QualType(), false, nullptr);
568f4a2713aSLionel Sambuc }
569f4a2713aSLionel Sambuc
570f4a2713aSLionel Sambuc NonTypeTemplateParmDecl *
CreateDeserialized(ASTContext & C,unsigned ID,unsigned NumExpandedTypes)571f4a2713aSLionel Sambuc NonTypeTemplateParmDecl::CreateDeserialized(ASTContext &C, unsigned ID,
572f4a2713aSLionel Sambuc unsigned NumExpandedTypes) {
573*0a6a1f1dSLionel Sambuc unsigned Extra = NumExpandedTypes * 2 * sizeof(void*);
574*0a6a1f1dSLionel Sambuc return new (C, ID, Extra) NonTypeTemplateParmDecl(
575*0a6a1f1dSLionel Sambuc nullptr, SourceLocation(), SourceLocation(), 0, 0, nullptr, QualType(),
576*0a6a1f1dSLionel Sambuc nullptr, nullptr, NumExpandedTypes, nullptr);
577f4a2713aSLionel Sambuc }
578f4a2713aSLionel Sambuc
getSourceRange() const579f4a2713aSLionel Sambuc SourceRange NonTypeTemplateParmDecl::getSourceRange() const {
580f4a2713aSLionel Sambuc if (hasDefaultArgument() && !defaultArgumentWasInherited())
581f4a2713aSLionel Sambuc return SourceRange(getOuterLocStart(),
582f4a2713aSLionel Sambuc getDefaultArgument()->getSourceRange().getEnd());
583f4a2713aSLionel Sambuc return DeclaratorDecl::getSourceRange();
584f4a2713aSLionel Sambuc }
585f4a2713aSLionel Sambuc
getDefaultArgumentLoc() const586f4a2713aSLionel Sambuc SourceLocation NonTypeTemplateParmDecl::getDefaultArgumentLoc() const {
587f4a2713aSLionel Sambuc return hasDefaultArgument()
588f4a2713aSLionel Sambuc ? getDefaultArgument()->getSourceRange().getBegin()
589f4a2713aSLionel Sambuc : SourceLocation();
590f4a2713aSLionel Sambuc }
591f4a2713aSLionel Sambuc
592f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
593f4a2713aSLionel Sambuc // TemplateTemplateParmDecl Method Implementations
594f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
595f4a2713aSLionel Sambuc
anchor()596f4a2713aSLionel Sambuc void TemplateTemplateParmDecl::anchor() { }
597f4a2713aSLionel Sambuc
TemplateTemplateParmDecl(DeclContext * DC,SourceLocation L,unsigned D,unsigned P,IdentifierInfo * Id,TemplateParameterList * Params,unsigned NumExpansions,TemplateParameterList * const * Expansions)598f4a2713aSLionel Sambuc TemplateTemplateParmDecl::TemplateTemplateParmDecl(
599f4a2713aSLionel Sambuc DeclContext *DC, SourceLocation L, unsigned D, unsigned P,
600f4a2713aSLionel Sambuc IdentifierInfo *Id, TemplateParameterList *Params,
601f4a2713aSLionel Sambuc unsigned NumExpansions, TemplateParameterList * const *Expansions)
602f4a2713aSLionel Sambuc : TemplateDecl(TemplateTemplateParm, DC, L, Id, Params),
603f4a2713aSLionel Sambuc TemplateParmPosition(D, P), DefaultArgument(),
604f4a2713aSLionel Sambuc DefaultArgumentWasInherited(false), ParameterPack(true),
605f4a2713aSLionel Sambuc ExpandedParameterPack(true), NumExpandedParams(NumExpansions) {
606f4a2713aSLionel Sambuc if (Expansions)
607f4a2713aSLionel Sambuc std::memcpy(reinterpret_cast<void*>(this + 1), Expansions,
608f4a2713aSLionel Sambuc sizeof(TemplateParameterList*) * NumExpandedParams);
609f4a2713aSLionel Sambuc }
610f4a2713aSLionel Sambuc
611f4a2713aSLionel Sambuc TemplateTemplateParmDecl *
Create(const ASTContext & C,DeclContext * DC,SourceLocation L,unsigned D,unsigned P,bool ParameterPack,IdentifierInfo * Id,TemplateParameterList * Params)612f4a2713aSLionel Sambuc TemplateTemplateParmDecl::Create(const ASTContext &C, DeclContext *DC,
613f4a2713aSLionel Sambuc SourceLocation L, unsigned D, unsigned P,
614f4a2713aSLionel Sambuc bool ParameterPack, IdentifierInfo *Id,
615f4a2713aSLionel Sambuc TemplateParameterList *Params) {
616*0a6a1f1dSLionel Sambuc return new (C, DC) TemplateTemplateParmDecl(DC, L, D, P, ParameterPack, Id,
617f4a2713aSLionel Sambuc Params);
618f4a2713aSLionel Sambuc }
619f4a2713aSLionel Sambuc
620f4a2713aSLionel Sambuc TemplateTemplateParmDecl *
Create(const ASTContext & C,DeclContext * DC,SourceLocation L,unsigned D,unsigned P,IdentifierInfo * Id,TemplateParameterList * Params,ArrayRef<TemplateParameterList * > Expansions)621f4a2713aSLionel Sambuc TemplateTemplateParmDecl::Create(const ASTContext &C, DeclContext *DC,
622f4a2713aSLionel Sambuc SourceLocation L, unsigned D, unsigned P,
623f4a2713aSLionel Sambuc IdentifierInfo *Id,
624f4a2713aSLionel Sambuc TemplateParameterList *Params,
625f4a2713aSLionel Sambuc ArrayRef<TemplateParameterList *> Expansions) {
626*0a6a1f1dSLionel Sambuc return new (C, DC, sizeof(TemplateParameterList*) * Expansions.size())
627*0a6a1f1dSLionel Sambuc TemplateTemplateParmDecl(DC, L, D, P, Id, Params,
628*0a6a1f1dSLionel Sambuc Expansions.size(), Expansions.data());
629f4a2713aSLionel Sambuc }
630f4a2713aSLionel Sambuc
631f4a2713aSLionel Sambuc TemplateTemplateParmDecl *
CreateDeserialized(ASTContext & C,unsigned ID)632f4a2713aSLionel Sambuc TemplateTemplateParmDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
633*0a6a1f1dSLionel Sambuc return new (C, ID) TemplateTemplateParmDecl(nullptr, SourceLocation(), 0, 0,
634*0a6a1f1dSLionel Sambuc false, nullptr, nullptr);
635f4a2713aSLionel Sambuc }
636f4a2713aSLionel Sambuc
637f4a2713aSLionel Sambuc TemplateTemplateParmDecl *
CreateDeserialized(ASTContext & C,unsigned ID,unsigned NumExpansions)638f4a2713aSLionel Sambuc TemplateTemplateParmDecl::CreateDeserialized(ASTContext &C, unsigned ID,
639f4a2713aSLionel Sambuc unsigned NumExpansions) {
640*0a6a1f1dSLionel Sambuc return new (C, ID, sizeof(TemplateParameterList*) * NumExpansions)
641*0a6a1f1dSLionel Sambuc TemplateTemplateParmDecl(nullptr, SourceLocation(), 0, 0, nullptr,
642*0a6a1f1dSLionel Sambuc nullptr, NumExpansions, nullptr);
643f4a2713aSLionel Sambuc }
644f4a2713aSLionel Sambuc
645f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
646f4a2713aSLionel Sambuc // TemplateArgumentList Implementation
647f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
648f4a2713aSLionel Sambuc TemplateArgumentList *
CreateCopy(ASTContext & Context,const TemplateArgument * Args,unsigned NumArgs)649f4a2713aSLionel Sambuc TemplateArgumentList::CreateCopy(ASTContext &Context,
650f4a2713aSLionel Sambuc const TemplateArgument *Args,
651f4a2713aSLionel Sambuc unsigned NumArgs) {
652f4a2713aSLionel Sambuc std::size_t Size = sizeof(TemplateArgumentList)
653f4a2713aSLionel Sambuc + NumArgs * sizeof(TemplateArgument);
654f4a2713aSLionel Sambuc void *Mem = Context.Allocate(Size);
655f4a2713aSLionel Sambuc TemplateArgument *StoredArgs
656f4a2713aSLionel Sambuc = reinterpret_cast<TemplateArgument *>(
657f4a2713aSLionel Sambuc static_cast<TemplateArgumentList *>(Mem) + 1);
658f4a2713aSLionel Sambuc std::uninitialized_copy(Args, Args + NumArgs, StoredArgs);
659f4a2713aSLionel Sambuc return new (Mem) TemplateArgumentList(StoredArgs, NumArgs, true);
660f4a2713aSLionel Sambuc }
661f4a2713aSLionel Sambuc
662f4a2713aSLionel Sambuc FunctionTemplateSpecializationInfo *
Create(ASTContext & C,FunctionDecl * FD,FunctionTemplateDecl * Template,TemplateSpecializationKind TSK,const TemplateArgumentList * TemplateArgs,const TemplateArgumentListInfo * TemplateArgsAsWritten,SourceLocation POI)663f4a2713aSLionel Sambuc FunctionTemplateSpecializationInfo::Create(ASTContext &C, FunctionDecl *FD,
664f4a2713aSLionel Sambuc FunctionTemplateDecl *Template,
665f4a2713aSLionel Sambuc TemplateSpecializationKind TSK,
666f4a2713aSLionel Sambuc const TemplateArgumentList *TemplateArgs,
667f4a2713aSLionel Sambuc const TemplateArgumentListInfo *TemplateArgsAsWritten,
668f4a2713aSLionel Sambuc SourceLocation POI) {
669*0a6a1f1dSLionel Sambuc const ASTTemplateArgumentListInfo *ArgsAsWritten = nullptr;
670f4a2713aSLionel Sambuc if (TemplateArgsAsWritten)
671f4a2713aSLionel Sambuc ArgsAsWritten = ASTTemplateArgumentListInfo::Create(C,
672f4a2713aSLionel Sambuc *TemplateArgsAsWritten);
673f4a2713aSLionel Sambuc
674f4a2713aSLionel Sambuc return new (C) FunctionTemplateSpecializationInfo(FD, Template, TSK,
675f4a2713aSLionel Sambuc TemplateArgs,
676f4a2713aSLionel Sambuc ArgsAsWritten,
677f4a2713aSLionel Sambuc POI);
678f4a2713aSLionel Sambuc }
679f4a2713aSLionel Sambuc
680f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
681f4a2713aSLionel Sambuc // TemplateDecl Implementation
682f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
683f4a2713aSLionel Sambuc
anchor()684f4a2713aSLionel Sambuc void TemplateDecl::anchor() { }
685f4a2713aSLionel Sambuc
686f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
687f4a2713aSLionel Sambuc // ClassTemplateSpecializationDecl Implementation
688f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
689f4a2713aSLionel Sambuc ClassTemplateSpecializationDecl::
ClassTemplateSpecializationDecl(ASTContext & Context,Kind DK,TagKind TK,DeclContext * DC,SourceLocation StartLoc,SourceLocation IdLoc,ClassTemplateDecl * SpecializedTemplate,const TemplateArgument * Args,unsigned NumArgs,ClassTemplateSpecializationDecl * PrevDecl)690f4a2713aSLionel Sambuc ClassTemplateSpecializationDecl(ASTContext &Context, Kind DK, TagKind TK,
691f4a2713aSLionel Sambuc DeclContext *DC, SourceLocation StartLoc,
692f4a2713aSLionel Sambuc SourceLocation IdLoc,
693f4a2713aSLionel Sambuc ClassTemplateDecl *SpecializedTemplate,
694f4a2713aSLionel Sambuc const TemplateArgument *Args,
695f4a2713aSLionel Sambuc unsigned NumArgs,
696f4a2713aSLionel Sambuc ClassTemplateSpecializationDecl *PrevDecl)
697*0a6a1f1dSLionel Sambuc : CXXRecordDecl(DK, TK, Context, DC, StartLoc, IdLoc,
698f4a2713aSLionel Sambuc SpecializedTemplate->getIdentifier(),
699f4a2713aSLionel Sambuc PrevDecl),
700f4a2713aSLionel Sambuc SpecializedTemplate(SpecializedTemplate),
701*0a6a1f1dSLionel Sambuc ExplicitInfo(nullptr),
702f4a2713aSLionel Sambuc TemplateArgs(TemplateArgumentList::CreateCopy(Context, Args, NumArgs)),
703f4a2713aSLionel Sambuc SpecializationKind(TSK_Undeclared) {
704f4a2713aSLionel Sambuc }
705f4a2713aSLionel Sambuc
ClassTemplateSpecializationDecl(ASTContext & C,Kind DK)706*0a6a1f1dSLionel Sambuc ClassTemplateSpecializationDecl::ClassTemplateSpecializationDecl(ASTContext &C,
707*0a6a1f1dSLionel Sambuc Kind DK)
708*0a6a1f1dSLionel Sambuc : CXXRecordDecl(DK, TTK_Struct, C, nullptr, SourceLocation(),
709*0a6a1f1dSLionel Sambuc SourceLocation(), nullptr, nullptr),
710*0a6a1f1dSLionel Sambuc ExplicitInfo(nullptr), SpecializationKind(TSK_Undeclared) {}
711f4a2713aSLionel Sambuc
712f4a2713aSLionel Sambuc ClassTemplateSpecializationDecl *
Create(ASTContext & Context,TagKind TK,DeclContext * DC,SourceLocation StartLoc,SourceLocation IdLoc,ClassTemplateDecl * SpecializedTemplate,const TemplateArgument * Args,unsigned NumArgs,ClassTemplateSpecializationDecl * PrevDecl)713f4a2713aSLionel Sambuc ClassTemplateSpecializationDecl::Create(ASTContext &Context, TagKind TK,
714f4a2713aSLionel Sambuc DeclContext *DC,
715f4a2713aSLionel Sambuc SourceLocation StartLoc,
716f4a2713aSLionel Sambuc SourceLocation IdLoc,
717f4a2713aSLionel Sambuc ClassTemplateDecl *SpecializedTemplate,
718f4a2713aSLionel Sambuc const TemplateArgument *Args,
719f4a2713aSLionel Sambuc unsigned NumArgs,
720f4a2713aSLionel Sambuc ClassTemplateSpecializationDecl *PrevDecl) {
721*0a6a1f1dSLionel Sambuc ClassTemplateSpecializationDecl *Result =
722*0a6a1f1dSLionel Sambuc new (Context, DC) ClassTemplateSpecializationDecl(
723*0a6a1f1dSLionel Sambuc Context, ClassTemplateSpecialization, TK, DC, StartLoc, IdLoc,
724*0a6a1f1dSLionel Sambuc SpecializedTemplate, Args, NumArgs, PrevDecl);
725f4a2713aSLionel Sambuc Result->MayHaveOutOfDateDef = false;
726f4a2713aSLionel Sambuc
727f4a2713aSLionel Sambuc Context.getTypeDeclType(Result, PrevDecl);
728f4a2713aSLionel Sambuc return Result;
729f4a2713aSLionel Sambuc }
730f4a2713aSLionel Sambuc
731f4a2713aSLionel Sambuc ClassTemplateSpecializationDecl *
CreateDeserialized(ASTContext & C,unsigned ID)732f4a2713aSLionel Sambuc ClassTemplateSpecializationDecl::CreateDeserialized(ASTContext &C,
733f4a2713aSLionel Sambuc unsigned ID) {
734f4a2713aSLionel Sambuc ClassTemplateSpecializationDecl *Result =
735*0a6a1f1dSLionel Sambuc new (C, ID) ClassTemplateSpecializationDecl(C, ClassTemplateSpecialization);
736f4a2713aSLionel Sambuc Result->MayHaveOutOfDateDef = false;
737f4a2713aSLionel Sambuc return Result;
738f4a2713aSLionel Sambuc }
739f4a2713aSLionel Sambuc
getNameForDiagnostic(raw_ostream & OS,const PrintingPolicy & Policy,bool Qualified) const740f4a2713aSLionel Sambuc void ClassTemplateSpecializationDecl::getNameForDiagnostic(
741f4a2713aSLionel Sambuc raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const {
742f4a2713aSLionel Sambuc NamedDecl::getNameForDiagnostic(OS, Policy, Qualified);
743f4a2713aSLionel Sambuc
744f4a2713aSLionel Sambuc const TemplateArgumentList &TemplateArgs = getTemplateArgs();
745f4a2713aSLionel Sambuc TemplateSpecializationType::PrintTemplateArgumentList(
746f4a2713aSLionel Sambuc OS, TemplateArgs.data(), TemplateArgs.size(), Policy);
747f4a2713aSLionel Sambuc }
748f4a2713aSLionel Sambuc
749f4a2713aSLionel Sambuc ClassTemplateDecl *
getSpecializedTemplate() const750f4a2713aSLionel Sambuc ClassTemplateSpecializationDecl::getSpecializedTemplate() const {
751f4a2713aSLionel Sambuc if (SpecializedPartialSpecialization *PartialSpec
752f4a2713aSLionel Sambuc = SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization*>())
753f4a2713aSLionel Sambuc return PartialSpec->PartialSpecialization->getSpecializedTemplate();
754f4a2713aSLionel Sambuc return SpecializedTemplate.get<ClassTemplateDecl*>();
755f4a2713aSLionel Sambuc }
756f4a2713aSLionel Sambuc
757f4a2713aSLionel Sambuc SourceRange
getSourceRange() const758f4a2713aSLionel Sambuc ClassTemplateSpecializationDecl::getSourceRange() const {
759f4a2713aSLionel Sambuc if (ExplicitInfo) {
760f4a2713aSLionel Sambuc SourceLocation Begin = getTemplateKeywordLoc();
761f4a2713aSLionel Sambuc if (Begin.isValid()) {
762f4a2713aSLionel Sambuc // Here we have an explicit (partial) specialization or instantiation.
763f4a2713aSLionel Sambuc assert(getSpecializationKind() == TSK_ExplicitSpecialization ||
764f4a2713aSLionel Sambuc getSpecializationKind() == TSK_ExplicitInstantiationDeclaration ||
765f4a2713aSLionel Sambuc getSpecializationKind() == TSK_ExplicitInstantiationDefinition);
766f4a2713aSLionel Sambuc if (getExternLoc().isValid())
767f4a2713aSLionel Sambuc Begin = getExternLoc();
768f4a2713aSLionel Sambuc SourceLocation End = getRBraceLoc();
769f4a2713aSLionel Sambuc if (End.isInvalid())
770f4a2713aSLionel Sambuc End = getTypeAsWritten()->getTypeLoc().getEndLoc();
771f4a2713aSLionel Sambuc return SourceRange(Begin, End);
772f4a2713aSLionel Sambuc }
773f4a2713aSLionel Sambuc // An implicit instantiation of a class template partial specialization
774f4a2713aSLionel Sambuc // uses ExplicitInfo to record the TypeAsWritten, but the source
775f4a2713aSLionel Sambuc // locations should be retrieved from the instantiation pattern.
776f4a2713aSLionel Sambuc typedef ClassTemplatePartialSpecializationDecl CTPSDecl;
777f4a2713aSLionel Sambuc CTPSDecl *ctpsd = const_cast<CTPSDecl*>(cast<CTPSDecl>(this));
778f4a2713aSLionel Sambuc CTPSDecl *inst_from = ctpsd->getInstantiatedFromMember();
779*0a6a1f1dSLionel Sambuc assert(inst_from != nullptr);
780f4a2713aSLionel Sambuc return inst_from->getSourceRange();
781f4a2713aSLionel Sambuc }
782f4a2713aSLionel Sambuc else {
783f4a2713aSLionel Sambuc // No explicit info available.
784f4a2713aSLionel Sambuc llvm::PointerUnion<ClassTemplateDecl *,
785f4a2713aSLionel Sambuc ClassTemplatePartialSpecializationDecl *>
786f4a2713aSLionel Sambuc inst_from = getInstantiatedFrom();
787f4a2713aSLionel Sambuc if (inst_from.isNull())
788f4a2713aSLionel Sambuc return getSpecializedTemplate()->getSourceRange();
789f4a2713aSLionel Sambuc if (ClassTemplateDecl *ctd = inst_from.dyn_cast<ClassTemplateDecl*>())
790f4a2713aSLionel Sambuc return ctd->getSourceRange();
791f4a2713aSLionel Sambuc return inst_from.get<ClassTemplatePartialSpecializationDecl*>()
792f4a2713aSLionel Sambuc ->getSourceRange();
793f4a2713aSLionel Sambuc }
794f4a2713aSLionel Sambuc }
795f4a2713aSLionel Sambuc
796f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
797f4a2713aSLionel Sambuc // ClassTemplatePartialSpecializationDecl Implementation
798f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
anchor()799f4a2713aSLionel Sambuc void ClassTemplatePartialSpecializationDecl::anchor() { }
800f4a2713aSLionel Sambuc
801f4a2713aSLionel Sambuc ClassTemplatePartialSpecializationDecl::
ClassTemplatePartialSpecializationDecl(ASTContext & Context,TagKind TK,DeclContext * DC,SourceLocation StartLoc,SourceLocation IdLoc,TemplateParameterList * Params,ClassTemplateDecl * SpecializedTemplate,const TemplateArgument * Args,unsigned NumArgs,const ASTTemplateArgumentListInfo * ArgInfos,ClassTemplatePartialSpecializationDecl * PrevDecl)802f4a2713aSLionel Sambuc ClassTemplatePartialSpecializationDecl(ASTContext &Context, TagKind TK,
803f4a2713aSLionel Sambuc DeclContext *DC,
804f4a2713aSLionel Sambuc SourceLocation StartLoc,
805f4a2713aSLionel Sambuc SourceLocation IdLoc,
806f4a2713aSLionel Sambuc TemplateParameterList *Params,
807f4a2713aSLionel Sambuc ClassTemplateDecl *SpecializedTemplate,
808f4a2713aSLionel Sambuc const TemplateArgument *Args,
809f4a2713aSLionel Sambuc unsigned NumArgs,
810f4a2713aSLionel Sambuc const ASTTemplateArgumentListInfo *ArgInfos,
811f4a2713aSLionel Sambuc ClassTemplatePartialSpecializationDecl *PrevDecl)
812f4a2713aSLionel Sambuc : ClassTemplateSpecializationDecl(Context,
813f4a2713aSLionel Sambuc ClassTemplatePartialSpecialization,
814f4a2713aSLionel Sambuc TK, DC, StartLoc, IdLoc,
815f4a2713aSLionel Sambuc SpecializedTemplate,
816f4a2713aSLionel Sambuc Args, NumArgs, PrevDecl),
817f4a2713aSLionel Sambuc TemplateParams(Params), ArgsAsWritten(ArgInfos),
818*0a6a1f1dSLionel Sambuc InstantiatedFromMember(nullptr, false)
819f4a2713aSLionel Sambuc {
820f4a2713aSLionel Sambuc AdoptTemplateParameterList(Params, this);
821f4a2713aSLionel Sambuc }
822f4a2713aSLionel Sambuc
823f4a2713aSLionel Sambuc ClassTemplatePartialSpecializationDecl *
824f4a2713aSLionel Sambuc ClassTemplatePartialSpecializationDecl::
Create(ASTContext & Context,TagKind TK,DeclContext * DC,SourceLocation StartLoc,SourceLocation IdLoc,TemplateParameterList * Params,ClassTemplateDecl * SpecializedTemplate,const TemplateArgument * Args,unsigned NumArgs,const TemplateArgumentListInfo & ArgInfos,QualType CanonInjectedType,ClassTemplatePartialSpecializationDecl * PrevDecl)825f4a2713aSLionel Sambuc Create(ASTContext &Context, TagKind TK,DeclContext *DC,
826f4a2713aSLionel Sambuc SourceLocation StartLoc, SourceLocation IdLoc,
827f4a2713aSLionel Sambuc TemplateParameterList *Params,
828f4a2713aSLionel Sambuc ClassTemplateDecl *SpecializedTemplate,
829f4a2713aSLionel Sambuc const TemplateArgument *Args,
830f4a2713aSLionel Sambuc unsigned NumArgs,
831f4a2713aSLionel Sambuc const TemplateArgumentListInfo &ArgInfos,
832f4a2713aSLionel Sambuc QualType CanonInjectedType,
833f4a2713aSLionel Sambuc ClassTemplatePartialSpecializationDecl *PrevDecl) {
834f4a2713aSLionel Sambuc const ASTTemplateArgumentListInfo *ASTArgInfos =
835f4a2713aSLionel Sambuc ASTTemplateArgumentListInfo::Create(Context, ArgInfos);
836f4a2713aSLionel Sambuc
837*0a6a1f1dSLionel Sambuc ClassTemplatePartialSpecializationDecl *Result = new (Context, DC)
838*0a6a1f1dSLionel Sambuc ClassTemplatePartialSpecializationDecl(Context, TK, DC, StartLoc, IdLoc,
839*0a6a1f1dSLionel Sambuc Params, SpecializedTemplate, Args,
840*0a6a1f1dSLionel Sambuc NumArgs, ASTArgInfos, PrevDecl);
841f4a2713aSLionel Sambuc Result->setSpecializationKind(TSK_ExplicitSpecialization);
842f4a2713aSLionel Sambuc Result->MayHaveOutOfDateDef = false;
843f4a2713aSLionel Sambuc
844f4a2713aSLionel Sambuc Context.getInjectedClassNameType(Result, CanonInjectedType);
845f4a2713aSLionel Sambuc return Result;
846f4a2713aSLionel Sambuc }
847f4a2713aSLionel Sambuc
848f4a2713aSLionel Sambuc ClassTemplatePartialSpecializationDecl *
CreateDeserialized(ASTContext & C,unsigned ID)849f4a2713aSLionel Sambuc ClassTemplatePartialSpecializationDecl::CreateDeserialized(ASTContext &C,
850f4a2713aSLionel Sambuc unsigned ID) {
851*0a6a1f1dSLionel Sambuc ClassTemplatePartialSpecializationDecl *Result =
852*0a6a1f1dSLionel Sambuc new (C, ID) ClassTemplatePartialSpecializationDecl(C);
853f4a2713aSLionel Sambuc Result->MayHaveOutOfDateDef = false;
854f4a2713aSLionel Sambuc return Result;
855f4a2713aSLionel Sambuc }
856f4a2713aSLionel Sambuc
857f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
858f4a2713aSLionel Sambuc // FriendTemplateDecl Implementation
859f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
860f4a2713aSLionel Sambuc
anchor()861f4a2713aSLionel Sambuc void FriendTemplateDecl::anchor() { }
862f4a2713aSLionel Sambuc
Create(ASTContext & Context,DeclContext * DC,SourceLocation L,unsigned NParams,TemplateParameterList ** Params,FriendUnion Friend,SourceLocation FLoc)863f4a2713aSLionel Sambuc FriendTemplateDecl *FriendTemplateDecl::Create(ASTContext &Context,
864f4a2713aSLionel Sambuc DeclContext *DC,
865f4a2713aSLionel Sambuc SourceLocation L,
866f4a2713aSLionel Sambuc unsigned NParams,
867f4a2713aSLionel Sambuc TemplateParameterList **Params,
868f4a2713aSLionel Sambuc FriendUnion Friend,
869f4a2713aSLionel Sambuc SourceLocation FLoc) {
870*0a6a1f1dSLionel Sambuc return new (Context, DC) FriendTemplateDecl(DC, L, NParams, Params,
871*0a6a1f1dSLionel Sambuc Friend, FLoc);
872f4a2713aSLionel Sambuc }
873f4a2713aSLionel Sambuc
CreateDeserialized(ASTContext & C,unsigned ID)874f4a2713aSLionel Sambuc FriendTemplateDecl *FriendTemplateDecl::CreateDeserialized(ASTContext &C,
875f4a2713aSLionel Sambuc unsigned ID) {
876*0a6a1f1dSLionel Sambuc return new (C, ID) FriendTemplateDecl(EmptyShell());
877f4a2713aSLionel Sambuc }
878f4a2713aSLionel Sambuc
879f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
880f4a2713aSLionel Sambuc // TypeAliasTemplateDecl Implementation
881f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
882f4a2713aSLionel Sambuc
Create(ASTContext & C,DeclContext * DC,SourceLocation L,DeclarationName Name,TemplateParameterList * Params,NamedDecl * Decl)883f4a2713aSLionel Sambuc TypeAliasTemplateDecl *TypeAliasTemplateDecl::Create(ASTContext &C,
884f4a2713aSLionel Sambuc DeclContext *DC,
885f4a2713aSLionel Sambuc SourceLocation L,
886f4a2713aSLionel Sambuc DeclarationName Name,
887f4a2713aSLionel Sambuc TemplateParameterList *Params,
888f4a2713aSLionel Sambuc NamedDecl *Decl) {
889f4a2713aSLionel Sambuc AdoptTemplateParameterList(Params, DC);
890*0a6a1f1dSLionel Sambuc return new (C, DC) TypeAliasTemplateDecl(C, DC, L, Name, Params, Decl);
891f4a2713aSLionel Sambuc }
892f4a2713aSLionel Sambuc
CreateDeserialized(ASTContext & C,unsigned ID)893f4a2713aSLionel Sambuc TypeAliasTemplateDecl *TypeAliasTemplateDecl::CreateDeserialized(ASTContext &C,
894f4a2713aSLionel Sambuc unsigned ID) {
895*0a6a1f1dSLionel Sambuc return new (C, ID) TypeAliasTemplateDecl(C, nullptr, SourceLocation(),
896*0a6a1f1dSLionel Sambuc DeclarationName(), nullptr, nullptr);
897f4a2713aSLionel Sambuc }
898f4a2713aSLionel Sambuc
DeallocateCommon(void * Ptr)899f4a2713aSLionel Sambuc void TypeAliasTemplateDecl::DeallocateCommon(void *Ptr) {
900f4a2713aSLionel Sambuc static_cast<Common *>(Ptr)->~Common();
901f4a2713aSLionel Sambuc }
902f4a2713aSLionel Sambuc RedeclarableTemplateDecl::CommonBase *
newCommon(ASTContext & C) const903f4a2713aSLionel Sambuc TypeAliasTemplateDecl::newCommon(ASTContext &C) const {
904f4a2713aSLionel Sambuc Common *CommonPtr = new (C) Common;
905f4a2713aSLionel Sambuc C.AddDeallocation(DeallocateCommon, CommonPtr);
906f4a2713aSLionel Sambuc return CommonPtr;
907f4a2713aSLionel Sambuc }
908f4a2713aSLionel Sambuc
909f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
910f4a2713aSLionel Sambuc // ClassScopeFunctionSpecializationDecl Implementation
911f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
912f4a2713aSLionel Sambuc
anchor()913f4a2713aSLionel Sambuc void ClassScopeFunctionSpecializationDecl::anchor() { }
914f4a2713aSLionel Sambuc
915f4a2713aSLionel Sambuc ClassScopeFunctionSpecializationDecl *
CreateDeserialized(ASTContext & C,unsigned ID)916f4a2713aSLionel Sambuc ClassScopeFunctionSpecializationDecl::CreateDeserialized(ASTContext &C,
917f4a2713aSLionel Sambuc unsigned ID) {
918*0a6a1f1dSLionel Sambuc return new (C, ID) ClassScopeFunctionSpecializationDecl(
919*0a6a1f1dSLionel Sambuc nullptr, SourceLocation(), nullptr, false, TemplateArgumentListInfo());
920f4a2713aSLionel Sambuc }
921f4a2713aSLionel Sambuc
922f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
923f4a2713aSLionel Sambuc // VarTemplateDecl Implementation
924f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
925f4a2713aSLionel Sambuc
DeallocateCommon(void * Ptr)926f4a2713aSLionel Sambuc void VarTemplateDecl::DeallocateCommon(void *Ptr) {
927f4a2713aSLionel Sambuc static_cast<Common *>(Ptr)->~Common();
928f4a2713aSLionel Sambuc }
929f4a2713aSLionel Sambuc
getDefinition()930f4a2713aSLionel Sambuc VarTemplateDecl *VarTemplateDecl::getDefinition() {
931f4a2713aSLionel Sambuc VarTemplateDecl *CurD = this;
932f4a2713aSLionel Sambuc while (CurD) {
933f4a2713aSLionel Sambuc if (CurD->isThisDeclarationADefinition())
934f4a2713aSLionel Sambuc return CurD;
935f4a2713aSLionel Sambuc CurD = CurD->getPreviousDecl();
936f4a2713aSLionel Sambuc }
937*0a6a1f1dSLionel Sambuc return nullptr;
938f4a2713aSLionel Sambuc }
939f4a2713aSLionel Sambuc
Create(ASTContext & C,DeclContext * DC,SourceLocation L,DeclarationName Name,TemplateParameterList * Params,VarDecl * Decl)940f4a2713aSLionel Sambuc VarTemplateDecl *VarTemplateDecl::Create(ASTContext &C, DeclContext *DC,
941f4a2713aSLionel Sambuc SourceLocation L, DeclarationName Name,
942f4a2713aSLionel Sambuc TemplateParameterList *Params,
943*0a6a1f1dSLionel Sambuc VarDecl *Decl) {
944*0a6a1f1dSLionel Sambuc return new (C, DC) VarTemplateDecl(C, DC, L, Name, Params, Decl);
945f4a2713aSLionel Sambuc }
946f4a2713aSLionel Sambuc
CreateDeserialized(ASTContext & C,unsigned ID)947f4a2713aSLionel Sambuc VarTemplateDecl *VarTemplateDecl::CreateDeserialized(ASTContext &C,
948f4a2713aSLionel Sambuc unsigned ID) {
949*0a6a1f1dSLionel Sambuc return new (C, ID) VarTemplateDecl(C, nullptr, SourceLocation(),
950*0a6a1f1dSLionel Sambuc DeclarationName(), nullptr, nullptr);
951f4a2713aSLionel Sambuc }
952f4a2713aSLionel Sambuc
953*0a6a1f1dSLionel Sambuc // TODO: Unify across class, function and variable templates?
954f4a2713aSLionel Sambuc // May require moving this and Common to RedeclarableTemplateDecl.
LoadLazySpecializations() const955f4a2713aSLionel Sambuc void VarTemplateDecl::LoadLazySpecializations() const {
956f4a2713aSLionel Sambuc Common *CommonPtr = getCommonPtr();
957f4a2713aSLionel Sambuc if (CommonPtr->LazySpecializations) {
958f4a2713aSLionel Sambuc ASTContext &Context = getASTContext();
959f4a2713aSLionel Sambuc uint32_t *Specs = CommonPtr->LazySpecializations;
960*0a6a1f1dSLionel Sambuc CommonPtr->LazySpecializations = nullptr;
961f4a2713aSLionel Sambuc for (uint32_t I = 0, N = *Specs++; I != N; ++I)
962f4a2713aSLionel Sambuc (void)Context.getExternalSource()->GetExternalDecl(Specs[I]);
963f4a2713aSLionel Sambuc }
964f4a2713aSLionel Sambuc }
965f4a2713aSLionel Sambuc
966f4a2713aSLionel Sambuc llvm::FoldingSetVector<VarTemplateSpecializationDecl> &
getSpecializations() const967f4a2713aSLionel Sambuc VarTemplateDecl::getSpecializations() const {
968f4a2713aSLionel Sambuc LoadLazySpecializations();
969f4a2713aSLionel Sambuc return getCommonPtr()->Specializations;
970f4a2713aSLionel Sambuc }
971f4a2713aSLionel Sambuc
972f4a2713aSLionel Sambuc llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl> &
getPartialSpecializations()973f4a2713aSLionel Sambuc VarTemplateDecl::getPartialSpecializations() {
974f4a2713aSLionel Sambuc LoadLazySpecializations();
975f4a2713aSLionel Sambuc return getCommonPtr()->PartialSpecializations;
976f4a2713aSLionel Sambuc }
977f4a2713aSLionel Sambuc
978f4a2713aSLionel Sambuc RedeclarableTemplateDecl::CommonBase *
newCommon(ASTContext & C) const979f4a2713aSLionel Sambuc VarTemplateDecl::newCommon(ASTContext &C) const {
980f4a2713aSLionel Sambuc Common *CommonPtr = new (C) Common;
981f4a2713aSLionel Sambuc C.AddDeallocation(DeallocateCommon, CommonPtr);
982f4a2713aSLionel Sambuc return CommonPtr;
983f4a2713aSLionel Sambuc }
984f4a2713aSLionel Sambuc
985f4a2713aSLionel Sambuc VarTemplateSpecializationDecl *
findSpecialization(ArrayRef<TemplateArgument> Args,void * & InsertPos)986*0a6a1f1dSLionel Sambuc VarTemplateDecl::findSpecialization(ArrayRef<TemplateArgument> Args,
987*0a6a1f1dSLionel Sambuc void *&InsertPos) {
988*0a6a1f1dSLionel Sambuc return findSpecializationImpl(getSpecializations(), Args, InsertPos);
989f4a2713aSLionel Sambuc }
990f4a2713aSLionel Sambuc
AddSpecialization(VarTemplateSpecializationDecl * D,void * InsertPos)991f4a2713aSLionel Sambuc void VarTemplateDecl::AddSpecialization(VarTemplateSpecializationDecl *D,
992f4a2713aSLionel Sambuc void *InsertPos) {
993f4a2713aSLionel Sambuc if (InsertPos)
994f4a2713aSLionel Sambuc getSpecializations().InsertNode(D, InsertPos);
995f4a2713aSLionel Sambuc else {
996f4a2713aSLionel Sambuc VarTemplateSpecializationDecl *Existing =
997f4a2713aSLionel Sambuc getSpecializations().GetOrInsertNode(D);
998f4a2713aSLionel Sambuc (void)Existing;
999f4a2713aSLionel Sambuc assert(Existing->isCanonicalDecl() && "Non-canonical specialization?");
1000f4a2713aSLionel Sambuc }
1001f4a2713aSLionel Sambuc if (ASTMutationListener *L = getASTMutationListener())
1002f4a2713aSLionel Sambuc L->AddedCXXTemplateSpecialization(this, D);
1003f4a2713aSLionel Sambuc }
1004f4a2713aSLionel Sambuc
1005f4a2713aSLionel Sambuc VarTemplatePartialSpecializationDecl *
findPartialSpecialization(ArrayRef<TemplateArgument> Args,void * & InsertPos)1006*0a6a1f1dSLionel Sambuc VarTemplateDecl::findPartialSpecialization(ArrayRef<TemplateArgument> Args,
1007*0a6a1f1dSLionel Sambuc void *&InsertPos) {
1008*0a6a1f1dSLionel Sambuc return findSpecializationImpl(getPartialSpecializations(), Args, InsertPos);
1009f4a2713aSLionel Sambuc }
1010f4a2713aSLionel Sambuc
AddPartialSpecialization(VarTemplatePartialSpecializationDecl * D,void * InsertPos)1011f4a2713aSLionel Sambuc void VarTemplateDecl::AddPartialSpecialization(
1012f4a2713aSLionel Sambuc VarTemplatePartialSpecializationDecl *D, void *InsertPos) {
1013f4a2713aSLionel Sambuc if (InsertPos)
1014f4a2713aSLionel Sambuc getPartialSpecializations().InsertNode(D, InsertPos);
1015f4a2713aSLionel Sambuc else {
1016f4a2713aSLionel Sambuc VarTemplatePartialSpecializationDecl *Existing =
1017f4a2713aSLionel Sambuc getPartialSpecializations().GetOrInsertNode(D);
1018f4a2713aSLionel Sambuc (void)Existing;
1019f4a2713aSLionel Sambuc assert(Existing->isCanonicalDecl() && "Non-canonical specialization?");
1020f4a2713aSLionel Sambuc }
1021f4a2713aSLionel Sambuc
1022f4a2713aSLionel Sambuc if (ASTMutationListener *L = getASTMutationListener())
1023f4a2713aSLionel Sambuc L->AddedCXXTemplateSpecialization(this, D);
1024f4a2713aSLionel Sambuc }
1025f4a2713aSLionel Sambuc
getPartialSpecializations(SmallVectorImpl<VarTemplatePartialSpecializationDecl * > & PS)1026f4a2713aSLionel Sambuc void VarTemplateDecl::getPartialSpecializations(
1027f4a2713aSLionel Sambuc SmallVectorImpl<VarTemplatePartialSpecializationDecl *> &PS) {
1028f4a2713aSLionel Sambuc llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl> &PartialSpecs =
1029f4a2713aSLionel Sambuc getPartialSpecializations();
1030f4a2713aSLionel Sambuc PS.clear();
1031f4a2713aSLionel Sambuc PS.reserve(PartialSpecs.size());
1032f4a2713aSLionel Sambuc for (llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl>::iterator
1033f4a2713aSLionel Sambuc P = PartialSpecs.begin(),
1034f4a2713aSLionel Sambuc PEnd = PartialSpecs.end();
1035f4a2713aSLionel Sambuc P != PEnd; ++P)
1036f4a2713aSLionel Sambuc PS.push_back(P->getMostRecentDecl());
1037f4a2713aSLionel Sambuc }
1038f4a2713aSLionel Sambuc
1039f4a2713aSLionel Sambuc VarTemplatePartialSpecializationDecl *
findPartialSpecInstantiatedFromMember(VarTemplatePartialSpecializationDecl * D)1040f4a2713aSLionel Sambuc VarTemplateDecl::findPartialSpecInstantiatedFromMember(
1041f4a2713aSLionel Sambuc VarTemplatePartialSpecializationDecl *D) {
1042f4a2713aSLionel Sambuc Decl *DCanon = D->getCanonicalDecl();
1043f4a2713aSLionel Sambuc for (llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl>::iterator
1044f4a2713aSLionel Sambuc P = getPartialSpecializations().begin(),
1045f4a2713aSLionel Sambuc PEnd = getPartialSpecializations().end();
1046f4a2713aSLionel Sambuc P != PEnd; ++P) {
1047f4a2713aSLionel Sambuc if (P->getInstantiatedFromMember()->getCanonicalDecl() == DCanon)
1048f4a2713aSLionel Sambuc return P->getMostRecentDecl();
1049f4a2713aSLionel Sambuc }
1050f4a2713aSLionel Sambuc
1051*0a6a1f1dSLionel Sambuc return nullptr;
1052f4a2713aSLionel Sambuc }
1053f4a2713aSLionel Sambuc
1054f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
1055f4a2713aSLionel Sambuc // VarTemplateSpecializationDecl Implementation
1056f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
VarTemplateSpecializationDecl(Kind DK,ASTContext & Context,DeclContext * DC,SourceLocation StartLoc,SourceLocation IdLoc,VarTemplateDecl * SpecializedTemplate,QualType T,TypeSourceInfo * TInfo,StorageClass S,const TemplateArgument * Args,unsigned NumArgs)1057f4a2713aSLionel Sambuc VarTemplateSpecializationDecl::VarTemplateSpecializationDecl(
1058*0a6a1f1dSLionel Sambuc Kind DK, ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
1059f4a2713aSLionel Sambuc SourceLocation IdLoc, VarTemplateDecl *SpecializedTemplate, QualType T,
1060f4a2713aSLionel Sambuc TypeSourceInfo *TInfo, StorageClass S, const TemplateArgument *Args,
1061f4a2713aSLionel Sambuc unsigned NumArgs)
1062*0a6a1f1dSLionel Sambuc : VarDecl(DK, Context, DC, StartLoc, IdLoc,
1063*0a6a1f1dSLionel Sambuc SpecializedTemplate->getIdentifier(), T, TInfo, S),
1064*0a6a1f1dSLionel Sambuc SpecializedTemplate(SpecializedTemplate), ExplicitInfo(nullptr),
1065f4a2713aSLionel Sambuc TemplateArgs(TemplateArgumentList::CreateCopy(Context, Args, NumArgs)),
1066f4a2713aSLionel Sambuc SpecializationKind(TSK_Undeclared) {}
1067f4a2713aSLionel Sambuc
VarTemplateSpecializationDecl(Kind DK,ASTContext & C)1068*0a6a1f1dSLionel Sambuc VarTemplateSpecializationDecl::VarTemplateSpecializationDecl(Kind DK,
1069*0a6a1f1dSLionel Sambuc ASTContext &C)
1070*0a6a1f1dSLionel Sambuc : VarDecl(DK, C, nullptr, SourceLocation(), SourceLocation(), nullptr,
1071*0a6a1f1dSLionel Sambuc QualType(), nullptr, SC_None),
1072*0a6a1f1dSLionel Sambuc ExplicitInfo(nullptr), SpecializationKind(TSK_Undeclared) {}
1073f4a2713aSLionel Sambuc
Create(ASTContext & Context,DeclContext * DC,SourceLocation StartLoc,SourceLocation IdLoc,VarTemplateDecl * SpecializedTemplate,QualType T,TypeSourceInfo * TInfo,StorageClass S,const TemplateArgument * Args,unsigned NumArgs)1074f4a2713aSLionel Sambuc VarTemplateSpecializationDecl *VarTemplateSpecializationDecl::Create(
1075f4a2713aSLionel Sambuc ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
1076f4a2713aSLionel Sambuc SourceLocation IdLoc, VarTemplateDecl *SpecializedTemplate, QualType T,
1077f4a2713aSLionel Sambuc TypeSourceInfo *TInfo, StorageClass S, const TemplateArgument *Args,
1078f4a2713aSLionel Sambuc unsigned NumArgs) {
1079*0a6a1f1dSLionel Sambuc return new (Context, DC) VarTemplateSpecializationDecl(
1080*0a6a1f1dSLionel Sambuc VarTemplateSpecialization, Context, DC, StartLoc, IdLoc,
1081*0a6a1f1dSLionel Sambuc SpecializedTemplate, T, TInfo, S, Args, NumArgs);
1082f4a2713aSLionel Sambuc }
1083f4a2713aSLionel Sambuc
1084f4a2713aSLionel Sambuc VarTemplateSpecializationDecl *
CreateDeserialized(ASTContext & C,unsigned ID)1085f4a2713aSLionel Sambuc VarTemplateSpecializationDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
1086*0a6a1f1dSLionel Sambuc return new (C, ID)
1087*0a6a1f1dSLionel Sambuc VarTemplateSpecializationDecl(VarTemplateSpecialization, C);
1088f4a2713aSLionel Sambuc }
1089f4a2713aSLionel Sambuc
getNameForDiagnostic(raw_ostream & OS,const PrintingPolicy & Policy,bool Qualified) const1090f4a2713aSLionel Sambuc void VarTemplateSpecializationDecl::getNameForDiagnostic(
1091f4a2713aSLionel Sambuc raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const {
1092f4a2713aSLionel Sambuc NamedDecl::getNameForDiagnostic(OS, Policy, Qualified);
1093f4a2713aSLionel Sambuc
1094f4a2713aSLionel Sambuc const TemplateArgumentList &TemplateArgs = getTemplateArgs();
1095f4a2713aSLionel Sambuc TemplateSpecializationType::PrintTemplateArgumentList(
1096f4a2713aSLionel Sambuc OS, TemplateArgs.data(), TemplateArgs.size(), Policy);
1097f4a2713aSLionel Sambuc }
1098f4a2713aSLionel Sambuc
getSpecializedTemplate() const1099f4a2713aSLionel Sambuc VarTemplateDecl *VarTemplateSpecializationDecl::getSpecializedTemplate() const {
1100f4a2713aSLionel Sambuc if (SpecializedPartialSpecialization *PartialSpec =
1101f4a2713aSLionel Sambuc SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>())
1102f4a2713aSLionel Sambuc return PartialSpec->PartialSpecialization->getSpecializedTemplate();
1103f4a2713aSLionel Sambuc return SpecializedTemplate.get<VarTemplateDecl *>();
1104f4a2713aSLionel Sambuc }
1105f4a2713aSLionel Sambuc
setTemplateArgsInfo(const TemplateArgumentListInfo & ArgsInfo)1106f4a2713aSLionel Sambuc void VarTemplateSpecializationDecl::setTemplateArgsInfo(
1107f4a2713aSLionel Sambuc const TemplateArgumentListInfo &ArgsInfo) {
1108f4a2713aSLionel Sambuc unsigned N = ArgsInfo.size();
1109f4a2713aSLionel Sambuc TemplateArgsInfo.setLAngleLoc(ArgsInfo.getLAngleLoc());
1110f4a2713aSLionel Sambuc TemplateArgsInfo.setRAngleLoc(ArgsInfo.getRAngleLoc());
1111f4a2713aSLionel Sambuc for (unsigned I = 0; I != N; ++I)
1112f4a2713aSLionel Sambuc TemplateArgsInfo.addArgument(ArgsInfo[I]);
1113f4a2713aSLionel Sambuc }
1114f4a2713aSLionel Sambuc
1115f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
1116f4a2713aSLionel Sambuc // VarTemplatePartialSpecializationDecl Implementation
1117f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
anchor()1118f4a2713aSLionel Sambuc void VarTemplatePartialSpecializationDecl::anchor() {}
1119f4a2713aSLionel Sambuc
VarTemplatePartialSpecializationDecl(ASTContext & Context,DeclContext * DC,SourceLocation StartLoc,SourceLocation IdLoc,TemplateParameterList * Params,VarTemplateDecl * SpecializedTemplate,QualType T,TypeSourceInfo * TInfo,StorageClass S,const TemplateArgument * Args,unsigned NumArgs,const ASTTemplateArgumentListInfo * ArgInfos)1120f4a2713aSLionel Sambuc VarTemplatePartialSpecializationDecl::VarTemplatePartialSpecializationDecl(
1121f4a2713aSLionel Sambuc ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
1122f4a2713aSLionel Sambuc SourceLocation IdLoc, TemplateParameterList *Params,
1123f4a2713aSLionel Sambuc VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo,
1124f4a2713aSLionel Sambuc StorageClass S, const TemplateArgument *Args, unsigned NumArgs,
1125f4a2713aSLionel Sambuc const ASTTemplateArgumentListInfo *ArgInfos)
1126*0a6a1f1dSLionel Sambuc : VarTemplateSpecializationDecl(VarTemplatePartialSpecialization, Context,
1127f4a2713aSLionel Sambuc DC, StartLoc, IdLoc, SpecializedTemplate, T,
1128f4a2713aSLionel Sambuc TInfo, S, Args, NumArgs),
1129f4a2713aSLionel Sambuc TemplateParams(Params), ArgsAsWritten(ArgInfos),
1130*0a6a1f1dSLionel Sambuc InstantiatedFromMember(nullptr, false) {
1131f4a2713aSLionel Sambuc // TODO: The template parameters should be in DC by now. Verify.
1132f4a2713aSLionel Sambuc // AdoptTemplateParameterList(Params, DC);
1133f4a2713aSLionel Sambuc }
1134f4a2713aSLionel Sambuc
1135f4a2713aSLionel Sambuc VarTemplatePartialSpecializationDecl *
Create(ASTContext & Context,DeclContext * DC,SourceLocation StartLoc,SourceLocation IdLoc,TemplateParameterList * Params,VarTemplateDecl * SpecializedTemplate,QualType T,TypeSourceInfo * TInfo,StorageClass S,const TemplateArgument * Args,unsigned NumArgs,const TemplateArgumentListInfo & ArgInfos)1136f4a2713aSLionel Sambuc VarTemplatePartialSpecializationDecl::Create(
1137f4a2713aSLionel Sambuc ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
1138f4a2713aSLionel Sambuc SourceLocation IdLoc, TemplateParameterList *Params,
1139f4a2713aSLionel Sambuc VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo,
1140f4a2713aSLionel Sambuc StorageClass S, const TemplateArgument *Args, unsigned NumArgs,
1141f4a2713aSLionel Sambuc const TemplateArgumentListInfo &ArgInfos) {
1142f4a2713aSLionel Sambuc const ASTTemplateArgumentListInfo *ASTArgInfos
1143f4a2713aSLionel Sambuc = ASTTemplateArgumentListInfo::Create(Context, ArgInfos);
1144f4a2713aSLionel Sambuc
1145f4a2713aSLionel Sambuc VarTemplatePartialSpecializationDecl *Result =
1146*0a6a1f1dSLionel Sambuc new (Context, DC) VarTemplatePartialSpecializationDecl(
1147f4a2713aSLionel Sambuc Context, DC, StartLoc, IdLoc, Params, SpecializedTemplate, T, TInfo,
1148f4a2713aSLionel Sambuc S, Args, NumArgs, ASTArgInfos);
1149f4a2713aSLionel Sambuc Result->setSpecializationKind(TSK_ExplicitSpecialization);
1150f4a2713aSLionel Sambuc return Result;
1151f4a2713aSLionel Sambuc }
1152f4a2713aSLionel Sambuc
1153f4a2713aSLionel Sambuc VarTemplatePartialSpecializationDecl *
CreateDeserialized(ASTContext & C,unsigned ID)1154f4a2713aSLionel Sambuc VarTemplatePartialSpecializationDecl::CreateDeserialized(ASTContext &C,
1155f4a2713aSLionel Sambuc unsigned ID) {
1156*0a6a1f1dSLionel Sambuc return new (C, ID) VarTemplatePartialSpecializationDecl(C);
1157f4a2713aSLionel Sambuc }
1158