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