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 | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 17 | #include "clang/AST/ASTContext.h" |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 18 | #include "clang/AST/TypeLoc.h" |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 19 | #include "clang/Basic/IdentifierTable.h" |
| 20 | #include "llvm/ADT/STLExtras.h" |
| 21 | using namespace clang; |
| 22 | |
| 23 | //===----------------------------------------------------------------------===// |
| 24 | // TemplateParameterList Implementation |
| 25 | //===----------------------------------------------------------------------===// |
| 26 | |
Douglas Gregor | ddc29e1 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 27 | TemplateParameterList::TemplateParameterList(SourceLocation TemplateLoc, |
| 28 | SourceLocation LAngleLoc, |
Douglas Gregor | bf4ea56 | 2009-09-15 16:23:51 +0000 | [diff] [blame] | 29 | NamedDecl **Params, unsigned NumParams, |
Douglas Gregor | ddc29e1 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 30 | SourceLocation RAngleLoc) |
| 31 | : TemplateLoc(TemplateLoc), LAngleLoc(LAngleLoc), RAngleLoc(RAngleLoc), |
| 32 | NumParams(NumParams) { |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 33 | for (unsigned Idx = 0; Idx < NumParams; ++Idx) |
| 34 | begin()[Idx] = Params[Idx]; |
| 35 | } |
| 36 | |
| 37 | TemplateParameterList * |
Douglas Gregor | ddc29e1 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 38 | TemplateParameterList::Create(ASTContext &C, SourceLocation TemplateLoc, |
Douglas Gregor | bf4ea56 | 2009-09-15 16:23:51 +0000 | [diff] [blame] | 39 | SourceLocation LAngleLoc, NamedDecl **Params, |
Douglas Gregor | ddc29e1 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 40 | unsigned NumParams, SourceLocation RAngleLoc) { |
Douglas Gregor | bf4ea56 | 2009-09-15 16:23:51 +0000 | [diff] [blame] | 41 | unsigned Size = sizeof(TemplateParameterList) |
| 42 | + sizeof(NamedDecl *) * NumParams; |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 43 | unsigned Align = llvm::AlignOf<TemplateParameterList>::Alignment; |
| 44 | void *Mem = C.Allocate(Size, Align); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 45 | return new (Mem) TemplateParameterList(TemplateLoc, LAngleLoc, Params, |
Douglas Gregor | ddc29e1 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 46 | NumParams, RAngleLoc); |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 47 | } |
| 48 | |
Douglas Gregor | 62cb18d | 2009-02-11 18:16:40 +0000 | [diff] [blame] | 49 | unsigned TemplateParameterList::getMinRequiredArguments() const { |
| 50 | unsigned NumRequiredArgs = size(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 51 | iterator Param = const_cast<TemplateParameterList *>(this)->end(), |
Douglas Gregor | 62cb18d | 2009-02-11 18:16:40 +0000 | [diff] [blame] | 52 | ParamBegin = const_cast<TemplateParameterList *>(this)->begin(); |
| 53 | while (Param != ParamBegin) { |
| 54 | --Param; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 55 | |
Anders Carlsson | 0ceffb5 | 2009-06-13 02:08:00 +0000 | [diff] [blame] | 56 | if (!(*Param)->isTemplateParameterPack() && |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 57 | !(isa<TemplateTypeParmDecl>(*Param) && |
Douglas Gregor | 62cb18d | 2009-02-11 18:16:40 +0000 | [diff] [blame] | 58 | cast<TemplateTypeParmDecl>(*Param)->hasDefaultArgument()) && |
| 59 | !(isa<NonTypeTemplateParmDecl>(*Param) && |
| 60 | cast<NonTypeTemplateParmDecl>(*Param)->hasDefaultArgument()) && |
| 61 | !(isa<TemplateTemplateParmDecl>(*Param) && |
| 62 | cast<TemplateTemplateParmDecl>(*Param)->hasDefaultArgument())) |
| 63 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 64 | |
Douglas Gregor | 62cb18d | 2009-02-11 18:16:40 +0000 | [diff] [blame] | 65 | --NumRequiredArgs; |
| 66 | } |
| 67 | |
| 68 | return NumRequiredArgs; |
| 69 | } |
| 70 | |
Douglas Gregor | ed9c0f9 | 2009-10-29 00:04:11 +0000 | [diff] [blame] | 71 | unsigned TemplateParameterList::getDepth() const { |
| 72 | if (size() == 0) |
| 73 | return 0; |
| 74 | |
| 75 | const NamedDecl *FirstParm = getParam(0); |
| 76 | if (const TemplateTypeParmDecl *TTP |
| 77 | = dyn_cast<TemplateTypeParmDecl>(FirstParm)) |
| 78 | return TTP->getDepth(); |
| 79 | else if (const NonTypeTemplateParmDecl *NTTP |
| 80 | = dyn_cast<NonTypeTemplateParmDecl>(FirstParm)) |
| 81 | return NTTP->getDepth(); |
| 82 | else |
| 83 | return cast<TemplateTemplateParmDecl>(FirstParm)->getDepth(); |
| 84 | } |
| 85 | |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 86 | //===----------------------------------------------------------------------===// |
Peter Collingbourne | 9eabeba | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 87 | // RedeclarableTemplateDecl Implementation |
| 88 | //===----------------------------------------------------------------------===// |
| 89 | |
| 90 | RedeclarableTemplateDecl::CommonBase *RedeclarableTemplateDecl::getCommonPtr() { |
| 91 | // Find the first declaration of this function template. |
| 92 | RedeclarableTemplateDecl *First = getCanonicalDecl(); |
| 93 | |
| 94 | if (First->CommonOrPrev.isNull()) { |
| 95 | CommonBase *CommonPtr = First->newCommon(); |
| 96 | First->CommonOrPrev = CommonPtr; |
Peter Collingbourne | 8a798a7 | 2010-07-29 16:12:01 +0000 | [diff] [blame] | 97 | CommonPtr->Latest = First; |
Peter Collingbourne | 9eabeba | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 98 | } |
| 99 | return First->CommonOrPrev.get<CommonBase*>(); |
| 100 | } |
| 101 | |
| 102 | |
| 103 | RedeclarableTemplateDecl *RedeclarableTemplateDecl::getCanonicalDeclImpl() { |
| 104 | RedeclarableTemplateDecl *Tmpl = this; |
| 105 | while (Tmpl->getPreviousDeclaration()) |
| 106 | Tmpl = Tmpl->getPreviousDeclaration(); |
| 107 | return Tmpl; |
| 108 | } |
| 109 | |
Peter Collingbourne | 8a798a7 | 2010-07-29 16:12:01 +0000 | [diff] [blame] | 110 | void RedeclarableTemplateDecl::setPreviousDeclarationImpl( |
| 111 | RedeclarableTemplateDecl *Prev) { |
| 112 | if (Prev) { |
| 113 | CommonBase *Common = Prev->getCommonPtr(); |
| 114 | Prev = Common->Latest; |
| 115 | Common->Latest = this; |
| 116 | CommonOrPrev = Prev; |
| 117 | } else { |
| 118 | assert(CommonOrPrev.is<CommonBase*>() && "Cannot reset TemplateDecl Prev"); |
| 119 | } |
| 120 | } |
| 121 | |
Peter Collingbourne | f88718e | 2010-07-29 16:12:09 +0000 | [diff] [blame] | 122 | RedeclarableTemplateDecl *RedeclarableTemplateDecl::getNextRedeclaration() { |
| 123 | if (CommonOrPrev.is<RedeclarableTemplateDecl*>()) |
| 124 | return CommonOrPrev.get<RedeclarableTemplateDecl*>(); |
| 125 | CommonBase *Common = CommonOrPrev.get<CommonBase*>(); |
| 126 | return Common ? Common->Latest : this; |
| 127 | } |
| 128 | |
Peter Collingbourne | 4048590 | 2010-07-30 17:09:04 +0000 | [diff] [blame^] | 129 | template <class EntryType> |
| 130 | typename RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::DeclType* |
| 131 | RedeclarableTemplateDecl::findSpecializationImpl( |
| 132 | llvm::FoldingSet<EntryType> &Specs, |
| 133 | const TemplateArgument *Args, unsigned NumArgs, |
| 134 | void *&InsertPos) { |
| 135 | typedef SpecEntryTraits<EntryType> SETraits; |
| 136 | llvm::FoldingSetNodeID ID; |
| 137 | EntryType::Profile(ID,Args,NumArgs, getASTContext()); |
| 138 | EntryType *Entry = Specs.FindNodeOrInsertPos(ID, InsertPos); |
| 139 | return Entry ? SETraits::getMostRecentDeclaration(Entry) : 0; |
| 140 | } |
| 141 | |
Peter Collingbourne | 9eabeba | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 142 | //===----------------------------------------------------------------------===// |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 143 | // FunctionTemplateDecl Implementation |
| 144 | //===----------------------------------------------------------------------===// |
| 145 | |
Douglas Gregor | 0054531 | 2010-05-23 18:26:36 +0000 | [diff] [blame] | 146 | void FunctionTemplateDecl::DeallocateCommon(void *Ptr) { |
| 147 | static_cast<Common *>(Ptr)->~Common(); |
| 148 | } |
| 149 | |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 150 | FunctionTemplateDecl *FunctionTemplateDecl::Create(ASTContext &C, |
| 151 | DeclContext *DC, |
| 152 | SourceLocation L, |
| 153 | DeclarationName Name, |
Douglas Gregor | 127102b | 2009-06-29 20:59:39 +0000 | [diff] [blame] | 154 | TemplateParameterList *Params, |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 155 | NamedDecl *Decl) { |
| 156 | return new (C) FunctionTemplateDecl(DC, L, Name, Params, Decl); |
| 157 | } |
| 158 | |
Peter Collingbourne | 9eabeba | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 159 | RedeclarableTemplateDecl::CommonBase *FunctionTemplateDecl::newCommon() { |
| 160 | Common *CommonPtr = new (getASTContext()) Common; |
| 161 | getASTContext().AddDeallocation(DeallocateCommon, CommonPtr); |
| 162 | return CommonPtr; |
| 163 | } |
| 164 | |
Argyrios Kyrtzidis | 2c853e4 | 2010-07-20 13:59:58 +0000 | [diff] [blame] | 165 | FunctionDecl * |
| 166 | FunctionTemplateDecl::findSpecialization(const TemplateArgument *Args, |
| 167 | unsigned NumArgs, void *&InsertPos) { |
Peter Collingbourne | 4048590 | 2010-07-30 17:09:04 +0000 | [diff] [blame^] | 168 | return findSpecializationImpl(getSpecializations(), Args, NumArgs, InsertPos); |
Argyrios Kyrtzidis | 2c853e4 | 2010-07-20 13:59:58 +0000 | [diff] [blame] | 169 | } |
| 170 | |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 171 | //===----------------------------------------------------------------------===// |
| 172 | // ClassTemplateDecl Implementation |
| 173 | //===----------------------------------------------------------------------===// |
| 174 | |
Douglas Gregor | 0054531 | 2010-05-23 18:26:36 +0000 | [diff] [blame] | 175 | void ClassTemplateDecl::DeallocateCommon(void *Ptr) { |
| 176 | static_cast<Common *>(Ptr)->~Common(); |
| 177 | } |
| 178 | |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 179 | ClassTemplateDecl *ClassTemplateDecl::Create(ASTContext &C, |
| 180 | DeclContext *DC, |
| 181 | SourceLocation L, |
| 182 | DeclarationName Name, |
| 183 | TemplateParameterList *Params, |
Douglas Gregor | 5953d8b | 2009-03-19 17:26:29 +0000 | [diff] [blame] | 184 | NamedDecl *Decl, |
| 185 | ClassTemplateDecl *PrevDecl) { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 186 | ClassTemplateDecl *New = new (C) ClassTemplateDecl(DC, L, Name, Params, Decl); |
Argyrios Kyrtzidis | 5bf1bdc | 2010-06-21 10:57:41 +0000 | [diff] [blame] | 187 | New->setPreviousDeclaration(PrevDecl); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 188 | return New; |
Douglas Gregor | 5953d8b | 2009-03-19 17:26:29 +0000 | [diff] [blame] | 189 | } |
| 190 | |
Peter Collingbourne | 9eabeba | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 191 | RedeclarableTemplateDecl::CommonBase *ClassTemplateDecl::newCommon() { |
| 192 | Common *CommonPtr = new (getASTContext()) Common; |
| 193 | getASTContext().AddDeallocation(DeallocateCommon, CommonPtr); |
| 194 | return CommonPtr; |
| 195 | } |
| 196 | |
Argyrios Kyrtzidis | cc0b1bc | 2010-07-20 13:59:28 +0000 | [diff] [blame] | 197 | ClassTemplateSpecializationDecl * |
| 198 | ClassTemplateDecl::findSpecialization(const TemplateArgument *Args, |
| 199 | unsigned NumArgs, void *&InsertPos) { |
Peter Collingbourne | 4048590 | 2010-07-30 17:09:04 +0000 | [diff] [blame^] | 200 | return findSpecializationImpl(getSpecializations(), Args, NumArgs, InsertPos); |
Argyrios Kyrtzidis | cc0b1bc | 2010-07-20 13:59:28 +0000 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | ClassTemplatePartialSpecializationDecl * |
| 204 | ClassTemplateDecl::findPartialSpecialization(const TemplateArgument *Args, |
| 205 | unsigned NumArgs, |
| 206 | void *&InsertPos) { |
Peter Collingbourne | 4048590 | 2010-07-30 17:09:04 +0000 | [diff] [blame^] | 207 | return findSpecializationImpl(getPartialSpecializations(), Args, NumArgs, |
| 208 | InsertPos); |
Argyrios Kyrtzidis | cc0b1bc | 2010-07-20 13:59:28 +0000 | [diff] [blame] | 209 | } |
| 210 | |
Douglas Gregor | dc60c1e | 2010-04-30 05:56:50 +0000 | [diff] [blame] | 211 | void ClassTemplateDecl::getPartialSpecializations( |
| 212 | llvm::SmallVectorImpl<ClassTemplatePartialSpecializationDecl *> &PS) { |
| 213 | llvm::FoldingSet<ClassTemplatePartialSpecializationDecl> &PartialSpecs |
Argyrios Kyrtzidis | 5bf1bdc | 2010-06-21 10:57:41 +0000 | [diff] [blame] | 214 | = getPartialSpecializations(); |
Douglas Gregor | dc60c1e | 2010-04-30 05:56:50 +0000 | [diff] [blame] | 215 | PS.clear(); |
| 216 | PS.resize(PartialSpecs.size()); |
| 217 | for (llvm::FoldingSet<ClassTemplatePartialSpecializationDecl>::iterator |
| 218 | P = PartialSpecs.begin(), PEnd = PartialSpecs.end(); |
| 219 | P != PEnd; ++P) { |
| 220 | assert(!PS[P->getSequenceNumber()]); |
Argyrios Kyrtzidis | cc0b1bc | 2010-07-20 13:59:28 +0000 | [diff] [blame] | 221 | PS[P->getSequenceNumber()] = P->getMostRecentDeclaration(); |
Douglas Gregor | dc60c1e | 2010-04-30 05:56:50 +0000 | [diff] [blame] | 222 | } |
| 223 | } |
| 224 | |
Douglas Gregor | b88e888 | 2009-07-30 17:40:51 +0000 | [diff] [blame] | 225 | ClassTemplatePartialSpecializationDecl * |
| 226 | ClassTemplateDecl::findPartialSpecialization(QualType T) { |
| 227 | ASTContext &Context = getASTContext(); |
| 228 | typedef llvm::FoldingSet<ClassTemplatePartialSpecializationDecl>::iterator |
| 229 | partial_spec_iterator; |
| 230 | for (partial_spec_iterator P = getPartialSpecializations().begin(), |
| 231 | PEnd = getPartialSpecializations().end(); |
| 232 | P != PEnd; ++P) { |
John McCall | 31f17ec | 2010-04-27 00:57:59 +0000 | [diff] [blame] | 233 | if (Context.hasSameType(P->getInjectedSpecializationType(), T)) |
Argyrios Kyrtzidis | cc0b1bc | 2010-07-20 13:59:28 +0000 | [diff] [blame] | 234 | return P->getMostRecentDeclaration(); |
| 235 | } |
| 236 | |
| 237 | return 0; |
| 238 | } |
| 239 | |
| 240 | ClassTemplatePartialSpecializationDecl * |
| 241 | ClassTemplateDecl::findPartialSpecInstantiatedFromMember( |
| 242 | ClassTemplatePartialSpecializationDecl *D) { |
| 243 | Decl *DCanon = D->getCanonicalDecl(); |
| 244 | for (llvm::FoldingSet<ClassTemplatePartialSpecializationDecl>::iterator |
| 245 | P = getPartialSpecializations().begin(), |
| 246 | PEnd = getPartialSpecializations().end(); |
| 247 | P != PEnd; ++P) { |
| 248 | if (P->getInstantiatedFromMember()->getCanonicalDecl() == DCanon) |
| 249 | return P->getMostRecentDeclaration(); |
Douglas Gregor | b88e888 | 2009-07-30 17:40:51 +0000 | [diff] [blame] | 250 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 251 | |
Douglas Gregor | b88e888 | 2009-07-30 17:40:51 +0000 | [diff] [blame] | 252 | return 0; |
| 253 | } |
| 254 | |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 255 | QualType |
Douglas Gregor | 24bae92 | 2010-07-08 18:37:38 +0000 | [diff] [blame] | 256 | ClassTemplateDecl::getInjectedClassNameSpecialization() { |
Argyrios Kyrtzidis | 5bf1bdc | 2010-06-21 10:57:41 +0000 | [diff] [blame] | 257 | Common *CommonPtr = getCommonPtr(); |
Douglas Gregor | 7da97d0 | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 258 | if (!CommonPtr->InjectedClassNameType.isNull()) |
| 259 | return CommonPtr->InjectedClassNameType; |
| 260 | |
| 261 | // FIXME: n2800 14.6.1p1 should say how the template arguments |
| 262 | // corresponding to template parameter packs should be pack |
| 263 | // expansions. We already say that in 14.6.2.1p2, so it would be |
| 264 | // better to fix that redundancy. |
Douglas Gregor | 24bae92 | 2010-07-08 18:37:38 +0000 | [diff] [blame] | 265 | ASTContext &Context = getASTContext(); |
Douglas Gregor | 7da97d0 | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 266 | TemplateParameterList *Params = getTemplateParameters(); |
Douglas Gregor | 7da97d0 | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 267 | llvm::SmallVector<TemplateArgument, 16> TemplateArgs; |
Douglas Gregor | 7da97d0 | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 268 | TemplateArgs.reserve(Params->size()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 269 | for (TemplateParameterList::iterator Param = Params->begin(), |
| 270 | ParamEnd = Params->end(); |
Douglas Gregor | 7da97d0 | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 271 | Param != ParamEnd; ++Param) { |
| 272 | if (isa<TemplateTypeParmDecl>(*Param)) { |
| 273 | QualType ParamType = Context.getTypeDeclType(cast<TypeDecl>(*Param)); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 274 | TemplateArgs.push_back(TemplateArgument(ParamType)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 275 | } else if (NonTypeTemplateParmDecl *NTTP = |
Douglas Gregor | 7da97d0 | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 276 | dyn_cast<NonTypeTemplateParmDecl>(*Param)) { |
Chandler Carruth | b7de181 | 2010-01-31 07:24:03 +0000 | [diff] [blame] | 277 | Expr *E = new (Context) DeclRefExpr(NTTP, |
Douglas Gregor | 6398235 | 2010-07-13 18:40:04 +0000 | [diff] [blame] | 278 | NTTP->getType().getNonLValueExprType(Context), |
Douglas Gregor | 0da76df | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 279 | NTTP->getLocation()); |
Douglas Gregor | 7da97d0 | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 280 | TemplateArgs.push_back(TemplateArgument(E)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 281 | } else { |
Douglas Gregor | 7da97d0 | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 282 | TemplateTemplateParmDecl *TTP = cast<TemplateTemplateParmDecl>(*Param); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 283 | TemplateArgs.push_back(TemplateArgument(TemplateName(TTP))); |
Douglas Gregor | 7da97d0 | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 284 | } |
| 285 | } |
| 286 | |
Douglas Gregor | 7da97d0 | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 287 | CommonPtr->InjectedClassNameType |
Douglas Gregor | 1275ae0 | 2009-07-28 23:00:59 +0000 | [diff] [blame] | 288 | = Context.getTemplateSpecializationType(TemplateName(this), |
Douglas Gregor | 7da97d0 | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 289 | &TemplateArgs[0], |
Douglas Gregor | 1275ae0 | 2009-07-28 23:00:59 +0000 | [diff] [blame] | 290 | TemplateArgs.size()); |
Douglas Gregor | 7da97d0 | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 291 | return CommonPtr->InjectedClassNameType; |
| 292 | } |
| 293 | |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 294 | //===----------------------------------------------------------------------===// |
| 295 | // TemplateTypeParm Allocation/Deallocation Method Implementations |
| 296 | //===----------------------------------------------------------------------===// |
| 297 | |
| 298 | TemplateTypeParmDecl * |
| 299 | TemplateTypeParmDecl::Create(ASTContext &C, DeclContext *DC, |
| 300 | SourceLocation L, unsigned D, unsigned P, |
Anders Carlsson | 6d845ae | 2009-06-12 22:23:22 +0000 | [diff] [blame] | 301 | IdentifierInfo *Id, bool Typename, |
| 302 | bool ParameterPack) { |
Douglas Gregor | efed5c8 | 2010-06-16 15:23:05 +0000 | [diff] [blame] | 303 | QualType Type = C.getTemplateTypeParmType(D, P, ParameterPack, Id); |
| 304 | return new (C) TemplateTypeParmDecl(DC, L, Id, Typename, Type, ParameterPack); |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 305 | } |
| 306 | |
Argyrios Kyrtzidis | b8b03e6 | 2010-07-02 11:54:55 +0000 | [diff] [blame] | 307 | TemplateTypeParmDecl * |
| 308 | TemplateTypeParmDecl::Create(ASTContext &C, EmptyShell Empty) { |
| 309 | return new (C) TemplateTypeParmDecl(0, SourceLocation(), 0, false, |
| 310 | QualType(), false); |
| 311 | } |
| 312 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 313 | SourceLocation TemplateTypeParmDecl::getDefaultArgumentLoc() const { |
Abramo Bagnara | bd054db | 2010-05-20 10:00:11 +0000 | [diff] [blame] | 314 | return DefaultArgument->getTypeLoc().getSourceRange().getBegin(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 315 | } |
| 316 | |
Douglas Gregor | ed9c0f9 | 2009-10-29 00:04:11 +0000 | [diff] [blame] | 317 | unsigned TemplateTypeParmDecl::getDepth() const { |
| 318 | return TypeForDecl->getAs<TemplateTypeParmType>()->getDepth(); |
| 319 | } |
| 320 | |
| 321 | unsigned TemplateTypeParmDecl::getIndex() const { |
| 322 | return TypeForDecl->getAs<TemplateTypeParmType>()->getIndex(); |
| 323 | } |
| 324 | |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 325 | //===----------------------------------------------------------------------===// |
| 326 | // NonTypeTemplateParmDecl Method Implementations |
| 327 | //===----------------------------------------------------------------------===// |
| 328 | |
| 329 | NonTypeTemplateParmDecl * |
| 330 | NonTypeTemplateParmDecl::Create(ASTContext &C, DeclContext *DC, |
| 331 | SourceLocation L, unsigned D, unsigned P, |
| 332 | IdentifierInfo *Id, QualType T, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 333 | TypeSourceInfo *TInfo) { |
| 334 | return new (C) NonTypeTemplateParmDecl(DC, L, D, P, Id, T, TInfo); |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 335 | } |
| 336 | |
Douglas Gregor | d684b00 | 2009-02-10 19:49:53 +0000 | [diff] [blame] | 337 | SourceLocation NonTypeTemplateParmDecl::getDefaultArgumentLoc() const { |
Abramo Bagnara | d92f7a2 | 2010-06-09 09:26:05 +0000 | [diff] [blame] | 338 | return hasDefaultArgument() |
| 339 | ? getDefaultArgument()->getSourceRange().getBegin() |
| 340 | : SourceLocation(); |
Douglas Gregor | d684b00 | 2009-02-10 19:49:53 +0000 | [diff] [blame] | 341 | } |
| 342 | |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 343 | //===----------------------------------------------------------------------===// |
| 344 | // TemplateTemplateParmDecl Method Implementations |
| 345 | //===----------------------------------------------------------------------===// |
| 346 | |
| 347 | TemplateTemplateParmDecl * |
| 348 | TemplateTemplateParmDecl::Create(ASTContext &C, DeclContext *DC, |
| 349 | SourceLocation L, unsigned D, unsigned P, |
| 350 | IdentifierInfo *Id, |
| 351 | TemplateParameterList *Params) { |
| 352 | return new (C) TemplateTemplateParmDecl(DC, L, D, P, Id, Params); |
| 353 | } |
| 354 | |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 355 | //===----------------------------------------------------------------------===// |
Anders Carlsson | 9ba4164 | 2009-06-05 05:31:27 +0000 | [diff] [blame] | 356 | // TemplateArgumentListBuilder Implementation |
| 357 | //===----------------------------------------------------------------------===// |
Anders Carlsson | fb25052 | 2009-06-23 01:26:57 +0000 | [diff] [blame] | 358 | |
Chris Lattner | 98d279b | 2010-05-20 00:25:36 +0000 | [diff] [blame] | 359 | void TemplateArgumentListBuilder::Append(const TemplateArgument &Arg) { |
| 360 | assert((Arg.getKind() != TemplateArgument::Type || |
| 361 | Arg.getAsType().isCanonical()) && "Type must be canonical!"); |
| 362 | assert(FlatArgs.size() < MaxFlatArgs && "Argument list builder is full!"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 363 | assert(!StructuredArgs && |
Anders Carlsson | fb25052 | 2009-06-23 01:26:57 +0000 | [diff] [blame] | 364 | "Can't append arguments when an argument pack has been added!"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 365 | |
Chris Lattner | 98d279b | 2010-05-20 00:25:36 +0000 | [diff] [blame] | 366 | FlatArgs.push_back(Arg); |
Anders Carlsson | 9ba4164 | 2009-06-05 05:31:27 +0000 | [diff] [blame] | 367 | } |
| 368 | |
Anders Carlsson | fb25052 | 2009-06-23 01:26:57 +0000 | [diff] [blame] | 369 | void TemplateArgumentListBuilder::BeginPack() { |
| 370 | assert(!AddingToPack && "Already adding to pack!"); |
| 371 | assert(!StructuredArgs && "Argument list already contains a pack!"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 372 | |
Anders Carlsson | fb25052 | 2009-06-23 01:26:57 +0000 | [diff] [blame] | 373 | AddingToPack = true; |
Chris Lattner | 98d279b | 2010-05-20 00:25:36 +0000 | [diff] [blame] | 374 | PackBeginIndex = FlatArgs.size(); |
Anders Carlsson | 67e3320 | 2009-06-13 00:08:58 +0000 | [diff] [blame] | 375 | } |
| 376 | |
Anders Carlsson | fb25052 | 2009-06-23 01:26:57 +0000 | [diff] [blame] | 377 | void TemplateArgumentListBuilder::EndPack() { |
| 378 | assert(AddingToPack && "Not adding to pack!"); |
| 379 | assert(!StructuredArgs && "Argument list already contains a pack!"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 380 | |
Anders Carlsson | fb25052 | 2009-06-23 01:26:57 +0000 | [diff] [blame] | 381 | AddingToPack = false; |
Anders Carlsson | 3b36b66 | 2009-06-15 17:56:45 +0000 | [diff] [blame] | 382 | |
Chris Lattner | 304d0fa | 2010-05-20 00:26:28 +0000 | [diff] [blame] | 383 | // FIXME: This is a memory leak! |
Anders Carlsson | fb25052 | 2009-06-23 01:26:57 +0000 | [diff] [blame] | 384 | StructuredArgs = new TemplateArgument[MaxStructuredArgs]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 385 | |
Anders Carlsson | fb25052 | 2009-06-23 01:26:57 +0000 | [diff] [blame] | 386 | // First copy the flat entries over to the list (if any) |
| 387 | for (unsigned I = 0; I != PackBeginIndex; ++I) { |
| 388 | NumStructuredArgs++; |
| 389 | StructuredArgs[I] = FlatArgs[I]; |
| 390 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 391 | |
Anders Carlsson | fb25052 | 2009-06-23 01:26:57 +0000 | [diff] [blame] | 392 | // Next, set the pack. |
| 393 | TemplateArgument *PackArgs = 0; |
| 394 | unsigned NumPackArgs = NumFlatArgs - PackBeginIndex; |
Chris Lattner | 98d279b | 2010-05-20 00:25:36 +0000 | [diff] [blame] | 395 | // FIXME: NumPackArgs shouldn't be negative here??? |
Anders Carlsson | fb25052 | 2009-06-23 01:26:57 +0000 | [diff] [blame] | 396 | if (NumPackArgs) |
Chris Lattner | 98d279b | 2010-05-20 00:25:36 +0000 | [diff] [blame] | 397 | PackArgs = FlatArgs.data()+PackBeginIndex; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 398 | |
| 399 | StructuredArgs[NumStructuredArgs++].setArgumentPack(PackArgs, NumPackArgs, |
Anders Carlsson | fb25052 | 2009-06-23 01:26:57 +0000 | [diff] [blame] | 400 | /*CopyArgs=*/false); |
| 401 | } |
| 402 | |
Anders Carlsson | 9ba4164 | 2009-06-05 05:31:27 +0000 | [diff] [blame] | 403 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 7e06390 | 2009-05-11 23:53:27 +0000 | [diff] [blame] | 404 | // TemplateArgumentList Implementation |
| 405 | //===----------------------------------------------------------------------===// |
| 406 | TemplateArgumentList::TemplateArgumentList(ASTContext &Context, |
Anders Carlsson | e9c904b | 2009-06-05 04:47:51 +0000 | [diff] [blame] | 407 | TemplateArgumentListBuilder &Builder, |
Anders Carlsson | fb25052 | 2009-06-23 01:26:57 +0000 | [diff] [blame] | 408 | bool TakeArgs) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 409 | : FlatArguments(Builder.getFlatArguments(), TakeArgs), |
| 410 | NumFlatArguments(Builder.flatSize()), |
Anders Carlsson | fb25052 | 2009-06-23 01:26:57 +0000 | [diff] [blame] | 411 | StructuredArguments(Builder.getStructuredArguments(), TakeArgs), |
| 412 | NumStructuredArguments(Builder.structuredSize()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 413 | |
Anders Carlsson | fb25052 | 2009-06-23 01:26:57 +0000 | [diff] [blame] | 414 | if (!TakeArgs) |
| 415 | return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 416 | |
Chris Lattner | 56ef550 | 2010-05-20 00:11:47 +0000 | [diff] [blame] | 417 | // If this does take ownership of the arguments, then we have to new them |
| 418 | // and copy over. |
Ted Kremenek | 3458d43 | 2010-05-25 20:43:29 +0000 | [diff] [blame] | 419 | TemplateArgument *NewArgs = |
| 420 | new (Context) TemplateArgument[Builder.flatSize()]; |
Chris Lattner | 56ef550 | 2010-05-20 00:11:47 +0000 | [diff] [blame] | 421 | std::copy(Builder.getFlatArguments(), |
| 422 | Builder.getFlatArguments()+Builder.flatSize(), NewArgs); |
| 423 | FlatArguments.setPointer(NewArgs); |
| 424 | |
| 425 | // Just reuse the structured and flat arguments array if possible. |
| 426 | if (Builder.getStructuredArguments() == Builder.getFlatArguments()) { |
| 427 | StructuredArguments.setPointer(NewArgs); |
Anders Carlsson | fb25052 | 2009-06-23 01:26:57 +0000 | [diff] [blame] | 428 | StructuredArguments.setInt(0); |
Chris Lattner | 56ef550 | 2010-05-20 00:11:47 +0000 | [diff] [blame] | 429 | } else { |
Ted Kremenek | 3458d43 | 2010-05-25 20:43:29 +0000 | [diff] [blame] | 430 | TemplateArgument *NewSArgs = |
| 431 | new (Context) TemplateArgument[Builder.flatSize()]; |
Chris Lattner | 56ef550 | 2010-05-20 00:11:47 +0000 | [diff] [blame] | 432 | std::copy(Builder.getFlatArguments(), |
| 433 | Builder.getFlatArguments()+Builder.flatSize(), NewSArgs); |
| 434 | StructuredArguments.setPointer(NewSArgs); |
| 435 | } |
Douglas Gregor | 7e06390 | 2009-05-11 23:53:27 +0000 | [diff] [blame] | 436 | } |
| 437 | |
Argyrios Kyrtzidis | d091355 | 2010-06-22 09:54:51 +0000 | [diff] [blame] | 438 | TemplateArgumentList::TemplateArgumentList(ASTContext &Context, |
Argyrios Kyrtzidis | 94d228d | 2010-06-23 13:48:23 +0000 | [diff] [blame] | 439 | const TemplateArgument *Args, |
Argyrios Kyrtzidis | dc767e3 | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 440 | unsigned NumArgs) |
| 441 | : NumFlatArguments(0), NumStructuredArguments(0) { |
Argyrios Kyrtzidis | 94d228d | 2010-06-23 13:48:23 +0000 | [diff] [blame] | 442 | init(Context, Args, NumArgs); |
Argyrios Kyrtzidis | d091355 | 2010-06-22 09:54:51 +0000 | [diff] [blame] | 443 | } |
| 444 | |
Chris Lattner | 8859891 | 2010-05-20 00:19:09 +0000 | [diff] [blame] | 445 | /// Produces a shallow copy of the given template argument list. This |
| 446 | /// assumes that the input argument list outlives it. This takes the list as |
| 447 | /// a pointer to avoid looking like a copy constructor, since this really |
| 448 | /// really isn't safe to use that way. |
| 449 | TemplateArgumentList::TemplateArgumentList(const TemplateArgumentList *Other) |
| 450 | : FlatArguments(Other->FlatArguments.getPointer(), false), |
| 451 | NumFlatArguments(Other->flat_size()), |
| 452 | StructuredArguments(Other->StructuredArguments.getPointer(), false), |
| 453 | NumStructuredArguments(Other->NumStructuredArguments) { } |
Douglas Gregor | b9aa6b2 | 2009-09-24 23:14:47 +0000 | [diff] [blame] | 454 | |
Argyrios Kyrtzidis | 94d228d | 2010-06-23 13:48:23 +0000 | [diff] [blame] | 455 | void TemplateArgumentList::init(ASTContext &Context, |
| 456 | const TemplateArgument *Args, |
| 457 | unsigned NumArgs) { |
| 458 | assert(NumFlatArguments == 0 && NumStructuredArguments == 0 && |
| 459 | "Already initialized!"); |
| 460 | |
| 461 | NumFlatArguments = NumStructuredArguments = NumArgs; |
| 462 | TemplateArgument *NewArgs = new (Context) TemplateArgument[NumArgs]; |
| 463 | std::copy(Args, Args+NumArgs, NewArgs); |
| 464 | FlatArguments.setPointer(NewArgs); |
| 465 | FlatArguments.setInt(1); // Owns the pointer. |
| 466 | |
| 467 | // Just reuse the flat arguments array. |
| 468 | StructuredArguments.setPointer(NewArgs); |
| 469 | StructuredArguments.setInt(0); // Doesn't own the pointer. |
| 470 | } |
| 471 | |
Douglas Gregor | 7e06390 | 2009-05-11 23:53:27 +0000 | [diff] [blame] | 472 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 473 | // ClassTemplateSpecializationDecl Implementation |
| 474 | //===----------------------------------------------------------------------===// |
| 475 | ClassTemplateSpecializationDecl:: |
Douglas Gregor | 13c8577 | 2010-05-06 00:28:52 +0000 | [diff] [blame] | 476 | ClassTemplateSpecializationDecl(ASTContext &Context, Kind DK, TagKind TK, |
Douglas Gregor | 7e06390 | 2009-05-11 23:53:27 +0000 | [diff] [blame] | 477 | DeclContext *DC, SourceLocation L, |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 478 | ClassTemplateDecl *SpecializedTemplate, |
Douglas Gregor | 8e9e9ef | 2009-07-29 23:36:44 +0000 | [diff] [blame] | 479 | TemplateArgumentListBuilder &Builder, |
| 480 | ClassTemplateSpecializationDecl *PrevDecl) |
Douglas Gregor | 13c8577 | 2010-05-06 00:28:52 +0000 | [diff] [blame] | 481 | : CXXRecordDecl(DK, TK, DC, L, |
Douglas Gregor | 8e9e9ef | 2009-07-29 23:36:44 +0000 | [diff] [blame] | 482 | SpecializedTemplate->getIdentifier(), |
| 483 | PrevDecl), |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 484 | SpecializedTemplate(SpecializedTemplate), |
Abramo Bagnara | c98971d | 2010-06-12 07:44:57 +0000 | [diff] [blame] | 485 | ExplicitInfo(0), |
Anders Carlsson | fb25052 | 2009-06-23 01:26:57 +0000 | [diff] [blame] | 486 | TemplateArgs(Context, Builder, /*TakeArgs=*/true), |
Douglas Gregor | 7e06390 | 2009-05-11 23:53:27 +0000 | [diff] [blame] | 487 | SpecializationKind(TSK_Undeclared) { |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 488 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 489 | |
Argyrios Kyrtzidis | 94d228d | 2010-06-23 13:48:23 +0000 | [diff] [blame] | 490 | ClassTemplateSpecializationDecl::ClassTemplateSpecializationDecl(Kind DK) |
| 491 | : CXXRecordDecl(DK, TTK_Struct, 0, SourceLocation(), 0, 0), |
| 492 | ExplicitInfo(0), |
| 493 | SpecializationKind(TSK_Undeclared) { |
| 494 | } |
| 495 | |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 496 | ClassTemplateSpecializationDecl * |
Douglas Gregor | 13c8577 | 2010-05-06 00:28:52 +0000 | [diff] [blame] | 497 | ClassTemplateSpecializationDecl::Create(ASTContext &Context, TagKind TK, |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 498 | DeclContext *DC, SourceLocation L, |
| 499 | ClassTemplateDecl *SpecializedTemplate, |
Anders Carlsson | 91fdf6f | 2009-06-05 04:06:48 +0000 | [diff] [blame] | 500 | TemplateArgumentListBuilder &Builder, |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 501 | ClassTemplateSpecializationDecl *PrevDecl) { |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 502 | ClassTemplateSpecializationDecl *Result |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 503 | = new (Context)ClassTemplateSpecializationDecl(Context, |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 504 | ClassTemplateSpecialization, |
Douglas Gregor | 13c8577 | 2010-05-06 00:28:52 +0000 | [diff] [blame] | 505 | TK, DC, L, |
Douglas Gregor | 7e06390 | 2009-05-11 23:53:27 +0000 | [diff] [blame] | 506 | SpecializedTemplate, |
Douglas Gregor | 8e9e9ef | 2009-07-29 23:36:44 +0000 | [diff] [blame] | 507 | Builder, |
| 508 | PrevDecl); |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 509 | Context.getTypeDeclType(Result, PrevDecl); |
| 510 | return Result; |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 511 | } |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 512 | |
Argyrios Kyrtzidis | 94d228d | 2010-06-23 13:48:23 +0000 | [diff] [blame] | 513 | ClassTemplateSpecializationDecl * |
Argyrios Kyrtzidis | b8b03e6 | 2010-07-02 11:54:55 +0000 | [diff] [blame] | 514 | ClassTemplateSpecializationDecl::Create(ASTContext &Context, EmptyShell Empty) { |
Argyrios Kyrtzidis | 94d228d | 2010-06-23 13:48:23 +0000 | [diff] [blame] | 515 | return |
| 516 | new (Context)ClassTemplateSpecializationDecl(ClassTemplateSpecialization); |
| 517 | } |
| 518 | |
John McCall | 136a698 | 2009-09-11 06:45:03 +0000 | [diff] [blame] | 519 | void |
| 520 | ClassTemplateSpecializationDecl::getNameForDiagnostic(std::string &S, |
| 521 | const PrintingPolicy &Policy, |
| 522 | bool Qualified) const { |
| 523 | NamedDecl::getNameForDiagnostic(S, Policy, Qualified); |
| 524 | |
| 525 | const TemplateArgumentList &TemplateArgs = getTemplateArgs(); |
| 526 | S += TemplateSpecializationType::PrintTemplateArgumentList( |
| 527 | TemplateArgs.getFlatArgumentList(), |
| 528 | TemplateArgs.flat_size(), |
| 529 | Policy); |
| 530 | } |
| 531 | |
Douglas Gregor | 37d93e9 | 2009-08-02 23:24:31 +0000 | [diff] [blame] | 532 | ClassTemplateDecl * |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 533 | ClassTemplateSpecializationDecl::getSpecializedTemplate() const { |
| 534 | if (SpecializedPartialSpecialization *PartialSpec |
Douglas Gregor | 37d93e9 | 2009-08-02 23:24:31 +0000 | [diff] [blame] | 535 | = SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization*>()) |
| 536 | return PartialSpec->PartialSpecialization->getSpecializedTemplate(); |
| 537 | return SpecializedTemplate.get<ClassTemplateDecl*>(); |
| 538 | } |
| 539 | |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 540 | //===----------------------------------------------------------------------===// |
| 541 | // ClassTemplatePartialSpecializationDecl Implementation |
| 542 | //===----------------------------------------------------------------------===// |
| 543 | ClassTemplatePartialSpecializationDecl * |
| 544 | ClassTemplatePartialSpecializationDecl:: |
Douglas Gregor | 13c8577 | 2010-05-06 00:28:52 +0000 | [diff] [blame] | 545 | Create(ASTContext &Context, TagKind TK,DeclContext *DC, SourceLocation L, |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 546 | TemplateParameterList *Params, |
| 547 | ClassTemplateDecl *SpecializedTemplate, |
Anders Carlsson | 91fdf6f | 2009-06-05 04:06:48 +0000 | [diff] [blame] | 548 | TemplateArgumentListBuilder &Builder, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 549 | const TemplateArgumentListInfo &ArgInfos, |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 550 | QualType CanonInjectedType, |
Douglas Gregor | dc60c1e | 2010-04-30 05:56:50 +0000 | [diff] [blame] | 551 | ClassTemplatePartialSpecializationDecl *PrevDecl, |
| 552 | unsigned SequenceNumber) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 553 | unsigned N = ArgInfos.size(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 554 | TemplateArgumentLoc *ClonedArgs = new (Context) TemplateArgumentLoc[N]; |
| 555 | for (unsigned I = 0; I != N; ++I) |
| 556 | ClonedArgs[I] = ArgInfos[I]; |
| 557 | |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 558 | ClassTemplatePartialSpecializationDecl *Result |
Douglas Gregor | 13c8577 | 2010-05-06 00:28:52 +0000 | [diff] [blame] | 559 | = new (Context)ClassTemplatePartialSpecializationDecl(Context, TK, |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 560 | DC, L, Params, |
| 561 | SpecializedTemplate, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 562 | Builder, |
| 563 | ClonedArgs, N, |
Douglas Gregor | dc60c1e | 2010-04-30 05:56:50 +0000 | [diff] [blame] | 564 | PrevDecl, |
| 565 | SequenceNumber); |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 566 | Result->setSpecializationKind(TSK_ExplicitSpecialization); |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 567 | |
| 568 | Context.getInjectedClassNameType(Result, CanonInjectedType); |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 569 | return Result; |
| 570 | } |
John McCall | dd4a3b0 | 2009-09-16 22:47:08 +0000 | [diff] [blame] | 571 | |
Argyrios Kyrtzidis | 94d228d | 2010-06-23 13:48:23 +0000 | [diff] [blame] | 572 | ClassTemplatePartialSpecializationDecl * |
Argyrios Kyrtzidis | b8b03e6 | 2010-07-02 11:54:55 +0000 | [diff] [blame] | 573 | ClassTemplatePartialSpecializationDecl::Create(ASTContext &Context, |
| 574 | EmptyShell Empty) { |
Argyrios Kyrtzidis | 94d228d | 2010-06-23 13:48:23 +0000 | [diff] [blame] | 575 | return new (Context)ClassTemplatePartialSpecializationDecl(); |
| 576 | } |
| 577 | |
| 578 | void ClassTemplatePartialSpecializationDecl:: |
| 579 | initTemplateArgsAsWritten(const TemplateArgumentListInfo &ArgInfos) { |
| 580 | assert(ArgsAsWritten == 0 && "ArgsAsWritten already set"); |
| 581 | unsigned N = ArgInfos.size(); |
| 582 | TemplateArgumentLoc *ClonedArgs |
| 583 | = new (getASTContext()) TemplateArgumentLoc[N]; |
| 584 | for (unsigned I = 0; I != N; ++I) |
| 585 | ClonedArgs[I] = ArgInfos[I]; |
| 586 | |
| 587 | ArgsAsWritten = ClonedArgs; |
| 588 | NumArgsAsWritten = N; |
| 589 | } |
| 590 | |
John McCall | dd4a3b0 | 2009-09-16 22:47:08 +0000 | [diff] [blame] | 591 | //===----------------------------------------------------------------------===// |
| 592 | // FriendTemplateDecl Implementation |
| 593 | //===----------------------------------------------------------------------===// |
| 594 | |
| 595 | FriendTemplateDecl *FriendTemplateDecl::Create(ASTContext &Context, |
| 596 | DeclContext *DC, |
| 597 | SourceLocation L, |
| 598 | unsigned NParams, |
| 599 | TemplateParameterList **Params, |
| 600 | FriendUnion Friend, |
| 601 | SourceLocation FLoc) { |
| 602 | FriendTemplateDecl *Result |
| 603 | = new (Context) FriendTemplateDecl(DC, L, NParams, Params, Friend, FLoc); |
| 604 | return Result; |
| 605 | } |
Argyrios Kyrtzidis | 554e6aa | 2010-07-22 16:04:10 +0000 | [diff] [blame] | 606 | |
| 607 | FriendTemplateDecl *FriendTemplateDecl::Create(ASTContext &Context, |
| 608 | EmptyShell Empty) { |
| 609 | return new (Context) FriendTemplateDecl(Empty); |
| 610 | } |