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