Sebastian Redl | 06a59bb | 2009-10-23 22:13:42 +0000 | [diff] [blame] | 1 | //===--- DeclTemplate.cpp - Template Declaration AST Node Implementation --===// |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the C++ related Decl classes for templates. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "clang/AST/DeclCXX.h" |
| 15 | #include "clang/AST/DeclTemplate.h" |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 16 | #include "clang/AST/Expr.h" |
Douglas Gregor | b95cc97 | 2011-01-04 02:33:52 +0000 | [diff] [blame] | 17 | #include "clang/AST/ExprCXX.h" |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 18 | #include "clang/AST/ASTContext.h" |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 19 | #include "clang/AST/TypeLoc.h" |
Argyrios Kyrtzidis | bef1a7b | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 20 | #include "clang/AST/ASTMutationListener.h" |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 21 | #include "clang/Basic/IdentifierTable.h" |
| 22 | #include "llvm/ADT/STLExtras.h" |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 23 | #include <memory> |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 24 | using namespace clang; |
| 25 | |
| 26 | //===----------------------------------------------------------------------===// |
| 27 | // TemplateParameterList Implementation |
| 28 | //===----------------------------------------------------------------------===// |
| 29 | |
Douglas Gregor | ddc29e1 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 30 | TemplateParameterList::TemplateParameterList(SourceLocation TemplateLoc, |
| 31 | SourceLocation LAngleLoc, |
Douglas Gregor | bf4ea56 | 2009-09-15 16:23:51 +0000 | [diff] [blame] | 32 | NamedDecl **Params, unsigned NumParams, |
Douglas Gregor | ddc29e1 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 33 | SourceLocation RAngleLoc) |
| 34 | : TemplateLoc(TemplateLoc), LAngleLoc(LAngleLoc), RAngleLoc(RAngleLoc), |
| 35 | NumParams(NumParams) { |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 36 | for (unsigned Idx = 0; Idx < NumParams; ++Idx) |
| 37 | begin()[Idx] = Params[Idx]; |
| 38 | } |
| 39 | |
| 40 | TemplateParameterList * |
Jay Foad | 4ba2a17 | 2011-01-12 09:06:06 +0000 | [diff] [blame] | 41 | TemplateParameterList::Create(const ASTContext &C, SourceLocation TemplateLoc, |
Douglas Gregor | bf4ea56 | 2009-09-15 16:23:51 +0000 | [diff] [blame] | 42 | SourceLocation LAngleLoc, NamedDecl **Params, |
Douglas Gregor | ddc29e1 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 43 | unsigned NumParams, SourceLocation RAngleLoc) { |
Douglas Gregor | bf4ea56 | 2009-09-15 16:23:51 +0000 | [diff] [blame] | 44 | unsigned Size = sizeof(TemplateParameterList) |
| 45 | + sizeof(NamedDecl *) * NumParams; |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 46 | unsigned Align = llvm::AlignOf<TemplateParameterList>::Alignment; |
| 47 | void *Mem = C.Allocate(Size, Align); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 48 | return new (Mem) TemplateParameterList(TemplateLoc, LAngleLoc, Params, |
Douglas Gregor | ddc29e1 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 49 | NumParams, RAngleLoc); |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 50 | } |
| 51 | |
Douglas Gregor | 62cb18d | 2009-02-11 18:16:40 +0000 | [diff] [blame] | 52 | unsigned TemplateParameterList::getMinRequiredArguments() const { |
| 53 | unsigned NumRequiredArgs = size(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 54 | iterator Param = const_cast<TemplateParameterList *>(this)->end(), |
Douglas Gregor | 62cb18d | 2009-02-11 18:16:40 +0000 | [diff] [blame] | 55 | ParamBegin = const_cast<TemplateParameterList *>(this)->begin(); |
| 56 | while (Param != ParamBegin) { |
| 57 | --Param; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 58 | |
Anders Carlsson | 0ceffb5 | 2009-06-13 02:08:00 +0000 | [diff] [blame] | 59 | if (!(*Param)->isTemplateParameterPack() && |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 60 | !(isa<TemplateTypeParmDecl>(*Param) && |
Douglas Gregor | 62cb18d | 2009-02-11 18:16:40 +0000 | [diff] [blame] | 61 | cast<TemplateTypeParmDecl>(*Param)->hasDefaultArgument()) && |
| 62 | !(isa<NonTypeTemplateParmDecl>(*Param) && |
| 63 | cast<NonTypeTemplateParmDecl>(*Param)->hasDefaultArgument()) && |
| 64 | !(isa<TemplateTemplateParmDecl>(*Param) && |
| 65 | cast<TemplateTemplateParmDecl>(*Param)->hasDefaultArgument())) |
| 66 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 67 | |
Douglas Gregor | 62cb18d | 2009-02-11 18:16:40 +0000 | [diff] [blame] | 68 | --NumRequiredArgs; |
| 69 | } |
| 70 | |
| 71 | return NumRequiredArgs; |
| 72 | } |
| 73 | |
Douglas Gregor | ed9c0f9 | 2009-10-29 00:04:11 +0000 | [diff] [blame] | 74 | unsigned TemplateParameterList::getDepth() const { |
| 75 | if (size() == 0) |
| 76 | return 0; |
| 77 | |
| 78 | const NamedDecl *FirstParm = getParam(0); |
| 79 | if (const TemplateTypeParmDecl *TTP |
| 80 | = dyn_cast<TemplateTypeParmDecl>(FirstParm)) |
| 81 | return TTP->getDepth(); |
| 82 | else if (const NonTypeTemplateParmDecl *NTTP |
| 83 | = dyn_cast<NonTypeTemplateParmDecl>(FirstParm)) |
| 84 | return NTTP->getDepth(); |
| 85 | else |
| 86 | return cast<TemplateTemplateParmDecl>(FirstParm)->getDepth(); |
| 87 | } |
| 88 | |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 89 | //===----------------------------------------------------------------------===// |
Peter Collingbourne | 9eabeba | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 90 | // RedeclarableTemplateDecl Implementation |
| 91 | //===----------------------------------------------------------------------===// |
| 92 | |
| 93 | RedeclarableTemplateDecl::CommonBase *RedeclarableTemplateDecl::getCommonPtr() { |
| 94 | // Find the first declaration of this function template. |
| 95 | RedeclarableTemplateDecl *First = getCanonicalDecl(); |
| 96 | |
| 97 | if (First->CommonOrPrev.isNull()) { |
Argyrios Kyrtzidis | 6b54151 | 2010-09-08 19:31:22 +0000 | [diff] [blame] | 98 | CommonBase *CommonPtr = First->newCommon(getASTContext()); |
Peter Collingbourne | 9eabeba | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 99 | First->CommonOrPrev = CommonPtr; |
Peter Collingbourne | 8a798a7 | 2010-07-29 16:12:01 +0000 | [diff] [blame] | 100 | CommonPtr->Latest = First; |
Peter Collingbourne | 9eabeba | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 101 | } |
| 102 | return First->CommonOrPrev.get<CommonBase*>(); |
| 103 | } |
| 104 | |
| 105 | |
| 106 | RedeclarableTemplateDecl *RedeclarableTemplateDecl::getCanonicalDeclImpl() { |
| 107 | RedeclarableTemplateDecl *Tmpl = this; |
| 108 | while (Tmpl->getPreviousDeclaration()) |
| 109 | Tmpl = Tmpl->getPreviousDeclaration(); |
| 110 | return Tmpl; |
| 111 | } |
| 112 | |
Peter Collingbourne | 8a798a7 | 2010-07-29 16:12:01 +0000 | [diff] [blame] | 113 | void RedeclarableTemplateDecl::setPreviousDeclarationImpl( |
| 114 | RedeclarableTemplateDecl *Prev) { |
| 115 | if (Prev) { |
| 116 | CommonBase *Common = Prev->getCommonPtr(); |
| 117 | Prev = Common->Latest; |
| 118 | Common->Latest = this; |
| 119 | CommonOrPrev = Prev; |
| 120 | } else { |
| 121 | assert(CommonOrPrev.is<CommonBase*>() && "Cannot reset TemplateDecl Prev"); |
| 122 | } |
| 123 | } |
| 124 | |
Peter Collingbourne | f88718e | 2010-07-29 16:12:09 +0000 | [diff] [blame] | 125 | RedeclarableTemplateDecl *RedeclarableTemplateDecl::getNextRedeclaration() { |
| 126 | if (CommonOrPrev.is<RedeclarableTemplateDecl*>()) |
| 127 | return CommonOrPrev.get<RedeclarableTemplateDecl*>(); |
| 128 | CommonBase *Common = CommonOrPrev.get<CommonBase*>(); |
| 129 | return Common ? Common->Latest : this; |
| 130 | } |
| 131 | |
Peter Collingbourne | 4048590 | 2010-07-30 17:09:04 +0000 | [diff] [blame] | 132 | template <class EntryType> |
| 133 | typename RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::DeclType* |
| 134 | RedeclarableTemplateDecl::findSpecializationImpl( |
| 135 | llvm::FoldingSet<EntryType> &Specs, |
| 136 | const TemplateArgument *Args, unsigned NumArgs, |
| 137 | void *&InsertPos) { |
| 138 | typedef SpecEntryTraits<EntryType> SETraits; |
| 139 | llvm::FoldingSetNodeID ID; |
| 140 | EntryType::Profile(ID,Args,NumArgs, getASTContext()); |
| 141 | EntryType *Entry = Specs.FindNodeOrInsertPos(ID, InsertPos); |
| 142 | return Entry ? SETraits::getMostRecentDeclaration(Entry) : 0; |
| 143 | } |
| 144 | |
Peter Collingbourne | 9eabeba | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 145 | //===----------------------------------------------------------------------===// |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 146 | // FunctionTemplateDecl Implementation |
| 147 | //===----------------------------------------------------------------------===// |
| 148 | |
Douglas Gregor | 0054531 | 2010-05-23 18:26:36 +0000 | [diff] [blame] | 149 | void FunctionTemplateDecl::DeallocateCommon(void *Ptr) { |
| 150 | static_cast<Common *>(Ptr)->~Common(); |
| 151 | } |
| 152 | |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 153 | FunctionTemplateDecl *FunctionTemplateDecl::Create(ASTContext &C, |
| 154 | DeclContext *DC, |
| 155 | SourceLocation L, |
| 156 | DeclarationName Name, |
Douglas Gregor | 127102b | 2009-06-29 20:59:39 +0000 | [diff] [blame] | 157 | TemplateParameterList *Params, |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 158 | NamedDecl *Decl) { |
| 159 | return new (C) FunctionTemplateDecl(DC, L, Name, Params, Decl); |
| 160 | } |
| 161 | |
Argyrios Kyrtzidis | 6b54151 | 2010-09-08 19:31:22 +0000 | [diff] [blame] | 162 | RedeclarableTemplateDecl::CommonBase * |
| 163 | FunctionTemplateDecl::newCommon(ASTContext &C) { |
| 164 | Common *CommonPtr = new (C) Common; |
| 165 | C.AddDeallocation(DeallocateCommon, CommonPtr); |
Peter Collingbourne | 9eabeba | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 166 | return CommonPtr; |
| 167 | } |
| 168 | |
Argyrios Kyrtzidis | 2c853e4 | 2010-07-20 13:59:58 +0000 | [diff] [blame] | 169 | FunctionDecl * |
| 170 | FunctionTemplateDecl::findSpecialization(const TemplateArgument *Args, |
| 171 | unsigned NumArgs, void *&InsertPos) { |
Peter Collingbourne | 4048590 | 2010-07-30 17:09:04 +0000 | [diff] [blame] | 172 | return findSpecializationImpl(getSpecializations(), Args, NumArgs, InsertPos); |
Argyrios Kyrtzidis | 2c853e4 | 2010-07-20 13:59:58 +0000 | [diff] [blame] | 173 | } |
| 174 | |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 175 | //===----------------------------------------------------------------------===// |
| 176 | // ClassTemplateDecl Implementation |
| 177 | //===----------------------------------------------------------------------===// |
| 178 | |
Douglas Gregor | 0054531 | 2010-05-23 18:26:36 +0000 | [diff] [blame] | 179 | void ClassTemplateDecl::DeallocateCommon(void *Ptr) { |
| 180 | static_cast<Common *>(Ptr)->~Common(); |
| 181 | } |
| 182 | |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 183 | ClassTemplateDecl *ClassTemplateDecl::Create(ASTContext &C, |
| 184 | DeclContext *DC, |
| 185 | SourceLocation L, |
| 186 | DeclarationName Name, |
| 187 | TemplateParameterList *Params, |
Douglas Gregor | 5953d8b | 2009-03-19 17:26:29 +0000 | [diff] [blame] | 188 | NamedDecl *Decl, |
| 189 | ClassTemplateDecl *PrevDecl) { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 190 | ClassTemplateDecl *New = new (C) ClassTemplateDecl(DC, L, Name, Params, Decl); |
Argyrios Kyrtzidis | 5bf1bdc | 2010-06-21 10:57:41 +0000 | [diff] [blame] | 191 | New->setPreviousDeclaration(PrevDecl); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 192 | return New; |
Douglas Gregor | 5953d8b | 2009-03-19 17:26:29 +0000 | [diff] [blame] | 193 | } |
| 194 | |
Douglas Gregor | c8e5cf8 | 2010-10-27 22:21:36 +0000 | [diff] [blame] | 195 | void ClassTemplateDecl::LoadLazySpecializations() { |
| 196 | Common *CommonPtr = getCommonPtr(); |
| 197 | if (CommonPtr->LazySpecializations) { |
| 198 | ASTContext &Context = getASTContext(); |
| 199 | uint32_t *Specs = CommonPtr->LazySpecializations; |
| 200 | CommonPtr->LazySpecializations = 0; |
| 201 | for (uint32_t I = 0, N = *Specs++; I != N; ++I) |
| 202 | (void)Context.getExternalSource()->GetExternalDecl(Specs[I]); |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | llvm::FoldingSet<ClassTemplateSpecializationDecl> & |
| 207 | ClassTemplateDecl::getSpecializations() { |
| 208 | LoadLazySpecializations(); |
| 209 | return getCommonPtr()->Specializations; |
| 210 | } |
| 211 | |
| 212 | llvm::FoldingSet<ClassTemplatePartialSpecializationDecl> & |
| 213 | ClassTemplateDecl::getPartialSpecializations() { |
| 214 | LoadLazySpecializations(); |
| 215 | return getCommonPtr()->PartialSpecializations; |
| 216 | } |
| 217 | |
Argyrios Kyrtzidis | 6b54151 | 2010-09-08 19:31:22 +0000 | [diff] [blame] | 218 | RedeclarableTemplateDecl::CommonBase * |
| 219 | ClassTemplateDecl::newCommon(ASTContext &C) { |
| 220 | Common *CommonPtr = new (C) Common; |
| 221 | C.AddDeallocation(DeallocateCommon, CommonPtr); |
Peter Collingbourne | 9eabeba | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 222 | return CommonPtr; |
| 223 | } |
| 224 | |
Argyrios Kyrtzidis | cc0b1bc | 2010-07-20 13:59:28 +0000 | [diff] [blame] | 225 | ClassTemplateSpecializationDecl * |
| 226 | ClassTemplateDecl::findSpecialization(const TemplateArgument *Args, |
| 227 | unsigned NumArgs, void *&InsertPos) { |
Peter Collingbourne | 4048590 | 2010-07-30 17:09:04 +0000 | [diff] [blame] | 228 | return findSpecializationImpl(getSpecializations(), Args, NumArgs, InsertPos); |
Argyrios Kyrtzidis | cc0b1bc | 2010-07-20 13:59:28 +0000 | [diff] [blame] | 229 | } |
| 230 | |
Argyrios Kyrtzidis | bef1a7b | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 231 | void ClassTemplateDecl::AddSpecialization(ClassTemplateSpecializationDecl *D, |
| 232 | void *InsertPos) { |
| 233 | getSpecializations().InsertNode(D, InsertPos); |
| 234 | if (ASTMutationListener *L = getASTMutationListener()) |
| 235 | L->AddedCXXTemplateSpecialization(this, D); |
| 236 | } |
| 237 | |
Argyrios Kyrtzidis | cc0b1bc | 2010-07-20 13:59:28 +0000 | [diff] [blame] | 238 | ClassTemplatePartialSpecializationDecl * |
| 239 | ClassTemplateDecl::findPartialSpecialization(const TemplateArgument *Args, |
| 240 | unsigned NumArgs, |
| 241 | void *&InsertPos) { |
Peter Collingbourne | 4048590 | 2010-07-30 17:09:04 +0000 | [diff] [blame] | 242 | return findSpecializationImpl(getPartialSpecializations(), Args, NumArgs, |
| 243 | InsertPos); |
Argyrios Kyrtzidis | cc0b1bc | 2010-07-20 13:59:28 +0000 | [diff] [blame] | 244 | } |
| 245 | |
Argyrios Kyrtzidis | bef1a7b | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 246 | void ClassTemplateDecl::AddPartialSpecialization( |
| 247 | ClassTemplatePartialSpecializationDecl *D, |
| 248 | void *InsertPos) { |
| 249 | getPartialSpecializations().InsertNode(D, InsertPos); |
| 250 | if (ASTMutationListener *L = getASTMutationListener()) |
| 251 | L->AddedCXXTemplateSpecialization(this, D); |
| 252 | } |
| 253 | |
Douglas Gregor | dc60c1e | 2010-04-30 05:56:50 +0000 | [diff] [blame] | 254 | void ClassTemplateDecl::getPartialSpecializations( |
| 255 | llvm::SmallVectorImpl<ClassTemplatePartialSpecializationDecl *> &PS) { |
| 256 | llvm::FoldingSet<ClassTemplatePartialSpecializationDecl> &PartialSpecs |
Argyrios Kyrtzidis | 5bf1bdc | 2010-06-21 10:57:41 +0000 | [diff] [blame] | 257 | = getPartialSpecializations(); |
Douglas Gregor | dc60c1e | 2010-04-30 05:56:50 +0000 | [diff] [blame] | 258 | PS.clear(); |
| 259 | PS.resize(PartialSpecs.size()); |
| 260 | for (llvm::FoldingSet<ClassTemplatePartialSpecializationDecl>::iterator |
| 261 | P = PartialSpecs.begin(), PEnd = PartialSpecs.end(); |
| 262 | P != PEnd; ++P) { |
| 263 | assert(!PS[P->getSequenceNumber()]); |
Argyrios Kyrtzidis | cc0b1bc | 2010-07-20 13:59:28 +0000 | [diff] [blame] | 264 | PS[P->getSequenceNumber()] = P->getMostRecentDeclaration(); |
Douglas Gregor | dc60c1e | 2010-04-30 05:56:50 +0000 | [diff] [blame] | 265 | } |
| 266 | } |
| 267 | |
Douglas Gregor | b88e888 | 2009-07-30 17:40:51 +0000 | [diff] [blame] | 268 | ClassTemplatePartialSpecializationDecl * |
| 269 | ClassTemplateDecl::findPartialSpecialization(QualType T) { |
| 270 | ASTContext &Context = getASTContext(); |
| 271 | typedef llvm::FoldingSet<ClassTemplatePartialSpecializationDecl>::iterator |
| 272 | partial_spec_iterator; |
| 273 | for (partial_spec_iterator P = getPartialSpecializations().begin(), |
| 274 | PEnd = getPartialSpecializations().end(); |
| 275 | P != PEnd; ++P) { |
John McCall | 31f17ec | 2010-04-27 00:57:59 +0000 | [diff] [blame] | 276 | if (Context.hasSameType(P->getInjectedSpecializationType(), T)) |
Argyrios Kyrtzidis | cc0b1bc | 2010-07-20 13:59:28 +0000 | [diff] [blame] | 277 | return P->getMostRecentDeclaration(); |
| 278 | } |
| 279 | |
| 280 | return 0; |
| 281 | } |
| 282 | |
| 283 | ClassTemplatePartialSpecializationDecl * |
| 284 | ClassTemplateDecl::findPartialSpecInstantiatedFromMember( |
| 285 | ClassTemplatePartialSpecializationDecl *D) { |
| 286 | Decl *DCanon = D->getCanonicalDecl(); |
| 287 | for (llvm::FoldingSet<ClassTemplatePartialSpecializationDecl>::iterator |
| 288 | P = getPartialSpecializations().begin(), |
| 289 | PEnd = getPartialSpecializations().end(); |
| 290 | P != PEnd; ++P) { |
| 291 | if (P->getInstantiatedFromMember()->getCanonicalDecl() == DCanon) |
| 292 | return P->getMostRecentDeclaration(); |
Douglas Gregor | b88e888 | 2009-07-30 17:40:51 +0000 | [diff] [blame] | 293 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 294 | |
Douglas Gregor | b88e888 | 2009-07-30 17:40:51 +0000 | [diff] [blame] | 295 | return 0; |
| 296 | } |
| 297 | |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 298 | QualType |
Douglas Gregor | 24bae92 | 2010-07-08 18:37:38 +0000 | [diff] [blame] | 299 | ClassTemplateDecl::getInjectedClassNameSpecialization() { |
Argyrios Kyrtzidis | 5bf1bdc | 2010-06-21 10:57:41 +0000 | [diff] [blame] | 300 | Common *CommonPtr = getCommonPtr(); |
Douglas Gregor | 7da97d0 | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 301 | if (!CommonPtr->InjectedClassNameType.isNull()) |
| 302 | return CommonPtr->InjectedClassNameType; |
| 303 | |
Douglas Gregor | b7d09d6 | 2010-12-23 16:00:30 +0000 | [diff] [blame] | 304 | // C++0x [temp.dep.type]p2: |
| 305 | // The template argument list of a primary template is a template argument |
| 306 | // list in which the nth template argument has the value of the nth template |
| 307 | // parameter of the class template. If the nth template parameter is a |
| 308 | // template parameter pack (14.5.3), the nth template argument is a pack |
| 309 | // expansion (14.5.3) whose pattern is the name of the template parameter |
| 310 | // pack. |
Douglas Gregor | 24bae92 | 2010-07-08 18:37:38 +0000 | [diff] [blame] | 311 | ASTContext &Context = getASTContext(); |
Douglas Gregor | 7da97d0 | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 312 | TemplateParameterList *Params = getTemplateParameters(); |
Douglas Gregor | 7da97d0 | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 313 | llvm::SmallVector<TemplateArgument, 16> TemplateArgs; |
Douglas Gregor | 7da97d0 | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 314 | TemplateArgs.reserve(Params->size()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 315 | for (TemplateParameterList::iterator Param = Params->begin(), |
| 316 | ParamEnd = Params->end(); |
Douglas Gregor | 7da97d0 | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 317 | Param != ParamEnd; ++Param) { |
Douglas Gregor | b7d09d6 | 2010-12-23 16:00:30 +0000 | [diff] [blame] | 318 | TemplateArgument Arg; |
| 319 | if (TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(*Param)) { |
| 320 | QualType ArgType = Context.getTypeDeclType(TTP); |
| 321 | if (TTP->isParameterPack()) |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 322 | ArgType = Context.getPackExpansionType(ArgType, |
| 323 | llvm::Optional<unsigned>()); |
Douglas Gregor | b7d09d6 | 2010-12-23 16:00:30 +0000 | [diff] [blame] | 324 | |
| 325 | Arg = TemplateArgument(ArgType); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 326 | } else if (NonTypeTemplateParmDecl *NTTP = |
Douglas Gregor | 7da97d0 | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 327 | dyn_cast<NonTypeTemplateParmDecl>(*Param)) { |
Chandler Carruth | b7de181 | 2010-01-31 07:24:03 +0000 | [diff] [blame] | 328 | Expr *E = new (Context) DeclRefExpr(NTTP, |
Douglas Gregor | 6398235 | 2010-07-13 18:40:04 +0000 | [diff] [blame] | 329 | NTTP->getType().getNonLValueExprType(Context), |
John McCall | f89e55a | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 330 | Expr::getValueKindForType(NTTP->getType()), |
Douglas Gregor | 0da76df | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 331 | NTTP->getLocation()); |
Douglas Gregor | b95cc97 | 2011-01-04 02:33:52 +0000 | [diff] [blame] | 332 | |
| 333 | if (NTTP->isParameterPack()) |
| 334 | E = new (Context) PackExpansionExpr(Context.DependentTy, E, |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 335 | NTTP->getLocation(), |
| 336 | llvm::Optional<unsigned>()); |
Douglas Gregor | b7d09d6 | 2010-12-23 16:00:30 +0000 | [diff] [blame] | 337 | Arg = TemplateArgument(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 338 | } else { |
Douglas Gregor | 7da97d0 | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 339 | TemplateTemplateParmDecl *TTP = cast<TemplateTemplateParmDecl>(*Param); |
Douglas Gregor | 2be29f4 | 2011-01-14 23:41:42 +0000 | [diff] [blame^] | 340 | if (TTP->isParameterPack()) |
| 341 | Arg = TemplateArgument(TemplateName(TTP), llvm::Optional<unsigned>()); |
| 342 | else |
| 343 | Arg = TemplateArgument(TemplateName(TTP)); |
Douglas Gregor | 7da97d0 | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 344 | } |
Douglas Gregor | b7d09d6 | 2010-12-23 16:00:30 +0000 | [diff] [blame] | 345 | |
Douglas Gregor | 203e6a3 | 2011-01-11 23:09:57 +0000 | [diff] [blame] | 346 | if ((*Param)->isTemplateParameterPack()) |
| 347 | Arg = TemplateArgument::CreatePackCopy(Context, &Arg, 1); |
Douglas Gregor | b7d09d6 | 2010-12-23 16:00:30 +0000 | [diff] [blame] | 348 | |
| 349 | TemplateArgs.push_back(Arg); |
Douglas Gregor | 7da97d0 | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 350 | } |
| 351 | |
Douglas Gregor | 7da97d0 | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 352 | CommonPtr->InjectedClassNameType |
Douglas Gregor | 1275ae0 | 2009-07-28 23:00:59 +0000 | [diff] [blame] | 353 | = Context.getTemplateSpecializationType(TemplateName(this), |
Douglas Gregor | 7da97d0 | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 354 | &TemplateArgs[0], |
Douglas Gregor | 1275ae0 | 2009-07-28 23:00:59 +0000 | [diff] [blame] | 355 | TemplateArgs.size()); |
Douglas Gregor | 7da97d0 | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 356 | return CommonPtr->InjectedClassNameType; |
| 357 | } |
| 358 | |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 359 | //===----------------------------------------------------------------------===// |
| 360 | // TemplateTypeParm Allocation/Deallocation Method Implementations |
| 361 | //===----------------------------------------------------------------------===// |
| 362 | |
| 363 | TemplateTypeParmDecl * |
Jay Foad | 4ba2a17 | 2011-01-12 09:06:06 +0000 | [diff] [blame] | 364 | TemplateTypeParmDecl::Create(const ASTContext &C, DeclContext *DC, |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 365 | SourceLocation L, unsigned D, unsigned P, |
Anders Carlsson | 6d845ae | 2009-06-12 22:23:22 +0000 | [diff] [blame] | 366 | IdentifierInfo *Id, bool Typename, |
| 367 | bool ParameterPack) { |
Douglas Gregor | efed5c8 | 2010-06-16 15:23:05 +0000 | [diff] [blame] | 368 | QualType Type = C.getTemplateTypeParmType(D, P, ParameterPack, Id); |
| 369 | return new (C) TemplateTypeParmDecl(DC, L, Id, Typename, Type, ParameterPack); |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 370 | } |
| 371 | |
Argyrios Kyrtzidis | b8b03e6 | 2010-07-02 11:54:55 +0000 | [diff] [blame] | 372 | TemplateTypeParmDecl * |
Jay Foad | 4ba2a17 | 2011-01-12 09:06:06 +0000 | [diff] [blame] | 373 | TemplateTypeParmDecl::Create(const ASTContext &C, EmptyShell Empty) { |
Argyrios Kyrtzidis | b8b03e6 | 2010-07-02 11:54:55 +0000 | [diff] [blame] | 374 | return new (C) TemplateTypeParmDecl(0, SourceLocation(), 0, false, |
| 375 | QualType(), false); |
| 376 | } |
| 377 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 378 | SourceLocation TemplateTypeParmDecl::getDefaultArgumentLoc() const { |
Abramo Bagnara | bd054db | 2010-05-20 10:00:11 +0000 | [diff] [blame] | 379 | return DefaultArgument->getTypeLoc().getSourceRange().getBegin(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 380 | } |
| 381 | |
Douglas Gregor | ed9c0f9 | 2009-10-29 00:04:11 +0000 | [diff] [blame] | 382 | unsigned TemplateTypeParmDecl::getDepth() const { |
| 383 | return TypeForDecl->getAs<TemplateTypeParmType>()->getDepth(); |
| 384 | } |
| 385 | |
| 386 | unsigned TemplateTypeParmDecl::getIndex() const { |
| 387 | return TypeForDecl->getAs<TemplateTypeParmType>()->getIndex(); |
| 388 | } |
| 389 | |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 390 | //===----------------------------------------------------------------------===// |
| 391 | // NonTypeTemplateParmDecl Method Implementations |
| 392 | //===----------------------------------------------------------------------===// |
| 393 | |
| 394 | NonTypeTemplateParmDecl * |
Jay Foad | 4ba2a17 | 2011-01-12 09:06:06 +0000 | [diff] [blame] | 395 | NonTypeTemplateParmDecl::Create(const ASTContext &C, DeclContext *DC, |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 396 | SourceLocation L, unsigned D, unsigned P, |
| 397 | IdentifierInfo *Id, QualType T, |
Douglas Gregor | 10738d3 | 2010-12-23 23:51:58 +0000 | [diff] [blame] | 398 | bool ParameterPack, TypeSourceInfo *TInfo) { |
| 399 | return new (C) NonTypeTemplateParmDecl(DC, L, D, P, Id, T, ParameterPack, |
| 400 | TInfo); |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 401 | } |
| 402 | |
Douglas Gregor | d684b00 | 2009-02-10 19:49:53 +0000 | [diff] [blame] | 403 | SourceLocation NonTypeTemplateParmDecl::getDefaultArgumentLoc() const { |
Abramo Bagnara | d92f7a2 | 2010-06-09 09:26:05 +0000 | [diff] [blame] | 404 | return hasDefaultArgument() |
| 405 | ? getDefaultArgument()->getSourceRange().getBegin() |
| 406 | : SourceLocation(); |
Douglas Gregor | d684b00 | 2009-02-10 19:49:53 +0000 | [diff] [blame] | 407 | } |
| 408 | |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 409 | //===----------------------------------------------------------------------===// |
| 410 | // TemplateTemplateParmDecl Method Implementations |
| 411 | //===----------------------------------------------------------------------===// |
| 412 | |
| 413 | TemplateTemplateParmDecl * |
Jay Foad | 4ba2a17 | 2011-01-12 09:06:06 +0000 | [diff] [blame] | 414 | TemplateTemplateParmDecl::Create(const ASTContext &C, DeclContext *DC, |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 415 | SourceLocation L, unsigned D, unsigned P, |
Douglas Gregor | 61c4d28 | 2011-01-05 15:48:55 +0000 | [diff] [blame] | 416 | bool ParameterPack, IdentifierInfo *Id, |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 417 | TemplateParameterList *Params) { |
Douglas Gregor | 61c4d28 | 2011-01-05 15:48:55 +0000 | [diff] [blame] | 418 | return new (C) TemplateTemplateParmDecl(DC, L, D, P, ParameterPack, Id, |
| 419 | Params); |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 420 | } |
| 421 | |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 422 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 7e06390 | 2009-05-11 23:53:27 +0000 | [diff] [blame] | 423 | // TemplateArgumentList Implementation |
| 424 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 425 | TemplateArgumentList * |
| 426 | TemplateArgumentList::CreateCopy(ASTContext &Context, |
| 427 | const TemplateArgument *Args, |
| 428 | unsigned NumArgs) { |
| 429 | std::size_t Size = sizeof(TemplateArgumentList) |
| 430 | + NumArgs * sizeof(TemplateArgument); |
| 431 | void *Mem = Context.Allocate(Size); |
| 432 | TemplateArgument *StoredArgs |
| 433 | = reinterpret_cast<TemplateArgument *>( |
| 434 | static_cast<TemplateArgumentList *>(Mem) + 1); |
| 435 | std::uninitialized_copy(Args, Args + NumArgs, StoredArgs); |
| 436 | return new (Mem) TemplateArgumentList(StoredArgs, NumArgs, true); |
Argyrios Kyrtzidis | 94d228d | 2010-06-23 13:48:23 +0000 | [diff] [blame] | 437 | } |
| 438 | |
Douglas Gregor | 7e06390 | 2009-05-11 23:53:27 +0000 | [diff] [blame] | 439 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 440 | // ClassTemplateSpecializationDecl Implementation |
| 441 | //===----------------------------------------------------------------------===// |
| 442 | ClassTemplateSpecializationDecl:: |
Douglas Gregor | 13c8577 | 2010-05-06 00:28:52 +0000 | [diff] [blame] | 443 | ClassTemplateSpecializationDecl(ASTContext &Context, Kind DK, TagKind TK, |
Douglas Gregor | 7e06390 | 2009-05-11 23:53:27 +0000 | [diff] [blame] | 444 | DeclContext *DC, SourceLocation L, |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 445 | ClassTemplateDecl *SpecializedTemplate, |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 446 | const TemplateArgument *Args, |
| 447 | unsigned NumArgs, |
Douglas Gregor | 8e9e9ef | 2009-07-29 23:36:44 +0000 | [diff] [blame] | 448 | ClassTemplateSpecializationDecl *PrevDecl) |
Douglas Gregor | 13c8577 | 2010-05-06 00:28:52 +0000 | [diff] [blame] | 449 | : CXXRecordDecl(DK, TK, DC, L, |
Douglas Gregor | 8e9e9ef | 2009-07-29 23:36:44 +0000 | [diff] [blame] | 450 | SpecializedTemplate->getIdentifier(), |
| 451 | PrevDecl), |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 452 | SpecializedTemplate(SpecializedTemplate), |
Abramo Bagnara | c98971d | 2010-06-12 07:44:57 +0000 | [diff] [blame] | 453 | ExplicitInfo(0), |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 454 | TemplateArgs(TemplateArgumentList::CreateCopy(Context, Args, NumArgs)), |
Douglas Gregor | 7e06390 | 2009-05-11 23:53:27 +0000 | [diff] [blame] | 455 | SpecializationKind(TSK_Undeclared) { |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 456 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 457 | |
Argyrios Kyrtzidis | 94d228d | 2010-06-23 13:48:23 +0000 | [diff] [blame] | 458 | ClassTemplateSpecializationDecl::ClassTemplateSpecializationDecl(Kind DK) |
| 459 | : CXXRecordDecl(DK, TTK_Struct, 0, SourceLocation(), 0, 0), |
| 460 | ExplicitInfo(0), |
| 461 | SpecializationKind(TSK_Undeclared) { |
| 462 | } |
| 463 | |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 464 | ClassTemplateSpecializationDecl * |
Douglas Gregor | 13c8577 | 2010-05-06 00:28:52 +0000 | [diff] [blame] | 465 | ClassTemplateSpecializationDecl::Create(ASTContext &Context, TagKind TK, |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 466 | DeclContext *DC, SourceLocation L, |
| 467 | ClassTemplateDecl *SpecializedTemplate, |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 468 | const TemplateArgument *Args, |
| 469 | unsigned NumArgs, |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 470 | ClassTemplateSpecializationDecl *PrevDecl) { |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 471 | ClassTemplateSpecializationDecl *Result |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 472 | = new (Context)ClassTemplateSpecializationDecl(Context, |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 473 | ClassTemplateSpecialization, |
Douglas Gregor | 13c8577 | 2010-05-06 00:28:52 +0000 | [diff] [blame] | 474 | TK, DC, L, |
Douglas Gregor | 7e06390 | 2009-05-11 23:53:27 +0000 | [diff] [blame] | 475 | SpecializedTemplate, |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 476 | Args, NumArgs, |
Douglas Gregor | 8e9e9ef | 2009-07-29 23:36:44 +0000 | [diff] [blame] | 477 | PrevDecl); |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 478 | Context.getTypeDeclType(Result, PrevDecl); |
| 479 | return Result; |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 480 | } |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 481 | |
Argyrios Kyrtzidis | 94d228d | 2010-06-23 13:48:23 +0000 | [diff] [blame] | 482 | ClassTemplateSpecializationDecl * |
Argyrios Kyrtzidis | b8b03e6 | 2010-07-02 11:54:55 +0000 | [diff] [blame] | 483 | ClassTemplateSpecializationDecl::Create(ASTContext &Context, EmptyShell Empty) { |
Argyrios Kyrtzidis | 94d228d | 2010-06-23 13:48:23 +0000 | [diff] [blame] | 484 | return |
| 485 | new (Context)ClassTemplateSpecializationDecl(ClassTemplateSpecialization); |
| 486 | } |
| 487 | |
John McCall | 136a698 | 2009-09-11 06:45:03 +0000 | [diff] [blame] | 488 | void |
| 489 | ClassTemplateSpecializationDecl::getNameForDiagnostic(std::string &S, |
| 490 | const PrintingPolicy &Policy, |
| 491 | bool Qualified) const { |
| 492 | NamedDecl::getNameForDiagnostic(S, Policy, Qualified); |
| 493 | |
| 494 | const TemplateArgumentList &TemplateArgs = getTemplateArgs(); |
| 495 | S += TemplateSpecializationType::PrintTemplateArgumentList( |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 496 | TemplateArgs.data(), |
| 497 | TemplateArgs.size(), |
John McCall | 136a698 | 2009-09-11 06:45:03 +0000 | [diff] [blame] | 498 | Policy); |
| 499 | } |
| 500 | |
Douglas Gregor | 37d93e9 | 2009-08-02 23:24:31 +0000 | [diff] [blame] | 501 | ClassTemplateDecl * |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 502 | ClassTemplateSpecializationDecl::getSpecializedTemplate() const { |
| 503 | if (SpecializedPartialSpecialization *PartialSpec |
Douglas Gregor | 37d93e9 | 2009-08-02 23:24:31 +0000 | [diff] [blame] | 504 | = SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization*>()) |
| 505 | return PartialSpec->PartialSpecialization->getSpecializedTemplate(); |
| 506 | return SpecializedTemplate.get<ClassTemplateDecl*>(); |
| 507 | } |
| 508 | |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 509 | //===----------------------------------------------------------------------===// |
| 510 | // ClassTemplatePartialSpecializationDecl Implementation |
| 511 | //===----------------------------------------------------------------------===// |
| 512 | ClassTemplatePartialSpecializationDecl * |
| 513 | ClassTemplatePartialSpecializationDecl:: |
Douglas Gregor | 13c8577 | 2010-05-06 00:28:52 +0000 | [diff] [blame] | 514 | Create(ASTContext &Context, TagKind TK,DeclContext *DC, SourceLocation L, |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 515 | TemplateParameterList *Params, |
| 516 | ClassTemplateDecl *SpecializedTemplate, |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 517 | const TemplateArgument *Args, |
| 518 | unsigned NumArgs, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 519 | const TemplateArgumentListInfo &ArgInfos, |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 520 | QualType CanonInjectedType, |
Douglas Gregor | dc60c1e | 2010-04-30 05:56:50 +0000 | [diff] [blame] | 521 | ClassTemplatePartialSpecializationDecl *PrevDecl, |
| 522 | unsigned SequenceNumber) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 523 | unsigned N = ArgInfos.size(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 524 | TemplateArgumentLoc *ClonedArgs = new (Context) TemplateArgumentLoc[N]; |
| 525 | for (unsigned I = 0; I != N; ++I) |
| 526 | ClonedArgs[I] = ArgInfos[I]; |
| 527 | |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 528 | ClassTemplatePartialSpecializationDecl *Result |
Douglas Gregor | 13c8577 | 2010-05-06 00:28:52 +0000 | [diff] [blame] | 529 | = new (Context)ClassTemplatePartialSpecializationDecl(Context, TK, |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 530 | DC, L, Params, |
| 531 | SpecializedTemplate, |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 532 | Args, NumArgs, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 533 | ClonedArgs, N, |
Douglas Gregor | dc60c1e | 2010-04-30 05:56:50 +0000 | [diff] [blame] | 534 | PrevDecl, |
| 535 | SequenceNumber); |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 536 | Result->setSpecializationKind(TSK_ExplicitSpecialization); |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 537 | |
| 538 | Context.getInjectedClassNameType(Result, CanonInjectedType); |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 539 | return Result; |
| 540 | } |
John McCall | dd4a3b0 | 2009-09-16 22:47:08 +0000 | [diff] [blame] | 541 | |
Argyrios Kyrtzidis | 94d228d | 2010-06-23 13:48:23 +0000 | [diff] [blame] | 542 | ClassTemplatePartialSpecializationDecl * |
Argyrios Kyrtzidis | b8b03e6 | 2010-07-02 11:54:55 +0000 | [diff] [blame] | 543 | ClassTemplatePartialSpecializationDecl::Create(ASTContext &Context, |
| 544 | EmptyShell Empty) { |
Argyrios Kyrtzidis | 94d228d | 2010-06-23 13:48:23 +0000 | [diff] [blame] | 545 | return new (Context)ClassTemplatePartialSpecializationDecl(); |
| 546 | } |
| 547 | |
John McCall | dd4a3b0 | 2009-09-16 22:47:08 +0000 | [diff] [blame] | 548 | //===----------------------------------------------------------------------===// |
| 549 | // FriendTemplateDecl Implementation |
| 550 | //===----------------------------------------------------------------------===// |
| 551 | |
| 552 | FriendTemplateDecl *FriendTemplateDecl::Create(ASTContext &Context, |
| 553 | DeclContext *DC, |
| 554 | SourceLocation L, |
| 555 | unsigned NParams, |
| 556 | TemplateParameterList **Params, |
| 557 | FriendUnion Friend, |
| 558 | SourceLocation FLoc) { |
| 559 | FriendTemplateDecl *Result |
| 560 | = new (Context) FriendTemplateDecl(DC, L, NParams, Params, Friend, FLoc); |
| 561 | return Result; |
| 562 | } |
Argyrios Kyrtzidis | 554e6aa | 2010-07-22 16:04:10 +0000 | [diff] [blame] | 563 | |
| 564 | FriendTemplateDecl *FriendTemplateDecl::Create(ASTContext &Context, |
| 565 | EmptyShell Empty) { |
| 566 | return new (Context) FriendTemplateDecl(Empty); |
| 567 | } |