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