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 | |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 14 | #include "clang/AST/DeclTemplate.h" |
Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 15 | #include "clang/AST/ASTContext.h" |
| 16 | #include "clang/AST/ASTMutationListener.h" |
| 17 | #include "clang/AST/DeclCXX.h" |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 18 | #include "clang/AST/Expr.h" |
Douglas Gregor | b95cc97 | 2011-01-04 02:33:52 +0000 | [diff] [blame] | 19 | #include "clang/AST/ExprCXX.h" |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 20 | #include "clang/AST/TypeLoc.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), |
Richard Smith | 6964b3f | 2012-09-07 02:06:42 +0000 | [diff] [blame] | 35 | NumParams(NumParams), ContainsUnexpandedParameterPack(false) { |
| 36 | assert(this->NumParams == NumParams && "Too many template parameters"); |
| 37 | for (unsigned Idx = 0; Idx < NumParams; ++Idx) { |
| 38 | NamedDecl *P = Params[Idx]; |
| 39 | begin()[Idx] = P; |
| 40 | |
| 41 | if (!P->isTemplateParameterPack()) { |
| 42 | if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(P)) |
| 43 | if (NTTP->getType()->containsUnexpandedParameterPack()) |
| 44 | ContainsUnexpandedParameterPack = true; |
| 45 | |
| 46 | if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(P)) |
| 47 | if (TTP->getTemplateParameters()->containsUnexpandedParameterPack()) |
| 48 | ContainsUnexpandedParameterPack = true; |
| 49 | |
| 50 | // FIXME: If a default argument contains an unexpanded parameter pack, the |
| 51 | // template parameter list does too. |
| 52 | } |
| 53 | } |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | TemplateParameterList * |
Jay Foad | 4ba2a17 | 2011-01-12 09:06:06 +0000 | [diff] [blame] | 57 | TemplateParameterList::Create(const ASTContext &C, SourceLocation TemplateLoc, |
Douglas Gregor | bf4ea56 | 2009-09-15 16:23:51 +0000 | [diff] [blame] | 58 | SourceLocation LAngleLoc, NamedDecl **Params, |
Douglas Gregor | ddc29e1 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 59 | unsigned NumParams, SourceLocation RAngleLoc) { |
Douglas Gregor | bf4ea56 | 2009-09-15 16:23:51 +0000 | [diff] [blame] | 60 | unsigned Size = sizeof(TemplateParameterList) |
| 61 | + sizeof(NamedDecl *) * NumParams; |
Richard Smith | 1a30edb | 2012-08-16 22:51:34 +0000 | [diff] [blame] | 62 | unsigned Align = std::max(llvm::alignOf<TemplateParameterList>(), |
| 63 | llvm::alignOf<NamedDecl*>()); |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 64 | void *Mem = C.Allocate(Size, Align); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 65 | return new (Mem) TemplateParameterList(TemplateLoc, LAngleLoc, Params, |
Douglas Gregor | ddc29e1 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 66 | NumParams, RAngleLoc); |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 67 | } |
| 68 | |
Douglas Gregor | 62cb18d | 2009-02-11 18:16:40 +0000 | [diff] [blame] | 69 | unsigned TemplateParameterList::getMinRequiredArguments() const { |
Douglas Gregor | 6952f1e | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 70 | unsigned NumRequiredArgs = 0; |
| 71 | for (iterator P = const_cast<TemplateParameterList *>(this)->begin(), |
| 72 | PEnd = const_cast<TemplateParameterList *>(this)->end(); |
| 73 | P != PEnd; ++P) { |
| 74 | if ((*P)->isTemplateParameterPack()) { |
| 75 | if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(*P)) |
| 76 | if (NTTP->isExpandedParameterPack()) { |
| 77 | NumRequiredArgs += NTTP->getNumExpansionTypes(); |
| 78 | continue; |
| 79 | } |
| 80 | |
Douglas Gregor | 62cb18d | 2009-02-11 18:16:40 +0000 | [diff] [blame] | 81 | break; |
Douglas Gregor | 6952f1e | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | if (TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(*P)) { |
| 85 | if (TTP->hasDefaultArgument()) |
| 86 | break; |
| 87 | } else if (NonTypeTemplateParmDecl *NTTP |
| 88 | = dyn_cast<NonTypeTemplateParmDecl>(*P)) { |
| 89 | if (NTTP->hasDefaultArgument()) |
| 90 | break; |
| 91 | } else if (cast<TemplateTemplateParmDecl>(*P)->hasDefaultArgument()) |
| 92 | break; |
| 93 | |
| 94 | ++NumRequiredArgs; |
Douglas Gregor | 62cb18d | 2009-02-11 18:16:40 +0000 | [diff] [blame] | 95 | } |
Douglas Gregor | 6952f1e | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 96 | |
Douglas Gregor | 62cb18d | 2009-02-11 18:16:40 +0000 | [diff] [blame] | 97 | return NumRequiredArgs; |
| 98 | } |
| 99 | |
Douglas Gregor | ed9c0f9 | 2009-10-29 00:04:11 +0000 | [diff] [blame] | 100 | unsigned TemplateParameterList::getDepth() const { |
| 101 | if (size() == 0) |
| 102 | return 0; |
| 103 | |
| 104 | const NamedDecl *FirstParm = getParam(0); |
| 105 | if (const TemplateTypeParmDecl *TTP |
| 106 | = dyn_cast<TemplateTypeParmDecl>(FirstParm)) |
| 107 | return TTP->getDepth(); |
| 108 | else if (const NonTypeTemplateParmDecl *NTTP |
| 109 | = dyn_cast<NonTypeTemplateParmDecl>(FirstParm)) |
| 110 | return NTTP->getDepth(); |
| 111 | else |
| 112 | return cast<TemplateTemplateParmDecl>(FirstParm)->getDepth(); |
| 113 | } |
| 114 | |
Douglas Gregor | 787a40d | 2011-03-04 18:32:38 +0000 | [diff] [blame] | 115 | static void AdoptTemplateParameterList(TemplateParameterList *Params, |
| 116 | DeclContext *Owner) { |
| 117 | for (TemplateParameterList::iterator P = Params->begin(), |
| 118 | PEnd = Params->end(); |
| 119 | P != PEnd; ++P) { |
| 120 | (*P)->setDeclContext(Owner); |
| 121 | |
| 122 | if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(*P)) |
| 123 | AdoptTemplateParameterList(TTP->getTemplateParameters(), Owner); |
| 124 | } |
| 125 | } |
| 126 | |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 127 | //===----------------------------------------------------------------------===// |
Peter Collingbourne | 9eabeba | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 128 | // RedeclarableTemplateDecl Implementation |
| 129 | //===----------------------------------------------------------------------===// |
| 130 | |
Dmitri Gribenko | b76d971 | 2013-01-23 16:52:57 +0000 | [diff] [blame] | 131 | RedeclarableTemplateDecl::CommonBase *RedeclarableTemplateDecl::getCommonPtr() const { |
Douglas Gregor | 7c99bb5c | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 132 | if (!Common) { |
| 133 | // Walk the previous-declaration chain until we either find a declaration |
| 134 | // with a common pointer or we run out of previous declarations. |
Dmitri Gribenko | b76d971 | 2013-01-23 16:52:57 +0000 | [diff] [blame] | 135 | SmallVector<const RedeclarableTemplateDecl *, 2> PrevDecls; |
| 136 | for (const RedeclarableTemplateDecl *Prev = getPreviousDecl(); Prev; |
Douglas Gregor | ef96ee0 | 2012-01-14 16:38:05 +0000 | [diff] [blame] | 137 | Prev = Prev->getPreviousDecl()) { |
Douglas Gregor | 7c99bb5c | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 138 | if (Prev->Common) { |
| 139 | Common = Prev->Common; |
| 140 | break; |
| 141 | } |
| 142 | |
| 143 | PrevDecls.push_back(Prev); |
| 144 | } |
Peter Collingbourne | 9eabeba | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 145 | |
Douglas Gregor | 7c99bb5c | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 146 | // If we never found a common pointer, allocate one now. |
Douglas Gregor | 8a8950b | 2012-01-14 15:30:55 +0000 | [diff] [blame] | 147 | if (!Common) { |
| 148 | // FIXME: If any of the declarations is from an AST file, we probably |
| 149 | // need an update record to add the common data. |
| 150 | |
Douglas Gregor | 7c99bb5c | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 151 | Common = newCommon(getASTContext()); |
Douglas Gregor | 8a8950b | 2012-01-14 15:30:55 +0000 | [diff] [blame] | 152 | } |
Douglas Gregor | 7c99bb5c | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 153 | |
| 154 | // Update any previous declarations we saw with the common pointer. |
| 155 | for (unsigned I = 0, N = PrevDecls.size(); I != N; ++I) |
| 156 | PrevDecls[I]->Common = Common; |
Peter Collingbourne | 9eabeba | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 157 | } |
Peter Collingbourne | 9eabeba | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 158 | |
Douglas Gregor | 7c99bb5c | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 159 | return Common; |
Peter Collingbourne | f88718e | 2010-07-29 16:12:09 +0000 | [diff] [blame] | 160 | } |
| 161 | |
Peter Collingbourne | 4048590 | 2010-07-30 17:09:04 +0000 | [diff] [blame] | 162 | template <class EntryType> |
| 163 | typename RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::DeclType* |
| 164 | RedeclarableTemplateDecl::findSpecializationImpl( |
Chandler Carruth | d964d63 | 2012-05-03 23:49:05 +0000 | [diff] [blame] | 165 | llvm::FoldingSetVector<EntryType> &Specs, |
Peter Collingbourne | 4048590 | 2010-07-30 17:09:04 +0000 | [diff] [blame] | 166 | const TemplateArgument *Args, unsigned NumArgs, |
| 167 | void *&InsertPos) { |
| 168 | typedef SpecEntryTraits<EntryType> SETraits; |
| 169 | llvm::FoldingSetNodeID ID; |
| 170 | EntryType::Profile(ID,Args,NumArgs, getASTContext()); |
| 171 | EntryType *Entry = Specs.FindNodeOrInsertPos(ID, InsertPos); |
Douglas Gregor | ef96ee0 | 2012-01-14 16:38:05 +0000 | [diff] [blame] | 172 | return Entry ? SETraits::getMostRecentDecl(Entry) : 0; |
Peter Collingbourne | 4048590 | 2010-07-30 17:09:04 +0000 | [diff] [blame] | 173 | } |
| 174 | |
Douglas Gregor | c494f77 | 2011-03-05 17:54:25 +0000 | [diff] [blame] | 175 | /// \brief Generate the injected template arguments for the given template |
| 176 | /// parameter list, e.g., for the injected-class-name of a class template. |
| 177 | static void GenerateInjectedTemplateArgs(ASTContext &Context, |
| 178 | TemplateParameterList *Params, |
| 179 | TemplateArgument *Args) { |
| 180 | for (TemplateParameterList::iterator Param = Params->begin(), |
| 181 | ParamEnd = Params->end(); |
| 182 | Param != ParamEnd; ++Param) { |
| 183 | TemplateArgument Arg; |
| 184 | if (TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(*Param)) { |
| 185 | QualType ArgType = Context.getTypeDeclType(TTP); |
| 186 | if (TTP->isParameterPack()) |
David Blaikie | 66874fb | 2013-02-21 01:47:18 +0000 | [diff] [blame] | 187 | ArgType = Context.getPackExpansionType(ArgType, None); |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 188 | |
Douglas Gregor | c494f77 | 2011-03-05 17:54:25 +0000 | [diff] [blame] | 189 | Arg = TemplateArgument(ArgType); |
| 190 | } else if (NonTypeTemplateParmDecl *NTTP = |
| 191 | dyn_cast<NonTypeTemplateParmDecl>(*Param)) { |
John McCall | f4b88a4 | 2012-03-10 09:33:50 +0000 | [diff] [blame] | 192 | Expr *E = new (Context) DeclRefExpr(NTTP, /*enclosing*/ false, |
Douglas Gregor | c494f77 | 2011-03-05 17:54:25 +0000 | [diff] [blame] | 193 | NTTP->getType().getNonLValueExprType(Context), |
| 194 | Expr::getValueKindForType(NTTP->getType()), |
| 195 | NTTP->getLocation()); |
| 196 | |
| 197 | if (NTTP->isParameterPack()) |
David Blaikie | 66874fb | 2013-02-21 01:47:18 +0000 | [diff] [blame] | 198 | E = new (Context) PackExpansionExpr(Context.DependentTy, E, |
| 199 | NTTP->getLocation(), None); |
Douglas Gregor | c494f77 | 2011-03-05 17:54:25 +0000 | [diff] [blame] | 200 | Arg = TemplateArgument(E); |
| 201 | } else { |
| 202 | TemplateTemplateParmDecl *TTP = cast<TemplateTemplateParmDecl>(*Param); |
| 203 | if (TTP->isParameterPack()) |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 204 | Arg = TemplateArgument(TemplateName(TTP), Optional<unsigned>()); |
Douglas Gregor | c494f77 | 2011-03-05 17:54:25 +0000 | [diff] [blame] | 205 | else |
| 206 | Arg = TemplateArgument(TemplateName(TTP)); |
| 207 | } |
| 208 | |
| 209 | if ((*Param)->isTemplateParameterPack()) |
| 210 | Arg = TemplateArgument::CreatePackCopy(Context, &Arg, 1); |
| 211 | |
| 212 | *Args++ = Arg; |
| 213 | } |
| 214 | } |
| 215 | |
Peter Collingbourne | 9eabeba | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 216 | //===----------------------------------------------------------------------===// |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 217 | // FunctionTemplateDecl Implementation |
| 218 | //===----------------------------------------------------------------------===// |
| 219 | |
Douglas Gregor | 0054531 | 2010-05-23 18:26:36 +0000 | [diff] [blame] | 220 | void FunctionTemplateDecl::DeallocateCommon(void *Ptr) { |
| 221 | static_cast<Common *>(Ptr)->~Common(); |
| 222 | } |
| 223 | |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 224 | FunctionTemplateDecl *FunctionTemplateDecl::Create(ASTContext &C, |
| 225 | DeclContext *DC, |
| 226 | SourceLocation L, |
| 227 | DeclarationName Name, |
Douglas Gregor | 127102b | 2009-06-29 20:59:39 +0000 | [diff] [blame] | 228 | TemplateParameterList *Params, |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 229 | NamedDecl *Decl) { |
Douglas Gregor | 787a40d | 2011-03-04 18:32:38 +0000 | [diff] [blame] | 230 | AdoptTemplateParameterList(Params, cast<DeclContext>(Decl)); |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 231 | return new (C) FunctionTemplateDecl(DC, L, Name, Params, Decl); |
| 232 | } |
| 233 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 234 | FunctionTemplateDecl *FunctionTemplateDecl::CreateDeserialized(ASTContext &C, |
| 235 | unsigned ID) { |
| 236 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(FunctionTemplateDecl)); |
| 237 | return new (Mem) FunctionTemplateDecl(0, SourceLocation(), DeclarationName(), |
| 238 | 0, 0); |
Douglas Gregor | 9a299e0 | 2011-03-04 17:52:15 +0000 | [diff] [blame] | 239 | } |
| 240 | |
Argyrios Kyrtzidis | 6b54151 | 2010-09-08 19:31:22 +0000 | [diff] [blame] | 241 | RedeclarableTemplateDecl::CommonBase * |
Dmitri Gribenko | b76d971 | 2013-01-23 16:52:57 +0000 | [diff] [blame] | 242 | FunctionTemplateDecl::newCommon(ASTContext &C) const { |
Argyrios Kyrtzidis | 6b54151 | 2010-09-08 19:31:22 +0000 | [diff] [blame] | 243 | Common *CommonPtr = new (C) Common; |
| 244 | C.AddDeallocation(DeallocateCommon, CommonPtr); |
Peter Collingbourne | 9eabeba | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 245 | return CommonPtr; |
| 246 | } |
| 247 | |
Richard Smith | 6982bf4 | 2013-06-28 04:37:53 +0000 | [diff] [blame] | 248 | void FunctionTemplateDecl::LoadLazySpecializations() const { |
| 249 | Common *CommonPtr = getCommonPtr(); |
| 250 | if (CommonPtr->LazySpecializations) { |
| 251 | ASTContext &Context = getASTContext(); |
| 252 | uint32_t *Specs = CommonPtr->LazySpecializations; |
| 253 | CommonPtr->LazySpecializations = 0; |
| 254 | for (uint32_t I = 0, N = *Specs++; I != N; ++I) |
| 255 | (void)Context.getExternalSource()->GetExternalDecl(Specs[I]); |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | llvm::FoldingSetVector<FunctionTemplateSpecializationInfo> & |
| 260 | FunctionTemplateDecl::getSpecializations() const { |
| 261 | LoadLazySpecializations(); |
| 262 | return getCommonPtr()->Specializations; |
| 263 | } |
| 264 | |
Argyrios Kyrtzidis | 2c853e4 | 2010-07-20 13:59:58 +0000 | [diff] [blame] | 265 | FunctionDecl * |
| 266 | FunctionTemplateDecl::findSpecialization(const TemplateArgument *Args, |
| 267 | unsigned NumArgs, void *&InsertPos) { |
Peter Collingbourne | 4048590 | 2010-07-30 17:09:04 +0000 | [diff] [blame] | 268 | return findSpecializationImpl(getSpecializations(), Args, NumArgs, InsertPos); |
Argyrios Kyrtzidis | 2c853e4 | 2010-07-20 13:59:58 +0000 | [diff] [blame] | 269 | } |
| 270 | |
Sebastian Redl | 5bbcdbf | 2011-04-14 14:07:59 +0000 | [diff] [blame] | 271 | void FunctionTemplateDecl::addSpecialization( |
| 272 | FunctionTemplateSpecializationInfo *Info, void *InsertPos) { |
Douglas Gregor | 1e1e972 | 2012-03-28 14:34:23 +0000 | [diff] [blame] | 273 | if (InsertPos) |
| 274 | getSpecializations().InsertNode(Info, InsertPos); |
| 275 | else |
| 276 | getSpecializations().GetOrInsertNode(Info); |
Sebastian Redl | 5bbcdbf | 2011-04-14 14:07:59 +0000 | [diff] [blame] | 277 | if (ASTMutationListener *L = getASTMutationListener()) |
| 278 | L->AddedCXXTemplateSpecialization(this, Info->Function); |
| 279 | } |
| 280 | |
Richard Smith | 7a9f7c7 | 2013-05-17 03:04:50 +0000 | [diff] [blame] | 281 | ArrayRef<TemplateArgument> FunctionTemplateDecl::getInjectedTemplateArgs() { |
Douglas Gregor | c494f77 | 2011-03-05 17:54:25 +0000 | [diff] [blame] | 282 | TemplateParameterList *Params = getTemplateParameters(); |
| 283 | Common *CommonPtr = getCommonPtr(); |
| 284 | if (!CommonPtr->InjectedArgs) { |
| 285 | CommonPtr->InjectedArgs |
Richard Smith | 7a9f7c7 | 2013-05-17 03:04:50 +0000 | [diff] [blame] | 286 | = new (getASTContext()) TemplateArgument[Params->size()]; |
| 287 | GenerateInjectedTemplateArgs(getASTContext(), Params, |
Douglas Gregor | c494f77 | 2011-03-05 17:54:25 +0000 | [diff] [blame] | 288 | CommonPtr->InjectedArgs); |
| 289 | } |
Richard Smith | 7a9f7c7 | 2013-05-17 03:04:50 +0000 | [diff] [blame] | 290 | |
| 291 | return llvm::makeArrayRef(CommonPtr->InjectedArgs, Params->size()); |
Douglas Gregor | c494f77 | 2011-03-05 17:54:25 +0000 | [diff] [blame] | 292 | } |
| 293 | |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 294 | //===----------------------------------------------------------------------===// |
| 295 | // ClassTemplateDecl Implementation |
| 296 | //===----------------------------------------------------------------------===// |
| 297 | |
Douglas Gregor | 0054531 | 2010-05-23 18:26:36 +0000 | [diff] [blame] | 298 | void ClassTemplateDecl::DeallocateCommon(void *Ptr) { |
| 299 | static_cast<Common *>(Ptr)->~Common(); |
| 300 | } |
| 301 | |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 302 | ClassTemplateDecl *ClassTemplateDecl::Create(ASTContext &C, |
| 303 | DeclContext *DC, |
| 304 | SourceLocation L, |
| 305 | DeclarationName Name, |
| 306 | TemplateParameterList *Params, |
Douglas Gregor | 5953d8b | 2009-03-19 17:26:29 +0000 | [diff] [blame] | 307 | NamedDecl *Decl, |
| 308 | ClassTemplateDecl *PrevDecl) { |
Douglas Gregor | 787a40d | 2011-03-04 18:32:38 +0000 | [diff] [blame] | 309 | AdoptTemplateParameterList(Params, cast<DeclContext>(Decl)); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 310 | ClassTemplateDecl *New = new (C) ClassTemplateDecl(DC, L, Name, Params, Decl); |
Argyrios Kyrtzidis | 5bf1bdc | 2010-06-21 10:57:41 +0000 | [diff] [blame] | 311 | New->setPreviousDeclaration(PrevDecl); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 312 | return New; |
Douglas Gregor | 5953d8b | 2009-03-19 17:26:29 +0000 | [diff] [blame] | 313 | } |
| 314 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 315 | ClassTemplateDecl *ClassTemplateDecl::CreateDeserialized(ASTContext &C, |
| 316 | unsigned ID) { |
| 317 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ClassTemplateDecl)); |
| 318 | return new (Mem) ClassTemplateDecl(EmptyShell()); |
Douglas Gregor | 9a299e0 | 2011-03-04 17:52:15 +0000 | [diff] [blame] | 319 | } |
| 320 | |
Dmitri Gribenko | e252a89 | 2013-02-14 13:20:36 +0000 | [diff] [blame] | 321 | void ClassTemplateDecl::LoadLazySpecializations() const { |
Douglas Gregor | c8e5cf8 | 2010-10-27 22:21:36 +0000 | [diff] [blame] | 322 | Common *CommonPtr = getCommonPtr(); |
| 323 | if (CommonPtr->LazySpecializations) { |
| 324 | ASTContext &Context = getASTContext(); |
| 325 | uint32_t *Specs = CommonPtr->LazySpecializations; |
| 326 | CommonPtr->LazySpecializations = 0; |
| 327 | for (uint32_t I = 0, N = *Specs++; I != N; ++I) |
| 328 | (void)Context.getExternalSource()->GetExternalDecl(Specs[I]); |
| 329 | } |
| 330 | } |
| 331 | |
Chandler Carruth | d964d63 | 2012-05-03 23:49:05 +0000 | [diff] [blame] | 332 | llvm::FoldingSetVector<ClassTemplateSpecializationDecl> & |
Dmitri Gribenko | e252a89 | 2013-02-14 13:20:36 +0000 | [diff] [blame] | 333 | ClassTemplateDecl::getSpecializations() const { |
Douglas Gregor | c8e5cf8 | 2010-10-27 22:21:36 +0000 | [diff] [blame] | 334 | LoadLazySpecializations(); |
| 335 | return getCommonPtr()->Specializations; |
| 336 | } |
| 337 | |
Chandler Carruth | d964d63 | 2012-05-03 23:49:05 +0000 | [diff] [blame] | 338 | llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> & |
Douglas Gregor | c8e5cf8 | 2010-10-27 22:21:36 +0000 | [diff] [blame] | 339 | ClassTemplateDecl::getPartialSpecializations() { |
| 340 | LoadLazySpecializations(); |
| 341 | return getCommonPtr()->PartialSpecializations; |
| 342 | } |
| 343 | |
Argyrios Kyrtzidis | 6b54151 | 2010-09-08 19:31:22 +0000 | [diff] [blame] | 344 | RedeclarableTemplateDecl::CommonBase * |
Dmitri Gribenko | b76d971 | 2013-01-23 16:52:57 +0000 | [diff] [blame] | 345 | ClassTemplateDecl::newCommon(ASTContext &C) const { |
Argyrios Kyrtzidis | 6b54151 | 2010-09-08 19:31:22 +0000 | [diff] [blame] | 346 | Common *CommonPtr = new (C) Common; |
| 347 | C.AddDeallocation(DeallocateCommon, CommonPtr); |
Peter Collingbourne | 9eabeba | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 348 | return CommonPtr; |
| 349 | } |
| 350 | |
Argyrios Kyrtzidis | cc0b1bc | 2010-07-20 13:59:28 +0000 | [diff] [blame] | 351 | ClassTemplateSpecializationDecl * |
| 352 | ClassTemplateDecl::findSpecialization(const TemplateArgument *Args, |
| 353 | unsigned NumArgs, void *&InsertPos) { |
Peter Collingbourne | 4048590 | 2010-07-30 17:09:04 +0000 | [diff] [blame] | 354 | return findSpecializationImpl(getSpecializations(), Args, NumArgs, InsertPos); |
Argyrios Kyrtzidis | cc0b1bc | 2010-07-20 13:59:28 +0000 | [diff] [blame] | 355 | } |
| 356 | |
Argyrios Kyrtzidis | bef1a7b | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 357 | void ClassTemplateDecl::AddSpecialization(ClassTemplateSpecializationDecl *D, |
| 358 | void *InsertPos) { |
Douglas Gregor | 1e1e972 | 2012-03-28 14:34:23 +0000 | [diff] [blame] | 359 | if (InsertPos) |
| 360 | getSpecializations().InsertNode(D, InsertPos); |
| 361 | else { |
| 362 | ClassTemplateSpecializationDecl *Existing |
| 363 | = getSpecializations().GetOrInsertNode(D); |
| 364 | (void)Existing; |
| 365 | assert(Existing->isCanonicalDecl() && "Non-canonical specialization?"); |
| 366 | } |
Argyrios Kyrtzidis | bef1a7b | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 367 | if (ASTMutationListener *L = getASTMutationListener()) |
| 368 | L->AddedCXXTemplateSpecialization(this, D); |
| 369 | } |
| 370 | |
Argyrios Kyrtzidis | cc0b1bc | 2010-07-20 13:59:28 +0000 | [diff] [blame] | 371 | ClassTemplatePartialSpecializationDecl * |
| 372 | ClassTemplateDecl::findPartialSpecialization(const TemplateArgument *Args, |
| 373 | unsigned NumArgs, |
| 374 | void *&InsertPos) { |
Peter Collingbourne | 4048590 | 2010-07-30 17:09:04 +0000 | [diff] [blame] | 375 | return findSpecializationImpl(getPartialSpecializations(), Args, NumArgs, |
| 376 | InsertPos); |
Argyrios Kyrtzidis | cc0b1bc | 2010-07-20 13:59:28 +0000 | [diff] [blame] | 377 | } |
| 378 | |
Argyrios Kyrtzidis | bef1a7b | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 379 | void ClassTemplateDecl::AddPartialSpecialization( |
| 380 | ClassTemplatePartialSpecializationDecl *D, |
| 381 | void *InsertPos) { |
Douglas Gregor | 1e1e972 | 2012-03-28 14:34:23 +0000 | [diff] [blame] | 382 | if (InsertPos) |
| 383 | getPartialSpecializations().InsertNode(D, InsertPos); |
| 384 | else { |
| 385 | ClassTemplatePartialSpecializationDecl *Existing |
| 386 | = getPartialSpecializations().GetOrInsertNode(D); |
| 387 | (void)Existing; |
| 388 | assert(Existing->isCanonicalDecl() && "Non-canonical specialization?"); |
| 389 | } |
| 390 | |
Argyrios Kyrtzidis | bef1a7b | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 391 | if (ASTMutationListener *L = getASTMutationListener()) |
| 392 | L->AddedCXXTemplateSpecialization(this, D); |
| 393 | } |
| 394 | |
Douglas Gregor | dc60c1e | 2010-04-30 05:56:50 +0000 | [diff] [blame] | 395 | void ClassTemplateDecl::getPartialSpecializations( |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 396 | SmallVectorImpl<ClassTemplatePartialSpecializationDecl *> &PS) { |
Chandler Carruth | d964d63 | 2012-05-03 23:49:05 +0000 | [diff] [blame] | 397 | llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> &PartialSpecs |
Argyrios Kyrtzidis | 5bf1bdc | 2010-06-21 10:57:41 +0000 | [diff] [blame] | 398 | = getPartialSpecializations(); |
Douglas Gregor | dc60c1e | 2010-04-30 05:56:50 +0000 | [diff] [blame] | 399 | PS.clear(); |
| 400 | PS.resize(PartialSpecs.size()); |
Chandler Carruth | d964d63 | 2012-05-03 23:49:05 +0000 | [diff] [blame] | 401 | for (llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl>::iterator |
Douglas Gregor | dc60c1e | 2010-04-30 05:56:50 +0000 | [diff] [blame] | 402 | P = PartialSpecs.begin(), PEnd = PartialSpecs.end(); |
| 403 | P != PEnd; ++P) { |
| 404 | assert(!PS[P->getSequenceNumber()]); |
Douglas Gregor | ef96ee0 | 2012-01-14 16:38:05 +0000 | [diff] [blame] | 405 | PS[P->getSequenceNumber()] = P->getMostRecentDecl(); |
Douglas Gregor | dc60c1e | 2010-04-30 05:56:50 +0000 | [diff] [blame] | 406 | } |
| 407 | } |
| 408 | |
Douglas Gregor | b88e888 | 2009-07-30 17:40:51 +0000 | [diff] [blame] | 409 | ClassTemplatePartialSpecializationDecl * |
| 410 | ClassTemplateDecl::findPartialSpecialization(QualType T) { |
| 411 | ASTContext &Context = getASTContext(); |
Chandler Carruth | d964d63 | 2012-05-03 23:49:05 +0000 | [diff] [blame] | 412 | using llvm::FoldingSetVector; |
| 413 | typedef FoldingSetVector<ClassTemplatePartialSpecializationDecl>::iterator |
Douglas Gregor | b88e888 | 2009-07-30 17:40:51 +0000 | [diff] [blame] | 414 | partial_spec_iterator; |
| 415 | for (partial_spec_iterator P = getPartialSpecializations().begin(), |
| 416 | PEnd = getPartialSpecializations().end(); |
| 417 | P != PEnd; ++P) { |
John McCall | 31f17ec | 2010-04-27 00:57:59 +0000 | [diff] [blame] | 418 | if (Context.hasSameType(P->getInjectedSpecializationType(), T)) |
Douglas Gregor | ef96ee0 | 2012-01-14 16:38:05 +0000 | [diff] [blame] | 419 | return P->getMostRecentDecl(); |
Argyrios Kyrtzidis | cc0b1bc | 2010-07-20 13:59:28 +0000 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | return 0; |
| 423 | } |
| 424 | |
| 425 | ClassTemplatePartialSpecializationDecl * |
| 426 | ClassTemplateDecl::findPartialSpecInstantiatedFromMember( |
| 427 | ClassTemplatePartialSpecializationDecl *D) { |
| 428 | Decl *DCanon = D->getCanonicalDecl(); |
Chandler Carruth | d964d63 | 2012-05-03 23:49:05 +0000 | [diff] [blame] | 429 | for (llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl>::iterator |
Argyrios Kyrtzidis | cc0b1bc | 2010-07-20 13:59:28 +0000 | [diff] [blame] | 430 | P = getPartialSpecializations().begin(), |
| 431 | PEnd = getPartialSpecializations().end(); |
| 432 | P != PEnd; ++P) { |
| 433 | if (P->getInstantiatedFromMember()->getCanonicalDecl() == DCanon) |
Douglas Gregor | ef96ee0 | 2012-01-14 16:38:05 +0000 | [diff] [blame] | 434 | return P->getMostRecentDecl(); |
Douglas Gregor | b88e888 | 2009-07-30 17:40:51 +0000 | [diff] [blame] | 435 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 436 | |
Douglas Gregor | b88e888 | 2009-07-30 17:40:51 +0000 | [diff] [blame] | 437 | return 0; |
| 438 | } |
| 439 | |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 440 | QualType |
Douglas Gregor | 24bae92 | 2010-07-08 18:37:38 +0000 | [diff] [blame] | 441 | ClassTemplateDecl::getInjectedClassNameSpecialization() { |
Argyrios Kyrtzidis | 5bf1bdc | 2010-06-21 10:57:41 +0000 | [diff] [blame] | 442 | Common *CommonPtr = getCommonPtr(); |
Douglas Gregor | 7da97d0 | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 443 | if (!CommonPtr->InjectedClassNameType.isNull()) |
| 444 | return CommonPtr->InjectedClassNameType; |
| 445 | |
Douglas Gregor | b7d09d6 | 2010-12-23 16:00:30 +0000 | [diff] [blame] | 446 | // C++0x [temp.dep.type]p2: |
| 447 | // The template argument list of a primary template is a template argument |
| 448 | // list in which the nth template argument has the value of the nth template |
| 449 | // parameter of the class template. If the nth template parameter is a |
| 450 | // template parameter pack (14.5.3), the nth template argument is a pack |
| 451 | // expansion (14.5.3) whose pattern is the name of the template parameter |
| 452 | // pack. |
Douglas Gregor | 24bae92 | 2010-07-08 18:37:38 +0000 | [diff] [blame] | 453 | ASTContext &Context = getASTContext(); |
Douglas Gregor | 7da97d0 | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 454 | TemplateParameterList *Params = getTemplateParameters(); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 455 | SmallVector<TemplateArgument, 16> TemplateArgs; |
Douglas Gregor | c494f77 | 2011-03-05 17:54:25 +0000 | [diff] [blame] | 456 | TemplateArgs.resize(Params->size()); |
| 457 | GenerateInjectedTemplateArgs(getASTContext(), Params, TemplateArgs.data()); |
Douglas Gregor | 7da97d0 | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 458 | CommonPtr->InjectedClassNameType |
Douglas Gregor | 1275ae0 | 2009-07-28 23:00:59 +0000 | [diff] [blame] | 459 | = Context.getTemplateSpecializationType(TemplateName(this), |
Douglas Gregor | 7da97d0 | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 460 | &TemplateArgs[0], |
Douglas Gregor | 1275ae0 | 2009-07-28 23:00:59 +0000 | [diff] [blame] | 461 | TemplateArgs.size()); |
Douglas Gregor | 7da97d0 | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 462 | return CommonPtr->InjectedClassNameType; |
| 463 | } |
| 464 | |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 465 | //===----------------------------------------------------------------------===// |
| 466 | // TemplateTypeParm Allocation/Deallocation Method Implementations |
| 467 | //===----------------------------------------------------------------------===// |
| 468 | |
| 469 | TemplateTypeParmDecl * |
Jay Foad | 4ba2a17 | 2011-01-12 09:06:06 +0000 | [diff] [blame] | 470 | TemplateTypeParmDecl::Create(const ASTContext &C, DeclContext *DC, |
Abramo Bagnara | 344577e | 2011-03-06 15:48:19 +0000 | [diff] [blame] | 471 | SourceLocation KeyLoc, SourceLocation NameLoc, |
| 472 | unsigned D, unsigned P, IdentifierInfo *Id, |
| 473 | bool Typename, bool ParameterPack) { |
Chandler Carruth | 4fb86f8 | 2011-05-01 00:51:33 +0000 | [diff] [blame] | 474 | TemplateTypeParmDecl *TTPDecl = |
| 475 | new (C) TemplateTypeParmDecl(DC, KeyLoc, NameLoc, Id, Typename); |
| 476 | QualType TTPType = C.getTemplateTypeParmType(D, P, ParameterPack, TTPDecl); |
| 477 | TTPDecl->TypeForDecl = TTPType.getTypePtr(); |
| 478 | return TTPDecl; |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 479 | } |
| 480 | |
Argyrios Kyrtzidis | b8b03e6 | 2010-07-02 11:54:55 +0000 | [diff] [blame] | 481 | TemplateTypeParmDecl * |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 482 | TemplateTypeParmDecl::CreateDeserialized(const ASTContext &C, unsigned ID) { |
| 483 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(TemplateTypeParmDecl)); |
| 484 | return new (Mem) TemplateTypeParmDecl(0, SourceLocation(), SourceLocation(), |
| 485 | 0, false); |
Argyrios Kyrtzidis | b8b03e6 | 2010-07-02 11:54:55 +0000 | [diff] [blame] | 486 | } |
| 487 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 488 | SourceLocation TemplateTypeParmDecl::getDefaultArgumentLoc() const { |
Abramo Bagnara | 77d4ee2 | 2011-03-04 12:42:03 +0000 | [diff] [blame] | 489 | return hasDefaultArgument() |
| 490 | ? DefaultArgument->getTypeLoc().getBeginLoc() |
| 491 | : SourceLocation(); |
| 492 | } |
| 493 | |
| 494 | SourceRange TemplateTypeParmDecl::getSourceRange() const { |
| 495 | if (hasDefaultArgument() && !defaultArgumentWasInherited()) |
Abramo Bagnara | 344577e | 2011-03-06 15:48:19 +0000 | [diff] [blame] | 496 | return SourceRange(getLocStart(), |
Abramo Bagnara | 77d4ee2 | 2011-03-04 12:42:03 +0000 | [diff] [blame] | 497 | DefaultArgument->getTypeLoc().getEndLoc()); |
| 498 | else |
Abramo Bagnara | 344577e | 2011-03-06 15:48:19 +0000 | [diff] [blame] | 499 | return TypeDecl::getSourceRange(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 500 | } |
| 501 | |
Douglas Gregor | ed9c0f9 | 2009-10-29 00:04:11 +0000 | [diff] [blame] | 502 | unsigned TemplateTypeParmDecl::getDepth() const { |
| 503 | return TypeForDecl->getAs<TemplateTypeParmType>()->getDepth(); |
| 504 | } |
| 505 | |
| 506 | unsigned TemplateTypeParmDecl::getIndex() const { |
| 507 | return TypeForDecl->getAs<TemplateTypeParmType>()->getIndex(); |
| 508 | } |
| 509 | |
Chandler Carruth | 4fb86f8 | 2011-05-01 00:51:33 +0000 | [diff] [blame] | 510 | bool TemplateTypeParmDecl::isParameterPack() const { |
| 511 | return TypeForDecl->getAs<TemplateTypeParmType>()->isParameterPack(); |
| 512 | } |
| 513 | |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 514 | //===----------------------------------------------------------------------===// |
| 515 | // NonTypeTemplateParmDecl Method Implementations |
| 516 | //===----------------------------------------------------------------------===// |
| 517 | |
Douglas Gregor | 6952f1e | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 518 | NonTypeTemplateParmDecl::NonTypeTemplateParmDecl(DeclContext *DC, |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 519 | SourceLocation StartLoc, |
| 520 | SourceLocation IdLoc, |
| 521 | unsigned D, unsigned P, |
| 522 | IdentifierInfo *Id, |
Douglas Gregor | 6952f1e | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 523 | QualType T, |
| 524 | TypeSourceInfo *TInfo, |
| 525 | const QualType *ExpandedTypes, |
| 526 | unsigned NumExpandedTypes, |
| 527 | TypeSourceInfo **ExpandedTInfos) |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 528 | : DeclaratorDecl(NonTypeTemplateParm, DC, IdLoc, Id, T, TInfo, StartLoc), |
Douglas Gregor | 6952f1e | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 529 | TemplateParmPosition(D, P), DefaultArgumentAndInherited(0, false), |
| 530 | ParameterPack(true), ExpandedParameterPack(true), |
| 531 | NumExpandedTypes(NumExpandedTypes) |
| 532 | { |
| 533 | if (ExpandedTypes && ExpandedTInfos) { |
| 534 | void **TypesAndInfos = reinterpret_cast<void **>(this + 1); |
| 535 | for (unsigned I = 0; I != NumExpandedTypes; ++I) { |
| 536 | TypesAndInfos[2*I] = ExpandedTypes[I].getAsOpaquePtr(); |
| 537 | TypesAndInfos[2*I + 1] = ExpandedTInfos[I]; |
| 538 | } |
| 539 | } |
| 540 | } |
| 541 | |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 542 | NonTypeTemplateParmDecl * |
Jay Foad | 4ba2a17 | 2011-01-12 09:06:06 +0000 | [diff] [blame] | 543 | NonTypeTemplateParmDecl::Create(const ASTContext &C, DeclContext *DC, |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 544 | SourceLocation StartLoc, SourceLocation IdLoc, |
| 545 | unsigned D, unsigned P, IdentifierInfo *Id, |
| 546 | QualType T, bool ParameterPack, |
| 547 | TypeSourceInfo *TInfo) { |
| 548 | return new (C) NonTypeTemplateParmDecl(DC, StartLoc, IdLoc, D, P, Id, |
| 549 | T, ParameterPack, TInfo); |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 550 | } |
| 551 | |
Douglas Gregor | 6952f1e | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 552 | NonTypeTemplateParmDecl * |
| 553 | NonTypeTemplateParmDecl::Create(const ASTContext &C, DeclContext *DC, |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 554 | SourceLocation StartLoc, SourceLocation IdLoc, |
| 555 | unsigned D, unsigned P, |
Douglas Gregor | 6952f1e | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 556 | IdentifierInfo *Id, QualType T, |
| 557 | TypeSourceInfo *TInfo, |
| 558 | const QualType *ExpandedTypes, |
| 559 | unsigned NumExpandedTypes, |
| 560 | TypeSourceInfo **ExpandedTInfos) { |
| 561 | unsigned Size = sizeof(NonTypeTemplateParmDecl) |
| 562 | + NumExpandedTypes * 2 * sizeof(void*); |
| 563 | void *Mem = C.Allocate(Size); |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 564 | return new (Mem) NonTypeTemplateParmDecl(DC, StartLoc, IdLoc, |
| 565 | D, P, Id, T, TInfo, |
Douglas Gregor | 6952f1e | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 566 | ExpandedTypes, NumExpandedTypes, |
| 567 | ExpandedTInfos); |
| 568 | } |
| 569 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 570 | NonTypeTemplateParmDecl * |
| 571 | NonTypeTemplateParmDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
| 572 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(NonTypeTemplateParmDecl)); |
| 573 | return new (Mem) NonTypeTemplateParmDecl(0, SourceLocation(), |
| 574 | SourceLocation(), 0, 0, 0, |
| 575 | QualType(), false, 0); |
| 576 | } |
| 577 | |
| 578 | NonTypeTemplateParmDecl * |
| 579 | NonTypeTemplateParmDecl::CreateDeserialized(ASTContext &C, unsigned ID, |
| 580 | unsigned NumExpandedTypes) { |
| 581 | unsigned Size = sizeof(NonTypeTemplateParmDecl) |
| 582 | + NumExpandedTypes * 2 * sizeof(void*); |
| 583 | |
| 584 | void *Mem = AllocateDeserializedDecl(C, ID, Size); |
| 585 | return new (Mem) NonTypeTemplateParmDecl(0, SourceLocation(), |
| 586 | SourceLocation(), 0, 0, 0, |
| 587 | QualType(), 0, 0, NumExpandedTypes, |
| 588 | 0); |
| 589 | } |
| 590 | |
John McCall | 76a4021 | 2011-02-09 01:13:10 +0000 | [diff] [blame] | 591 | SourceRange NonTypeTemplateParmDecl::getSourceRange() const { |
Abramo Bagnara | ee4bfd4 | 2011-03-04 11:03:48 +0000 | [diff] [blame] | 592 | if (hasDefaultArgument() && !defaultArgumentWasInherited()) |
Abramo Bagnara | a2026c9 | 2011-03-08 16:41:52 +0000 | [diff] [blame] | 593 | return SourceRange(getOuterLocStart(), |
| 594 | getDefaultArgument()->getSourceRange().getEnd()); |
| 595 | return DeclaratorDecl::getSourceRange(); |
John McCall | 76a4021 | 2011-02-09 01:13:10 +0000 | [diff] [blame] | 596 | } |
| 597 | |
Douglas Gregor | d684b00 | 2009-02-10 19:49:53 +0000 | [diff] [blame] | 598 | SourceLocation NonTypeTemplateParmDecl::getDefaultArgumentLoc() const { |
Abramo Bagnara | d92f7a2 | 2010-06-09 09:26:05 +0000 | [diff] [blame] | 599 | return hasDefaultArgument() |
| 600 | ? getDefaultArgument()->getSourceRange().getBegin() |
| 601 | : SourceLocation(); |
Douglas Gregor | d684b00 | 2009-02-10 19:49:53 +0000 | [diff] [blame] | 602 | } |
| 603 | |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 604 | //===----------------------------------------------------------------------===// |
| 605 | // TemplateTemplateParmDecl Method Implementations |
| 606 | //===----------------------------------------------------------------------===// |
| 607 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 608 | void TemplateTemplateParmDecl::anchor() { } |
| 609 | |
Richard Smith | 6964b3f | 2012-09-07 02:06:42 +0000 | [diff] [blame] | 610 | TemplateTemplateParmDecl::TemplateTemplateParmDecl( |
| 611 | DeclContext *DC, SourceLocation L, unsigned D, unsigned P, |
| 612 | IdentifierInfo *Id, TemplateParameterList *Params, |
| 613 | unsigned NumExpansions, TemplateParameterList * const *Expansions) |
| 614 | : TemplateDecl(TemplateTemplateParm, DC, L, Id, Params), |
| 615 | TemplateParmPosition(D, P), DefaultArgument(), |
| 616 | DefaultArgumentWasInherited(false), ParameterPack(true), |
| 617 | ExpandedParameterPack(true), NumExpandedParams(NumExpansions) { |
| 618 | if (Expansions) |
| 619 | std::memcpy(reinterpret_cast<void*>(this + 1), Expansions, |
| 620 | sizeof(TemplateParameterList*) * NumExpandedParams); |
| 621 | } |
| 622 | |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 623 | TemplateTemplateParmDecl * |
Jay Foad | 4ba2a17 | 2011-01-12 09:06:06 +0000 | [diff] [blame] | 624 | TemplateTemplateParmDecl::Create(const ASTContext &C, DeclContext *DC, |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 625 | SourceLocation L, unsigned D, unsigned P, |
Douglas Gregor | 61c4d28 | 2011-01-05 15:48:55 +0000 | [diff] [blame] | 626 | bool ParameterPack, IdentifierInfo *Id, |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 627 | TemplateParameterList *Params) { |
Douglas Gregor | 61c4d28 | 2011-01-05 15:48:55 +0000 | [diff] [blame] | 628 | return new (C) TemplateTemplateParmDecl(DC, L, D, P, ParameterPack, Id, |
| 629 | Params); |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 630 | } |
| 631 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 632 | TemplateTemplateParmDecl * |
Richard Smith | 6964b3f | 2012-09-07 02:06:42 +0000 | [diff] [blame] | 633 | TemplateTemplateParmDecl::Create(const ASTContext &C, DeclContext *DC, |
| 634 | SourceLocation L, unsigned D, unsigned P, |
| 635 | IdentifierInfo *Id, |
| 636 | TemplateParameterList *Params, |
Dmitri Gribenko | cfa88f8 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 637 | ArrayRef<TemplateParameterList *> Expansions) { |
Richard Smith | 6964b3f | 2012-09-07 02:06:42 +0000 | [diff] [blame] | 638 | void *Mem = C.Allocate(sizeof(TemplateTemplateParmDecl) + |
| 639 | sizeof(TemplateParameterList*) * Expansions.size()); |
| 640 | return new (Mem) TemplateTemplateParmDecl(DC, L, D, P, Id, Params, |
| 641 | Expansions.size(), |
| 642 | Expansions.data()); |
| 643 | } |
| 644 | |
| 645 | TemplateTemplateParmDecl * |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 646 | TemplateTemplateParmDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
| 647 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(TemplateTemplateParmDecl)); |
| 648 | return new (Mem) TemplateTemplateParmDecl(0, SourceLocation(), 0, 0, false, |
| 649 | 0, 0); |
| 650 | } |
| 651 | |
Richard Smith | 6964b3f | 2012-09-07 02:06:42 +0000 | [diff] [blame] | 652 | TemplateTemplateParmDecl * |
| 653 | TemplateTemplateParmDecl::CreateDeserialized(ASTContext &C, unsigned ID, |
| 654 | unsigned NumExpansions) { |
| 655 | unsigned Size = sizeof(TemplateTemplateParmDecl) + |
| 656 | sizeof(TemplateParameterList*) * NumExpansions; |
| 657 | void *Mem = AllocateDeserializedDecl(C, ID, Size); |
| 658 | return new (Mem) TemplateTemplateParmDecl(0, SourceLocation(), 0, 0, 0, 0, |
| 659 | NumExpansions, 0); |
| 660 | } |
| 661 | |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 662 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 7e06390 | 2009-05-11 23:53:27 +0000 | [diff] [blame] | 663 | // TemplateArgumentList Implementation |
| 664 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 665 | TemplateArgumentList * |
| 666 | TemplateArgumentList::CreateCopy(ASTContext &Context, |
| 667 | const TemplateArgument *Args, |
| 668 | unsigned NumArgs) { |
| 669 | std::size_t Size = sizeof(TemplateArgumentList) |
| 670 | + NumArgs * sizeof(TemplateArgument); |
| 671 | void *Mem = Context.Allocate(Size); |
| 672 | TemplateArgument *StoredArgs |
| 673 | = reinterpret_cast<TemplateArgument *>( |
| 674 | static_cast<TemplateArgumentList *>(Mem) + 1); |
| 675 | std::uninitialized_copy(Args, Args + NumArgs, StoredArgs); |
| 676 | return new (Mem) TemplateArgumentList(StoredArgs, NumArgs, true); |
Argyrios Kyrtzidis | 94d228d | 2010-06-23 13:48:23 +0000 | [diff] [blame] | 677 | } |
| 678 | |
Argyrios Kyrtzidis | 71a7605 | 2011-09-22 20:07:09 +0000 | [diff] [blame] | 679 | FunctionTemplateSpecializationInfo * |
| 680 | FunctionTemplateSpecializationInfo::Create(ASTContext &C, FunctionDecl *FD, |
| 681 | FunctionTemplateDecl *Template, |
| 682 | TemplateSpecializationKind TSK, |
| 683 | const TemplateArgumentList *TemplateArgs, |
| 684 | const TemplateArgumentListInfo *TemplateArgsAsWritten, |
| 685 | SourceLocation POI) { |
| 686 | const ASTTemplateArgumentListInfo *ArgsAsWritten = 0; |
| 687 | if (TemplateArgsAsWritten) |
| 688 | ArgsAsWritten = ASTTemplateArgumentListInfo::Create(C, |
| 689 | *TemplateArgsAsWritten); |
| 690 | |
| 691 | return new (C) FunctionTemplateSpecializationInfo(FD, Template, TSK, |
| 692 | TemplateArgs, |
| 693 | ArgsAsWritten, |
| 694 | POI); |
| 695 | } |
| 696 | |
Douglas Gregor | 7e06390 | 2009-05-11 23:53:27 +0000 | [diff] [blame] | 697 | //===----------------------------------------------------------------------===// |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 698 | // TemplateDecl Implementation |
| 699 | //===----------------------------------------------------------------------===// |
| 700 | |
| 701 | void TemplateDecl::anchor() { } |
| 702 | |
| 703 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 704 | // ClassTemplateSpecializationDecl Implementation |
| 705 | //===----------------------------------------------------------------------===// |
| 706 | ClassTemplateSpecializationDecl:: |
Douglas Gregor | 13c8577 | 2010-05-06 00:28:52 +0000 | [diff] [blame] | 707 | ClassTemplateSpecializationDecl(ASTContext &Context, Kind DK, TagKind TK, |
Abramo Bagnara | ba877ad | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 708 | DeclContext *DC, SourceLocation StartLoc, |
| 709 | SourceLocation IdLoc, |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 710 | ClassTemplateDecl *SpecializedTemplate, |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 711 | const TemplateArgument *Args, |
| 712 | unsigned NumArgs, |
Douglas Gregor | 8e9e9ef | 2009-07-29 23:36:44 +0000 | [diff] [blame] | 713 | ClassTemplateSpecializationDecl *PrevDecl) |
Abramo Bagnara | ba877ad | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 714 | : CXXRecordDecl(DK, TK, DC, StartLoc, IdLoc, |
Douglas Gregor | 8e9e9ef | 2009-07-29 23:36:44 +0000 | [diff] [blame] | 715 | SpecializedTemplate->getIdentifier(), |
| 716 | PrevDecl), |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 717 | SpecializedTemplate(SpecializedTemplate), |
Abramo Bagnara | c98971d | 2010-06-12 07:44:57 +0000 | [diff] [blame] | 718 | ExplicitInfo(0), |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 719 | TemplateArgs(TemplateArgumentList::CreateCopy(Context, Args, NumArgs)), |
Douglas Gregor | 7e06390 | 2009-05-11 23:53:27 +0000 | [diff] [blame] | 720 | SpecializationKind(TSK_Undeclared) { |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 721 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 722 | |
Argyrios Kyrtzidis | 94d228d | 2010-06-23 13:48:23 +0000 | [diff] [blame] | 723 | ClassTemplateSpecializationDecl::ClassTemplateSpecializationDecl(Kind DK) |
Abramo Bagnara | ba877ad | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 724 | : CXXRecordDecl(DK, TTK_Struct, 0, SourceLocation(), SourceLocation(), 0, 0), |
Argyrios Kyrtzidis | 94d228d | 2010-06-23 13:48:23 +0000 | [diff] [blame] | 725 | ExplicitInfo(0), |
| 726 | SpecializationKind(TSK_Undeclared) { |
| 727 | } |
| 728 | |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 729 | ClassTemplateSpecializationDecl * |
Douglas Gregor | 13c8577 | 2010-05-06 00:28:52 +0000 | [diff] [blame] | 730 | ClassTemplateSpecializationDecl::Create(ASTContext &Context, TagKind TK, |
Abramo Bagnara | ba877ad | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 731 | DeclContext *DC, |
| 732 | SourceLocation StartLoc, |
| 733 | SourceLocation IdLoc, |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 734 | ClassTemplateDecl *SpecializedTemplate, |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 735 | const TemplateArgument *Args, |
| 736 | unsigned NumArgs, |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 737 | ClassTemplateSpecializationDecl *PrevDecl) { |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 738 | ClassTemplateSpecializationDecl *Result |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 739 | = new (Context)ClassTemplateSpecializationDecl(Context, |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 740 | ClassTemplateSpecialization, |
Abramo Bagnara | ba877ad | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 741 | TK, DC, StartLoc, IdLoc, |
Douglas Gregor | 7e06390 | 2009-05-11 23:53:27 +0000 | [diff] [blame] | 742 | SpecializedTemplate, |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 743 | Args, NumArgs, |
Douglas Gregor | 8e9e9ef | 2009-07-29 23:36:44 +0000 | [diff] [blame] | 744 | PrevDecl); |
Douglas Gregor | 6bd9929 | 2013-02-09 01:35:03 +0000 | [diff] [blame] | 745 | Result->MayHaveOutOfDateDef = false; |
| 746 | |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 747 | Context.getTypeDeclType(Result, PrevDecl); |
| 748 | return Result; |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 749 | } |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 750 | |
Argyrios Kyrtzidis | 94d228d | 2010-06-23 13:48:23 +0000 | [diff] [blame] | 751 | ClassTemplateSpecializationDecl * |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 752 | ClassTemplateSpecializationDecl::CreateDeserialized(ASTContext &C, |
| 753 | unsigned ID) { |
| 754 | void *Mem = AllocateDeserializedDecl(C, ID, |
| 755 | sizeof(ClassTemplateSpecializationDecl)); |
Douglas Gregor | 6bd9929 | 2013-02-09 01:35:03 +0000 | [diff] [blame] | 756 | ClassTemplateSpecializationDecl *Result = |
| 757 | new (Mem) ClassTemplateSpecializationDecl(ClassTemplateSpecialization); |
| 758 | Result->MayHaveOutOfDateDef = false; |
| 759 | return Result; |
Argyrios Kyrtzidis | 94d228d | 2010-06-23 13:48:23 +0000 | [diff] [blame] | 760 | } |
| 761 | |
Benjamin Kramer | 5eada84 | 2013-02-22 15:46:01 +0000 | [diff] [blame] | 762 | void ClassTemplateSpecializationDecl::getNameForDiagnostic( |
| 763 | raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const { |
| 764 | NamedDecl::getNameForDiagnostic(OS, Policy, Qualified); |
Douglas Gregor | da2142f | 2011-02-19 18:51:44 +0000 | [diff] [blame] | 765 | |
| 766 | const TemplateArgumentList &TemplateArgs = getTemplateArgs(); |
Benjamin Kramer | 5eada84 | 2013-02-22 15:46:01 +0000 | [diff] [blame] | 767 | TemplateSpecializationType::PrintTemplateArgumentList( |
| 768 | OS, TemplateArgs.data(), TemplateArgs.size(), Policy); |
Douglas Gregor | da2142f | 2011-02-19 18:51:44 +0000 | [diff] [blame] | 769 | } |
| 770 | |
Douglas Gregor | 37d93e9 | 2009-08-02 23:24:31 +0000 | [diff] [blame] | 771 | ClassTemplateDecl * |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 772 | ClassTemplateSpecializationDecl::getSpecializedTemplate() const { |
| 773 | if (SpecializedPartialSpecialization *PartialSpec |
Douglas Gregor | 37d93e9 | 2009-08-02 23:24:31 +0000 | [diff] [blame] | 774 | = SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization*>()) |
| 775 | return PartialSpec->PartialSpecialization->getSpecializedTemplate(); |
| 776 | return SpecializedTemplate.get<ClassTemplateDecl*>(); |
| 777 | } |
| 778 | |
Abramo Bagnara | 4a85a73 | 2011-03-04 14:20:30 +0000 | [diff] [blame] | 779 | SourceRange |
| 780 | ClassTemplateSpecializationDecl::getSourceRange() const { |
Abramo Bagnara | 09d8212 | 2011-10-03 20:34:03 +0000 | [diff] [blame] | 781 | if (ExplicitInfo) { |
Abramo Bagnara | b2e8001 | 2012-10-15 21:06:42 +0000 | [diff] [blame] | 782 | SourceLocation Begin = getTemplateKeywordLoc(); |
| 783 | if (Begin.isValid()) { |
| 784 | // Here we have an explicit (partial) specialization or instantiation. |
| 785 | assert(getSpecializationKind() == TSK_ExplicitSpecialization || |
| 786 | getSpecializationKind() == TSK_ExplicitInstantiationDeclaration || |
| 787 | getSpecializationKind() == TSK_ExplicitInstantiationDefinition); |
| 788 | if (getExternLoc().isValid()) |
| 789 | Begin = getExternLoc(); |
| 790 | SourceLocation End = getRBraceLoc(); |
| 791 | if (End.isInvalid()) |
| 792 | End = getTypeAsWritten()->getTypeLoc().getEndLoc(); |
| 793 | return SourceRange(Begin, End); |
| 794 | } |
| 795 | // An implicit instantiation of a class template partial specialization |
| 796 | // uses ExplicitInfo to record the TypeAsWritten, but the source |
| 797 | // locations should be retrieved from the instantiation pattern. |
| 798 | typedef ClassTemplatePartialSpecializationDecl CTPSDecl; |
| 799 | CTPSDecl *ctpsd = const_cast<CTPSDecl*>(cast<CTPSDecl>(this)); |
| 800 | CTPSDecl *inst_from = ctpsd->getInstantiatedFromMember(); |
| 801 | assert(inst_from != 0); |
| 802 | return inst_from->getSourceRange(); |
Abramo Bagnara | 09d8212 | 2011-10-03 20:34:03 +0000 | [diff] [blame] | 803 | } |
| 804 | else { |
| 805 | // No explicit info available. |
| 806 | llvm::PointerUnion<ClassTemplateDecl *, |
| 807 | ClassTemplatePartialSpecializationDecl *> |
| 808 | inst_from = getInstantiatedFrom(); |
| 809 | if (inst_from.isNull()) |
| 810 | return getSpecializedTemplate()->getSourceRange(); |
| 811 | if (ClassTemplateDecl *ctd = inst_from.dyn_cast<ClassTemplateDecl*>()) |
| 812 | return ctd->getSourceRange(); |
| 813 | return inst_from.get<ClassTemplatePartialSpecializationDecl*>() |
| 814 | ->getSourceRange(); |
| 815 | } |
Abramo Bagnara | 4a85a73 | 2011-03-04 14:20:30 +0000 | [diff] [blame] | 816 | } |
| 817 | |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 818 | //===----------------------------------------------------------------------===// |
| 819 | // ClassTemplatePartialSpecializationDecl Implementation |
| 820 | //===----------------------------------------------------------------------===// |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 821 | void ClassTemplatePartialSpecializationDecl::anchor() { } |
| 822 | |
Douglas Gregor | 9a299e0 | 2011-03-04 17:52:15 +0000 | [diff] [blame] | 823 | ClassTemplatePartialSpecializationDecl:: |
| 824 | ClassTemplatePartialSpecializationDecl(ASTContext &Context, TagKind TK, |
Abramo Bagnara | ba877ad | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 825 | DeclContext *DC, |
| 826 | SourceLocation StartLoc, |
| 827 | SourceLocation IdLoc, |
Douglas Gregor | 9a299e0 | 2011-03-04 17:52:15 +0000 | [diff] [blame] | 828 | TemplateParameterList *Params, |
| 829 | ClassTemplateDecl *SpecializedTemplate, |
| 830 | const TemplateArgument *Args, |
| 831 | unsigned NumArgs, |
| 832 | TemplateArgumentLoc *ArgInfos, |
| 833 | unsigned NumArgInfos, |
| 834 | ClassTemplatePartialSpecializationDecl *PrevDecl, |
| 835 | unsigned SequenceNumber) |
| 836 | : ClassTemplateSpecializationDecl(Context, |
| 837 | ClassTemplatePartialSpecialization, |
Abramo Bagnara | ba877ad | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 838 | TK, DC, StartLoc, IdLoc, |
| 839 | SpecializedTemplate, |
Douglas Gregor | 9a299e0 | 2011-03-04 17:52:15 +0000 | [diff] [blame] | 840 | Args, NumArgs, PrevDecl), |
| 841 | TemplateParams(Params), ArgsAsWritten(ArgInfos), |
| 842 | NumArgsAsWritten(NumArgInfos), SequenceNumber(SequenceNumber), |
| 843 | InstantiatedFromMember(0, false) |
| 844 | { |
Douglas Gregor | 787a40d | 2011-03-04 18:32:38 +0000 | [diff] [blame] | 845 | AdoptTemplateParameterList(Params, this); |
Douglas Gregor | 9a299e0 | 2011-03-04 17:52:15 +0000 | [diff] [blame] | 846 | } |
| 847 | |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 848 | ClassTemplatePartialSpecializationDecl * |
| 849 | ClassTemplatePartialSpecializationDecl:: |
Abramo Bagnara | ba877ad | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 850 | Create(ASTContext &Context, TagKind TK,DeclContext *DC, |
| 851 | SourceLocation StartLoc, SourceLocation IdLoc, |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 852 | TemplateParameterList *Params, |
| 853 | ClassTemplateDecl *SpecializedTemplate, |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 854 | const TemplateArgument *Args, |
| 855 | unsigned NumArgs, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 856 | const TemplateArgumentListInfo &ArgInfos, |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 857 | QualType CanonInjectedType, |
Douglas Gregor | dc60c1e | 2010-04-30 05:56:50 +0000 | [diff] [blame] | 858 | ClassTemplatePartialSpecializationDecl *PrevDecl, |
| 859 | unsigned SequenceNumber) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 860 | unsigned N = ArgInfos.size(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 861 | TemplateArgumentLoc *ClonedArgs = new (Context) TemplateArgumentLoc[N]; |
| 862 | for (unsigned I = 0; I != N; ++I) |
| 863 | ClonedArgs[I] = ArgInfos[I]; |
| 864 | |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 865 | ClassTemplatePartialSpecializationDecl *Result |
Abramo Bagnara | ba877ad | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 866 | = new (Context)ClassTemplatePartialSpecializationDecl(Context, TK, DC, |
| 867 | StartLoc, IdLoc, |
| 868 | Params, |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 869 | SpecializedTemplate, |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 870 | Args, NumArgs, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 871 | ClonedArgs, N, |
Douglas Gregor | dc60c1e | 2010-04-30 05:56:50 +0000 | [diff] [blame] | 872 | PrevDecl, |
| 873 | SequenceNumber); |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 874 | Result->setSpecializationKind(TSK_ExplicitSpecialization); |
Douglas Gregor | 6bd9929 | 2013-02-09 01:35:03 +0000 | [diff] [blame] | 875 | Result->MayHaveOutOfDateDef = false; |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 876 | |
| 877 | Context.getInjectedClassNameType(Result, CanonInjectedType); |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 878 | return Result; |
| 879 | } |
John McCall | dd4a3b0 | 2009-09-16 22:47:08 +0000 | [diff] [blame] | 880 | |
Argyrios Kyrtzidis | 94d228d | 2010-06-23 13:48:23 +0000 | [diff] [blame] | 881 | ClassTemplatePartialSpecializationDecl * |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 882 | ClassTemplatePartialSpecializationDecl::CreateDeserialized(ASTContext &C, |
| 883 | unsigned ID) { |
| 884 | void *Mem = AllocateDeserializedDecl(C, ID, |
| 885 | sizeof(ClassTemplatePartialSpecializationDecl)); |
Douglas Gregor | 6bd9929 | 2013-02-09 01:35:03 +0000 | [diff] [blame] | 886 | ClassTemplatePartialSpecializationDecl *Result |
| 887 | = new (Mem) ClassTemplatePartialSpecializationDecl(); |
| 888 | Result->MayHaveOutOfDateDef = false; |
| 889 | return Result; |
Argyrios Kyrtzidis | 94d228d | 2010-06-23 13:48:23 +0000 | [diff] [blame] | 890 | } |
| 891 | |
John McCall | dd4a3b0 | 2009-09-16 22:47:08 +0000 | [diff] [blame] | 892 | //===----------------------------------------------------------------------===// |
| 893 | // FriendTemplateDecl Implementation |
| 894 | //===----------------------------------------------------------------------===// |
| 895 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 896 | void FriendTemplateDecl::anchor() { } |
| 897 | |
John McCall | dd4a3b0 | 2009-09-16 22:47:08 +0000 | [diff] [blame] | 898 | FriendTemplateDecl *FriendTemplateDecl::Create(ASTContext &Context, |
| 899 | DeclContext *DC, |
| 900 | SourceLocation L, |
| 901 | unsigned NParams, |
| 902 | TemplateParameterList **Params, |
| 903 | FriendUnion Friend, |
| 904 | SourceLocation FLoc) { |
| 905 | FriendTemplateDecl *Result |
| 906 | = new (Context) FriendTemplateDecl(DC, L, NParams, Params, Friend, FLoc); |
| 907 | return Result; |
| 908 | } |
Argyrios Kyrtzidis | 554e6aa | 2010-07-22 16:04:10 +0000 | [diff] [blame] | 909 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 910 | FriendTemplateDecl *FriendTemplateDecl::CreateDeserialized(ASTContext &C, |
| 911 | unsigned ID) { |
| 912 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(FriendTemplateDecl)); |
| 913 | return new (Mem) FriendTemplateDecl(EmptyShell()); |
Argyrios Kyrtzidis | 554e6aa | 2010-07-22 16:04:10 +0000 | [diff] [blame] | 914 | } |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 915 | |
| 916 | //===----------------------------------------------------------------------===// |
| 917 | // TypeAliasTemplateDecl Implementation |
| 918 | //===----------------------------------------------------------------------===// |
| 919 | |
| 920 | TypeAliasTemplateDecl *TypeAliasTemplateDecl::Create(ASTContext &C, |
| 921 | DeclContext *DC, |
| 922 | SourceLocation L, |
| 923 | DeclarationName Name, |
| 924 | TemplateParameterList *Params, |
| 925 | NamedDecl *Decl) { |
| 926 | AdoptTemplateParameterList(Params, DC); |
| 927 | return new (C) TypeAliasTemplateDecl(DC, L, Name, Params, Decl); |
| 928 | } |
| 929 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 930 | TypeAliasTemplateDecl *TypeAliasTemplateDecl::CreateDeserialized(ASTContext &C, |
| 931 | unsigned ID) { |
| 932 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(TypeAliasTemplateDecl)); |
| 933 | return new (Mem) TypeAliasTemplateDecl(0, SourceLocation(), DeclarationName(), |
| 934 | 0, 0); |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 935 | } |
| 936 | |
| 937 | void TypeAliasTemplateDecl::DeallocateCommon(void *Ptr) { |
| 938 | static_cast<Common *>(Ptr)->~Common(); |
| 939 | } |
| 940 | RedeclarableTemplateDecl::CommonBase * |
Dmitri Gribenko | b76d971 | 2013-01-23 16:52:57 +0000 | [diff] [blame] | 941 | TypeAliasTemplateDecl::newCommon(ASTContext &C) const { |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 942 | Common *CommonPtr = new (C) Common; |
| 943 | C.AddDeallocation(DeallocateCommon, CommonPtr); |
| 944 | return CommonPtr; |
| 945 | } |
| 946 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 947 | //===----------------------------------------------------------------------===// |
| 948 | // ClassScopeFunctionSpecializationDecl Implementation |
| 949 | //===----------------------------------------------------------------------===// |
| 950 | |
| 951 | void ClassScopeFunctionSpecializationDecl::anchor() { } |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 952 | |
| 953 | ClassScopeFunctionSpecializationDecl * |
| 954 | ClassScopeFunctionSpecializationDecl::CreateDeserialized(ASTContext &C, |
| 955 | unsigned ID) { |
| 956 | void *Mem = AllocateDeserializedDecl(C, ID, |
| 957 | sizeof(ClassScopeFunctionSpecializationDecl)); |
Nico Weber | 6b02009 | 2012-06-25 17:21:05 +0000 | [diff] [blame] | 958 | return new (Mem) ClassScopeFunctionSpecializationDecl(0, SourceLocation(), 0, |
| 959 | false, TemplateArgumentListInfo()); |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 960 | } |
Larisse Voufo | ef4579c | 2013-08-06 01:03:05 +0000 | [diff] [blame^] | 961 | |
| 962 | //===----------------------------------------------------------------------===// |
| 963 | // VarTemplateDecl Implementation |
| 964 | //===----------------------------------------------------------------------===// |
| 965 | |
| 966 | void VarTemplateDecl::DeallocateCommon(void *Ptr) { |
| 967 | static_cast<Common *>(Ptr)->~Common(); |
| 968 | } |
| 969 | |
| 970 | VarTemplateDecl *VarTemplateDecl::Create(ASTContext &C, DeclContext *DC, |
| 971 | SourceLocation L, DeclarationName Name, |
| 972 | TemplateParameterList *Params, |
| 973 | NamedDecl *Decl, |
| 974 | VarTemplateDecl *PrevDecl) { |
| 975 | VarTemplateDecl *New = new (C) VarTemplateDecl(DC, L, Name, Params, Decl); |
| 976 | New->setPreviousDeclaration(PrevDecl); |
| 977 | return New; |
| 978 | } |
| 979 | |
| 980 | VarTemplateDecl *VarTemplateDecl::CreateDeserialized(ASTContext &C, |
| 981 | unsigned ID) { |
| 982 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(VarTemplateDecl)); |
| 983 | return new (Mem) VarTemplateDecl(EmptyShell()); |
| 984 | } |
| 985 | |
| 986 | // FIXME: Should this be unified accross class, function and variable |
| 987 | // templates? Perhaps also moved to RedeclarableTemplateDecl? |
| 988 | void VarTemplateDecl::LoadLazySpecializations() const { |
| 989 | Common *CommonPtr = getCommonPtr(); |
| 990 | if (CommonPtr->LazySpecializations) { |
| 991 | ASTContext &Context = getASTContext(); |
| 992 | uint32_t *Specs = CommonPtr->LazySpecializations; |
| 993 | CommonPtr->LazySpecializations = 0; |
| 994 | for (uint32_t I = 0, N = *Specs++; I != N; ++I) |
| 995 | (void)Context.getExternalSource()->GetExternalDecl(Specs[I]); |
| 996 | } |
| 997 | } |
| 998 | |
| 999 | llvm::FoldingSetVector<VarTemplateSpecializationDecl> & |
| 1000 | VarTemplateDecl::getSpecializations() const { |
| 1001 | LoadLazySpecializations(); |
| 1002 | return getCommonPtr()->Specializations; |
| 1003 | } |
| 1004 | |
| 1005 | llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl> & |
| 1006 | VarTemplateDecl::getPartialSpecializations() { |
| 1007 | LoadLazySpecializations(); |
| 1008 | return getCommonPtr()->PartialSpecializations; |
| 1009 | } |
| 1010 | |
| 1011 | RedeclarableTemplateDecl::CommonBase * |
| 1012 | VarTemplateDecl::newCommon(ASTContext &C) const { |
| 1013 | Common *CommonPtr = new (C) Common; |
| 1014 | C.AddDeallocation(DeallocateCommon, CommonPtr); |
| 1015 | return CommonPtr; |
| 1016 | } |
| 1017 | |
| 1018 | VarTemplateSpecializationDecl * |
| 1019 | VarTemplateDecl::findSpecialization(const TemplateArgument *Args, |
| 1020 | unsigned NumArgs, void *&InsertPos) { |
| 1021 | return findSpecializationImpl(getSpecializations(), Args, NumArgs, InsertPos); |
| 1022 | } |
| 1023 | |
| 1024 | void VarTemplateDecl::AddSpecialization(VarTemplateSpecializationDecl *D, |
| 1025 | void *InsertPos) { |
| 1026 | if (InsertPos) |
| 1027 | getSpecializations().InsertNode(D, InsertPos); |
| 1028 | else { |
| 1029 | VarTemplateSpecializationDecl *Existing = |
| 1030 | getSpecializations().GetOrInsertNode(D); |
| 1031 | (void)Existing; |
| 1032 | assert(Existing->isCanonicalDecl() && "Non-canonical specialization?"); |
| 1033 | } |
| 1034 | if (ASTMutationListener *L = getASTMutationListener()) |
| 1035 | L->AddedCXXTemplateSpecialization(this, D); |
| 1036 | } |
| 1037 | |
| 1038 | VarTemplatePartialSpecializationDecl * |
| 1039 | VarTemplateDecl::findPartialSpecialization(const TemplateArgument *Args, |
| 1040 | unsigned NumArgs, void *&InsertPos) { |
| 1041 | return findSpecializationImpl(getPartialSpecializations(), Args, NumArgs, |
| 1042 | InsertPos); |
| 1043 | } |
| 1044 | |
| 1045 | void VarTemplateDecl::AddPartialSpecialization( |
| 1046 | VarTemplatePartialSpecializationDecl *D, void *InsertPos) { |
| 1047 | if (InsertPos) |
| 1048 | getPartialSpecializations().InsertNode(D, InsertPos); |
| 1049 | else { |
| 1050 | VarTemplatePartialSpecializationDecl *Existing = |
| 1051 | getPartialSpecializations().GetOrInsertNode(D); |
| 1052 | (void)Existing; |
| 1053 | assert(Existing->isCanonicalDecl() && "Non-canonical specialization?"); |
| 1054 | } |
| 1055 | |
| 1056 | if (ASTMutationListener *L = getASTMutationListener()) |
| 1057 | L->AddedCXXTemplateSpecialization(this, D); |
| 1058 | } |
| 1059 | |
| 1060 | void VarTemplateDecl::getPartialSpecializations( |
| 1061 | SmallVectorImpl<VarTemplatePartialSpecializationDecl *> &PS) { |
| 1062 | llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl> &PartialSpecs = |
| 1063 | getPartialSpecializations(); |
| 1064 | PS.clear(); |
| 1065 | PS.resize(PartialSpecs.size()); |
| 1066 | for (llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl>::iterator |
| 1067 | P = PartialSpecs.begin(), |
| 1068 | PEnd = PartialSpecs.end(); |
| 1069 | P != PEnd; ++P) { |
| 1070 | assert(!PS[P->getSequenceNumber()]); |
| 1071 | PS[P->getSequenceNumber()] = P->getMostRecentDecl(); |
| 1072 | } |
| 1073 | } |
| 1074 | |
| 1075 | VarTemplatePartialSpecializationDecl * |
| 1076 | VarTemplateDecl::findPartialSpecInstantiatedFromMember( |
| 1077 | VarTemplatePartialSpecializationDecl *D) { |
| 1078 | Decl *DCanon = D->getCanonicalDecl(); |
| 1079 | for (llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl>::iterator |
| 1080 | P = getPartialSpecializations().begin(), |
| 1081 | PEnd = getPartialSpecializations().end(); |
| 1082 | P != PEnd; ++P) { |
| 1083 | if (P->getInstantiatedFromMember()->getCanonicalDecl() == DCanon) |
| 1084 | return P->getMostRecentDecl(); |
| 1085 | } |
| 1086 | |
| 1087 | return 0; |
| 1088 | } |
| 1089 | |
| 1090 | //===----------------------------------------------------------------------===// |
| 1091 | // VarTemplateSpecializationDecl Implementation |
| 1092 | //===----------------------------------------------------------------------===// |
| 1093 | VarTemplateSpecializationDecl::VarTemplateSpecializationDecl( |
| 1094 | ASTContext &Context, Kind DK, DeclContext *DC, SourceLocation StartLoc, |
| 1095 | SourceLocation IdLoc, VarTemplateDecl *SpecializedTemplate, QualType T, |
| 1096 | TypeSourceInfo *TInfo, StorageClass S, const TemplateArgument *Args, |
| 1097 | unsigned NumArgs) |
| 1098 | : VarDecl(DK, DC, StartLoc, IdLoc, SpecializedTemplate->getIdentifier(), T, |
| 1099 | TInfo, S), |
| 1100 | SpecializedTemplate(SpecializedTemplate), ExplicitInfo(0), |
| 1101 | TemplateArgs(TemplateArgumentList::CreateCopy(Context, Args, NumArgs)), |
| 1102 | SpecializationKind(TSK_Undeclared) {} |
| 1103 | |
| 1104 | VarTemplateSpecializationDecl::VarTemplateSpecializationDecl(Kind DK) |
| 1105 | : VarDecl(DK, 0, SourceLocation(), SourceLocation(), 0, QualType(), 0, |
| 1106 | SC_None), |
| 1107 | ExplicitInfo(0), SpecializationKind(TSK_Undeclared) {} |
| 1108 | |
| 1109 | VarTemplateSpecializationDecl *VarTemplateSpecializationDecl::Create( |
| 1110 | ASTContext &Context, DeclContext *DC, SourceLocation StartLoc, |
| 1111 | SourceLocation IdLoc, VarTemplateDecl *SpecializedTemplate, QualType T, |
| 1112 | TypeSourceInfo *TInfo, StorageClass S, const TemplateArgument *Args, |
| 1113 | unsigned NumArgs) { |
| 1114 | VarTemplateSpecializationDecl *Result = new (Context) |
| 1115 | VarTemplateSpecializationDecl(Context, VarTemplateSpecialization, DC, |
| 1116 | StartLoc, IdLoc, SpecializedTemplate, T, |
| 1117 | TInfo, S, Args, NumArgs); |
| 1118 | return Result; |
| 1119 | } |
| 1120 | |
| 1121 | VarTemplateSpecializationDecl * |
| 1122 | VarTemplateSpecializationDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
| 1123 | void *Mem = |
| 1124 | AllocateDeserializedDecl(C, ID, sizeof(VarTemplateSpecializationDecl)); |
| 1125 | VarTemplateSpecializationDecl *Result = |
| 1126 | new (Mem) VarTemplateSpecializationDecl(VarTemplateSpecialization); |
| 1127 | return Result; |
| 1128 | } |
| 1129 | |
| 1130 | void VarTemplateSpecializationDecl::getNameForDiagnostic( |
| 1131 | raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const { |
| 1132 | NamedDecl::getNameForDiagnostic(OS, Policy, Qualified); |
| 1133 | |
| 1134 | const TemplateArgumentList &TemplateArgs = getTemplateArgs(); |
| 1135 | TemplateSpecializationType::PrintTemplateArgumentList( |
| 1136 | OS, TemplateArgs.data(), TemplateArgs.size(), Policy); |
| 1137 | } |
| 1138 | |
| 1139 | VarTemplateDecl *VarTemplateSpecializationDecl::getSpecializedTemplate() const { |
| 1140 | if (SpecializedPartialSpecialization *PartialSpec = |
| 1141 | SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>()) |
| 1142 | return PartialSpec->PartialSpecialization->getSpecializedTemplate(); |
| 1143 | return SpecializedTemplate.get<VarTemplateDecl *>(); |
| 1144 | } |
| 1145 | |
| 1146 | void VarTemplateSpecializationDecl::setTemplateArgsInfo( |
| 1147 | const TemplateArgumentListInfo &ArgsInfo) { |
| 1148 | unsigned N = ArgsInfo.size(); |
| 1149 | TemplateArgsInfo.setLAngleLoc(ArgsInfo.getLAngleLoc()); |
| 1150 | TemplateArgsInfo.setRAngleLoc(ArgsInfo.getRAngleLoc()); |
| 1151 | for (unsigned I = 0; I != N; ++I) |
| 1152 | TemplateArgsInfo.addArgument(ArgsInfo[I]); |
| 1153 | } |
| 1154 | |
| 1155 | //===----------------------------------------------------------------------===// |
| 1156 | // VarTemplatePartialSpecializationDecl Implementation |
| 1157 | //===----------------------------------------------------------------------===// |
| 1158 | void VarTemplatePartialSpecializationDecl::anchor() {} |
| 1159 | |
| 1160 | VarTemplatePartialSpecializationDecl::VarTemplatePartialSpecializationDecl( |
| 1161 | ASTContext &Context, DeclContext *DC, SourceLocation StartLoc, |
| 1162 | SourceLocation IdLoc, TemplateParameterList *Params, |
| 1163 | VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo, |
| 1164 | StorageClass S, const TemplateArgument *Args, unsigned NumArgs, |
| 1165 | TemplateArgumentLoc *ArgInfos, unsigned NumArgInfos, |
| 1166 | unsigned SequenceNumber) |
| 1167 | : VarTemplateSpecializationDecl(Context, VarTemplatePartialSpecialization, |
| 1168 | DC, StartLoc, IdLoc, SpecializedTemplate, T, |
| 1169 | TInfo, S, Args, NumArgs), |
| 1170 | TemplateParams(Params), ArgsAsWritten(ArgInfos), |
| 1171 | NumArgsAsWritten(NumArgInfos), SequenceNumber(SequenceNumber), |
| 1172 | InstantiatedFromMember(0, false) { |
| 1173 | // TODO: The template parameters should be in DC by now. Verify. |
| 1174 | // AdoptTemplateParameterList(Params, DC); |
| 1175 | } |
| 1176 | |
| 1177 | VarTemplatePartialSpecializationDecl * |
| 1178 | VarTemplatePartialSpecializationDecl::Create( |
| 1179 | ASTContext &Context, DeclContext *DC, SourceLocation StartLoc, |
| 1180 | SourceLocation IdLoc, TemplateParameterList *Params, |
| 1181 | VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo, |
| 1182 | StorageClass S, const TemplateArgument *Args, unsigned NumArgs, |
| 1183 | const TemplateArgumentListInfo &ArgInfos, unsigned SequenceNumber) { |
| 1184 | unsigned N = ArgInfos.size(); |
| 1185 | TemplateArgumentLoc *ClonedArgs = new (Context) TemplateArgumentLoc[N]; |
| 1186 | for (unsigned I = 0; I != N; ++I) |
| 1187 | ClonedArgs[I] = ArgInfos[I]; |
| 1188 | |
| 1189 | VarTemplatePartialSpecializationDecl *Result = |
| 1190 | new (Context) VarTemplatePartialSpecializationDecl( |
| 1191 | Context, DC, StartLoc, IdLoc, Params, SpecializedTemplate, T, TInfo, |
| 1192 | S, Args, NumArgs, ClonedArgs, N, SequenceNumber); |
| 1193 | Result->setSpecializationKind(TSK_ExplicitSpecialization); |
| 1194 | return Result; |
| 1195 | } |
| 1196 | |
| 1197 | VarTemplatePartialSpecializationDecl * |
| 1198 | VarTemplatePartialSpecializationDecl::CreateDeserialized(ASTContext &C, |
| 1199 | unsigned ID) { |
| 1200 | void *Mem = AllocateDeserializedDecl( |
| 1201 | C, ID, sizeof(VarTemplatePartialSpecializationDecl)); |
| 1202 | VarTemplatePartialSpecializationDecl *Result = |
| 1203 | new (Mem) VarTemplatePartialSpecializationDecl(); |
| 1204 | return Result; |
| 1205 | } |