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