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