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, |
Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 167 | ArrayRef<TemplateArgument> Args, |
Peter Collingbourne | b498ed6 | 2010-07-30 17:09:04 +0000 | [diff] [blame] | 168 | void *&InsertPos) { |
| 169 | typedef SpecEntryTraits<EntryType> SETraits; |
| 170 | llvm::FoldingSetNodeID ID; |
Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 171 | EntryType::Profile(ID,Args, getASTContext()); |
Peter Collingbourne | b498ed6 | 2010-07-30 17:09:04 +0000 | [diff] [blame] | 172 | EntryType *Entry = Specs.FindNodeOrInsertPos(ID, InsertPos); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 173 | return Entry ? SETraits::getMostRecentDecl(Entry) : nullptr; |
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 | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 232 | return new (C, DC) FunctionTemplateDecl(C, 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 | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 237 | return new (C, ID) FunctionTemplateDecl(C, nullptr, SourceLocation(), |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 238 | DeclarationName(), nullptr, nullptr); |
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; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 253 | CommonPtr->LazySpecializations = nullptr; |
Richard Smith | feb3e1a | 2013-06-28 04:37:53 +0000 | [diff] [blame] | 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 * |
Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 266 | FunctionTemplateDecl::findSpecialization(ArrayRef<TemplateArgument> Args, |
| 267 | void *&InsertPos) { |
| 268 | return findSpecializationImpl(getSpecializations(), Args, 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 | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 310 | ClassTemplateDecl *New = new (C, DC) ClassTemplateDecl(C, DC, L, Name, |
| 311 | 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 | |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 316 | ClassTemplateDecl *ClassTemplateDecl::CreateDeserialized(ASTContext &C, |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 317 | unsigned ID) { |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 318 | return new (C, ID) ClassTemplateDecl(C, nullptr, SourceLocation(), |
| 319 | DeclarationName(), nullptr, nullptr); |
Douglas Gregor | fd7c225 | 2011-03-04 17:52:15 +0000 | [diff] [blame] | 320 | } |
| 321 | |
Dmitri Gribenko | 81f2575 | 2013-02-14 13:20:36 +0000 | [diff] [blame] | 322 | void ClassTemplateDecl::LoadLazySpecializations() const { |
Douglas Gregor | 7e8c4e0 | 2010-10-27 22:21:36 +0000 | [diff] [blame] | 323 | Common *CommonPtr = getCommonPtr(); |
| 324 | if (CommonPtr->LazySpecializations) { |
| 325 | ASTContext &Context = getASTContext(); |
| 326 | uint32_t *Specs = CommonPtr->LazySpecializations; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 327 | CommonPtr->LazySpecializations = nullptr; |
Douglas Gregor | 7e8c4e0 | 2010-10-27 22:21:36 +0000 | [diff] [blame] | 328 | for (uint32_t I = 0, N = *Specs++; I != N; ++I) |
| 329 | (void)Context.getExternalSource()->GetExternalDecl(Specs[I]); |
| 330 | } |
| 331 | } |
| 332 | |
Chandler Carruth | b41171b | 2012-05-03 23:49:05 +0000 | [diff] [blame] | 333 | llvm::FoldingSetVector<ClassTemplateSpecializationDecl> & |
Dmitri Gribenko | 81f2575 | 2013-02-14 13:20:36 +0000 | [diff] [blame] | 334 | ClassTemplateDecl::getSpecializations() const { |
Douglas Gregor | 7e8c4e0 | 2010-10-27 22:21:36 +0000 | [diff] [blame] | 335 | LoadLazySpecializations(); |
| 336 | return getCommonPtr()->Specializations; |
| 337 | } |
| 338 | |
Chandler Carruth | b41171b | 2012-05-03 23:49:05 +0000 | [diff] [blame] | 339 | llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> & |
Douglas Gregor | 7e8c4e0 | 2010-10-27 22:21:36 +0000 | [diff] [blame] | 340 | ClassTemplateDecl::getPartialSpecializations() { |
| 341 | LoadLazySpecializations(); |
| 342 | return getCommonPtr()->PartialSpecializations; |
| 343 | } |
| 344 | |
Argyrios Kyrtzidis | f4bc0d8 | 2010-09-08 19:31:22 +0000 | [diff] [blame] | 345 | RedeclarableTemplateDecl::CommonBase * |
Dmitri Gribenko | b53f37c | 2013-01-23 16:52:57 +0000 | [diff] [blame] | 346 | ClassTemplateDecl::newCommon(ASTContext &C) const { |
Argyrios Kyrtzidis | f4bc0d8 | 2010-09-08 19:31:22 +0000 | [diff] [blame] | 347 | Common *CommonPtr = new (C) Common; |
| 348 | C.AddDeallocation(DeallocateCommon, CommonPtr); |
Peter Collingbourne | 91b25b7 | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 349 | return CommonPtr; |
| 350 | } |
| 351 | |
Argyrios Kyrtzidis | 47470f2 | 2010-07-20 13:59:28 +0000 | [diff] [blame] | 352 | ClassTemplateSpecializationDecl * |
Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 353 | ClassTemplateDecl::findSpecialization(ArrayRef<TemplateArgument> Args, |
| 354 | void *&InsertPos) { |
| 355 | return findSpecializationImpl(getSpecializations(), Args, InsertPos); |
Argyrios Kyrtzidis | 47470f2 | 2010-07-20 13:59:28 +0000 | [diff] [blame] | 356 | } |
| 357 | |
Argyrios Kyrtzidis | 402dbbb | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 358 | void ClassTemplateDecl::AddSpecialization(ClassTemplateSpecializationDecl *D, |
| 359 | void *InsertPos) { |
Douglas Gregor | ce9978f | 2012-03-28 14:34:23 +0000 | [diff] [blame] | 360 | if (InsertPos) |
| 361 | getSpecializations().InsertNode(D, InsertPos); |
| 362 | else { |
| 363 | ClassTemplateSpecializationDecl *Existing |
| 364 | = getSpecializations().GetOrInsertNode(D); |
| 365 | (void)Existing; |
| 366 | assert(Existing->isCanonicalDecl() && "Non-canonical specialization?"); |
| 367 | } |
Argyrios Kyrtzidis | 402dbbb | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 368 | if (ASTMutationListener *L = getASTMutationListener()) |
| 369 | L->AddedCXXTemplateSpecialization(this, D); |
| 370 | } |
| 371 | |
Argyrios Kyrtzidis | 47470f2 | 2010-07-20 13:59:28 +0000 | [diff] [blame] | 372 | ClassTemplatePartialSpecializationDecl * |
Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 373 | ClassTemplateDecl::findPartialSpecialization(ArrayRef<TemplateArgument> Args, |
Argyrios Kyrtzidis | 47470f2 | 2010-07-20 13:59:28 +0000 | [diff] [blame] | 374 | void *&InsertPos) { |
Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 375 | return findSpecializationImpl(getPartialSpecializations(), Args, InsertPos); |
Argyrios Kyrtzidis | 47470f2 | 2010-07-20 13:59:28 +0000 | [diff] [blame] | 376 | } |
| 377 | |
Argyrios Kyrtzidis | 402dbbb | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 378 | void ClassTemplateDecl::AddPartialSpecialization( |
| 379 | ClassTemplatePartialSpecializationDecl *D, |
| 380 | void *InsertPos) { |
Douglas Gregor | ce9978f | 2012-03-28 14:34:23 +0000 | [diff] [blame] | 381 | if (InsertPos) |
| 382 | getPartialSpecializations().InsertNode(D, InsertPos); |
| 383 | else { |
| 384 | ClassTemplatePartialSpecializationDecl *Existing |
| 385 | = getPartialSpecializations().GetOrInsertNode(D); |
| 386 | (void)Existing; |
| 387 | assert(Existing->isCanonicalDecl() && "Non-canonical specialization?"); |
| 388 | } |
| 389 | |
Argyrios Kyrtzidis | 402dbbb | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 390 | if (ASTMutationListener *L = getASTMutationListener()) |
| 391 | L->AddedCXXTemplateSpecialization(this, D); |
| 392 | } |
| 393 | |
Douglas Gregor | 407e961 | 2010-04-30 05:56:50 +0000 | [diff] [blame] | 394 | void ClassTemplateDecl::getPartialSpecializations( |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 395 | SmallVectorImpl<ClassTemplatePartialSpecializationDecl *> &PS) { |
Chandler Carruth | b41171b | 2012-05-03 23:49:05 +0000 | [diff] [blame] | 396 | llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> &PartialSpecs |
Argyrios Kyrtzidis | a35c8e4 | 2010-06-21 10:57:41 +0000 | [diff] [blame] | 397 | = getPartialSpecializations(); |
Douglas Gregor | 407e961 | 2010-04-30 05:56:50 +0000 | [diff] [blame] | 398 | PS.clear(); |
Richard Smith | b2f61b4 | 2013-08-22 23:27:37 +0000 | [diff] [blame] | 399 | PS.reserve(PartialSpecs.size()); |
Chandler Carruth | b41171b | 2012-05-03 23:49:05 +0000 | [diff] [blame] | 400 | for (llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl>::iterator |
Douglas Gregor | 407e961 | 2010-04-30 05:56:50 +0000 | [diff] [blame] | 401 | P = PartialSpecs.begin(), PEnd = PartialSpecs.end(); |
Richard Smith | b2f61b4 | 2013-08-22 23:27:37 +0000 | [diff] [blame] | 402 | P != PEnd; ++P) |
| 403 | PS.push_back(P->getMostRecentDecl()); |
Douglas Gregor | 407e961 | 2010-04-30 05:56:50 +0000 | [diff] [blame] | 404 | } |
| 405 | |
Douglas Gregor | 1530138 | 2009-07-30 17:40:51 +0000 | [diff] [blame] | 406 | ClassTemplatePartialSpecializationDecl * |
| 407 | ClassTemplateDecl::findPartialSpecialization(QualType T) { |
| 408 | ASTContext &Context = getASTContext(); |
Chandler Carruth | b41171b | 2012-05-03 23:49:05 +0000 | [diff] [blame] | 409 | using llvm::FoldingSetVector; |
| 410 | typedef FoldingSetVector<ClassTemplatePartialSpecializationDecl>::iterator |
Douglas Gregor | 1530138 | 2009-07-30 17:40:51 +0000 | [diff] [blame] | 411 | partial_spec_iterator; |
| 412 | for (partial_spec_iterator P = getPartialSpecializations().begin(), |
| 413 | PEnd = getPartialSpecializations().end(); |
| 414 | P != PEnd; ++P) { |
John McCall | 2408e32 | 2010-04-27 00:57:59 +0000 | [diff] [blame] | 415 | if (Context.hasSameType(P->getInjectedSpecializationType(), T)) |
Douglas Gregor | ec9fd13 | 2012-01-14 16:38:05 +0000 | [diff] [blame] | 416 | return P->getMostRecentDecl(); |
Argyrios Kyrtzidis | 47470f2 | 2010-07-20 13:59:28 +0000 | [diff] [blame] | 417 | } |
| 418 | |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 419 | return nullptr; |
Argyrios Kyrtzidis | 47470f2 | 2010-07-20 13:59:28 +0000 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | ClassTemplatePartialSpecializationDecl * |
| 423 | ClassTemplateDecl::findPartialSpecInstantiatedFromMember( |
| 424 | ClassTemplatePartialSpecializationDecl *D) { |
| 425 | Decl *DCanon = D->getCanonicalDecl(); |
Chandler Carruth | b41171b | 2012-05-03 23:49:05 +0000 | [diff] [blame] | 426 | for (llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl>::iterator |
Argyrios Kyrtzidis | 47470f2 | 2010-07-20 13:59:28 +0000 | [diff] [blame] | 427 | P = getPartialSpecializations().begin(), |
| 428 | PEnd = getPartialSpecializations().end(); |
| 429 | P != PEnd; ++P) { |
| 430 | if (P->getInstantiatedFromMember()->getCanonicalDecl() == DCanon) |
Douglas Gregor | ec9fd13 | 2012-01-14 16:38:05 +0000 | [diff] [blame] | 431 | return P->getMostRecentDecl(); |
Douglas Gregor | 1530138 | 2009-07-30 17:40:51 +0000 | [diff] [blame] | 432 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 433 | |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 434 | return nullptr; |
Douglas Gregor | 1530138 | 2009-07-30 17:40:51 +0000 | [diff] [blame] | 435 | } |
| 436 | |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 437 | QualType |
Douglas Gregor | 9961ce9 | 2010-07-08 18:37:38 +0000 | [diff] [blame] | 438 | ClassTemplateDecl::getInjectedClassNameSpecialization() { |
Argyrios Kyrtzidis | a35c8e4 | 2010-06-21 10:57:41 +0000 | [diff] [blame] | 439 | Common *CommonPtr = getCommonPtr(); |
Douglas Gregor | e362cea | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 440 | if (!CommonPtr->InjectedClassNameType.isNull()) |
| 441 | return CommonPtr->InjectedClassNameType; |
| 442 | |
Douglas Gregor | 8092e80 | 2010-12-23 16:00:30 +0000 | [diff] [blame] | 443 | // C++0x [temp.dep.type]p2: |
| 444 | // The template argument list of a primary template is a template argument |
| 445 | // list in which the nth template argument has the value of the nth template |
| 446 | // parameter of the class template. If the nth template parameter is a |
| 447 | // template parameter pack (14.5.3), the nth template argument is a pack |
| 448 | // expansion (14.5.3) whose pattern is the name of the template parameter |
| 449 | // pack. |
Douglas Gregor | 9961ce9 | 2010-07-08 18:37:38 +0000 | [diff] [blame] | 450 | ASTContext &Context = getASTContext(); |
Douglas Gregor | e362cea | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 451 | TemplateParameterList *Params = getTemplateParameters(); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 452 | SmallVector<TemplateArgument, 16> TemplateArgs; |
Douglas Gregor | 43669f8 | 2011-03-05 17:54:25 +0000 | [diff] [blame] | 453 | TemplateArgs.resize(Params->size()); |
| 454 | GenerateInjectedTemplateArgs(getASTContext(), Params, TemplateArgs.data()); |
Douglas Gregor | e362cea | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 455 | CommonPtr->InjectedClassNameType |
Douglas Gregor | a8e02e7 | 2009-07-28 23:00:59 +0000 | [diff] [blame] | 456 | = Context.getTemplateSpecializationType(TemplateName(this), |
Douglas Gregor | e362cea | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 457 | &TemplateArgs[0], |
Douglas Gregor | a8e02e7 | 2009-07-28 23:00:59 +0000 | [diff] [blame] | 458 | TemplateArgs.size()); |
Douglas Gregor | e362cea | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 459 | return CommonPtr->InjectedClassNameType; |
| 460 | } |
| 461 | |
Douglas Gregor | ded2d7b | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 462 | //===----------------------------------------------------------------------===// |
| 463 | // TemplateTypeParm Allocation/Deallocation Method Implementations |
| 464 | //===----------------------------------------------------------------------===// |
| 465 | |
| 466 | TemplateTypeParmDecl * |
Jay Foad | 39c7980 | 2011-01-12 09:06:06 +0000 | [diff] [blame] | 467 | TemplateTypeParmDecl::Create(const ASTContext &C, DeclContext *DC, |
Abramo Bagnara | b3185b0 | 2011-03-06 15:48:19 +0000 | [diff] [blame] | 468 | SourceLocation KeyLoc, SourceLocation NameLoc, |
| 469 | unsigned D, unsigned P, IdentifierInfo *Id, |
| 470 | bool Typename, bool ParameterPack) { |
Chandler Carruth | 0883632 | 2011-05-01 00:51:33 +0000 | [diff] [blame] | 471 | TemplateTypeParmDecl *TTPDecl = |
Richard Smith | f798172 | 2013-11-22 09:01:48 +0000 | [diff] [blame] | 472 | new (C, DC) TemplateTypeParmDecl(DC, KeyLoc, NameLoc, Id, Typename); |
Chandler Carruth | 0883632 | 2011-05-01 00:51:33 +0000 | [diff] [blame] | 473 | QualType TTPType = C.getTemplateTypeParmType(D, P, ParameterPack, TTPDecl); |
Richard Smith | 5b21db8 | 2014-04-23 18:20:42 +0000 | [diff] [blame] | 474 | TTPDecl->setTypeForDecl(TTPType.getTypePtr()); |
Chandler Carruth | 0883632 | 2011-05-01 00:51:33 +0000 | [diff] [blame] | 475 | return TTPDecl; |
Douglas Gregor | ded2d7b | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 476 | } |
| 477 | |
Argyrios Kyrtzidis | 39f0e30 | 2010-07-02 11:54:55 +0000 | [diff] [blame] | 478 | TemplateTypeParmDecl * |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 479 | TemplateTypeParmDecl::CreateDeserialized(const ASTContext &C, unsigned ID) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 480 | return new (C, ID) TemplateTypeParmDecl(nullptr, SourceLocation(), |
| 481 | SourceLocation(), nullptr, false); |
Argyrios Kyrtzidis | 39f0e30 | 2010-07-02 11:54:55 +0000 | [diff] [blame] | 482 | } |
| 483 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 484 | SourceLocation TemplateTypeParmDecl::getDefaultArgumentLoc() const { |
Abramo Bagnara | 23485e0 | 2011-03-04 12:42:03 +0000 | [diff] [blame] | 485 | return hasDefaultArgument() |
| 486 | ? DefaultArgument->getTypeLoc().getBeginLoc() |
| 487 | : SourceLocation(); |
| 488 | } |
| 489 | |
| 490 | SourceRange TemplateTypeParmDecl::getSourceRange() const { |
| 491 | if (hasDefaultArgument() && !defaultArgumentWasInherited()) |
Abramo Bagnara | b3185b0 | 2011-03-06 15:48:19 +0000 | [diff] [blame] | 492 | return SourceRange(getLocStart(), |
Abramo Bagnara | 23485e0 | 2011-03-04 12:42:03 +0000 | [diff] [blame] | 493 | DefaultArgument->getTypeLoc().getEndLoc()); |
| 494 | else |
Abramo Bagnara | b3185b0 | 2011-03-06 15:48:19 +0000 | [diff] [blame] | 495 | return TypeDecl::getSourceRange(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 496 | } |
| 497 | |
Douglas Gregor | 2161038 | 2009-10-29 00:04:11 +0000 | [diff] [blame] | 498 | unsigned TemplateTypeParmDecl::getDepth() const { |
Richard Smith | 5b21db8 | 2014-04-23 18:20:42 +0000 | [diff] [blame] | 499 | return getTypeForDecl()->getAs<TemplateTypeParmType>()->getDepth(); |
Douglas Gregor | 2161038 | 2009-10-29 00:04:11 +0000 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | unsigned TemplateTypeParmDecl::getIndex() const { |
Richard Smith | 5b21db8 | 2014-04-23 18:20:42 +0000 | [diff] [blame] | 503 | return getTypeForDecl()->getAs<TemplateTypeParmType>()->getIndex(); |
Douglas Gregor | 2161038 | 2009-10-29 00:04:11 +0000 | [diff] [blame] | 504 | } |
| 505 | |
Chandler Carruth | 0883632 | 2011-05-01 00:51:33 +0000 | [diff] [blame] | 506 | bool TemplateTypeParmDecl::isParameterPack() const { |
Richard Smith | 5b21db8 | 2014-04-23 18:20:42 +0000 | [diff] [blame] | 507 | return getTypeForDecl()->getAs<TemplateTypeParmType>()->isParameterPack(); |
Chandler Carruth | 0883632 | 2011-05-01 00:51:33 +0000 | [diff] [blame] | 508 | } |
| 509 | |
Douglas Gregor | ded2d7b | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 510 | //===----------------------------------------------------------------------===// |
| 511 | // NonTypeTemplateParmDecl Method Implementations |
| 512 | //===----------------------------------------------------------------------===// |
| 513 | |
Douglas Gregor | 0231d8d | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 514 | NonTypeTemplateParmDecl::NonTypeTemplateParmDecl(DeclContext *DC, |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 515 | SourceLocation StartLoc, |
| 516 | SourceLocation IdLoc, |
| 517 | unsigned D, unsigned P, |
| 518 | IdentifierInfo *Id, |
Douglas Gregor | 0231d8d | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 519 | QualType T, |
| 520 | TypeSourceInfo *TInfo, |
| 521 | const QualType *ExpandedTypes, |
| 522 | unsigned NumExpandedTypes, |
| 523 | TypeSourceInfo **ExpandedTInfos) |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 524 | : DeclaratorDecl(NonTypeTemplateParm, DC, IdLoc, Id, T, TInfo, StartLoc), |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 525 | TemplateParmPosition(D, P), DefaultArgumentAndInherited(nullptr, false), |
Douglas Gregor | 0231d8d | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 526 | ParameterPack(true), ExpandedParameterPack(true), |
| 527 | NumExpandedTypes(NumExpandedTypes) |
| 528 | { |
| 529 | if (ExpandedTypes && ExpandedTInfos) { |
| 530 | void **TypesAndInfos = reinterpret_cast<void **>(this + 1); |
| 531 | for (unsigned I = 0; I != NumExpandedTypes; ++I) { |
| 532 | TypesAndInfos[2*I] = ExpandedTypes[I].getAsOpaquePtr(); |
| 533 | TypesAndInfos[2*I + 1] = ExpandedTInfos[I]; |
| 534 | } |
| 535 | } |
| 536 | } |
| 537 | |
Douglas Gregor | ded2d7b | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 538 | NonTypeTemplateParmDecl * |
Jay Foad | 39c7980 | 2011-01-12 09:06:06 +0000 | [diff] [blame] | 539 | NonTypeTemplateParmDecl::Create(const ASTContext &C, DeclContext *DC, |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 540 | SourceLocation StartLoc, SourceLocation IdLoc, |
| 541 | unsigned D, unsigned P, IdentifierInfo *Id, |
| 542 | QualType T, bool ParameterPack, |
| 543 | TypeSourceInfo *TInfo) { |
Richard Smith | f798172 | 2013-11-22 09:01:48 +0000 | [diff] [blame] | 544 | return new (C, DC) NonTypeTemplateParmDecl(DC, StartLoc, IdLoc, D, P, Id, |
| 545 | T, ParameterPack, TInfo); |
Douglas Gregor | ded2d7b | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 546 | } |
| 547 | |
Douglas Gregor | 0231d8d | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 548 | NonTypeTemplateParmDecl * |
| 549 | NonTypeTemplateParmDecl::Create(const ASTContext &C, DeclContext *DC, |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 550 | SourceLocation StartLoc, SourceLocation IdLoc, |
| 551 | unsigned D, unsigned P, |
Douglas Gregor | 0231d8d | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 552 | IdentifierInfo *Id, QualType T, |
| 553 | TypeSourceInfo *TInfo, |
| 554 | const QualType *ExpandedTypes, |
| 555 | unsigned NumExpandedTypes, |
| 556 | TypeSourceInfo **ExpandedTInfos) { |
Richard Smith | f798172 | 2013-11-22 09:01:48 +0000 | [diff] [blame] | 557 | unsigned Extra = NumExpandedTypes * 2 * sizeof(void*); |
| 558 | return new (C, DC, Extra) NonTypeTemplateParmDecl( |
| 559 | DC, StartLoc, IdLoc, D, P, Id, T, TInfo, |
| 560 | ExpandedTypes, NumExpandedTypes, ExpandedTInfos); |
Douglas Gregor | 0231d8d | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 561 | } |
| 562 | |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 563 | NonTypeTemplateParmDecl * |
| 564 | NonTypeTemplateParmDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 565 | return new (C, ID) NonTypeTemplateParmDecl(nullptr, SourceLocation(), |
| 566 | SourceLocation(), 0, 0, nullptr, |
| 567 | QualType(), false, nullptr); |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | NonTypeTemplateParmDecl * |
| 571 | NonTypeTemplateParmDecl::CreateDeserialized(ASTContext &C, unsigned ID, |
| 572 | unsigned NumExpandedTypes) { |
Richard Smith | f798172 | 2013-11-22 09:01:48 +0000 | [diff] [blame] | 573 | unsigned Extra = NumExpandedTypes * 2 * sizeof(void*); |
| 574 | return new (C, ID, Extra) NonTypeTemplateParmDecl( |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 575 | nullptr, SourceLocation(), SourceLocation(), 0, 0, nullptr, QualType(), |
| 576 | nullptr, nullptr, NumExpandedTypes, nullptr); |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 577 | } |
| 578 | |
John McCall | f4cd4f9 | 2011-02-09 01:13:10 +0000 | [diff] [blame] | 579 | SourceRange NonTypeTemplateParmDecl::getSourceRange() const { |
Abramo Bagnara | e15d553 | 2011-03-04 11:03:48 +0000 | [diff] [blame] | 580 | if (hasDefaultArgument() && !defaultArgumentWasInherited()) |
Abramo Bagnara | ea94788 | 2011-03-08 16:41:52 +0000 | [diff] [blame] | 581 | return SourceRange(getOuterLocStart(), |
| 582 | getDefaultArgument()->getSourceRange().getEnd()); |
| 583 | return DeclaratorDecl::getSourceRange(); |
John McCall | f4cd4f9 | 2011-02-09 01:13:10 +0000 | [diff] [blame] | 584 | } |
| 585 | |
Douglas Gregor | dba3263 | 2009-02-10 19:49:53 +0000 | [diff] [blame] | 586 | SourceLocation NonTypeTemplateParmDecl::getDefaultArgumentLoc() const { |
Abramo Bagnara | 656e300 | 2010-06-09 09:26:05 +0000 | [diff] [blame] | 587 | return hasDefaultArgument() |
| 588 | ? getDefaultArgument()->getSourceRange().getBegin() |
| 589 | : SourceLocation(); |
Douglas Gregor | dba3263 | 2009-02-10 19:49:53 +0000 | [diff] [blame] | 590 | } |
| 591 | |
Douglas Gregor | ded2d7b | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 592 | //===----------------------------------------------------------------------===// |
| 593 | // TemplateTemplateParmDecl Method Implementations |
| 594 | //===----------------------------------------------------------------------===// |
| 595 | |
David Blaikie | 68e081d | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 596 | void TemplateTemplateParmDecl::anchor() { } |
| 597 | |
Richard Smith | 1fde8ec | 2012-09-07 02:06:42 +0000 | [diff] [blame] | 598 | TemplateTemplateParmDecl::TemplateTemplateParmDecl( |
| 599 | DeclContext *DC, SourceLocation L, unsigned D, unsigned P, |
| 600 | IdentifierInfo *Id, TemplateParameterList *Params, |
| 601 | unsigned NumExpansions, TemplateParameterList * const *Expansions) |
| 602 | : TemplateDecl(TemplateTemplateParm, DC, L, Id, Params), |
| 603 | TemplateParmPosition(D, P), DefaultArgument(), |
| 604 | DefaultArgumentWasInherited(false), ParameterPack(true), |
| 605 | ExpandedParameterPack(true), NumExpandedParams(NumExpansions) { |
| 606 | if (Expansions) |
| 607 | std::memcpy(reinterpret_cast<void*>(this + 1), Expansions, |
| 608 | sizeof(TemplateParameterList*) * NumExpandedParams); |
| 609 | } |
| 610 | |
Douglas Gregor | ded2d7b | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 611 | TemplateTemplateParmDecl * |
Jay Foad | 39c7980 | 2011-01-12 09:06:06 +0000 | [diff] [blame] | 612 | TemplateTemplateParmDecl::Create(const ASTContext &C, DeclContext *DC, |
Douglas Gregor | ded2d7b | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 613 | SourceLocation L, unsigned D, unsigned P, |
Douglas Gregor | f550077 | 2011-01-05 15:48:55 +0000 | [diff] [blame] | 614 | bool ParameterPack, IdentifierInfo *Id, |
Douglas Gregor | ded2d7b | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 615 | TemplateParameterList *Params) { |
Richard Smith | f798172 | 2013-11-22 09:01:48 +0000 | [diff] [blame] | 616 | return new (C, DC) TemplateTemplateParmDecl(DC, L, D, P, ParameterPack, Id, |
| 617 | Params); |
Douglas Gregor | ded2d7b | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 618 | } |
| 619 | |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 620 | TemplateTemplateParmDecl * |
Richard Smith | 1fde8ec | 2012-09-07 02:06:42 +0000 | [diff] [blame] | 621 | TemplateTemplateParmDecl::Create(const ASTContext &C, DeclContext *DC, |
| 622 | SourceLocation L, unsigned D, unsigned P, |
| 623 | IdentifierInfo *Id, |
| 624 | TemplateParameterList *Params, |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 625 | ArrayRef<TemplateParameterList *> Expansions) { |
Richard Smith | f798172 | 2013-11-22 09:01:48 +0000 | [diff] [blame] | 626 | return new (C, DC, sizeof(TemplateParameterList*) * Expansions.size()) |
| 627 | TemplateTemplateParmDecl(DC, L, D, P, Id, Params, |
| 628 | Expansions.size(), Expansions.data()); |
Richard Smith | 1fde8ec | 2012-09-07 02:06:42 +0000 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | TemplateTemplateParmDecl * |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 632 | TemplateTemplateParmDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 633 | return new (C, ID) TemplateTemplateParmDecl(nullptr, SourceLocation(), 0, 0, |
| 634 | false, nullptr, nullptr); |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 635 | } |
| 636 | |
Richard Smith | 1fde8ec | 2012-09-07 02:06:42 +0000 | [diff] [blame] | 637 | TemplateTemplateParmDecl * |
| 638 | TemplateTemplateParmDecl::CreateDeserialized(ASTContext &C, unsigned ID, |
| 639 | unsigned NumExpansions) { |
Richard Smith | f798172 | 2013-11-22 09:01:48 +0000 | [diff] [blame] | 640 | return new (C, ID, sizeof(TemplateParameterList*) * NumExpansions) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 641 | TemplateTemplateParmDecl(nullptr, SourceLocation(), 0, 0, nullptr, |
| 642 | nullptr, NumExpansions, nullptr); |
Richard Smith | 1fde8ec | 2012-09-07 02:06:42 +0000 | [diff] [blame] | 643 | } |
| 644 | |
Douglas Gregor | 264ec4f | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 645 | //===----------------------------------------------------------------------===// |
Douglas Gregor | d002c7b | 2009-05-11 23:53:27 +0000 | [diff] [blame] | 646 | // TemplateArgumentList Implementation |
| 647 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 1ccc841 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 648 | TemplateArgumentList * |
| 649 | TemplateArgumentList::CreateCopy(ASTContext &Context, |
| 650 | const TemplateArgument *Args, |
| 651 | unsigned NumArgs) { |
| 652 | std::size_t Size = sizeof(TemplateArgumentList) |
| 653 | + NumArgs * sizeof(TemplateArgument); |
| 654 | void *Mem = Context.Allocate(Size); |
| 655 | TemplateArgument *StoredArgs |
| 656 | = reinterpret_cast<TemplateArgument *>( |
| 657 | static_cast<TemplateArgumentList *>(Mem) + 1); |
| 658 | std::uninitialized_copy(Args, Args + NumArgs, StoredArgs); |
| 659 | return new (Mem) TemplateArgumentList(StoredArgs, NumArgs, true); |
Argyrios Kyrtzidis | fe6ba88 | 2010-06-23 13:48:23 +0000 | [diff] [blame] | 660 | } |
| 661 | |
Argyrios Kyrtzidis | e9a2443 | 2011-09-22 20:07:09 +0000 | [diff] [blame] | 662 | FunctionTemplateSpecializationInfo * |
| 663 | FunctionTemplateSpecializationInfo::Create(ASTContext &C, FunctionDecl *FD, |
| 664 | FunctionTemplateDecl *Template, |
| 665 | TemplateSpecializationKind TSK, |
| 666 | const TemplateArgumentList *TemplateArgs, |
| 667 | const TemplateArgumentListInfo *TemplateArgsAsWritten, |
| 668 | SourceLocation POI) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 669 | const ASTTemplateArgumentListInfo *ArgsAsWritten = nullptr; |
Argyrios Kyrtzidis | e9a2443 | 2011-09-22 20:07:09 +0000 | [diff] [blame] | 670 | if (TemplateArgsAsWritten) |
| 671 | ArgsAsWritten = ASTTemplateArgumentListInfo::Create(C, |
| 672 | *TemplateArgsAsWritten); |
| 673 | |
| 674 | return new (C) FunctionTemplateSpecializationInfo(FD, Template, TSK, |
| 675 | TemplateArgs, |
| 676 | ArgsAsWritten, |
| 677 | POI); |
| 678 | } |
| 679 | |
Douglas Gregor | d002c7b | 2009-05-11 23:53:27 +0000 | [diff] [blame] | 680 | //===----------------------------------------------------------------------===// |
David Blaikie | 68e081d | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 681 | // TemplateDecl Implementation |
| 682 | //===----------------------------------------------------------------------===// |
| 683 | |
| 684 | void TemplateDecl::anchor() { } |
| 685 | |
| 686 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 264ec4f | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 687 | // ClassTemplateSpecializationDecl Implementation |
| 688 | //===----------------------------------------------------------------------===// |
| 689 | ClassTemplateSpecializationDecl:: |
Douglas Gregor | e902956 | 2010-05-06 00:28:52 +0000 | [diff] [blame] | 690 | ClassTemplateSpecializationDecl(ASTContext &Context, Kind DK, TagKind TK, |
Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 691 | DeclContext *DC, SourceLocation StartLoc, |
| 692 | SourceLocation IdLoc, |
Douglas Gregor | 264ec4f | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 693 | ClassTemplateDecl *SpecializedTemplate, |
Douglas Gregor | 1ccc841 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 694 | const TemplateArgument *Args, |
| 695 | unsigned NumArgs, |
Douglas Gregor | b6b8f9e | 2009-07-29 23:36:44 +0000 | [diff] [blame] | 696 | ClassTemplateSpecializationDecl *PrevDecl) |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 697 | : CXXRecordDecl(DK, TK, Context, DC, StartLoc, IdLoc, |
Douglas Gregor | b6b8f9e | 2009-07-29 23:36:44 +0000 | [diff] [blame] | 698 | SpecializedTemplate->getIdentifier(), |
| 699 | PrevDecl), |
Douglas Gregor | 264ec4f | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 700 | SpecializedTemplate(SpecializedTemplate), |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 701 | ExplicitInfo(nullptr), |
Douglas Gregor | 1ccc841 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 702 | TemplateArgs(TemplateArgumentList::CreateCopy(Context, Args, NumArgs)), |
Douglas Gregor | d002c7b | 2009-05-11 23:53:27 +0000 | [diff] [blame] | 703 | SpecializationKind(TSK_Undeclared) { |
Douglas Gregor | 264ec4f | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 704 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 705 | |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 706 | ClassTemplateSpecializationDecl::ClassTemplateSpecializationDecl(ASTContext &C, |
| 707 | Kind DK) |
| 708 | : CXXRecordDecl(DK, TTK_Struct, C, nullptr, SourceLocation(), |
| 709 | SourceLocation(), nullptr, nullptr), |
| 710 | ExplicitInfo(nullptr), SpecializationKind(TSK_Undeclared) {} |
Argyrios Kyrtzidis | fe6ba88 | 2010-06-23 13:48:23 +0000 | [diff] [blame] | 711 | |
Douglas Gregor | 264ec4f | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 712 | ClassTemplateSpecializationDecl * |
Douglas Gregor | e902956 | 2010-05-06 00:28:52 +0000 | [diff] [blame] | 713 | ClassTemplateSpecializationDecl::Create(ASTContext &Context, TagKind TK, |
Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 714 | DeclContext *DC, |
| 715 | SourceLocation StartLoc, |
| 716 | SourceLocation IdLoc, |
Douglas Gregor | 264ec4f | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 717 | ClassTemplateDecl *SpecializedTemplate, |
Douglas Gregor | 1ccc841 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 718 | const TemplateArgument *Args, |
| 719 | unsigned NumArgs, |
Douglas Gregor | 67a6564 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 720 | ClassTemplateSpecializationDecl *PrevDecl) { |
Richard Smith | f798172 | 2013-11-22 09:01:48 +0000 | [diff] [blame] | 721 | ClassTemplateSpecializationDecl *Result = |
| 722 | new (Context, DC) ClassTemplateSpecializationDecl( |
| 723 | Context, ClassTemplateSpecialization, TK, DC, StartLoc, IdLoc, |
| 724 | SpecializedTemplate, Args, NumArgs, PrevDecl); |
Douglas Gregor | 7dab26b | 2013-02-09 01:35:03 +0000 | [diff] [blame] | 725 | Result->MayHaveOutOfDateDef = false; |
| 726 | |
Douglas Gregor | 67a6564 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 727 | Context.getTypeDeclType(Result, PrevDecl); |
| 728 | return Result; |
Douglas Gregor | 264ec4f | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 729 | } |
Douglas Gregor | 2373c59 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 730 | |
Argyrios Kyrtzidis | fe6ba88 | 2010-06-23 13:48:23 +0000 | [diff] [blame] | 731 | ClassTemplateSpecializationDecl * |
Richard Smith | f798172 | 2013-11-22 09:01:48 +0000 | [diff] [blame] | 732 | ClassTemplateSpecializationDecl::CreateDeserialized(ASTContext &C, |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 733 | unsigned ID) { |
Douglas Gregor | 7dab26b | 2013-02-09 01:35:03 +0000 | [diff] [blame] | 734 | ClassTemplateSpecializationDecl *Result = |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 735 | new (C, ID) ClassTemplateSpecializationDecl(C, ClassTemplateSpecialization); |
Douglas Gregor | 7dab26b | 2013-02-09 01:35:03 +0000 | [diff] [blame] | 736 | Result->MayHaveOutOfDateDef = false; |
| 737 | return Result; |
Argyrios Kyrtzidis | fe6ba88 | 2010-06-23 13:48:23 +0000 | [diff] [blame] | 738 | } |
| 739 | |
Benjamin Kramer | 9170e91 | 2013-02-22 15:46:01 +0000 | [diff] [blame] | 740 | void ClassTemplateSpecializationDecl::getNameForDiagnostic( |
| 741 | raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const { |
| 742 | NamedDecl::getNameForDiagnostic(OS, Policy, Qualified); |
Douglas Gregor | b11aad8 | 2011-02-19 18:51:44 +0000 | [diff] [blame] | 743 | |
| 744 | const TemplateArgumentList &TemplateArgs = getTemplateArgs(); |
Benjamin Kramer | 9170e91 | 2013-02-22 15:46:01 +0000 | [diff] [blame] | 745 | TemplateSpecializationType::PrintTemplateArgumentList( |
| 746 | OS, TemplateArgs.data(), TemplateArgs.size(), Policy); |
Douglas Gregor | b11aad8 | 2011-02-19 18:51:44 +0000 | [diff] [blame] | 747 | } |
| 748 | |
Douglas Gregor | 9dc8bd3 | 2009-08-02 23:24:31 +0000 | [diff] [blame] | 749 | ClassTemplateDecl * |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 750 | ClassTemplateSpecializationDecl::getSpecializedTemplate() const { |
| 751 | if (SpecializedPartialSpecialization *PartialSpec |
Douglas Gregor | 9dc8bd3 | 2009-08-02 23:24:31 +0000 | [diff] [blame] | 752 | = SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization*>()) |
| 753 | return PartialSpec->PartialSpecialization->getSpecializedTemplate(); |
| 754 | return SpecializedTemplate.get<ClassTemplateDecl*>(); |
| 755 | } |
| 756 | |
Abramo Bagnara | a093526 | 2011-03-04 14:20:30 +0000 | [diff] [blame] | 757 | SourceRange |
| 758 | ClassTemplateSpecializationDecl::getSourceRange() const { |
Abramo Bagnara | fd3a455 | 2011-10-03 20:34:03 +0000 | [diff] [blame] | 759 | if (ExplicitInfo) { |
Abramo Bagnara | c76dcbd | 2012-10-15 21:06:42 +0000 | [diff] [blame] | 760 | SourceLocation Begin = getTemplateKeywordLoc(); |
| 761 | if (Begin.isValid()) { |
| 762 | // Here we have an explicit (partial) specialization or instantiation. |
| 763 | assert(getSpecializationKind() == TSK_ExplicitSpecialization || |
| 764 | getSpecializationKind() == TSK_ExplicitInstantiationDeclaration || |
| 765 | getSpecializationKind() == TSK_ExplicitInstantiationDefinition); |
| 766 | if (getExternLoc().isValid()) |
| 767 | Begin = getExternLoc(); |
| 768 | SourceLocation End = getRBraceLoc(); |
| 769 | if (End.isInvalid()) |
| 770 | End = getTypeAsWritten()->getTypeLoc().getEndLoc(); |
| 771 | return SourceRange(Begin, End); |
| 772 | } |
| 773 | // An implicit instantiation of a class template partial specialization |
| 774 | // uses ExplicitInfo to record the TypeAsWritten, but the source |
| 775 | // locations should be retrieved from the instantiation pattern. |
| 776 | typedef ClassTemplatePartialSpecializationDecl CTPSDecl; |
| 777 | CTPSDecl *ctpsd = const_cast<CTPSDecl*>(cast<CTPSDecl>(this)); |
| 778 | CTPSDecl *inst_from = ctpsd->getInstantiatedFromMember(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 779 | assert(inst_from != nullptr); |
Abramo Bagnara | c76dcbd | 2012-10-15 21:06:42 +0000 | [diff] [blame] | 780 | return inst_from->getSourceRange(); |
Abramo Bagnara | fd3a455 | 2011-10-03 20:34:03 +0000 | [diff] [blame] | 781 | } |
| 782 | else { |
| 783 | // No explicit info available. |
| 784 | llvm::PointerUnion<ClassTemplateDecl *, |
| 785 | ClassTemplatePartialSpecializationDecl *> |
| 786 | inst_from = getInstantiatedFrom(); |
| 787 | if (inst_from.isNull()) |
| 788 | return getSpecializedTemplate()->getSourceRange(); |
| 789 | if (ClassTemplateDecl *ctd = inst_from.dyn_cast<ClassTemplateDecl*>()) |
| 790 | return ctd->getSourceRange(); |
| 791 | return inst_from.get<ClassTemplatePartialSpecializationDecl*>() |
| 792 | ->getSourceRange(); |
| 793 | } |
Abramo Bagnara | a093526 | 2011-03-04 14:20:30 +0000 | [diff] [blame] | 794 | } |
| 795 | |
Douglas Gregor | 2373c59 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 796 | //===----------------------------------------------------------------------===// |
| 797 | // ClassTemplatePartialSpecializationDecl Implementation |
| 798 | //===----------------------------------------------------------------------===// |
David Blaikie | 68e081d | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 799 | void ClassTemplatePartialSpecializationDecl::anchor() { } |
| 800 | |
Douglas Gregor | fd7c225 | 2011-03-04 17:52:15 +0000 | [diff] [blame] | 801 | ClassTemplatePartialSpecializationDecl:: |
| 802 | ClassTemplatePartialSpecializationDecl(ASTContext &Context, TagKind TK, |
Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 803 | DeclContext *DC, |
| 804 | SourceLocation StartLoc, |
| 805 | SourceLocation IdLoc, |
Douglas Gregor | fd7c225 | 2011-03-04 17:52:15 +0000 | [diff] [blame] | 806 | TemplateParameterList *Params, |
| 807 | ClassTemplateDecl *SpecializedTemplate, |
| 808 | const TemplateArgument *Args, |
| 809 | unsigned NumArgs, |
Enea Zaffanella | 6dbe187 | 2013-08-10 07:24:53 +0000 | [diff] [blame] | 810 | const ASTTemplateArgumentListInfo *ArgInfos, |
Richard Smith | b2f61b4 | 2013-08-22 23:27:37 +0000 | [diff] [blame] | 811 | ClassTemplatePartialSpecializationDecl *PrevDecl) |
Douglas Gregor | fd7c225 | 2011-03-04 17:52:15 +0000 | [diff] [blame] | 812 | : ClassTemplateSpecializationDecl(Context, |
| 813 | ClassTemplatePartialSpecialization, |
Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 814 | TK, DC, StartLoc, IdLoc, |
| 815 | SpecializedTemplate, |
Douglas Gregor | fd7c225 | 2011-03-04 17:52:15 +0000 | [diff] [blame] | 816 | Args, NumArgs, PrevDecl), |
| 817 | TemplateParams(Params), ArgsAsWritten(ArgInfos), |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 818 | InstantiatedFromMember(nullptr, false) |
Enea Zaffanella | 6dbe187 | 2013-08-10 07:24:53 +0000 | [diff] [blame] | 819 | { |
Douglas Gregor | 3c41bf7 | 2011-03-04 18:32:38 +0000 | [diff] [blame] | 820 | AdoptTemplateParameterList(Params, this); |
Douglas Gregor | fd7c225 | 2011-03-04 17:52:15 +0000 | [diff] [blame] | 821 | } |
| 822 | |
Douglas Gregor | 2373c59 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 823 | ClassTemplatePartialSpecializationDecl * |
| 824 | ClassTemplatePartialSpecializationDecl:: |
Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 825 | Create(ASTContext &Context, TagKind TK,DeclContext *DC, |
| 826 | SourceLocation StartLoc, SourceLocation IdLoc, |
Douglas Gregor | 2373c59 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 827 | TemplateParameterList *Params, |
| 828 | ClassTemplateDecl *SpecializedTemplate, |
Douglas Gregor | 1ccc841 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 829 | const TemplateArgument *Args, |
| 830 | unsigned NumArgs, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 831 | const TemplateArgumentListInfo &ArgInfos, |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 832 | QualType CanonInjectedType, |
Richard Smith | b2f61b4 | 2013-08-22 23:27:37 +0000 | [diff] [blame] | 833 | ClassTemplatePartialSpecializationDecl *PrevDecl) { |
Enea Zaffanella | 6dbe187 | 2013-08-10 07:24:53 +0000 | [diff] [blame] | 834 | const ASTTemplateArgumentListInfo *ASTArgInfos = |
| 835 | ASTTemplateArgumentListInfo::Create(Context, ArgInfos); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 836 | |
Richard Smith | f798172 | 2013-11-22 09:01:48 +0000 | [diff] [blame] | 837 | ClassTemplatePartialSpecializationDecl *Result = new (Context, DC) |
| 838 | ClassTemplatePartialSpecializationDecl(Context, TK, DC, StartLoc, IdLoc, |
| 839 | Params, SpecializedTemplate, Args, |
| 840 | NumArgs, ASTArgInfos, PrevDecl); |
Douglas Gregor | 2373c59 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 841 | Result->setSpecializationKind(TSK_ExplicitSpecialization); |
Douglas Gregor | 7dab26b | 2013-02-09 01:35:03 +0000 | [diff] [blame] | 842 | Result->MayHaveOutOfDateDef = false; |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 843 | |
| 844 | Context.getInjectedClassNameType(Result, CanonInjectedType); |
Douglas Gregor | 2373c59 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 845 | return Result; |
| 846 | } |
John McCall | 11083da | 2009-09-16 22:47:08 +0000 | [diff] [blame] | 847 | |
Argyrios Kyrtzidis | fe6ba88 | 2010-06-23 13:48:23 +0000 | [diff] [blame] | 848 | ClassTemplatePartialSpecializationDecl * |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 849 | ClassTemplatePartialSpecializationDecl::CreateDeserialized(ASTContext &C, |
| 850 | unsigned ID) { |
Richard Smith | f798172 | 2013-11-22 09:01:48 +0000 | [diff] [blame] | 851 | ClassTemplatePartialSpecializationDecl *Result = |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 852 | new (C, ID) ClassTemplatePartialSpecializationDecl(C); |
Douglas Gregor | 7dab26b | 2013-02-09 01:35:03 +0000 | [diff] [blame] | 853 | Result->MayHaveOutOfDateDef = false; |
| 854 | return Result; |
Argyrios Kyrtzidis | fe6ba88 | 2010-06-23 13:48:23 +0000 | [diff] [blame] | 855 | } |
| 856 | |
John McCall | 11083da | 2009-09-16 22:47:08 +0000 | [diff] [blame] | 857 | //===----------------------------------------------------------------------===// |
| 858 | // FriendTemplateDecl Implementation |
| 859 | //===----------------------------------------------------------------------===// |
| 860 | |
David Blaikie | 68e081d | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 861 | void FriendTemplateDecl::anchor() { } |
| 862 | |
John McCall | 11083da | 2009-09-16 22:47:08 +0000 | [diff] [blame] | 863 | FriendTemplateDecl *FriendTemplateDecl::Create(ASTContext &Context, |
| 864 | DeclContext *DC, |
| 865 | SourceLocation L, |
| 866 | unsigned NParams, |
| 867 | TemplateParameterList **Params, |
| 868 | FriendUnion Friend, |
| 869 | SourceLocation FLoc) { |
Richard Smith | f798172 | 2013-11-22 09:01:48 +0000 | [diff] [blame] | 870 | return new (Context, DC) FriendTemplateDecl(DC, L, NParams, Params, |
| 871 | Friend, FLoc); |
John McCall | 11083da | 2009-09-16 22:47:08 +0000 | [diff] [blame] | 872 | } |
Argyrios Kyrtzidis | 165b581 | 2010-07-22 16:04:10 +0000 | [diff] [blame] | 873 | |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 874 | FriendTemplateDecl *FriendTemplateDecl::CreateDeserialized(ASTContext &C, |
| 875 | unsigned ID) { |
Richard Smith | f798172 | 2013-11-22 09:01:48 +0000 | [diff] [blame] | 876 | return new (C, ID) FriendTemplateDecl(EmptyShell()); |
Argyrios Kyrtzidis | 165b581 | 2010-07-22 16:04:10 +0000 | [diff] [blame] | 877 | } |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 878 | |
| 879 | //===----------------------------------------------------------------------===// |
| 880 | // TypeAliasTemplateDecl Implementation |
| 881 | //===----------------------------------------------------------------------===// |
| 882 | |
| 883 | TypeAliasTemplateDecl *TypeAliasTemplateDecl::Create(ASTContext &C, |
| 884 | DeclContext *DC, |
| 885 | SourceLocation L, |
| 886 | DeclarationName Name, |
| 887 | TemplateParameterList *Params, |
| 888 | NamedDecl *Decl) { |
| 889 | AdoptTemplateParameterList(Params, DC); |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 890 | return new (C, DC) TypeAliasTemplateDecl(C, DC, L, Name, Params, Decl); |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 891 | } |
| 892 | |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 893 | TypeAliasTemplateDecl *TypeAliasTemplateDecl::CreateDeserialized(ASTContext &C, |
| 894 | unsigned ID) { |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 895 | return new (C, ID) TypeAliasTemplateDecl(C, nullptr, SourceLocation(), |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 896 | DeclarationName(), nullptr, nullptr); |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 897 | } |
| 898 | |
| 899 | void TypeAliasTemplateDecl::DeallocateCommon(void *Ptr) { |
| 900 | static_cast<Common *>(Ptr)->~Common(); |
| 901 | } |
| 902 | RedeclarableTemplateDecl::CommonBase * |
Dmitri Gribenko | b53f37c | 2013-01-23 16:52:57 +0000 | [diff] [blame] | 903 | TypeAliasTemplateDecl::newCommon(ASTContext &C) const { |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 904 | Common *CommonPtr = new (C) Common; |
| 905 | C.AddDeallocation(DeallocateCommon, CommonPtr); |
| 906 | return CommonPtr; |
| 907 | } |
| 908 | |
David Blaikie | 68e081d | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 909 | //===----------------------------------------------------------------------===// |
| 910 | // ClassScopeFunctionSpecializationDecl Implementation |
| 911 | //===----------------------------------------------------------------------===// |
| 912 | |
| 913 | void ClassScopeFunctionSpecializationDecl::anchor() { } |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 914 | |
| 915 | ClassScopeFunctionSpecializationDecl * |
| 916 | ClassScopeFunctionSpecializationDecl::CreateDeserialized(ASTContext &C, |
| 917 | unsigned ID) { |
Richard Smith | f798172 | 2013-11-22 09:01:48 +0000 | [diff] [blame] | 918 | return new (C, ID) ClassScopeFunctionSpecializationDecl( |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 919 | nullptr, SourceLocation(), nullptr, false, TemplateArgumentListInfo()); |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 920 | } |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 921 | |
| 922 | //===----------------------------------------------------------------------===// |
| 923 | // VarTemplateDecl Implementation |
| 924 | //===----------------------------------------------------------------------===// |
| 925 | |
| 926 | void VarTemplateDecl::DeallocateCommon(void *Ptr) { |
| 927 | static_cast<Common *>(Ptr)->~Common(); |
| 928 | } |
| 929 | |
Larisse Voufo | a11bd8a | 2013-08-13 02:02:26 +0000 | [diff] [blame] | 930 | VarTemplateDecl *VarTemplateDecl::getDefinition() { |
| 931 | VarTemplateDecl *CurD = this; |
| 932 | while (CurD) { |
| 933 | if (CurD->isThisDeclarationADefinition()) |
| 934 | return CurD; |
| 935 | CurD = CurD->getPreviousDecl(); |
| 936 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 937 | return nullptr; |
Larisse Voufo | a11bd8a | 2013-08-13 02:02:26 +0000 | [diff] [blame] | 938 | } |
| 939 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 940 | VarTemplateDecl *VarTemplateDecl::Create(ASTContext &C, DeclContext *DC, |
| 941 | SourceLocation L, DeclarationName Name, |
| 942 | TemplateParameterList *Params, |
Richard Smith | beef345 | 2014-01-16 23:39:20 +0000 | [diff] [blame] | 943 | VarDecl *Decl) { |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 944 | return new (C, DC) VarTemplateDecl(C, DC, L, Name, Params, Decl); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 945 | } |
| 946 | |
| 947 | VarTemplateDecl *VarTemplateDecl::CreateDeserialized(ASTContext &C, |
| 948 | unsigned ID) { |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 949 | return new (C, ID) VarTemplateDecl(C, nullptr, SourceLocation(), |
| 950 | DeclarationName(), nullptr, nullptr); |
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; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 960 | CommonPtr->LazySpecializations = nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 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 * |
Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 986 | VarTemplateDecl::findSpecialization(ArrayRef<TemplateArgument> Args, |
| 987 | void *&InsertPos) { |
| 988 | return findSpecializationImpl(getSpecializations(), Args, InsertPos); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 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 * |
Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 1006 | VarTemplateDecl::findPartialSpecialization(ArrayRef<TemplateArgument> Args, |
| 1007 | void *&InsertPos) { |
| 1008 | return findSpecializationImpl(getPartialSpecializations(), Args, InsertPos); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1009 | } |
| 1010 | |
| 1011 | void VarTemplateDecl::AddPartialSpecialization( |
| 1012 | VarTemplatePartialSpecializationDecl *D, void *InsertPos) { |
| 1013 | if (InsertPos) |
| 1014 | getPartialSpecializations().InsertNode(D, InsertPos); |
| 1015 | else { |
| 1016 | VarTemplatePartialSpecializationDecl *Existing = |
| 1017 | getPartialSpecializations().GetOrInsertNode(D); |
| 1018 | (void)Existing; |
| 1019 | assert(Existing->isCanonicalDecl() && "Non-canonical specialization?"); |
| 1020 | } |
| 1021 | |
| 1022 | if (ASTMutationListener *L = getASTMutationListener()) |
| 1023 | L->AddedCXXTemplateSpecialization(this, D); |
| 1024 | } |
| 1025 | |
| 1026 | void VarTemplateDecl::getPartialSpecializations( |
| 1027 | SmallVectorImpl<VarTemplatePartialSpecializationDecl *> &PS) { |
| 1028 | llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl> &PartialSpecs = |
| 1029 | getPartialSpecializations(); |
| 1030 | PS.clear(); |
Richard Smith | b2f61b4 | 2013-08-22 23:27:37 +0000 | [diff] [blame] | 1031 | PS.reserve(PartialSpecs.size()); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1032 | for (llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl>::iterator |
| 1033 | P = PartialSpecs.begin(), |
| 1034 | PEnd = PartialSpecs.end(); |
Richard Smith | b2f61b4 | 2013-08-22 23:27:37 +0000 | [diff] [blame] | 1035 | P != PEnd; ++P) |
| 1036 | PS.push_back(P->getMostRecentDecl()); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1037 | } |
| 1038 | |
| 1039 | VarTemplatePartialSpecializationDecl * |
| 1040 | VarTemplateDecl::findPartialSpecInstantiatedFromMember( |
| 1041 | VarTemplatePartialSpecializationDecl *D) { |
| 1042 | Decl *DCanon = D->getCanonicalDecl(); |
| 1043 | for (llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl>::iterator |
| 1044 | P = getPartialSpecializations().begin(), |
| 1045 | PEnd = getPartialSpecializations().end(); |
| 1046 | P != PEnd; ++P) { |
| 1047 | if (P->getInstantiatedFromMember()->getCanonicalDecl() == DCanon) |
| 1048 | return P->getMostRecentDecl(); |
| 1049 | } |
| 1050 | |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1051 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1052 | } |
| 1053 | |
| 1054 | //===----------------------------------------------------------------------===// |
| 1055 | // VarTemplateSpecializationDecl Implementation |
| 1056 | //===----------------------------------------------------------------------===// |
| 1057 | VarTemplateSpecializationDecl::VarTemplateSpecializationDecl( |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 1058 | Kind DK, ASTContext &Context, DeclContext *DC, SourceLocation StartLoc, |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1059 | SourceLocation IdLoc, VarTemplateDecl *SpecializedTemplate, QualType T, |
| 1060 | TypeSourceInfo *TInfo, StorageClass S, const TemplateArgument *Args, |
| 1061 | unsigned NumArgs) |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 1062 | : VarDecl(DK, Context, DC, StartLoc, IdLoc, |
| 1063 | SpecializedTemplate->getIdentifier(), T, TInfo, S), |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1064 | SpecializedTemplate(SpecializedTemplate), ExplicitInfo(nullptr), |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1065 | TemplateArgs(TemplateArgumentList::CreateCopy(Context, Args, NumArgs)), |
| 1066 | SpecializationKind(TSK_Undeclared) {} |
| 1067 | |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 1068 | VarTemplateSpecializationDecl::VarTemplateSpecializationDecl(Kind DK, |
| 1069 | ASTContext &C) |
| 1070 | : VarDecl(DK, C, nullptr, SourceLocation(), SourceLocation(), nullptr, |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1071 | QualType(), nullptr, SC_None), |
| 1072 | ExplicitInfo(nullptr), SpecializationKind(TSK_Undeclared) {} |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 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( |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 1080 | VarTemplateSpecialization, Context, DC, StartLoc, IdLoc, |
Richard Smith | f798172 | 2013-11-22 09:01:48 +0000 | [diff] [blame] | 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 | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 1086 | return new (C, ID) |
| 1087 | VarTemplateSpecializationDecl(VarTemplateSpecialization, C); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1088 | } |
| 1089 | |
| 1090 | void VarTemplateSpecializationDecl::getNameForDiagnostic( |
| 1091 | raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const { |
| 1092 | NamedDecl::getNameForDiagnostic(OS, Policy, Qualified); |
| 1093 | |
| 1094 | const TemplateArgumentList &TemplateArgs = getTemplateArgs(); |
| 1095 | TemplateSpecializationType::PrintTemplateArgumentList( |
| 1096 | OS, TemplateArgs.data(), TemplateArgs.size(), Policy); |
| 1097 | } |
| 1098 | |
| 1099 | VarTemplateDecl *VarTemplateSpecializationDecl::getSpecializedTemplate() const { |
| 1100 | if (SpecializedPartialSpecialization *PartialSpec = |
| 1101 | SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>()) |
| 1102 | return PartialSpec->PartialSpecialization->getSpecializedTemplate(); |
| 1103 | return SpecializedTemplate.get<VarTemplateDecl *>(); |
| 1104 | } |
| 1105 | |
| 1106 | void VarTemplateSpecializationDecl::setTemplateArgsInfo( |
| 1107 | const TemplateArgumentListInfo &ArgsInfo) { |
| 1108 | unsigned N = ArgsInfo.size(); |
| 1109 | TemplateArgsInfo.setLAngleLoc(ArgsInfo.getLAngleLoc()); |
| 1110 | TemplateArgsInfo.setRAngleLoc(ArgsInfo.getRAngleLoc()); |
| 1111 | for (unsigned I = 0; I != N; ++I) |
| 1112 | TemplateArgsInfo.addArgument(ArgsInfo[I]); |
| 1113 | } |
| 1114 | |
| 1115 | //===----------------------------------------------------------------------===// |
| 1116 | // VarTemplatePartialSpecializationDecl Implementation |
| 1117 | //===----------------------------------------------------------------------===// |
| 1118 | void VarTemplatePartialSpecializationDecl::anchor() {} |
| 1119 | |
| 1120 | VarTemplatePartialSpecializationDecl::VarTemplatePartialSpecializationDecl( |
| 1121 | ASTContext &Context, DeclContext *DC, SourceLocation StartLoc, |
| 1122 | SourceLocation IdLoc, TemplateParameterList *Params, |
| 1123 | VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo, |
| 1124 | StorageClass S, const TemplateArgument *Args, unsigned NumArgs, |
Richard Smith | b2f61b4 | 2013-08-22 23:27:37 +0000 | [diff] [blame] | 1125 | const ASTTemplateArgumentListInfo *ArgInfos) |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 1126 | : VarTemplateSpecializationDecl(VarTemplatePartialSpecialization, Context, |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1127 | DC, StartLoc, IdLoc, SpecializedTemplate, T, |
| 1128 | TInfo, S, Args, NumArgs), |
| 1129 | TemplateParams(Params), ArgsAsWritten(ArgInfos), |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1130 | InstantiatedFromMember(nullptr, false) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1131 | // TODO: The template parameters should be in DC by now. Verify. |
| 1132 | // AdoptTemplateParameterList(Params, DC); |
| 1133 | } |
| 1134 | |
| 1135 | VarTemplatePartialSpecializationDecl * |
| 1136 | VarTemplatePartialSpecializationDecl::Create( |
| 1137 | ASTContext &Context, DeclContext *DC, SourceLocation StartLoc, |
| 1138 | SourceLocation IdLoc, TemplateParameterList *Params, |
| 1139 | VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo, |
| 1140 | StorageClass S, const TemplateArgument *Args, unsigned NumArgs, |
Richard Smith | b2f61b4 | 2013-08-22 23:27:37 +0000 | [diff] [blame] | 1141 | const TemplateArgumentListInfo &ArgInfos) { |
Enea Zaffanella | 6dbe187 | 2013-08-10 07:24:53 +0000 | [diff] [blame] | 1142 | const ASTTemplateArgumentListInfo *ASTArgInfos |
| 1143 | = ASTTemplateArgumentListInfo::Create(Context, ArgInfos); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1144 | |
| 1145 | VarTemplatePartialSpecializationDecl *Result = |
Richard Smith | f798172 | 2013-11-22 09:01:48 +0000 | [diff] [blame] | 1146 | new (Context, DC) VarTemplatePartialSpecializationDecl( |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1147 | Context, DC, StartLoc, IdLoc, Params, SpecializedTemplate, T, TInfo, |
Richard Smith | b2f61b4 | 2013-08-22 23:27:37 +0000 | [diff] [blame] | 1148 | S, Args, NumArgs, ASTArgInfos); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1149 | Result->setSpecializationKind(TSK_ExplicitSpecialization); |
| 1150 | return Result; |
| 1151 | } |
| 1152 | |
| 1153 | VarTemplatePartialSpecializationDecl * |
| 1154 | VarTemplatePartialSpecializationDecl::CreateDeserialized(ASTContext &C, |
| 1155 | unsigned ID) { |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 1156 | return new (C, ID) VarTemplatePartialSpecializationDecl(C); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1157 | } |