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 | |
Argyrios Kyrtzidis | 2c853e4 | 2010-07-20 13:59:58 +0000 | [diff] [blame] | 248 | FunctionDecl * |
| 249 | FunctionTemplateDecl::findSpecialization(const TemplateArgument *Args, |
| 250 | unsigned NumArgs, void *&InsertPos) { |
Peter Collingbourne | 4048590 | 2010-07-30 17:09:04 +0000 | [diff] [blame] | 251 | return findSpecializationImpl(getSpecializations(), Args, NumArgs, InsertPos); |
Argyrios Kyrtzidis | 2c853e4 | 2010-07-20 13:59:58 +0000 | [diff] [blame] | 252 | } |
| 253 | |
Sebastian Redl | 5bbcdbf | 2011-04-14 14:07:59 +0000 | [diff] [blame] | 254 | void FunctionTemplateDecl::addSpecialization( |
| 255 | FunctionTemplateSpecializationInfo *Info, void *InsertPos) { |
Douglas Gregor | 1e1e972 | 2012-03-28 14:34:23 +0000 | [diff] [blame] | 256 | if (InsertPos) |
| 257 | getSpecializations().InsertNode(Info, InsertPos); |
| 258 | else |
| 259 | getSpecializations().GetOrInsertNode(Info); |
Sebastian Redl | 5bbcdbf | 2011-04-14 14:07:59 +0000 | [diff] [blame] | 260 | if (ASTMutationListener *L = getASTMutationListener()) |
| 261 | L->AddedCXXTemplateSpecialization(this, Info->Function); |
| 262 | } |
| 263 | |
Douglas Gregor | c494f77 | 2011-03-05 17:54:25 +0000 | [diff] [blame] | 264 | std::pair<const TemplateArgument *, unsigned> |
| 265 | FunctionTemplateDecl::getInjectedTemplateArgs() { |
| 266 | TemplateParameterList *Params = getTemplateParameters(); |
| 267 | Common *CommonPtr = getCommonPtr(); |
| 268 | if (!CommonPtr->InjectedArgs) { |
| 269 | CommonPtr->InjectedArgs |
| 270 | = new (getASTContext()) TemplateArgument [Params->size()]; |
| 271 | GenerateInjectedTemplateArgs(getASTContext(), Params, |
| 272 | CommonPtr->InjectedArgs); |
| 273 | } |
| 274 | |
| 275 | return std::make_pair(CommonPtr->InjectedArgs, Params->size()); |
| 276 | } |
| 277 | |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 278 | //===----------------------------------------------------------------------===// |
| 279 | // ClassTemplateDecl Implementation |
| 280 | //===----------------------------------------------------------------------===// |
| 281 | |
Douglas Gregor | 0054531 | 2010-05-23 18:26:36 +0000 | [diff] [blame] | 282 | void ClassTemplateDecl::DeallocateCommon(void *Ptr) { |
| 283 | static_cast<Common *>(Ptr)->~Common(); |
| 284 | } |
| 285 | |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 286 | ClassTemplateDecl *ClassTemplateDecl::Create(ASTContext &C, |
| 287 | DeclContext *DC, |
| 288 | SourceLocation L, |
| 289 | DeclarationName Name, |
| 290 | TemplateParameterList *Params, |
Douglas Gregor | 5953d8b | 2009-03-19 17:26:29 +0000 | [diff] [blame] | 291 | NamedDecl *Decl, |
| 292 | ClassTemplateDecl *PrevDecl) { |
Douglas Gregor | 787a40d | 2011-03-04 18:32:38 +0000 | [diff] [blame] | 293 | AdoptTemplateParameterList(Params, cast<DeclContext>(Decl)); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 294 | ClassTemplateDecl *New = new (C) ClassTemplateDecl(DC, L, Name, Params, Decl); |
Argyrios Kyrtzidis | 5bf1bdc | 2010-06-21 10:57:41 +0000 | [diff] [blame] | 295 | New->setPreviousDeclaration(PrevDecl); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 296 | return New; |
Douglas Gregor | 5953d8b | 2009-03-19 17:26:29 +0000 | [diff] [blame] | 297 | } |
| 298 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 299 | ClassTemplateDecl *ClassTemplateDecl::CreateDeserialized(ASTContext &C, |
| 300 | unsigned ID) { |
| 301 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ClassTemplateDecl)); |
| 302 | return new (Mem) ClassTemplateDecl(EmptyShell()); |
Douglas Gregor | 9a299e0 | 2011-03-04 17:52:15 +0000 | [diff] [blame] | 303 | } |
| 304 | |
Dmitri Gribenko | e252a89 | 2013-02-14 13:20:36 +0000 | [diff] [blame] | 305 | void ClassTemplateDecl::LoadLazySpecializations() const { |
Douglas Gregor | c8e5cf8 | 2010-10-27 22:21:36 +0000 | [diff] [blame] | 306 | Common *CommonPtr = getCommonPtr(); |
| 307 | if (CommonPtr->LazySpecializations) { |
| 308 | ASTContext &Context = getASTContext(); |
| 309 | uint32_t *Specs = CommonPtr->LazySpecializations; |
| 310 | CommonPtr->LazySpecializations = 0; |
| 311 | for (uint32_t I = 0, N = *Specs++; I != N; ++I) |
| 312 | (void)Context.getExternalSource()->GetExternalDecl(Specs[I]); |
| 313 | } |
| 314 | } |
| 315 | |
Chandler Carruth | d964d63 | 2012-05-03 23:49:05 +0000 | [diff] [blame] | 316 | llvm::FoldingSetVector<ClassTemplateSpecializationDecl> & |
Dmitri Gribenko | e252a89 | 2013-02-14 13:20:36 +0000 | [diff] [blame] | 317 | ClassTemplateDecl::getSpecializations() const { |
Douglas Gregor | c8e5cf8 | 2010-10-27 22:21:36 +0000 | [diff] [blame] | 318 | LoadLazySpecializations(); |
| 319 | return getCommonPtr()->Specializations; |
| 320 | } |
| 321 | |
Chandler Carruth | d964d63 | 2012-05-03 23:49:05 +0000 | [diff] [blame] | 322 | llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> & |
Douglas Gregor | c8e5cf8 | 2010-10-27 22:21:36 +0000 | [diff] [blame] | 323 | ClassTemplateDecl::getPartialSpecializations() { |
| 324 | LoadLazySpecializations(); |
| 325 | return getCommonPtr()->PartialSpecializations; |
| 326 | } |
| 327 | |
Argyrios Kyrtzidis | 6b54151 | 2010-09-08 19:31:22 +0000 | [diff] [blame] | 328 | RedeclarableTemplateDecl::CommonBase * |
Dmitri Gribenko | b76d971 | 2013-01-23 16:52:57 +0000 | [diff] [blame] | 329 | ClassTemplateDecl::newCommon(ASTContext &C) const { |
Argyrios Kyrtzidis | 6b54151 | 2010-09-08 19:31:22 +0000 | [diff] [blame] | 330 | Common *CommonPtr = new (C) Common; |
| 331 | C.AddDeallocation(DeallocateCommon, CommonPtr); |
Peter Collingbourne | 9eabeba | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 332 | return CommonPtr; |
| 333 | } |
| 334 | |
Argyrios Kyrtzidis | cc0b1bc | 2010-07-20 13:59:28 +0000 | [diff] [blame] | 335 | ClassTemplateSpecializationDecl * |
| 336 | ClassTemplateDecl::findSpecialization(const TemplateArgument *Args, |
| 337 | unsigned NumArgs, void *&InsertPos) { |
Peter Collingbourne | 4048590 | 2010-07-30 17:09:04 +0000 | [diff] [blame] | 338 | return findSpecializationImpl(getSpecializations(), Args, NumArgs, InsertPos); |
Argyrios Kyrtzidis | cc0b1bc | 2010-07-20 13:59:28 +0000 | [diff] [blame] | 339 | } |
| 340 | |
Argyrios Kyrtzidis | bef1a7b | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 341 | void ClassTemplateDecl::AddSpecialization(ClassTemplateSpecializationDecl *D, |
| 342 | void *InsertPos) { |
Douglas Gregor | 1e1e972 | 2012-03-28 14:34:23 +0000 | [diff] [blame] | 343 | if (InsertPos) |
| 344 | getSpecializations().InsertNode(D, InsertPos); |
| 345 | else { |
| 346 | ClassTemplateSpecializationDecl *Existing |
| 347 | = getSpecializations().GetOrInsertNode(D); |
| 348 | (void)Existing; |
| 349 | assert(Existing->isCanonicalDecl() && "Non-canonical specialization?"); |
| 350 | } |
Argyrios Kyrtzidis | bef1a7b | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 351 | if (ASTMutationListener *L = getASTMutationListener()) |
| 352 | L->AddedCXXTemplateSpecialization(this, D); |
| 353 | } |
| 354 | |
Argyrios Kyrtzidis | cc0b1bc | 2010-07-20 13:59:28 +0000 | [diff] [blame] | 355 | ClassTemplatePartialSpecializationDecl * |
| 356 | ClassTemplateDecl::findPartialSpecialization(const TemplateArgument *Args, |
| 357 | unsigned NumArgs, |
| 358 | void *&InsertPos) { |
Peter Collingbourne | 4048590 | 2010-07-30 17:09:04 +0000 | [diff] [blame] | 359 | return findSpecializationImpl(getPartialSpecializations(), Args, NumArgs, |
| 360 | InsertPos); |
Argyrios Kyrtzidis | cc0b1bc | 2010-07-20 13:59:28 +0000 | [diff] [blame] | 361 | } |
| 362 | |
Argyrios Kyrtzidis | bef1a7b | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 363 | void ClassTemplateDecl::AddPartialSpecialization( |
| 364 | ClassTemplatePartialSpecializationDecl *D, |
| 365 | void *InsertPos) { |
Douglas Gregor | 1e1e972 | 2012-03-28 14:34:23 +0000 | [diff] [blame] | 366 | if (InsertPos) |
| 367 | getPartialSpecializations().InsertNode(D, InsertPos); |
| 368 | else { |
| 369 | ClassTemplatePartialSpecializationDecl *Existing |
| 370 | = getPartialSpecializations().GetOrInsertNode(D); |
| 371 | (void)Existing; |
| 372 | assert(Existing->isCanonicalDecl() && "Non-canonical specialization?"); |
| 373 | } |
| 374 | |
Argyrios Kyrtzidis | bef1a7b | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 375 | if (ASTMutationListener *L = getASTMutationListener()) |
| 376 | L->AddedCXXTemplateSpecialization(this, D); |
| 377 | } |
| 378 | |
Douglas Gregor | dc60c1e | 2010-04-30 05:56:50 +0000 | [diff] [blame] | 379 | void ClassTemplateDecl::getPartialSpecializations( |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 380 | SmallVectorImpl<ClassTemplatePartialSpecializationDecl *> &PS) { |
Chandler Carruth | d964d63 | 2012-05-03 23:49:05 +0000 | [diff] [blame] | 381 | llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> &PartialSpecs |
Argyrios Kyrtzidis | 5bf1bdc | 2010-06-21 10:57:41 +0000 | [diff] [blame] | 382 | = getPartialSpecializations(); |
Douglas Gregor | dc60c1e | 2010-04-30 05:56:50 +0000 | [diff] [blame] | 383 | PS.clear(); |
| 384 | PS.resize(PartialSpecs.size()); |
Chandler Carruth | d964d63 | 2012-05-03 23:49:05 +0000 | [diff] [blame] | 385 | for (llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl>::iterator |
Douglas Gregor | dc60c1e | 2010-04-30 05:56:50 +0000 | [diff] [blame] | 386 | P = PartialSpecs.begin(), PEnd = PartialSpecs.end(); |
| 387 | P != PEnd; ++P) { |
| 388 | assert(!PS[P->getSequenceNumber()]); |
Douglas Gregor | ef96ee0 | 2012-01-14 16:38:05 +0000 | [diff] [blame] | 389 | PS[P->getSequenceNumber()] = P->getMostRecentDecl(); |
Douglas Gregor | dc60c1e | 2010-04-30 05:56:50 +0000 | [diff] [blame] | 390 | } |
| 391 | } |
| 392 | |
Douglas Gregor | b88e888 | 2009-07-30 17:40:51 +0000 | [diff] [blame] | 393 | ClassTemplatePartialSpecializationDecl * |
| 394 | ClassTemplateDecl::findPartialSpecialization(QualType T) { |
| 395 | ASTContext &Context = getASTContext(); |
Chandler Carruth | d964d63 | 2012-05-03 23:49:05 +0000 | [diff] [blame] | 396 | using llvm::FoldingSetVector; |
| 397 | typedef FoldingSetVector<ClassTemplatePartialSpecializationDecl>::iterator |
Douglas Gregor | b88e888 | 2009-07-30 17:40:51 +0000 | [diff] [blame] | 398 | partial_spec_iterator; |
| 399 | for (partial_spec_iterator P = getPartialSpecializations().begin(), |
| 400 | PEnd = getPartialSpecializations().end(); |
| 401 | P != PEnd; ++P) { |
John McCall | 31f17ec | 2010-04-27 00:57:59 +0000 | [diff] [blame] | 402 | if (Context.hasSameType(P->getInjectedSpecializationType(), T)) |
Douglas Gregor | ef96ee0 | 2012-01-14 16:38:05 +0000 | [diff] [blame] | 403 | return P->getMostRecentDecl(); |
Argyrios Kyrtzidis | cc0b1bc | 2010-07-20 13:59:28 +0000 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | return 0; |
| 407 | } |
| 408 | |
| 409 | ClassTemplatePartialSpecializationDecl * |
| 410 | ClassTemplateDecl::findPartialSpecInstantiatedFromMember( |
| 411 | ClassTemplatePartialSpecializationDecl *D) { |
| 412 | Decl *DCanon = D->getCanonicalDecl(); |
Chandler Carruth | d964d63 | 2012-05-03 23:49:05 +0000 | [diff] [blame] | 413 | for (llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl>::iterator |
Argyrios Kyrtzidis | cc0b1bc | 2010-07-20 13:59:28 +0000 | [diff] [blame] | 414 | P = getPartialSpecializations().begin(), |
| 415 | PEnd = getPartialSpecializations().end(); |
| 416 | P != PEnd; ++P) { |
| 417 | if (P->getInstantiatedFromMember()->getCanonicalDecl() == DCanon) |
Douglas Gregor | ef96ee0 | 2012-01-14 16:38:05 +0000 | [diff] [blame] | 418 | return P->getMostRecentDecl(); |
Douglas Gregor | b88e888 | 2009-07-30 17:40:51 +0000 | [diff] [blame] | 419 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 420 | |
Douglas Gregor | b88e888 | 2009-07-30 17:40:51 +0000 | [diff] [blame] | 421 | return 0; |
| 422 | } |
| 423 | |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 424 | QualType |
Douglas Gregor | 24bae92 | 2010-07-08 18:37:38 +0000 | [diff] [blame] | 425 | ClassTemplateDecl::getInjectedClassNameSpecialization() { |
Argyrios Kyrtzidis | 5bf1bdc | 2010-06-21 10:57:41 +0000 | [diff] [blame] | 426 | Common *CommonPtr = getCommonPtr(); |
Douglas Gregor | 7da97d0 | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 427 | if (!CommonPtr->InjectedClassNameType.isNull()) |
| 428 | return CommonPtr->InjectedClassNameType; |
| 429 | |
Douglas Gregor | b7d09d6 | 2010-12-23 16:00:30 +0000 | [diff] [blame] | 430 | // C++0x [temp.dep.type]p2: |
| 431 | // The template argument list of a primary template is a template argument |
| 432 | // list in which the nth template argument has the value of the nth template |
| 433 | // parameter of the class template. If the nth template parameter is a |
| 434 | // template parameter pack (14.5.3), the nth template argument is a pack |
| 435 | // expansion (14.5.3) whose pattern is the name of the template parameter |
| 436 | // pack. |
Douglas Gregor | 24bae92 | 2010-07-08 18:37:38 +0000 | [diff] [blame] | 437 | ASTContext &Context = getASTContext(); |
Douglas Gregor | 7da97d0 | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 438 | TemplateParameterList *Params = getTemplateParameters(); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 439 | SmallVector<TemplateArgument, 16> TemplateArgs; |
Douglas Gregor | c494f77 | 2011-03-05 17:54:25 +0000 | [diff] [blame] | 440 | TemplateArgs.resize(Params->size()); |
| 441 | GenerateInjectedTemplateArgs(getASTContext(), Params, TemplateArgs.data()); |
Douglas Gregor | 7da97d0 | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 442 | CommonPtr->InjectedClassNameType |
Douglas Gregor | 1275ae0 | 2009-07-28 23:00:59 +0000 | [diff] [blame] | 443 | = Context.getTemplateSpecializationType(TemplateName(this), |
Douglas Gregor | 7da97d0 | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 444 | &TemplateArgs[0], |
Douglas Gregor | 1275ae0 | 2009-07-28 23:00:59 +0000 | [diff] [blame] | 445 | TemplateArgs.size()); |
Douglas Gregor | 7da97d0 | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 446 | return CommonPtr->InjectedClassNameType; |
| 447 | } |
| 448 | |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 449 | //===----------------------------------------------------------------------===// |
| 450 | // TemplateTypeParm Allocation/Deallocation Method Implementations |
| 451 | //===----------------------------------------------------------------------===// |
| 452 | |
| 453 | TemplateTypeParmDecl * |
Jay Foad | 4ba2a17 | 2011-01-12 09:06:06 +0000 | [diff] [blame] | 454 | TemplateTypeParmDecl::Create(const ASTContext &C, DeclContext *DC, |
Abramo Bagnara | 344577e | 2011-03-06 15:48:19 +0000 | [diff] [blame] | 455 | SourceLocation KeyLoc, SourceLocation NameLoc, |
| 456 | unsigned D, unsigned P, IdentifierInfo *Id, |
| 457 | bool Typename, bool ParameterPack) { |
Chandler Carruth | 4fb86f8 | 2011-05-01 00:51:33 +0000 | [diff] [blame] | 458 | TemplateTypeParmDecl *TTPDecl = |
| 459 | new (C) TemplateTypeParmDecl(DC, KeyLoc, NameLoc, Id, Typename); |
| 460 | QualType TTPType = C.getTemplateTypeParmType(D, P, ParameterPack, TTPDecl); |
| 461 | TTPDecl->TypeForDecl = TTPType.getTypePtr(); |
| 462 | return TTPDecl; |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 463 | } |
| 464 | |
Argyrios Kyrtzidis | b8b03e6 | 2010-07-02 11:54:55 +0000 | [diff] [blame] | 465 | TemplateTypeParmDecl * |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 466 | TemplateTypeParmDecl::CreateDeserialized(const ASTContext &C, unsigned ID) { |
| 467 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(TemplateTypeParmDecl)); |
| 468 | return new (Mem) TemplateTypeParmDecl(0, SourceLocation(), SourceLocation(), |
| 469 | 0, false); |
Argyrios Kyrtzidis | b8b03e6 | 2010-07-02 11:54:55 +0000 | [diff] [blame] | 470 | } |
| 471 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 472 | SourceLocation TemplateTypeParmDecl::getDefaultArgumentLoc() const { |
Abramo Bagnara | 77d4ee2 | 2011-03-04 12:42:03 +0000 | [diff] [blame] | 473 | return hasDefaultArgument() |
| 474 | ? DefaultArgument->getTypeLoc().getBeginLoc() |
| 475 | : SourceLocation(); |
| 476 | } |
| 477 | |
| 478 | SourceRange TemplateTypeParmDecl::getSourceRange() const { |
| 479 | if (hasDefaultArgument() && !defaultArgumentWasInherited()) |
Abramo Bagnara | 344577e | 2011-03-06 15:48:19 +0000 | [diff] [blame] | 480 | return SourceRange(getLocStart(), |
Abramo Bagnara | 77d4ee2 | 2011-03-04 12:42:03 +0000 | [diff] [blame] | 481 | DefaultArgument->getTypeLoc().getEndLoc()); |
| 482 | else |
Abramo Bagnara | 344577e | 2011-03-06 15:48:19 +0000 | [diff] [blame] | 483 | return TypeDecl::getSourceRange(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 484 | } |
| 485 | |
Douglas Gregor | ed9c0f9 | 2009-10-29 00:04:11 +0000 | [diff] [blame] | 486 | unsigned TemplateTypeParmDecl::getDepth() const { |
| 487 | return TypeForDecl->getAs<TemplateTypeParmType>()->getDepth(); |
| 488 | } |
| 489 | |
| 490 | unsigned TemplateTypeParmDecl::getIndex() const { |
| 491 | return TypeForDecl->getAs<TemplateTypeParmType>()->getIndex(); |
| 492 | } |
| 493 | |
Chandler Carruth | 4fb86f8 | 2011-05-01 00:51:33 +0000 | [diff] [blame] | 494 | bool TemplateTypeParmDecl::isParameterPack() const { |
| 495 | return TypeForDecl->getAs<TemplateTypeParmType>()->isParameterPack(); |
| 496 | } |
| 497 | |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 498 | //===----------------------------------------------------------------------===// |
| 499 | // NonTypeTemplateParmDecl Method Implementations |
| 500 | //===----------------------------------------------------------------------===// |
| 501 | |
Douglas Gregor | 6952f1e | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 502 | NonTypeTemplateParmDecl::NonTypeTemplateParmDecl(DeclContext *DC, |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 503 | SourceLocation StartLoc, |
| 504 | SourceLocation IdLoc, |
| 505 | unsigned D, unsigned P, |
| 506 | IdentifierInfo *Id, |
Douglas Gregor | 6952f1e | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 507 | QualType T, |
| 508 | TypeSourceInfo *TInfo, |
| 509 | const QualType *ExpandedTypes, |
| 510 | unsigned NumExpandedTypes, |
| 511 | TypeSourceInfo **ExpandedTInfos) |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 512 | : DeclaratorDecl(NonTypeTemplateParm, DC, IdLoc, Id, T, TInfo, StartLoc), |
Douglas Gregor | 6952f1e | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 513 | TemplateParmPosition(D, P), DefaultArgumentAndInherited(0, false), |
| 514 | ParameterPack(true), ExpandedParameterPack(true), |
| 515 | NumExpandedTypes(NumExpandedTypes) |
| 516 | { |
| 517 | if (ExpandedTypes && ExpandedTInfos) { |
| 518 | void **TypesAndInfos = reinterpret_cast<void **>(this + 1); |
| 519 | for (unsigned I = 0; I != NumExpandedTypes; ++I) { |
| 520 | TypesAndInfos[2*I] = ExpandedTypes[I].getAsOpaquePtr(); |
| 521 | TypesAndInfos[2*I + 1] = ExpandedTInfos[I]; |
| 522 | } |
| 523 | } |
| 524 | } |
| 525 | |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 526 | NonTypeTemplateParmDecl * |
Jay Foad | 4ba2a17 | 2011-01-12 09:06:06 +0000 | [diff] [blame] | 527 | NonTypeTemplateParmDecl::Create(const ASTContext &C, DeclContext *DC, |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 528 | SourceLocation StartLoc, SourceLocation IdLoc, |
| 529 | unsigned D, unsigned P, IdentifierInfo *Id, |
| 530 | QualType T, bool ParameterPack, |
| 531 | TypeSourceInfo *TInfo) { |
| 532 | return new (C) NonTypeTemplateParmDecl(DC, StartLoc, IdLoc, D, P, Id, |
| 533 | T, ParameterPack, TInfo); |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 534 | } |
| 535 | |
Douglas Gregor | 6952f1e | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 536 | NonTypeTemplateParmDecl * |
| 537 | NonTypeTemplateParmDecl::Create(const ASTContext &C, DeclContext *DC, |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 538 | SourceLocation StartLoc, SourceLocation IdLoc, |
| 539 | unsigned D, unsigned P, |
Douglas Gregor | 6952f1e | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 540 | IdentifierInfo *Id, QualType T, |
| 541 | TypeSourceInfo *TInfo, |
| 542 | const QualType *ExpandedTypes, |
| 543 | unsigned NumExpandedTypes, |
| 544 | TypeSourceInfo **ExpandedTInfos) { |
| 545 | unsigned Size = sizeof(NonTypeTemplateParmDecl) |
| 546 | + NumExpandedTypes * 2 * sizeof(void*); |
| 547 | void *Mem = C.Allocate(Size); |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 548 | return new (Mem) NonTypeTemplateParmDecl(DC, StartLoc, IdLoc, |
| 549 | D, P, Id, T, TInfo, |
Douglas Gregor | 6952f1e | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 550 | ExpandedTypes, NumExpandedTypes, |
| 551 | ExpandedTInfos); |
| 552 | } |
| 553 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 554 | NonTypeTemplateParmDecl * |
| 555 | NonTypeTemplateParmDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
| 556 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(NonTypeTemplateParmDecl)); |
| 557 | return new (Mem) NonTypeTemplateParmDecl(0, SourceLocation(), |
| 558 | SourceLocation(), 0, 0, 0, |
| 559 | QualType(), false, 0); |
| 560 | } |
| 561 | |
| 562 | NonTypeTemplateParmDecl * |
| 563 | NonTypeTemplateParmDecl::CreateDeserialized(ASTContext &C, unsigned ID, |
| 564 | unsigned NumExpandedTypes) { |
| 565 | unsigned Size = sizeof(NonTypeTemplateParmDecl) |
| 566 | + NumExpandedTypes * 2 * sizeof(void*); |
| 567 | |
| 568 | void *Mem = AllocateDeserializedDecl(C, ID, Size); |
| 569 | return new (Mem) NonTypeTemplateParmDecl(0, SourceLocation(), |
| 570 | SourceLocation(), 0, 0, 0, |
| 571 | QualType(), 0, 0, NumExpandedTypes, |
| 572 | 0); |
| 573 | } |
| 574 | |
John McCall | 76a4021 | 2011-02-09 01:13:10 +0000 | [diff] [blame] | 575 | SourceRange NonTypeTemplateParmDecl::getSourceRange() const { |
Abramo Bagnara | ee4bfd4 | 2011-03-04 11:03:48 +0000 | [diff] [blame] | 576 | if (hasDefaultArgument() && !defaultArgumentWasInherited()) |
Abramo Bagnara | a2026c9 | 2011-03-08 16:41:52 +0000 | [diff] [blame] | 577 | return SourceRange(getOuterLocStart(), |
| 578 | getDefaultArgument()->getSourceRange().getEnd()); |
| 579 | return DeclaratorDecl::getSourceRange(); |
John McCall | 76a4021 | 2011-02-09 01:13:10 +0000 | [diff] [blame] | 580 | } |
| 581 | |
Douglas Gregor | d684b00 | 2009-02-10 19:49:53 +0000 | [diff] [blame] | 582 | SourceLocation NonTypeTemplateParmDecl::getDefaultArgumentLoc() const { |
Abramo Bagnara | d92f7a2 | 2010-06-09 09:26:05 +0000 | [diff] [blame] | 583 | return hasDefaultArgument() |
| 584 | ? getDefaultArgument()->getSourceRange().getBegin() |
| 585 | : SourceLocation(); |
Douglas Gregor | d684b00 | 2009-02-10 19:49:53 +0000 | [diff] [blame] | 586 | } |
| 587 | |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 588 | //===----------------------------------------------------------------------===// |
| 589 | // TemplateTemplateParmDecl Method Implementations |
| 590 | //===----------------------------------------------------------------------===// |
| 591 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 592 | void TemplateTemplateParmDecl::anchor() { } |
| 593 | |
Richard Smith | 6964b3f | 2012-09-07 02:06:42 +0000 | [diff] [blame] | 594 | TemplateTemplateParmDecl::TemplateTemplateParmDecl( |
| 595 | DeclContext *DC, SourceLocation L, unsigned D, unsigned P, |
| 596 | IdentifierInfo *Id, TemplateParameterList *Params, |
| 597 | unsigned NumExpansions, TemplateParameterList * const *Expansions) |
| 598 | : TemplateDecl(TemplateTemplateParm, DC, L, Id, Params), |
| 599 | TemplateParmPosition(D, P), DefaultArgument(), |
| 600 | DefaultArgumentWasInherited(false), ParameterPack(true), |
| 601 | ExpandedParameterPack(true), NumExpandedParams(NumExpansions) { |
| 602 | if (Expansions) |
| 603 | std::memcpy(reinterpret_cast<void*>(this + 1), Expansions, |
| 604 | sizeof(TemplateParameterList*) * NumExpandedParams); |
| 605 | } |
| 606 | |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 607 | TemplateTemplateParmDecl * |
Jay Foad | 4ba2a17 | 2011-01-12 09:06:06 +0000 | [diff] [blame] | 608 | TemplateTemplateParmDecl::Create(const ASTContext &C, DeclContext *DC, |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 609 | SourceLocation L, unsigned D, unsigned P, |
Douglas Gregor | 61c4d28 | 2011-01-05 15:48:55 +0000 | [diff] [blame] | 610 | bool ParameterPack, IdentifierInfo *Id, |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 611 | TemplateParameterList *Params) { |
Douglas Gregor | 61c4d28 | 2011-01-05 15:48:55 +0000 | [diff] [blame] | 612 | return new (C) TemplateTemplateParmDecl(DC, L, D, P, ParameterPack, Id, |
| 613 | Params); |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 614 | } |
| 615 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 616 | TemplateTemplateParmDecl * |
Richard Smith | 6964b3f | 2012-09-07 02:06:42 +0000 | [diff] [blame] | 617 | TemplateTemplateParmDecl::Create(const ASTContext &C, DeclContext *DC, |
| 618 | SourceLocation L, unsigned D, unsigned P, |
| 619 | IdentifierInfo *Id, |
| 620 | TemplateParameterList *Params, |
Dmitri Gribenko | cfa88f8 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 621 | ArrayRef<TemplateParameterList *> Expansions) { |
Richard Smith | 6964b3f | 2012-09-07 02:06:42 +0000 | [diff] [blame] | 622 | void *Mem = C.Allocate(sizeof(TemplateTemplateParmDecl) + |
| 623 | sizeof(TemplateParameterList*) * Expansions.size()); |
| 624 | return new (Mem) TemplateTemplateParmDecl(DC, L, D, P, Id, Params, |
| 625 | Expansions.size(), |
| 626 | Expansions.data()); |
| 627 | } |
| 628 | |
| 629 | TemplateTemplateParmDecl * |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 630 | TemplateTemplateParmDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
| 631 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(TemplateTemplateParmDecl)); |
| 632 | return new (Mem) TemplateTemplateParmDecl(0, SourceLocation(), 0, 0, false, |
| 633 | 0, 0); |
| 634 | } |
| 635 | |
Richard Smith | 6964b3f | 2012-09-07 02:06:42 +0000 | [diff] [blame] | 636 | TemplateTemplateParmDecl * |
| 637 | TemplateTemplateParmDecl::CreateDeserialized(ASTContext &C, unsigned ID, |
| 638 | unsigned NumExpansions) { |
| 639 | unsigned Size = sizeof(TemplateTemplateParmDecl) + |
| 640 | sizeof(TemplateParameterList*) * NumExpansions; |
| 641 | void *Mem = AllocateDeserializedDecl(C, ID, Size); |
| 642 | return new (Mem) TemplateTemplateParmDecl(0, SourceLocation(), 0, 0, 0, 0, |
| 643 | NumExpansions, 0); |
| 644 | } |
| 645 | |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 646 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 7e06390 | 2009-05-11 23:53:27 +0000 | [diff] [blame] | 647 | // TemplateArgumentList Implementation |
| 648 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 649 | TemplateArgumentList * |
| 650 | TemplateArgumentList::CreateCopy(ASTContext &Context, |
| 651 | const TemplateArgument *Args, |
| 652 | unsigned NumArgs) { |
| 653 | std::size_t Size = sizeof(TemplateArgumentList) |
| 654 | + NumArgs * sizeof(TemplateArgument); |
| 655 | void *Mem = Context.Allocate(Size); |
| 656 | TemplateArgument *StoredArgs |
| 657 | = reinterpret_cast<TemplateArgument *>( |
| 658 | static_cast<TemplateArgumentList *>(Mem) + 1); |
| 659 | std::uninitialized_copy(Args, Args + NumArgs, StoredArgs); |
| 660 | return new (Mem) TemplateArgumentList(StoredArgs, NumArgs, true); |
Argyrios Kyrtzidis | 94d228d | 2010-06-23 13:48:23 +0000 | [diff] [blame] | 661 | } |
| 662 | |
Argyrios Kyrtzidis | 71a7605 | 2011-09-22 20:07:09 +0000 | [diff] [blame] | 663 | FunctionTemplateSpecializationInfo * |
| 664 | FunctionTemplateSpecializationInfo::Create(ASTContext &C, FunctionDecl *FD, |
| 665 | FunctionTemplateDecl *Template, |
| 666 | TemplateSpecializationKind TSK, |
| 667 | const TemplateArgumentList *TemplateArgs, |
| 668 | const TemplateArgumentListInfo *TemplateArgsAsWritten, |
| 669 | SourceLocation POI) { |
| 670 | const ASTTemplateArgumentListInfo *ArgsAsWritten = 0; |
| 671 | if (TemplateArgsAsWritten) |
| 672 | ArgsAsWritten = ASTTemplateArgumentListInfo::Create(C, |
| 673 | *TemplateArgsAsWritten); |
| 674 | |
| 675 | return new (C) FunctionTemplateSpecializationInfo(FD, Template, TSK, |
| 676 | TemplateArgs, |
| 677 | ArgsAsWritten, |
| 678 | POI); |
| 679 | } |
| 680 | |
Douglas Gregor | 7e06390 | 2009-05-11 23:53:27 +0000 | [diff] [blame] | 681 | //===----------------------------------------------------------------------===// |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 682 | // TemplateDecl Implementation |
| 683 | //===----------------------------------------------------------------------===// |
| 684 | |
| 685 | void TemplateDecl::anchor() { } |
| 686 | |
| 687 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 688 | // ClassTemplateSpecializationDecl Implementation |
| 689 | //===----------------------------------------------------------------------===// |
| 690 | ClassTemplateSpecializationDecl:: |
Douglas Gregor | 13c8577 | 2010-05-06 00:28:52 +0000 | [diff] [blame] | 691 | ClassTemplateSpecializationDecl(ASTContext &Context, Kind DK, TagKind TK, |
Abramo Bagnara | ba877ad | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 692 | DeclContext *DC, SourceLocation StartLoc, |
| 693 | SourceLocation IdLoc, |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 694 | ClassTemplateDecl *SpecializedTemplate, |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 695 | const TemplateArgument *Args, |
| 696 | unsigned NumArgs, |
Douglas Gregor | 8e9e9ef | 2009-07-29 23:36:44 +0000 | [diff] [blame] | 697 | ClassTemplateSpecializationDecl *PrevDecl) |
Abramo Bagnara | ba877ad | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 698 | : CXXRecordDecl(DK, TK, DC, StartLoc, IdLoc, |
Douglas Gregor | 8e9e9ef | 2009-07-29 23:36:44 +0000 | [diff] [blame] | 699 | SpecializedTemplate->getIdentifier(), |
| 700 | PrevDecl), |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 701 | SpecializedTemplate(SpecializedTemplate), |
Abramo Bagnara | c98971d | 2010-06-12 07:44:57 +0000 | [diff] [blame] | 702 | ExplicitInfo(0), |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 703 | TemplateArgs(TemplateArgumentList::CreateCopy(Context, Args, NumArgs)), |
Douglas Gregor | 7e06390 | 2009-05-11 23:53:27 +0000 | [diff] [blame] | 704 | SpecializationKind(TSK_Undeclared) { |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 705 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 706 | |
Argyrios Kyrtzidis | 94d228d | 2010-06-23 13:48:23 +0000 | [diff] [blame] | 707 | ClassTemplateSpecializationDecl::ClassTemplateSpecializationDecl(Kind DK) |
Abramo Bagnara | ba877ad | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 708 | : CXXRecordDecl(DK, TTK_Struct, 0, SourceLocation(), SourceLocation(), 0, 0), |
Argyrios Kyrtzidis | 94d228d | 2010-06-23 13:48:23 +0000 | [diff] [blame] | 709 | ExplicitInfo(0), |
| 710 | SpecializationKind(TSK_Undeclared) { |
| 711 | } |
| 712 | |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 713 | ClassTemplateSpecializationDecl * |
Douglas Gregor | 13c8577 | 2010-05-06 00:28:52 +0000 | [diff] [blame] | 714 | ClassTemplateSpecializationDecl::Create(ASTContext &Context, TagKind TK, |
Abramo Bagnara | ba877ad | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 715 | DeclContext *DC, |
| 716 | SourceLocation StartLoc, |
| 717 | SourceLocation IdLoc, |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 718 | ClassTemplateDecl *SpecializedTemplate, |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 719 | const TemplateArgument *Args, |
| 720 | unsigned NumArgs, |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 721 | ClassTemplateSpecializationDecl *PrevDecl) { |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 722 | ClassTemplateSpecializationDecl *Result |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 723 | = new (Context)ClassTemplateSpecializationDecl(Context, |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 724 | ClassTemplateSpecialization, |
Abramo Bagnara | ba877ad | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 725 | TK, DC, StartLoc, IdLoc, |
Douglas Gregor | 7e06390 | 2009-05-11 23:53:27 +0000 | [diff] [blame] | 726 | SpecializedTemplate, |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 727 | Args, NumArgs, |
Douglas Gregor | 8e9e9ef | 2009-07-29 23:36:44 +0000 | [diff] [blame] | 728 | PrevDecl); |
Douglas Gregor | 6bd9929 | 2013-02-09 01:35:03 +0000 | [diff] [blame] | 729 | Result->MayHaveOutOfDateDef = false; |
| 730 | |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 731 | Context.getTypeDeclType(Result, PrevDecl); |
| 732 | return Result; |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 733 | } |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 734 | |
Argyrios Kyrtzidis | 94d228d | 2010-06-23 13:48:23 +0000 | [diff] [blame] | 735 | ClassTemplateSpecializationDecl * |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 736 | ClassTemplateSpecializationDecl::CreateDeserialized(ASTContext &C, |
| 737 | unsigned ID) { |
| 738 | void *Mem = AllocateDeserializedDecl(C, ID, |
| 739 | sizeof(ClassTemplateSpecializationDecl)); |
Douglas Gregor | 6bd9929 | 2013-02-09 01:35:03 +0000 | [diff] [blame] | 740 | ClassTemplateSpecializationDecl *Result = |
| 741 | new (Mem) ClassTemplateSpecializationDecl(ClassTemplateSpecialization); |
| 742 | Result->MayHaveOutOfDateDef = false; |
| 743 | return Result; |
Argyrios Kyrtzidis | 94d228d | 2010-06-23 13:48:23 +0000 | [diff] [blame] | 744 | } |
| 745 | |
Douglas Gregor | da2142f | 2011-02-19 18:51:44 +0000 | [diff] [blame] | 746 | void |
| 747 | ClassTemplateSpecializationDecl::getNameForDiagnostic(std::string &S, |
| 748 | const PrintingPolicy &Policy, |
| 749 | bool Qualified) const { |
| 750 | NamedDecl::getNameForDiagnostic(S, Policy, Qualified); |
| 751 | |
| 752 | const TemplateArgumentList &TemplateArgs = getTemplateArgs(); |
| 753 | S += TemplateSpecializationType::PrintTemplateArgumentList( |
| 754 | TemplateArgs.data(), |
| 755 | TemplateArgs.size(), |
| 756 | Policy); |
| 757 | } |
| 758 | |
Douglas Gregor | 37d93e9 | 2009-08-02 23:24:31 +0000 | [diff] [blame] | 759 | ClassTemplateDecl * |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 760 | ClassTemplateSpecializationDecl::getSpecializedTemplate() const { |
| 761 | if (SpecializedPartialSpecialization *PartialSpec |
Douglas Gregor | 37d93e9 | 2009-08-02 23:24:31 +0000 | [diff] [blame] | 762 | = SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization*>()) |
| 763 | return PartialSpec->PartialSpecialization->getSpecializedTemplate(); |
| 764 | return SpecializedTemplate.get<ClassTemplateDecl*>(); |
| 765 | } |
| 766 | |
Abramo Bagnara | 4a85a73 | 2011-03-04 14:20:30 +0000 | [diff] [blame] | 767 | SourceRange |
| 768 | ClassTemplateSpecializationDecl::getSourceRange() const { |
Abramo Bagnara | 09d8212 | 2011-10-03 20:34:03 +0000 | [diff] [blame] | 769 | if (ExplicitInfo) { |
Abramo Bagnara | b2e8001 | 2012-10-15 21:06:42 +0000 | [diff] [blame] | 770 | SourceLocation Begin = getTemplateKeywordLoc(); |
| 771 | if (Begin.isValid()) { |
| 772 | // Here we have an explicit (partial) specialization or instantiation. |
| 773 | assert(getSpecializationKind() == TSK_ExplicitSpecialization || |
| 774 | getSpecializationKind() == TSK_ExplicitInstantiationDeclaration || |
| 775 | getSpecializationKind() == TSK_ExplicitInstantiationDefinition); |
| 776 | if (getExternLoc().isValid()) |
| 777 | Begin = getExternLoc(); |
| 778 | SourceLocation End = getRBraceLoc(); |
| 779 | if (End.isInvalid()) |
| 780 | End = getTypeAsWritten()->getTypeLoc().getEndLoc(); |
| 781 | return SourceRange(Begin, End); |
| 782 | } |
| 783 | // An implicit instantiation of a class template partial specialization |
| 784 | // uses ExplicitInfo to record the TypeAsWritten, but the source |
| 785 | // locations should be retrieved from the instantiation pattern. |
| 786 | typedef ClassTemplatePartialSpecializationDecl CTPSDecl; |
| 787 | CTPSDecl *ctpsd = const_cast<CTPSDecl*>(cast<CTPSDecl>(this)); |
| 788 | CTPSDecl *inst_from = ctpsd->getInstantiatedFromMember(); |
| 789 | assert(inst_from != 0); |
| 790 | return inst_from->getSourceRange(); |
Abramo Bagnara | 09d8212 | 2011-10-03 20:34:03 +0000 | [diff] [blame] | 791 | } |
| 792 | else { |
| 793 | // No explicit info available. |
| 794 | llvm::PointerUnion<ClassTemplateDecl *, |
| 795 | ClassTemplatePartialSpecializationDecl *> |
| 796 | inst_from = getInstantiatedFrom(); |
| 797 | if (inst_from.isNull()) |
| 798 | return getSpecializedTemplate()->getSourceRange(); |
| 799 | if (ClassTemplateDecl *ctd = inst_from.dyn_cast<ClassTemplateDecl*>()) |
| 800 | return ctd->getSourceRange(); |
| 801 | return inst_from.get<ClassTemplatePartialSpecializationDecl*>() |
| 802 | ->getSourceRange(); |
| 803 | } |
Abramo Bagnara | 4a85a73 | 2011-03-04 14:20:30 +0000 | [diff] [blame] | 804 | } |
| 805 | |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 806 | //===----------------------------------------------------------------------===// |
| 807 | // ClassTemplatePartialSpecializationDecl Implementation |
| 808 | //===----------------------------------------------------------------------===// |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 809 | void ClassTemplatePartialSpecializationDecl::anchor() { } |
| 810 | |
Douglas Gregor | 9a299e0 | 2011-03-04 17:52:15 +0000 | [diff] [blame] | 811 | ClassTemplatePartialSpecializationDecl:: |
| 812 | ClassTemplatePartialSpecializationDecl(ASTContext &Context, TagKind TK, |
Abramo Bagnara | ba877ad | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 813 | DeclContext *DC, |
| 814 | SourceLocation StartLoc, |
| 815 | SourceLocation IdLoc, |
Douglas Gregor | 9a299e0 | 2011-03-04 17:52:15 +0000 | [diff] [blame] | 816 | TemplateParameterList *Params, |
| 817 | ClassTemplateDecl *SpecializedTemplate, |
| 818 | const TemplateArgument *Args, |
| 819 | unsigned NumArgs, |
| 820 | TemplateArgumentLoc *ArgInfos, |
| 821 | unsigned NumArgInfos, |
| 822 | ClassTemplatePartialSpecializationDecl *PrevDecl, |
| 823 | unsigned SequenceNumber) |
| 824 | : ClassTemplateSpecializationDecl(Context, |
| 825 | ClassTemplatePartialSpecialization, |
Abramo Bagnara | ba877ad | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 826 | TK, DC, StartLoc, IdLoc, |
| 827 | SpecializedTemplate, |
Douglas Gregor | 9a299e0 | 2011-03-04 17:52:15 +0000 | [diff] [blame] | 828 | Args, NumArgs, PrevDecl), |
| 829 | TemplateParams(Params), ArgsAsWritten(ArgInfos), |
| 830 | NumArgsAsWritten(NumArgInfos), SequenceNumber(SequenceNumber), |
| 831 | InstantiatedFromMember(0, false) |
| 832 | { |
Douglas Gregor | 787a40d | 2011-03-04 18:32:38 +0000 | [diff] [blame] | 833 | AdoptTemplateParameterList(Params, this); |
Douglas Gregor | 9a299e0 | 2011-03-04 17:52:15 +0000 | [diff] [blame] | 834 | } |
| 835 | |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 836 | ClassTemplatePartialSpecializationDecl * |
| 837 | ClassTemplatePartialSpecializationDecl:: |
Abramo Bagnara | ba877ad | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 838 | Create(ASTContext &Context, TagKind TK,DeclContext *DC, |
| 839 | SourceLocation StartLoc, SourceLocation IdLoc, |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 840 | TemplateParameterList *Params, |
| 841 | ClassTemplateDecl *SpecializedTemplate, |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 842 | const TemplateArgument *Args, |
| 843 | unsigned NumArgs, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 844 | const TemplateArgumentListInfo &ArgInfos, |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 845 | QualType CanonInjectedType, |
Douglas Gregor | dc60c1e | 2010-04-30 05:56:50 +0000 | [diff] [blame] | 846 | ClassTemplatePartialSpecializationDecl *PrevDecl, |
| 847 | unsigned SequenceNumber) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 848 | unsigned N = ArgInfos.size(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 849 | TemplateArgumentLoc *ClonedArgs = new (Context) TemplateArgumentLoc[N]; |
| 850 | for (unsigned I = 0; I != N; ++I) |
| 851 | ClonedArgs[I] = ArgInfos[I]; |
| 852 | |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 853 | ClassTemplatePartialSpecializationDecl *Result |
Abramo Bagnara | ba877ad | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 854 | = new (Context)ClassTemplatePartialSpecializationDecl(Context, TK, DC, |
| 855 | StartLoc, IdLoc, |
| 856 | Params, |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 857 | SpecializedTemplate, |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 858 | Args, NumArgs, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 859 | ClonedArgs, N, |
Douglas Gregor | dc60c1e | 2010-04-30 05:56:50 +0000 | [diff] [blame] | 860 | PrevDecl, |
| 861 | SequenceNumber); |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 862 | Result->setSpecializationKind(TSK_ExplicitSpecialization); |
Douglas Gregor | 6bd9929 | 2013-02-09 01:35:03 +0000 | [diff] [blame] | 863 | Result->MayHaveOutOfDateDef = false; |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 864 | |
| 865 | Context.getInjectedClassNameType(Result, CanonInjectedType); |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 866 | return Result; |
| 867 | } |
John McCall | dd4a3b0 | 2009-09-16 22:47:08 +0000 | [diff] [blame] | 868 | |
Argyrios Kyrtzidis | 94d228d | 2010-06-23 13:48:23 +0000 | [diff] [blame] | 869 | ClassTemplatePartialSpecializationDecl * |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 870 | ClassTemplatePartialSpecializationDecl::CreateDeserialized(ASTContext &C, |
| 871 | unsigned ID) { |
| 872 | void *Mem = AllocateDeserializedDecl(C, ID, |
| 873 | sizeof(ClassTemplatePartialSpecializationDecl)); |
Douglas Gregor | 6bd9929 | 2013-02-09 01:35:03 +0000 | [diff] [blame] | 874 | ClassTemplatePartialSpecializationDecl *Result |
| 875 | = new (Mem) ClassTemplatePartialSpecializationDecl(); |
| 876 | Result->MayHaveOutOfDateDef = false; |
| 877 | return Result; |
Argyrios Kyrtzidis | 94d228d | 2010-06-23 13:48:23 +0000 | [diff] [blame] | 878 | } |
| 879 | |
John McCall | dd4a3b0 | 2009-09-16 22:47:08 +0000 | [diff] [blame] | 880 | //===----------------------------------------------------------------------===// |
| 881 | // FriendTemplateDecl Implementation |
| 882 | //===----------------------------------------------------------------------===// |
| 883 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 884 | void FriendTemplateDecl::anchor() { } |
| 885 | |
John McCall | dd4a3b0 | 2009-09-16 22:47:08 +0000 | [diff] [blame] | 886 | FriendTemplateDecl *FriendTemplateDecl::Create(ASTContext &Context, |
| 887 | DeclContext *DC, |
| 888 | SourceLocation L, |
| 889 | unsigned NParams, |
| 890 | TemplateParameterList **Params, |
| 891 | FriendUnion Friend, |
| 892 | SourceLocation FLoc) { |
| 893 | FriendTemplateDecl *Result |
| 894 | = new (Context) FriendTemplateDecl(DC, L, NParams, Params, Friend, FLoc); |
| 895 | return Result; |
| 896 | } |
Argyrios Kyrtzidis | 554e6aa | 2010-07-22 16:04:10 +0000 | [diff] [blame] | 897 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 898 | FriendTemplateDecl *FriendTemplateDecl::CreateDeserialized(ASTContext &C, |
| 899 | unsigned ID) { |
| 900 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(FriendTemplateDecl)); |
| 901 | return new (Mem) FriendTemplateDecl(EmptyShell()); |
Argyrios Kyrtzidis | 554e6aa | 2010-07-22 16:04:10 +0000 | [diff] [blame] | 902 | } |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 903 | |
| 904 | //===----------------------------------------------------------------------===// |
| 905 | // TypeAliasTemplateDecl Implementation |
| 906 | //===----------------------------------------------------------------------===// |
| 907 | |
| 908 | TypeAliasTemplateDecl *TypeAliasTemplateDecl::Create(ASTContext &C, |
| 909 | DeclContext *DC, |
| 910 | SourceLocation L, |
| 911 | DeclarationName Name, |
| 912 | TemplateParameterList *Params, |
| 913 | NamedDecl *Decl) { |
| 914 | AdoptTemplateParameterList(Params, DC); |
| 915 | return new (C) TypeAliasTemplateDecl(DC, L, Name, Params, Decl); |
| 916 | } |
| 917 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 918 | TypeAliasTemplateDecl *TypeAliasTemplateDecl::CreateDeserialized(ASTContext &C, |
| 919 | unsigned ID) { |
| 920 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(TypeAliasTemplateDecl)); |
| 921 | return new (Mem) TypeAliasTemplateDecl(0, SourceLocation(), DeclarationName(), |
| 922 | 0, 0); |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | void TypeAliasTemplateDecl::DeallocateCommon(void *Ptr) { |
| 926 | static_cast<Common *>(Ptr)->~Common(); |
| 927 | } |
| 928 | RedeclarableTemplateDecl::CommonBase * |
Dmitri Gribenko | b76d971 | 2013-01-23 16:52:57 +0000 | [diff] [blame] | 929 | TypeAliasTemplateDecl::newCommon(ASTContext &C) const { |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 930 | Common *CommonPtr = new (C) Common; |
| 931 | C.AddDeallocation(DeallocateCommon, CommonPtr); |
| 932 | return CommonPtr; |
| 933 | } |
| 934 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 935 | //===----------------------------------------------------------------------===// |
| 936 | // ClassScopeFunctionSpecializationDecl Implementation |
| 937 | //===----------------------------------------------------------------------===// |
| 938 | |
| 939 | void ClassScopeFunctionSpecializationDecl::anchor() { } |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 940 | |
| 941 | ClassScopeFunctionSpecializationDecl * |
| 942 | ClassScopeFunctionSpecializationDecl::CreateDeserialized(ASTContext &C, |
| 943 | unsigned ID) { |
| 944 | void *Mem = AllocateDeserializedDecl(C, ID, |
| 945 | sizeof(ClassScopeFunctionSpecializationDecl)); |
Nico Weber | 6b02009 | 2012-06-25 17:21:05 +0000 | [diff] [blame] | 946 | return new (Mem) ClassScopeFunctionSpecializationDecl(0, SourceLocation(), 0, |
| 947 | false, TemplateArgumentListInfo()); |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 948 | } |