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