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