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), |
| 35 | NumParams(NumParams) { |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 36 | for (unsigned Idx = 0; Idx < NumParams; ++Idx) |
| 37 | begin()[Idx] = Params[Idx]; |
| 38 | } |
| 39 | |
| 40 | TemplateParameterList * |
Jay Foad | 4ba2a17 | 2011-01-12 09:06:06 +0000 | [diff] [blame] | 41 | TemplateParameterList::Create(const ASTContext &C, SourceLocation TemplateLoc, |
Douglas Gregor | bf4ea56 | 2009-09-15 16:23:51 +0000 | [diff] [blame] | 42 | SourceLocation LAngleLoc, NamedDecl **Params, |
Douglas Gregor | ddc29e1 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 43 | unsigned NumParams, SourceLocation RAngleLoc) { |
Douglas Gregor | bf4ea56 | 2009-09-15 16:23:51 +0000 | [diff] [blame] | 44 | unsigned Size = sizeof(TemplateParameterList) |
| 45 | + sizeof(NamedDecl *) * NumParams; |
Richard Smith | 1a30edb | 2012-08-16 22:51:34 +0000 | [diff] [blame] | 46 | unsigned Align = std::max(llvm::alignOf<TemplateParameterList>(), |
| 47 | llvm::alignOf<NamedDecl*>()); |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 48 | void *Mem = C.Allocate(Size, Align); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 49 | return new (Mem) TemplateParameterList(TemplateLoc, LAngleLoc, Params, |
Douglas Gregor | ddc29e1 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 50 | NumParams, RAngleLoc); |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 51 | } |
| 52 | |
Douglas Gregor | 62cb18d | 2009-02-11 18:16:40 +0000 | [diff] [blame] | 53 | unsigned TemplateParameterList::getMinRequiredArguments() const { |
Douglas Gregor | 6952f1e | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 54 | unsigned NumRequiredArgs = 0; |
| 55 | for (iterator P = const_cast<TemplateParameterList *>(this)->begin(), |
| 56 | PEnd = const_cast<TemplateParameterList *>(this)->end(); |
| 57 | P != PEnd; ++P) { |
| 58 | if ((*P)->isTemplateParameterPack()) { |
| 59 | if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(*P)) |
| 60 | if (NTTP->isExpandedParameterPack()) { |
| 61 | NumRequiredArgs += NTTP->getNumExpansionTypes(); |
| 62 | continue; |
| 63 | } |
| 64 | |
Douglas Gregor | 62cb18d | 2009-02-11 18:16:40 +0000 | [diff] [blame] | 65 | break; |
Douglas Gregor | 6952f1e | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | if (TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(*P)) { |
| 69 | if (TTP->hasDefaultArgument()) |
| 70 | break; |
| 71 | } else if (NonTypeTemplateParmDecl *NTTP |
| 72 | = dyn_cast<NonTypeTemplateParmDecl>(*P)) { |
| 73 | if (NTTP->hasDefaultArgument()) |
| 74 | break; |
| 75 | } else if (cast<TemplateTemplateParmDecl>(*P)->hasDefaultArgument()) |
| 76 | break; |
| 77 | |
| 78 | ++NumRequiredArgs; |
Douglas Gregor | 62cb18d | 2009-02-11 18:16:40 +0000 | [diff] [blame] | 79 | } |
Douglas Gregor | 6952f1e | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 80 | |
Douglas Gregor | 62cb18d | 2009-02-11 18:16:40 +0000 | [diff] [blame] | 81 | return NumRequiredArgs; |
| 82 | } |
| 83 | |
Douglas Gregor | ed9c0f9 | 2009-10-29 00:04:11 +0000 | [diff] [blame] | 84 | unsigned TemplateParameterList::getDepth() const { |
| 85 | if (size() == 0) |
| 86 | return 0; |
| 87 | |
| 88 | const NamedDecl *FirstParm = getParam(0); |
| 89 | if (const TemplateTypeParmDecl *TTP |
| 90 | = dyn_cast<TemplateTypeParmDecl>(FirstParm)) |
| 91 | return TTP->getDepth(); |
| 92 | else if (const NonTypeTemplateParmDecl *NTTP |
| 93 | = dyn_cast<NonTypeTemplateParmDecl>(FirstParm)) |
| 94 | return NTTP->getDepth(); |
| 95 | else |
| 96 | return cast<TemplateTemplateParmDecl>(FirstParm)->getDepth(); |
| 97 | } |
| 98 | |
Douglas Gregor | 787a40d | 2011-03-04 18:32:38 +0000 | [diff] [blame] | 99 | static void AdoptTemplateParameterList(TemplateParameterList *Params, |
| 100 | DeclContext *Owner) { |
| 101 | for (TemplateParameterList::iterator P = Params->begin(), |
| 102 | PEnd = Params->end(); |
| 103 | P != PEnd; ++P) { |
| 104 | (*P)->setDeclContext(Owner); |
| 105 | |
| 106 | if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(*P)) |
| 107 | AdoptTemplateParameterList(TTP->getTemplateParameters(), Owner); |
| 108 | } |
| 109 | } |
| 110 | |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 111 | //===----------------------------------------------------------------------===// |
Peter Collingbourne | 9eabeba | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 112 | // RedeclarableTemplateDecl Implementation |
| 113 | //===----------------------------------------------------------------------===// |
| 114 | |
| 115 | RedeclarableTemplateDecl::CommonBase *RedeclarableTemplateDecl::getCommonPtr() { |
Douglas Gregor | 7c99bb5c | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 116 | if (!Common) { |
| 117 | // Walk the previous-declaration chain until we either find a declaration |
| 118 | // with a common pointer or we run out of previous declarations. |
| 119 | llvm::SmallVector<RedeclarableTemplateDecl *, 2> PrevDecls; |
Douglas Gregor | ef96ee0 | 2012-01-14 16:38:05 +0000 | [diff] [blame] | 120 | for (RedeclarableTemplateDecl *Prev = getPreviousDecl(); Prev; |
| 121 | Prev = Prev->getPreviousDecl()) { |
Douglas Gregor | 7c99bb5c | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 122 | if (Prev->Common) { |
| 123 | Common = Prev->Common; |
| 124 | break; |
| 125 | } |
| 126 | |
| 127 | PrevDecls.push_back(Prev); |
| 128 | } |
Peter Collingbourne | 9eabeba | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 129 | |
Douglas Gregor | 7c99bb5c | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 130 | // If we never found a common pointer, allocate one now. |
Douglas Gregor | 8a8950b | 2012-01-14 15:30:55 +0000 | [diff] [blame] | 131 | if (!Common) { |
| 132 | // FIXME: If any of the declarations is from an AST file, we probably |
| 133 | // need an update record to add the common data. |
| 134 | |
Douglas Gregor | 7c99bb5c | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 135 | Common = newCommon(getASTContext()); |
Douglas Gregor | 8a8950b | 2012-01-14 15:30:55 +0000 | [diff] [blame] | 136 | } |
Douglas Gregor | 7c99bb5c | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 137 | |
| 138 | // Update any previous declarations we saw with the common pointer. |
| 139 | for (unsigned I = 0, N = PrevDecls.size(); I != N; ++I) |
| 140 | PrevDecls[I]->Common = Common; |
Peter Collingbourne | 9eabeba | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 141 | } |
Peter Collingbourne | 9eabeba | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 142 | |
Douglas Gregor | 7c99bb5c | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 143 | return Common; |
Peter Collingbourne | f88718e | 2010-07-29 16:12:09 +0000 | [diff] [blame] | 144 | } |
| 145 | |
Peter Collingbourne | 4048590 | 2010-07-30 17:09:04 +0000 | [diff] [blame] | 146 | template <class EntryType> |
| 147 | typename RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::DeclType* |
| 148 | RedeclarableTemplateDecl::findSpecializationImpl( |
Chandler Carruth | d964d63 | 2012-05-03 23:49:05 +0000 | [diff] [blame] | 149 | llvm::FoldingSetVector<EntryType> &Specs, |
Peter Collingbourne | 4048590 | 2010-07-30 17:09:04 +0000 | [diff] [blame] | 150 | const TemplateArgument *Args, unsigned NumArgs, |
| 151 | void *&InsertPos) { |
| 152 | typedef SpecEntryTraits<EntryType> SETraits; |
| 153 | llvm::FoldingSetNodeID ID; |
| 154 | EntryType::Profile(ID,Args,NumArgs, getASTContext()); |
| 155 | EntryType *Entry = Specs.FindNodeOrInsertPos(ID, InsertPos); |
Douglas Gregor | ef96ee0 | 2012-01-14 16:38:05 +0000 | [diff] [blame] | 156 | return Entry ? SETraits::getMostRecentDecl(Entry) : 0; |
Peter Collingbourne | 4048590 | 2010-07-30 17:09:04 +0000 | [diff] [blame] | 157 | } |
| 158 | |
Douglas Gregor | c494f77 | 2011-03-05 17:54:25 +0000 | [diff] [blame] | 159 | /// \brief Generate the injected template arguments for the given template |
| 160 | /// parameter list, e.g., for the injected-class-name of a class template. |
| 161 | static void GenerateInjectedTemplateArgs(ASTContext &Context, |
| 162 | TemplateParameterList *Params, |
| 163 | TemplateArgument *Args) { |
| 164 | for (TemplateParameterList::iterator Param = Params->begin(), |
| 165 | ParamEnd = Params->end(); |
| 166 | Param != ParamEnd; ++Param) { |
| 167 | TemplateArgument Arg; |
| 168 | if (TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(*Param)) { |
| 169 | QualType ArgType = Context.getTypeDeclType(TTP); |
| 170 | if (TTP->isParameterPack()) |
| 171 | ArgType = Context.getPackExpansionType(ArgType, |
| 172 | llvm::Optional<unsigned>()); |
| 173 | |
| 174 | Arg = TemplateArgument(ArgType); |
| 175 | } else if (NonTypeTemplateParmDecl *NTTP = |
| 176 | dyn_cast<NonTypeTemplateParmDecl>(*Param)) { |
John McCall | f4b88a4 | 2012-03-10 09:33:50 +0000 | [diff] [blame] | 177 | Expr *E = new (Context) DeclRefExpr(NTTP, /*enclosing*/ false, |
Douglas Gregor | c494f77 | 2011-03-05 17:54:25 +0000 | [diff] [blame] | 178 | NTTP->getType().getNonLValueExprType(Context), |
| 179 | Expr::getValueKindForType(NTTP->getType()), |
| 180 | NTTP->getLocation()); |
| 181 | |
| 182 | if (NTTP->isParameterPack()) |
| 183 | E = new (Context) PackExpansionExpr(Context.DependentTy, E, |
| 184 | NTTP->getLocation(), |
| 185 | llvm::Optional<unsigned>()); |
| 186 | Arg = TemplateArgument(E); |
| 187 | } else { |
| 188 | TemplateTemplateParmDecl *TTP = cast<TemplateTemplateParmDecl>(*Param); |
| 189 | if (TTP->isParameterPack()) |
| 190 | Arg = TemplateArgument(TemplateName(TTP), llvm::Optional<unsigned>()); |
| 191 | else |
| 192 | Arg = TemplateArgument(TemplateName(TTP)); |
| 193 | } |
| 194 | |
| 195 | if ((*Param)->isTemplateParameterPack()) |
| 196 | Arg = TemplateArgument::CreatePackCopy(Context, &Arg, 1); |
| 197 | |
| 198 | *Args++ = Arg; |
| 199 | } |
| 200 | } |
| 201 | |
Peter Collingbourne | 9eabeba | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 202 | //===----------------------------------------------------------------------===// |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 203 | // FunctionTemplateDecl Implementation |
| 204 | //===----------------------------------------------------------------------===// |
| 205 | |
Douglas Gregor | 0054531 | 2010-05-23 18:26:36 +0000 | [diff] [blame] | 206 | void FunctionTemplateDecl::DeallocateCommon(void *Ptr) { |
| 207 | static_cast<Common *>(Ptr)->~Common(); |
| 208 | } |
| 209 | |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 210 | FunctionTemplateDecl *FunctionTemplateDecl::Create(ASTContext &C, |
| 211 | DeclContext *DC, |
| 212 | SourceLocation L, |
| 213 | DeclarationName Name, |
Douglas Gregor | 127102b | 2009-06-29 20:59:39 +0000 | [diff] [blame] | 214 | TemplateParameterList *Params, |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 215 | NamedDecl *Decl) { |
Douglas Gregor | 787a40d | 2011-03-04 18:32:38 +0000 | [diff] [blame] | 216 | AdoptTemplateParameterList(Params, cast<DeclContext>(Decl)); |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 217 | return new (C) FunctionTemplateDecl(DC, L, Name, Params, Decl); |
| 218 | } |
| 219 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 220 | FunctionTemplateDecl *FunctionTemplateDecl::CreateDeserialized(ASTContext &C, |
| 221 | unsigned ID) { |
| 222 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(FunctionTemplateDecl)); |
| 223 | return new (Mem) FunctionTemplateDecl(0, SourceLocation(), DeclarationName(), |
| 224 | 0, 0); |
Douglas Gregor | 9a299e0 | 2011-03-04 17:52:15 +0000 | [diff] [blame] | 225 | } |
| 226 | |
Argyrios Kyrtzidis | 6b54151 | 2010-09-08 19:31:22 +0000 | [diff] [blame] | 227 | RedeclarableTemplateDecl::CommonBase * |
| 228 | FunctionTemplateDecl::newCommon(ASTContext &C) { |
| 229 | Common *CommonPtr = new (C) Common; |
| 230 | C.AddDeallocation(DeallocateCommon, CommonPtr); |
Peter Collingbourne | 9eabeba | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 231 | return CommonPtr; |
| 232 | } |
| 233 | |
Argyrios Kyrtzidis | 2c853e4 | 2010-07-20 13:59:58 +0000 | [diff] [blame] | 234 | FunctionDecl * |
| 235 | FunctionTemplateDecl::findSpecialization(const TemplateArgument *Args, |
| 236 | unsigned NumArgs, void *&InsertPos) { |
Peter Collingbourne | 4048590 | 2010-07-30 17:09:04 +0000 | [diff] [blame] | 237 | return findSpecializationImpl(getSpecializations(), Args, NumArgs, InsertPos); |
Argyrios Kyrtzidis | 2c853e4 | 2010-07-20 13:59:58 +0000 | [diff] [blame] | 238 | } |
| 239 | |
Sebastian Redl | 5bbcdbf | 2011-04-14 14:07:59 +0000 | [diff] [blame] | 240 | void FunctionTemplateDecl::addSpecialization( |
| 241 | FunctionTemplateSpecializationInfo *Info, void *InsertPos) { |
Douglas Gregor | 1e1e972 | 2012-03-28 14:34:23 +0000 | [diff] [blame] | 242 | if (InsertPos) |
| 243 | getSpecializations().InsertNode(Info, InsertPos); |
| 244 | else |
| 245 | getSpecializations().GetOrInsertNode(Info); |
Sebastian Redl | 5bbcdbf | 2011-04-14 14:07:59 +0000 | [diff] [blame] | 246 | if (ASTMutationListener *L = getASTMutationListener()) |
| 247 | L->AddedCXXTemplateSpecialization(this, Info->Function); |
| 248 | } |
| 249 | |
Douglas Gregor | c494f77 | 2011-03-05 17:54:25 +0000 | [diff] [blame] | 250 | std::pair<const TemplateArgument *, unsigned> |
| 251 | FunctionTemplateDecl::getInjectedTemplateArgs() { |
| 252 | TemplateParameterList *Params = getTemplateParameters(); |
| 253 | Common *CommonPtr = getCommonPtr(); |
| 254 | if (!CommonPtr->InjectedArgs) { |
| 255 | CommonPtr->InjectedArgs |
| 256 | = new (getASTContext()) TemplateArgument [Params->size()]; |
| 257 | GenerateInjectedTemplateArgs(getASTContext(), Params, |
| 258 | CommonPtr->InjectedArgs); |
| 259 | } |
| 260 | |
| 261 | return std::make_pair(CommonPtr->InjectedArgs, Params->size()); |
| 262 | } |
| 263 | |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 264 | //===----------------------------------------------------------------------===// |
| 265 | // ClassTemplateDecl Implementation |
| 266 | //===----------------------------------------------------------------------===// |
| 267 | |
Douglas Gregor | 0054531 | 2010-05-23 18:26:36 +0000 | [diff] [blame] | 268 | void ClassTemplateDecl::DeallocateCommon(void *Ptr) { |
| 269 | static_cast<Common *>(Ptr)->~Common(); |
| 270 | } |
| 271 | |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 272 | ClassTemplateDecl *ClassTemplateDecl::Create(ASTContext &C, |
| 273 | DeclContext *DC, |
| 274 | SourceLocation L, |
| 275 | DeclarationName Name, |
| 276 | TemplateParameterList *Params, |
Douglas Gregor | 5953d8b | 2009-03-19 17:26:29 +0000 | [diff] [blame] | 277 | NamedDecl *Decl, |
| 278 | ClassTemplateDecl *PrevDecl) { |
Douglas Gregor | 787a40d | 2011-03-04 18:32:38 +0000 | [diff] [blame] | 279 | AdoptTemplateParameterList(Params, cast<DeclContext>(Decl)); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 280 | ClassTemplateDecl *New = new (C) ClassTemplateDecl(DC, L, Name, Params, Decl); |
Argyrios Kyrtzidis | 5bf1bdc | 2010-06-21 10:57:41 +0000 | [diff] [blame] | 281 | New->setPreviousDeclaration(PrevDecl); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 282 | return New; |
Douglas Gregor | 5953d8b | 2009-03-19 17:26:29 +0000 | [diff] [blame] | 283 | } |
| 284 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 285 | ClassTemplateDecl *ClassTemplateDecl::CreateDeserialized(ASTContext &C, |
| 286 | unsigned ID) { |
| 287 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ClassTemplateDecl)); |
| 288 | return new (Mem) ClassTemplateDecl(EmptyShell()); |
Douglas Gregor | 9a299e0 | 2011-03-04 17:52:15 +0000 | [diff] [blame] | 289 | } |
| 290 | |
Douglas Gregor | c8e5cf8 | 2010-10-27 22:21:36 +0000 | [diff] [blame] | 291 | void ClassTemplateDecl::LoadLazySpecializations() { |
| 292 | Common *CommonPtr = getCommonPtr(); |
| 293 | if (CommonPtr->LazySpecializations) { |
| 294 | ASTContext &Context = getASTContext(); |
| 295 | uint32_t *Specs = CommonPtr->LazySpecializations; |
| 296 | CommonPtr->LazySpecializations = 0; |
| 297 | for (uint32_t I = 0, N = *Specs++; I != N; ++I) |
| 298 | (void)Context.getExternalSource()->GetExternalDecl(Specs[I]); |
| 299 | } |
| 300 | } |
| 301 | |
Chandler Carruth | d964d63 | 2012-05-03 23:49:05 +0000 | [diff] [blame] | 302 | llvm::FoldingSetVector<ClassTemplateSpecializationDecl> & |
Douglas Gregor | c8e5cf8 | 2010-10-27 22:21:36 +0000 | [diff] [blame] | 303 | ClassTemplateDecl::getSpecializations() { |
| 304 | LoadLazySpecializations(); |
| 305 | return getCommonPtr()->Specializations; |
| 306 | } |
| 307 | |
Chandler Carruth | d964d63 | 2012-05-03 23:49:05 +0000 | [diff] [blame] | 308 | llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> & |
Douglas Gregor | c8e5cf8 | 2010-10-27 22:21:36 +0000 | [diff] [blame] | 309 | ClassTemplateDecl::getPartialSpecializations() { |
| 310 | LoadLazySpecializations(); |
| 311 | return getCommonPtr()->PartialSpecializations; |
| 312 | } |
| 313 | |
Argyrios Kyrtzidis | 6b54151 | 2010-09-08 19:31:22 +0000 | [diff] [blame] | 314 | RedeclarableTemplateDecl::CommonBase * |
| 315 | ClassTemplateDecl::newCommon(ASTContext &C) { |
| 316 | Common *CommonPtr = new (C) Common; |
| 317 | C.AddDeallocation(DeallocateCommon, CommonPtr); |
Peter Collingbourne | 9eabeba | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 318 | return CommonPtr; |
| 319 | } |
| 320 | |
Argyrios Kyrtzidis | cc0b1bc | 2010-07-20 13:59:28 +0000 | [diff] [blame] | 321 | ClassTemplateSpecializationDecl * |
| 322 | ClassTemplateDecl::findSpecialization(const TemplateArgument *Args, |
| 323 | unsigned NumArgs, void *&InsertPos) { |
Peter Collingbourne | 4048590 | 2010-07-30 17:09:04 +0000 | [diff] [blame] | 324 | return findSpecializationImpl(getSpecializations(), Args, NumArgs, InsertPos); |
Argyrios Kyrtzidis | cc0b1bc | 2010-07-20 13:59:28 +0000 | [diff] [blame] | 325 | } |
| 326 | |
Argyrios Kyrtzidis | bef1a7b | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 327 | void ClassTemplateDecl::AddSpecialization(ClassTemplateSpecializationDecl *D, |
| 328 | void *InsertPos) { |
Douglas Gregor | 1e1e972 | 2012-03-28 14:34:23 +0000 | [diff] [blame] | 329 | if (InsertPos) |
| 330 | getSpecializations().InsertNode(D, InsertPos); |
| 331 | else { |
| 332 | ClassTemplateSpecializationDecl *Existing |
| 333 | = getSpecializations().GetOrInsertNode(D); |
| 334 | (void)Existing; |
| 335 | assert(Existing->isCanonicalDecl() && "Non-canonical specialization?"); |
| 336 | } |
Argyrios Kyrtzidis | bef1a7b | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 337 | if (ASTMutationListener *L = getASTMutationListener()) |
| 338 | L->AddedCXXTemplateSpecialization(this, D); |
| 339 | } |
| 340 | |
Argyrios Kyrtzidis | cc0b1bc | 2010-07-20 13:59:28 +0000 | [diff] [blame] | 341 | ClassTemplatePartialSpecializationDecl * |
| 342 | ClassTemplateDecl::findPartialSpecialization(const TemplateArgument *Args, |
| 343 | unsigned NumArgs, |
| 344 | void *&InsertPos) { |
Peter Collingbourne | 4048590 | 2010-07-30 17:09:04 +0000 | [diff] [blame] | 345 | return findSpecializationImpl(getPartialSpecializations(), Args, NumArgs, |
| 346 | InsertPos); |
Argyrios Kyrtzidis | cc0b1bc | 2010-07-20 13:59:28 +0000 | [diff] [blame] | 347 | } |
| 348 | |
Argyrios Kyrtzidis | bef1a7b | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 349 | void ClassTemplateDecl::AddPartialSpecialization( |
| 350 | ClassTemplatePartialSpecializationDecl *D, |
| 351 | void *InsertPos) { |
Douglas Gregor | 1e1e972 | 2012-03-28 14:34:23 +0000 | [diff] [blame] | 352 | if (InsertPos) |
| 353 | getPartialSpecializations().InsertNode(D, InsertPos); |
| 354 | else { |
| 355 | ClassTemplatePartialSpecializationDecl *Existing |
| 356 | = getPartialSpecializations().GetOrInsertNode(D); |
| 357 | (void)Existing; |
| 358 | assert(Existing->isCanonicalDecl() && "Non-canonical specialization?"); |
| 359 | } |
| 360 | |
Argyrios Kyrtzidis | bef1a7b | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 361 | if (ASTMutationListener *L = getASTMutationListener()) |
| 362 | L->AddedCXXTemplateSpecialization(this, D); |
| 363 | } |
| 364 | |
Douglas Gregor | dc60c1e | 2010-04-30 05:56:50 +0000 | [diff] [blame] | 365 | void ClassTemplateDecl::getPartialSpecializations( |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 366 | SmallVectorImpl<ClassTemplatePartialSpecializationDecl *> &PS) { |
Chandler Carruth | d964d63 | 2012-05-03 23:49:05 +0000 | [diff] [blame] | 367 | llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> &PartialSpecs |
Argyrios Kyrtzidis | 5bf1bdc | 2010-06-21 10:57:41 +0000 | [diff] [blame] | 368 | = getPartialSpecializations(); |
Douglas Gregor | dc60c1e | 2010-04-30 05:56:50 +0000 | [diff] [blame] | 369 | PS.clear(); |
| 370 | PS.resize(PartialSpecs.size()); |
Chandler Carruth | d964d63 | 2012-05-03 23:49:05 +0000 | [diff] [blame] | 371 | for (llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl>::iterator |
Douglas Gregor | dc60c1e | 2010-04-30 05:56:50 +0000 | [diff] [blame] | 372 | P = PartialSpecs.begin(), PEnd = PartialSpecs.end(); |
| 373 | P != PEnd; ++P) { |
| 374 | assert(!PS[P->getSequenceNumber()]); |
Douglas Gregor | ef96ee0 | 2012-01-14 16:38:05 +0000 | [diff] [blame] | 375 | PS[P->getSequenceNumber()] = P->getMostRecentDecl(); |
Douglas Gregor | dc60c1e | 2010-04-30 05:56:50 +0000 | [diff] [blame] | 376 | } |
| 377 | } |
| 378 | |
Douglas Gregor | b88e888 | 2009-07-30 17:40:51 +0000 | [diff] [blame] | 379 | ClassTemplatePartialSpecializationDecl * |
| 380 | ClassTemplateDecl::findPartialSpecialization(QualType T) { |
| 381 | ASTContext &Context = getASTContext(); |
Chandler Carruth | d964d63 | 2012-05-03 23:49:05 +0000 | [diff] [blame] | 382 | using llvm::FoldingSetVector; |
| 383 | typedef FoldingSetVector<ClassTemplatePartialSpecializationDecl>::iterator |
Douglas Gregor | b88e888 | 2009-07-30 17:40:51 +0000 | [diff] [blame] | 384 | partial_spec_iterator; |
| 385 | for (partial_spec_iterator P = getPartialSpecializations().begin(), |
| 386 | PEnd = getPartialSpecializations().end(); |
| 387 | P != PEnd; ++P) { |
John McCall | 31f17ec | 2010-04-27 00:57:59 +0000 | [diff] [blame] | 388 | if (Context.hasSameType(P->getInjectedSpecializationType(), T)) |
Douglas Gregor | ef96ee0 | 2012-01-14 16:38:05 +0000 | [diff] [blame] | 389 | return P->getMostRecentDecl(); |
Argyrios Kyrtzidis | cc0b1bc | 2010-07-20 13:59:28 +0000 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | return 0; |
| 393 | } |
| 394 | |
| 395 | ClassTemplatePartialSpecializationDecl * |
| 396 | ClassTemplateDecl::findPartialSpecInstantiatedFromMember( |
| 397 | ClassTemplatePartialSpecializationDecl *D) { |
| 398 | Decl *DCanon = D->getCanonicalDecl(); |
Chandler Carruth | d964d63 | 2012-05-03 23:49:05 +0000 | [diff] [blame] | 399 | for (llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl>::iterator |
Argyrios Kyrtzidis | cc0b1bc | 2010-07-20 13:59:28 +0000 | [diff] [blame] | 400 | P = getPartialSpecializations().begin(), |
| 401 | PEnd = getPartialSpecializations().end(); |
| 402 | P != PEnd; ++P) { |
| 403 | if (P->getInstantiatedFromMember()->getCanonicalDecl() == DCanon) |
Douglas Gregor | ef96ee0 | 2012-01-14 16:38:05 +0000 | [diff] [blame] | 404 | return P->getMostRecentDecl(); |
Douglas Gregor | b88e888 | 2009-07-30 17:40:51 +0000 | [diff] [blame] | 405 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 406 | |
Douglas Gregor | b88e888 | 2009-07-30 17:40:51 +0000 | [diff] [blame] | 407 | return 0; |
| 408 | } |
| 409 | |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 410 | QualType |
Douglas Gregor | 24bae92 | 2010-07-08 18:37:38 +0000 | [diff] [blame] | 411 | ClassTemplateDecl::getInjectedClassNameSpecialization() { |
Argyrios Kyrtzidis | 5bf1bdc | 2010-06-21 10:57:41 +0000 | [diff] [blame] | 412 | Common *CommonPtr = getCommonPtr(); |
Douglas Gregor | 7da97d0 | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 413 | if (!CommonPtr->InjectedClassNameType.isNull()) |
| 414 | return CommonPtr->InjectedClassNameType; |
| 415 | |
Douglas Gregor | b7d09d6 | 2010-12-23 16:00:30 +0000 | [diff] [blame] | 416 | // C++0x [temp.dep.type]p2: |
| 417 | // The template argument list of a primary template is a template argument |
| 418 | // list in which the nth template argument has the value of the nth template |
| 419 | // parameter of the class template. If the nth template parameter is a |
| 420 | // template parameter pack (14.5.3), the nth template argument is a pack |
| 421 | // expansion (14.5.3) whose pattern is the name of the template parameter |
| 422 | // pack. |
Douglas Gregor | 24bae92 | 2010-07-08 18:37:38 +0000 | [diff] [blame] | 423 | ASTContext &Context = getASTContext(); |
Douglas Gregor | 7da97d0 | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 424 | TemplateParameterList *Params = getTemplateParameters(); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 425 | SmallVector<TemplateArgument, 16> TemplateArgs; |
Douglas Gregor | c494f77 | 2011-03-05 17:54:25 +0000 | [diff] [blame] | 426 | TemplateArgs.resize(Params->size()); |
| 427 | GenerateInjectedTemplateArgs(getASTContext(), Params, TemplateArgs.data()); |
Douglas Gregor | 7da97d0 | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 428 | CommonPtr->InjectedClassNameType |
Douglas Gregor | 1275ae0 | 2009-07-28 23:00:59 +0000 | [diff] [blame] | 429 | = Context.getTemplateSpecializationType(TemplateName(this), |
Douglas Gregor | 7da97d0 | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 430 | &TemplateArgs[0], |
Douglas Gregor | 1275ae0 | 2009-07-28 23:00:59 +0000 | [diff] [blame] | 431 | TemplateArgs.size()); |
Douglas Gregor | 7da97d0 | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 432 | return CommonPtr->InjectedClassNameType; |
| 433 | } |
| 434 | |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 435 | //===----------------------------------------------------------------------===// |
| 436 | // TemplateTypeParm Allocation/Deallocation Method Implementations |
| 437 | //===----------------------------------------------------------------------===// |
| 438 | |
| 439 | TemplateTypeParmDecl * |
Jay Foad | 4ba2a17 | 2011-01-12 09:06:06 +0000 | [diff] [blame] | 440 | TemplateTypeParmDecl::Create(const ASTContext &C, DeclContext *DC, |
Abramo Bagnara | 344577e | 2011-03-06 15:48:19 +0000 | [diff] [blame] | 441 | SourceLocation KeyLoc, SourceLocation NameLoc, |
| 442 | unsigned D, unsigned P, IdentifierInfo *Id, |
| 443 | bool Typename, bool ParameterPack) { |
Chandler Carruth | 4fb86f8 | 2011-05-01 00:51:33 +0000 | [diff] [blame] | 444 | TemplateTypeParmDecl *TTPDecl = |
| 445 | new (C) TemplateTypeParmDecl(DC, KeyLoc, NameLoc, Id, Typename); |
| 446 | QualType TTPType = C.getTemplateTypeParmType(D, P, ParameterPack, TTPDecl); |
| 447 | TTPDecl->TypeForDecl = TTPType.getTypePtr(); |
| 448 | return TTPDecl; |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 449 | } |
| 450 | |
Argyrios Kyrtzidis | b8b03e6 | 2010-07-02 11:54:55 +0000 | [diff] [blame] | 451 | TemplateTypeParmDecl * |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 452 | TemplateTypeParmDecl::CreateDeserialized(const ASTContext &C, unsigned ID) { |
| 453 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(TemplateTypeParmDecl)); |
| 454 | return new (Mem) TemplateTypeParmDecl(0, SourceLocation(), SourceLocation(), |
| 455 | 0, false); |
Argyrios Kyrtzidis | b8b03e6 | 2010-07-02 11:54:55 +0000 | [diff] [blame] | 456 | } |
| 457 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 458 | SourceLocation TemplateTypeParmDecl::getDefaultArgumentLoc() const { |
Abramo Bagnara | 77d4ee2 | 2011-03-04 12:42:03 +0000 | [diff] [blame] | 459 | return hasDefaultArgument() |
| 460 | ? DefaultArgument->getTypeLoc().getBeginLoc() |
| 461 | : SourceLocation(); |
| 462 | } |
| 463 | |
| 464 | SourceRange TemplateTypeParmDecl::getSourceRange() const { |
| 465 | if (hasDefaultArgument() && !defaultArgumentWasInherited()) |
Abramo Bagnara | 344577e | 2011-03-06 15:48:19 +0000 | [diff] [blame] | 466 | return SourceRange(getLocStart(), |
Abramo Bagnara | 77d4ee2 | 2011-03-04 12:42:03 +0000 | [diff] [blame] | 467 | DefaultArgument->getTypeLoc().getEndLoc()); |
| 468 | else |
Abramo Bagnara | 344577e | 2011-03-06 15:48:19 +0000 | [diff] [blame] | 469 | return TypeDecl::getSourceRange(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 470 | } |
| 471 | |
Douglas Gregor | ed9c0f9 | 2009-10-29 00:04:11 +0000 | [diff] [blame] | 472 | unsigned TemplateTypeParmDecl::getDepth() const { |
| 473 | return TypeForDecl->getAs<TemplateTypeParmType>()->getDepth(); |
| 474 | } |
| 475 | |
| 476 | unsigned TemplateTypeParmDecl::getIndex() const { |
| 477 | return TypeForDecl->getAs<TemplateTypeParmType>()->getIndex(); |
| 478 | } |
| 479 | |
Chandler Carruth | 4fb86f8 | 2011-05-01 00:51:33 +0000 | [diff] [blame] | 480 | bool TemplateTypeParmDecl::isParameterPack() const { |
| 481 | return TypeForDecl->getAs<TemplateTypeParmType>()->isParameterPack(); |
| 482 | } |
| 483 | |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 484 | //===----------------------------------------------------------------------===// |
| 485 | // NonTypeTemplateParmDecl Method Implementations |
| 486 | //===----------------------------------------------------------------------===// |
| 487 | |
Douglas Gregor | 6952f1e | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 488 | NonTypeTemplateParmDecl::NonTypeTemplateParmDecl(DeclContext *DC, |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 489 | SourceLocation StartLoc, |
| 490 | SourceLocation IdLoc, |
| 491 | unsigned D, unsigned P, |
| 492 | IdentifierInfo *Id, |
Douglas Gregor | 6952f1e | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 493 | QualType T, |
| 494 | TypeSourceInfo *TInfo, |
| 495 | const QualType *ExpandedTypes, |
| 496 | unsigned NumExpandedTypes, |
| 497 | TypeSourceInfo **ExpandedTInfos) |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 498 | : DeclaratorDecl(NonTypeTemplateParm, DC, IdLoc, Id, T, TInfo, StartLoc), |
Douglas Gregor | 6952f1e | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 499 | TemplateParmPosition(D, P), DefaultArgumentAndInherited(0, false), |
| 500 | ParameterPack(true), ExpandedParameterPack(true), |
| 501 | NumExpandedTypes(NumExpandedTypes) |
| 502 | { |
| 503 | if (ExpandedTypes && ExpandedTInfos) { |
| 504 | void **TypesAndInfos = reinterpret_cast<void **>(this + 1); |
| 505 | for (unsigned I = 0; I != NumExpandedTypes; ++I) { |
| 506 | TypesAndInfos[2*I] = ExpandedTypes[I].getAsOpaquePtr(); |
| 507 | TypesAndInfos[2*I + 1] = ExpandedTInfos[I]; |
| 508 | } |
| 509 | } |
| 510 | } |
| 511 | |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 512 | NonTypeTemplateParmDecl * |
Jay Foad | 4ba2a17 | 2011-01-12 09:06:06 +0000 | [diff] [blame] | 513 | NonTypeTemplateParmDecl::Create(const ASTContext &C, DeclContext *DC, |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 514 | SourceLocation StartLoc, SourceLocation IdLoc, |
| 515 | unsigned D, unsigned P, IdentifierInfo *Id, |
| 516 | QualType T, bool ParameterPack, |
| 517 | TypeSourceInfo *TInfo) { |
| 518 | return new (C) NonTypeTemplateParmDecl(DC, StartLoc, IdLoc, D, P, Id, |
| 519 | T, ParameterPack, TInfo); |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 520 | } |
| 521 | |
Douglas Gregor | 6952f1e | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 522 | NonTypeTemplateParmDecl * |
| 523 | NonTypeTemplateParmDecl::Create(const ASTContext &C, DeclContext *DC, |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 524 | SourceLocation StartLoc, SourceLocation IdLoc, |
| 525 | unsigned D, unsigned P, |
Douglas Gregor | 6952f1e | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 526 | IdentifierInfo *Id, QualType T, |
| 527 | TypeSourceInfo *TInfo, |
| 528 | const QualType *ExpandedTypes, |
| 529 | unsigned NumExpandedTypes, |
| 530 | TypeSourceInfo **ExpandedTInfos) { |
| 531 | unsigned Size = sizeof(NonTypeTemplateParmDecl) |
| 532 | + NumExpandedTypes * 2 * sizeof(void*); |
| 533 | void *Mem = C.Allocate(Size); |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 534 | return new (Mem) NonTypeTemplateParmDecl(DC, StartLoc, IdLoc, |
| 535 | D, P, Id, T, TInfo, |
Douglas Gregor | 6952f1e | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 536 | ExpandedTypes, NumExpandedTypes, |
| 537 | ExpandedTInfos); |
| 538 | } |
| 539 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 540 | NonTypeTemplateParmDecl * |
| 541 | NonTypeTemplateParmDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
| 542 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(NonTypeTemplateParmDecl)); |
| 543 | return new (Mem) NonTypeTemplateParmDecl(0, SourceLocation(), |
| 544 | SourceLocation(), 0, 0, 0, |
| 545 | QualType(), false, 0); |
| 546 | } |
| 547 | |
| 548 | NonTypeTemplateParmDecl * |
| 549 | NonTypeTemplateParmDecl::CreateDeserialized(ASTContext &C, unsigned ID, |
| 550 | unsigned NumExpandedTypes) { |
| 551 | unsigned Size = sizeof(NonTypeTemplateParmDecl) |
| 552 | + NumExpandedTypes * 2 * sizeof(void*); |
| 553 | |
| 554 | void *Mem = AllocateDeserializedDecl(C, ID, Size); |
| 555 | return new (Mem) NonTypeTemplateParmDecl(0, SourceLocation(), |
| 556 | SourceLocation(), 0, 0, 0, |
| 557 | QualType(), 0, 0, NumExpandedTypes, |
| 558 | 0); |
| 559 | } |
| 560 | |
John McCall | 76a4021 | 2011-02-09 01:13:10 +0000 | [diff] [blame] | 561 | SourceRange NonTypeTemplateParmDecl::getSourceRange() const { |
Abramo Bagnara | ee4bfd4 | 2011-03-04 11:03:48 +0000 | [diff] [blame] | 562 | if (hasDefaultArgument() && !defaultArgumentWasInherited()) |
Abramo Bagnara | a2026c9 | 2011-03-08 16:41:52 +0000 | [diff] [blame] | 563 | return SourceRange(getOuterLocStart(), |
| 564 | getDefaultArgument()->getSourceRange().getEnd()); |
| 565 | return DeclaratorDecl::getSourceRange(); |
John McCall | 76a4021 | 2011-02-09 01:13:10 +0000 | [diff] [blame] | 566 | } |
| 567 | |
Douglas Gregor | d684b00 | 2009-02-10 19:49:53 +0000 | [diff] [blame] | 568 | SourceLocation NonTypeTemplateParmDecl::getDefaultArgumentLoc() const { |
Abramo Bagnara | d92f7a2 | 2010-06-09 09:26:05 +0000 | [diff] [blame] | 569 | return hasDefaultArgument() |
| 570 | ? getDefaultArgument()->getSourceRange().getBegin() |
| 571 | : SourceLocation(); |
Douglas Gregor | d684b00 | 2009-02-10 19:49:53 +0000 | [diff] [blame] | 572 | } |
| 573 | |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 574 | //===----------------------------------------------------------------------===// |
| 575 | // TemplateTemplateParmDecl Method Implementations |
| 576 | //===----------------------------------------------------------------------===// |
| 577 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 578 | void TemplateTemplateParmDecl::anchor() { } |
| 579 | |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 580 | TemplateTemplateParmDecl * |
Jay Foad | 4ba2a17 | 2011-01-12 09:06:06 +0000 | [diff] [blame] | 581 | TemplateTemplateParmDecl::Create(const ASTContext &C, DeclContext *DC, |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 582 | SourceLocation L, unsigned D, unsigned P, |
Douglas Gregor | 61c4d28 | 2011-01-05 15:48:55 +0000 | [diff] [blame] | 583 | bool ParameterPack, IdentifierInfo *Id, |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 584 | TemplateParameterList *Params) { |
Douglas Gregor | 61c4d28 | 2011-01-05 15:48:55 +0000 | [diff] [blame] | 585 | return new (C) TemplateTemplateParmDecl(DC, L, D, P, ParameterPack, Id, |
| 586 | Params); |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 587 | } |
| 588 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 589 | TemplateTemplateParmDecl * |
| 590 | TemplateTemplateParmDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
| 591 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(TemplateTemplateParmDecl)); |
| 592 | return new (Mem) TemplateTemplateParmDecl(0, SourceLocation(), 0, 0, false, |
| 593 | 0, 0); |
| 594 | } |
| 595 | |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 596 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 7e06390 | 2009-05-11 23:53:27 +0000 | [diff] [blame] | 597 | // TemplateArgumentList Implementation |
| 598 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 599 | TemplateArgumentList * |
| 600 | TemplateArgumentList::CreateCopy(ASTContext &Context, |
| 601 | const TemplateArgument *Args, |
| 602 | unsigned NumArgs) { |
| 603 | std::size_t Size = sizeof(TemplateArgumentList) |
| 604 | + NumArgs * sizeof(TemplateArgument); |
| 605 | void *Mem = Context.Allocate(Size); |
| 606 | TemplateArgument *StoredArgs |
| 607 | = reinterpret_cast<TemplateArgument *>( |
| 608 | static_cast<TemplateArgumentList *>(Mem) + 1); |
| 609 | std::uninitialized_copy(Args, Args + NumArgs, StoredArgs); |
| 610 | return new (Mem) TemplateArgumentList(StoredArgs, NumArgs, true); |
Argyrios Kyrtzidis | 94d228d | 2010-06-23 13:48:23 +0000 | [diff] [blame] | 611 | } |
| 612 | |
Argyrios Kyrtzidis | 71a7605 | 2011-09-22 20:07:09 +0000 | [diff] [blame] | 613 | FunctionTemplateSpecializationInfo * |
| 614 | FunctionTemplateSpecializationInfo::Create(ASTContext &C, FunctionDecl *FD, |
| 615 | FunctionTemplateDecl *Template, |
| 616 | TemplateSpecializationKind TSK, |
| 617 | const TemplateArgumentList *TemplateArgs, |
| 618 | const TemplateArgumentListInfo *TemplateArgsAsWritten, |
| 619 | SourceLocation POI) { |
| 620 | const ASTTemplateArgumentListInfo *ArgsAsWritten = 0; |
| 621 | if (TemplateArgsAsWritten) |
| 622 | ArgsAsWritten = ASTTemplateArgumentListInfo::Create(C, |
| 623 | *TemplateArgsAsWritten); |
| 624 | |
| 625 | return new (C) FunctionTemplateSpecializationInfo(FD, Template, TSK, |
| 626 | TemplateArgs, |
| 627 | ArgsAsWritten, |
| 628 | POI); |
| 629 | } |
| 630 | |
Douglas Gregor | 7e06390 | 2009-05-11 23:53:27 +0000 | [diff] [blame] | 631 | //===----------------------------------------------------------------------===// |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 632 | // TemplateDecl Implementation |
| 633 | //===----------------------------------------------------------------------===// |
| 634 | |
| 635 | void TemplateDecl::anchor() { } |
| 636 | |
| 637 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 638 | // ClassTemplateSpecializationDecl Implementation |
| 639 | //===----------------------------------------------------------------------===// |
| 640 | ClassTemplateSpecializationDecl:: |
Douglas Gregor | 13c8577 | 2010-05-06 00:28:52 +0000 | [diff] [blame] | 641 | ClassTemplateSpecializationDecl(ASTContext &Context, Kind DK, TagKind TK, |
Abramo Bagnara | ba877ad | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 642 | DeclContext *DC, SourceLocation StartLoc, |
| 643 | SourceLocation IdLoc, |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 644 | ClassTemplateDecl *SpecializedTemplate, |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 645 | const TemplateArgument *Args, |
| 646 | unsigned NumArgs, |
Douglas Gregor | 8e9e9ef | 2009-07-29 23:36:44 +0000 | [diff] [blame] | 647 | ClassTemplateSpecializationDecl *PrevDecl) |
Abramo Bagnara | ba877ad | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 648 | : CXXRecordDecl(DK, TK, DC, StartLoc, IdLoc, |
Douglas Gregor | 8e9e9ef | 2009-07-29 23:36:44 +0000 | [diff] [blame] | 649 | SpecializedTemplate->getIdentifier(), |
| 650 | PrevDecl), |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 651 | SpecializedTemplate(SpecializedTemplate), |
Abramo Bagnara | c98971d | 2010-06-12 07:44:57 +0000 | [diff] [blame] | 652 | ExplicitInfo(0), |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 653 | TemplateArgs(TemplateArgumentList::CreateCopy(Context, Args, NumArgs)), |
Douglas Gregor | 7e06390 | 2009-05-11 23:53:27 +0000 | [diff] [blame] | 654 | SpecializationKind(TSK_Undeclared) { |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 655 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 656 | |
Argyrios Kyrtzidis | 94d228d | 2010-06-23 13:48:23 +0000 | [diff] [blame] | 657 | ClassTemplateSpecializationDecl::ClassTemplateSpecializationDecl(Kind DK) |
Abramo Bagnara | ba877ad | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 658 | : CXXRecordDecl(DK, TTK_Struct, 0, SourceLocation(), SourceLocation(), 0, 0), |
Argyrios Kyrtzidis | 94d228d | 2010-06-23 13:48:23 +0000 | [diff] [blame] | 659 | ExplicitInfo(0), |
| 660 | SpecializationKind(TSK_Undeclared) { |
| 661 | } |
| 662 | |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 663 | ClassTemplateSpecializationDecl * |
Douglas Gregor | 13c8577 | 2010-05-06 00:28:52 +0000 | [diff] [blame] | 664 | ClassTemplateSpecializationDecl::Create(ASTContext &Context, TagKind TK, |
Abramo Bagnara | ba877ad | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 665 | DeclContext *DC, |
| 666 | SourceLocation StartLoc, |
| 667 | SourceLocation IdLoc, |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 668 | ClassTemplateDecl *SpecializedTemplate, |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 669 | const TemplateArgument *Args, |
| 670 | unsigned NumArgs, |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 671 | ClassTemplateSpecializationDecl *PrevDecl) { |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 672 | ClassTemplateSpecializationDecl *Result |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 673 | = new (Context)ClassTemplateSpecializationDecl(Context, |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 674 | ClassTemplateSpecialization, |
Abramo Bagnara | ba877ad | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 675 | TK, DC, StartLoc, IdLoc, |
Douglas Gregor | 7e06390 | 2009-05-11 23:53:27 +0000 | [diff] [blame] | 676 | SpecializedTemplate, |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 677 | Args, NumArgs, |
Douglas Gregor | 8e9e9ef | 2009-07-29 23:36:44 +0000 | [diff] [blame] | 678 | PrevDecl); |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 679 | Context.getTypeDeclType(Result, PrevDecl); |
| 680 | return Result; |
Douglas Gregor | 3e00bad | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 681 | } |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 682 | |
Argyrios Kyrtzidis | 94d228d | 2010-06-23 13:48:23 +0000 | [diff] [blame] | 683 | ClassTemplateSpecializationDecl * |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 684 | ClassTemplateSpecializationDecl::CreateDeserialized(ASTContext &C, |
| 685 | unsigned ID) { |
| 686 | void *Mem = AllocateDeserializedDecl(C, ID, |
| 687 | sizeof(ClassTemplateSpecializationDecl)); |
| 688 | return new (Mem) ClassTemplateSpecializationDecl(ClassTemplateSpecialization); |
Argyrios Kyrtzidis | 94d228d | 2010-06-23 13:48:23 +0000 | [diff] [blame] | 689 | } |
| 690 | |
Douglas Gregor | da2142f | 2011-02-19 18:51:44 +0000 | [diff] [blame] | 691 | void |
| 692 | ClassTemplateSpecializationDecl::getNameForDiagnostic(std::string &S, |
| 693 | const PrintingPolicy &Policy, |
| 694 | bool Qualified) const { |
| 695 | NamedDecl::getNameForDiagnostic(S, Policy, Qualified); |
| 696 | |
| 697 | const TemplateArgumentList &TemplateArgs = getTemplateArgs(); |
| 698 | S += TemplateSpecializationType::PrintTemplateArgumentList( |
| 699 | TemplateArgs.data(), |
| 700 | TemplateArgs.size(), |
| 701 | Policy); |
| 702 | } |
| 703 | |
Douglas Gregor | 37d93e9 | 2009-08-02 23:24:31 +0000 | [diff] [blame] | 704 | ClassTemplateDecl * |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 705 | ClassTemplateSpecializationDecl::getSpecializedTemplate() const { |
| 706 | if (SpecializedPartialSpecialization *PartialSpec |
Douglas Gregor | 37d93e9 | 2009-08-02 23:24:31 +0000 | [diff] [blame] | 707 | = SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization*>()) |
| 708 | return PartialSpec->PartialSpecialization->getSpecializedTemplate(); |
| 709 | return SpecializedTemplate.get<ClassTemplateDecl*>(); |
| 710 | } |
| 711 | |
Abramo Bagnara | 4a85a73 | 2011-03-04 14:20:30 +0000 | [diff] [blame] | 712 | SourceRange |
| 713 | ClassTemplateSpecializationDecl::getSourceRange() const { |
Abramo Bagnara | 09d8212 | 2011-10-03 20:34:03 +0000 | [diff] [blame] | 714 | if (ExplicitInfo) { |
| 715 | SourceLocation Begin = getExternLoc(); |
| 716 | if (Begin.isInvalid()) |
| 717 | Begin = getTemplateKeywordLoc(); |
| 718 | SourceLocation End = getRBraceLoc(); |
| 719 | if (End.isInvalid()) |
| 720 | End = getTypeAsWritten()->getTypeLoc().getEndLoc(); |
| 721 | return SourceRange(Begin, End); |
| 722 | } |
| 723 | else { |
| 724 | // No explicit info available. |
| 725 | llvm::PointerUnion<ClassTemplateDecl *, |
| 726 | ClassTemplatePartialSpecializationDecl *> |
| 727 | inst_from = getInstantiatedFrom(); |
| 728 | if (inst_from.isNull()) |
| 729 | return getSpecializedTemplate()->getSourceRange(); |
| 730 | if (ClassTemplateDecl *ctd = inst_from.dyn_cast<ClassTemplateDecl*>()) |
| 731 | return ctd->getSourceRange(); |
| 732 | return inst_from.get<ClassTemplatePartialSpecializationDecl*>() |
| 733 | ->getSourceRange(); |
| 734 | } |
Abramo Bagnara | 4a85a73 | 2011-03-04 14:20:30 +0000 | [diff] [blame] | 735 | } |
| 736 | |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 737 | //===----------------------------------------------------------------------===// |
| 738 | // ClassTemplatePartialSpecializationDecl Implementation |
| 739 | //===----------------------------------------------------------------------===// |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 740 | void ClassTemplatePartialSpecializationDecl::anchor() { } |
| 741 | |
Douglas Gregor | 9a299e0 | 2011-03-04 17:52:15 +0000 | [diff] [blame] | 742 | ClassTemplatePartialSpecializationDecl:: |
| 743 | ClassTemplatePartialSpecializationDecl(ASTContext &Context, TagKind TK, |
Abramo Bagnara | ba877ad | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 744 | DeclContext *DC, |
| 745 | SourceLocation StartLoc, |
| 746 | SourceLocation IdLoc, |
Douglas Gregor | 9a299e0 | 2011-03-04 17:52:15 +0000 | [diff] [blame] | 747 | TemplateParameterList *Params, |
| 748 | ClassTemplateDecl *SpecializedTemplate, |
| 749 | const TemplateArgument *Args, |
| 750 | unsigned NumArgs, |
| 751 | TemplateArgumentLoc *ArgInfos, |
| 752 | unsigned NumArgInfos, |
| 753 | ClassTemplatePartialSpecializationDecl *PrevDecl, |
| 754 | unsigned SequenceNumber) |
| 755 | : ClassTemplateSpecializationDecl(Context, |
| 756 | ClassTemplatePartialSpecialization, |
Abramo Bagnara | ba877ad | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 757 | TK, DC, StartLoc, IdLoc, |
| 758 | SpecializedTemplate, |
Douglas Gregor | 9a299e0 | 2011-03-04 17:52:15 +0000 | [diff] [blame] | 759 | Args, NumArgs, PrevDecl), |
| 760 | TemplateParams(Params), ArgsAsWritten(ArgInfos), |
| 761 | NumArgsAsWritten(NumArgInfos), SequenceNumber(SequenceNumber), |
| 762 | InstantiatedFromMember(0, false) |
| 763 | { |
Douglas Gregor | 787a40d | 2011-03-04 18:32:38 +0000 | [diff] [blame] | 764 | AdoptTemplateParameterList(Params, this); |
Douglas Gregor | 9a299e0 | 2011-03-04 17:52:15 +0000 | [diff] [blame] | 765 | } |
| 766 | |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 767 | ClassTemplatePartialSpecializationDecl * |
| 768 | ClassTemplatePartialSpecializationDecl:: |
Abramo Bagnara | ba877ad | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 769 | Create(ASTContext &Context, TagKind TK,DeclContext *DC, |
| 770 | SourceLocation StartLoc, SourceLocation IdLoc, |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 771 | TemplateParameterList *Params, |
| 772 | ClassTemplateDecl *SpecializedTemplate, |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 773 | const TemplateArgument *Args, |
| 774 | unsigned NumArgs, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 775 | const TemplateArgumentListInfo &ArgInfos, |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 776 | QualType CanonInjectedType, |
Douglas Gregor | dc60c1e | 2010-04-30 05:56:50 +0000 | [diff] [blame] | 777 | ClassTemplatePartialSpecializationDecl *PrevDecl, |
| 778 | unsigned SequenceNumber) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 779 | unsigned N = ArgInfos.size(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 780 | TemplateArgumentLoc *ClonedArgs = new (Context) TemplateArgumentLoc[N]; |
| 781 | for (unsigned I = 0; I != N; ++I) |
| 782 | ClonedArgs[I] = ArgInfos[I]; |
| 783 | |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 784 | ClassTemplatePartialSpecializationDecl *Result |
Abramo Bagnara | ba877ad | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 785 | = new (Context)ClassTemplatePartialSpecializationDecl(Context, TK, DC, |
| 786 | StartLoc, IdLoc, |
| 787 | Params, |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 788 | SpecializedTemplate, |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 789 | Args, NumArgs, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 790 | ClonedArgs, N, |
Douglas Gregor | dc60c1e | 2010-04-30 05:56:50 +0000 | [diff] [blame] | 791 | PrevDecl, |
| 792 | SequenceNumber); |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 793 | Result->setSpecializationKind(TSK_ExplicitSpecialization); |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 794 | |
| 795 | Context.getInjectedClassNameType(Result, CanonInjectedType); |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 796 | return Result; |
| 797 | } |
John McCall | dd4a3b0 | 2009-09-16 22:47:08 +0000 | [diff] [blame] | 798 | |
Argyrios Kyrtzidis | 94d228d | 2010-06-23 13:48:23 +0000 | [diff] [blame] | 799 | ClassTemplatePartialSpecializationDecl * |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 800 | ClassTemplatePartialSpecializationDecl::CreateDeserialized(ASTContext &C, |
| 801 | unsigned ID) { |
| 802 | void *Mem = AllocateDeserializedDecl(C, ID, |
| 803 | sizeof(ClassTemplatePartialSpecializationDecl)); |
| 804 | return new (Mem) ClassTemplatePartialSpecializationDecl(); |
Argyrios Kyrtzidis | 94d228d | 2010-06-23 13:48:23 +0000 | [diff] [blame] | 805 | } |
| 806 | |
John McCall | dd4a3b0 | 2009-09-16 22:47:08 +0000 | [diff] [blame] | 807 | //===----------------------------------------------------------------------===// |
| 808 | // FriendTemplateDecl Implementation |
| 809 | //===----------------------------------------------------------------------===// |
| 810 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 811 | void FriendTemplateDecl::anchor() { } |
| 812 | |
John McCall | dd4a3b0 | 2009-09-16 22:47:08 +0000 | [diff] [blame] | 813 | FriendTemplateDecl *FriendTemplateDecl::Create(ASTContext &Context, |
| 814 | DeclContext *DC, |
| 815 | SourceLocation L, |
| 816 | unsigned NParams, |
| 817 | TemplateParameterList **Params, |
| 818 | FriendUnion Friend, |
| 819 | SourceLocation FLoc) { |
| 820 | FriendTemplateDecl *Result |
| 821 | = new (Context) FriendTemplateDecl(DC, L, NParams, Params, Friend, FLoc); |
| 822 | return Result; |
| 823 | } |
Argyrios Kyrtzidis | 554e6aa | 2010-07-22 16:04:10 +0000 | [diff] [blame] | 824 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 825 | FriendTemplateDecl *FriendTemplateDecl::CreateDeserialized(ASTContext &C, |
| 826 | unsigned ID) { |
| 827 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(FriendTemplateDecl)); |
| 828 | return new (Mem) FriendTemplateDecl(EmptyShell()); |
Argyrios Kyrtzidis | 554e6aa | 2010-07-22 16:04:10 +0000 | [diff] [blame] | 829 | } |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 830 | |
| 831 | //===----------------------------------------------------------------------===// |
| 832 | // TypeAliasTemplateDecl Implementation |
| 833 | //===----------------------------------------------------------------------===// |
| 834 | |
| 835 | TypeAliasTemplateDecl *TypeAliasTemplateDecl::Create(ASTContext &C, |
| 836 | DeclContext *DC, |
| 837 | SourceLocation L, |
| 838 | DeclarationName Name, |
| 839 | TemplateParameterList *Params, |
| 840 | NamedDecl *Decl) { |
| 841 | AdoptTemplateParameterList(Params, DC); |
| 842 | return new (C) TypeAliasTemplateDecl(DC, L, Name, Params, Decl); |
| 843 | } |
| 844 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 845 | TypeAliasTemplateDecl *TypeAliasTemplateDecl::CreateDeserialized(ASTContext &C, |
| 846 | unsigned ID) { |
| 847 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(TypeAliasTemplateDecl)); |
| 848 | return new (Mem) TypeAliasTemplateDecl(0, SourceLocation(), DeclarationName(), |
| 849 | 0, 0); |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 850 | } |
| 851 | |
| 852 | void TypeAliasTemplateDecl::DeallocateCommon(void *Ptr) { |
| 853 | static_cast<Common *>(Ptr)->~Common(); |
| 854 | } |
| 855 | RedeclarableTemplateDecl::CommonBase * |
| 856 | TypeAliasTemplateDecl::newCommon(ASTContext &C) { |
| 857 | Common *CommonPtr = new (C) Common; |
| 858 | C.AddDeallocation(DeallocateCommon, CommonPtr); |
| 859 | return CommonPtr; |
| 860 | } |
| 861 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 862 | //===----------------------------------------------------------------------===// |
| 863 | // ClassScopeFunctionSpecializationDecl Implementation |
| 864 | //===----------------------------------------------------------------------===// |
| 865 | |
| 866 | void ClassScopeFunctionSpecializationDecl::anchor() { } |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 867 | |
| 868 | ClassScopeFunctionSpecializationDecl * |
| 869 | ClassScopeFunctionSpecializationDecl::CreateDeserialized(ASTContext &C, |
| 870 | unsigned ID) { |
| 871 | void *Mem = AllocateDeserializedDecl(C, ID, |
| 872 | sizeof(ClassScopeFunctionSpecializationDecl)); |
Nico Weber | 6b02009 | 2012-06-25 17:21:05 +0000 | [diff] [blame] | 873 | return new (Mem) ClassScopeFunctionSpecializationDecl(0, SourceLocation(), 0, |
| 874 | false, TemplateArgumentListInfo()); |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 875 | } |