Eugene Zelenko | 421e890 | 2017-11-29 22:39:22 +0000 | [diff] [blame] | 1 | //===- DeclTemplate.cpp - Template Declaration AST Node Implementation ----===// |
Douglas Gregor | ded2d7b | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Douglas Gregor | ded2d7b | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file implements the C++ related Decl classes for templates. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
Douglas Gregor | ded2d7b | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 13 | #include "clang/AST/DeclTemplate.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 14 | #include "clang/AST/ASTContext.h" |
| 15 | #include "clang/AST/ASTMutationListener.h" |
| 16 | #include "clang/AST/DeclCXX.h" |
Eugene Zelenko | 421e890 | 2017-11-29 22:39:22 +0000 | [diff] [blame] | 17 | #include "clang/AST/DeclarationName.h" |
Douglas Gregor | 8bf4205 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 18 | #include "clang/AST/Expr.h" |
Eugene Zelenko | 309e29d | 2018-03-29 20:51:59 +0000 | [diff] [blame] | 19 | #include "clang/AST/ExternalASTSource.h" |
Eugene Zelenko | 421e890 | 2017-11-29 22:39:22 +0000 | [diff] [blame] | 20 | #include "clang/AST/TemplateBase.h" |
| 21 | #include "clang/AST/TemplateName.h" |
| 22 | #include "clang/AST/Type.h" |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 23 | #include "clang/AST/TypeLoc.h" |
David Majnemer | d9b1a4f | 2015-11-04 03:40:30 +0000 | [diff] [blame] | 24 | #include "clang/Basic/Builtins.h" |
Eugene Zelenko | 421e890 | 2017-11-29 22:39:22 +0000 | [diff] [blame] | 25 | #include "clang/Basic/LLVM.h" |
| 26 | #include "clang/Basic/SourceLocation.h" |
| 27 | #include "llvm/ADT/ArrayRef.h" |
| 28 | #include "llvm/ADT/FoldingSet.h" |
| 29 | #include "llvm/ADT/None.h" |
| 30 | #include "llvm/ADT/PointerUnion.h" |
| 31 | #include "llvm/ADT/SmallVector.h" |
| 32 | #include "llvm/Support/Casting.h" |
| 33 | #include "llvm/Support/ErrorHandling.h" |
| 34 | #include <algorithm> |
| 35 | #include <cassert> |
| 36 | #include <cstdint> |
Douglas Gregor | 1ccc841 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 37 | #include <memory> |
Eugene Zelenko | 421e890 | 2017-11-29 22:39:22 +0000 | [diff] [blame] | 38 | #include <utility> |
| 39 | |
Douglas Gregor | ded2d7b | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 40 | using namespace clang; |
| 41 | |
| 42 | //===----------------------------------------------------------------------===// |
| 43 | // TemplateParameterList Implementation |
| 44 | //===----------------------------------------------------------------------===// |
| 45 | |
Douglas Gregor | cd72ba9 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 46 | TemplateParameterList::TemplateParameterList(SourceLocation TemplateLoc, |
| 47 | SourceLocation LAngleLoc, |
David Majnemer | 902f8c6 | 2015-12-27 07:16:27 +0000 | [diff] [blame] | 48 | ArrayRef<NamedDecl *> Params, |
Hubert Tong | e4a0c0e | 2016-07-30 22:33:34 +0000 | [diff] [blame] | 49 | SourceLocation RAngleLoc, |
| 50 | Expr *RequiresClause) |
Eugene Zelenko | 421e890 | 2017-11-29 22:39:22 +0000 | [diff] [blame] | 51 | : TemplateLoc(TemplateLoc), LAngleLoc(LAngleLoc), RAngleLoc(RAngleLoc), |
| 52 | NumParams(Params.size()), ContainsUnexpandedParameterPack(false), |
| 53 | HasRequiresClause(static_cast<bool>(RequiresClause)) { |
Richard Smith | 1fde8ec | 2012-09-07 02:06:42 +0000 | [diff] [blame] | 54 | for (unsigned Idx = 0; Idx < NumParams; ++Idx) { |
| 55 | NamedDecl *P = Params[Idx]; |
| 56 | begin()[Idx] = P; |
| 57 | |
| 58 | if (!P->isTemplateParameterPack()) { |
Eugene Zelenko | 309e29d | 2018-03-29 20:51:59 +0000 | [diff] [blame] | 59 | if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(P)) |
Richard Smith | 1fde8ec | 2012-09-07 02:06:42 +0000 | [diff] [blame] | 60 | if (NTTP->getType()->containsUnexpandedParameterPack()) |
| 61 | ContainsUnexpandedParameterPack = true; |
| 62 | |
Eugene Zelenko | 309e29d | 2018-03-29 20:51:59 +0000 | [diff] [blame] | 63 | if (const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(P)) |
Richard Smith | 1fde8ec | 2012-09-07 02:06:42 +0000 | [diff] [blame] | 64 | if (TTP->getTemplateParameters()->containsUnexpandedParameterPack()) |
| 65 | ContainsUnexpandedParameterPack = true; |
| 66 | |
| 67 | // FIXME: If a default argument contains an unexpanded parameter pack, the |
| 68 | // template parameter list does too. |
| 69 | } |
| 70 | } |
Hubert Tong | e4a0c0e | 2016-07-30 22:33:34 +0000 | [diff] [blame] | 71 | if (RequiresClause) { |
| 72 | *getTrailingObjects<Expr *>() = RequiresClause; |
| 73 | } |
Douglas Gregor | ded2d7b | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 74 | } |
| 75 | |
Hubert Tong | e4a0c0e | 2016-07-30 22:33:34 +0000 | [diff] [blame] | 76 | TemplateParameterList * |
| 77 | TemplateParameterList::Create(const ASTContext &C, SourceLocation TemplateLoc, |
| 78 | SourceLocation LAngleLoc, |
| 79 | ArrayRef<NamedDecl *> Params, |
| 80 | SourceLocation RAngleLoc, Expr *RequiresClause) { |
| 81 | void *Mem = C.Allocate(totalSizeToAlloc<NamedDecl *, Expr *>( |
| 82 | Params.size(), RequiresClause ? 1u : 0u), |
Benjamin Kramer | c3f8925 | 2016-10-20 14:27:22 +0000 | [diff] [blame] | 83 | alignof(TemplateParameterList)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 84 | return new (Mem) TemplateParameterList(TemplateLoc, LAngleLoc, Params, |
Hubert Tong | e4a0c0e | 2016-07-30 22:33:34 +0000 | [diff] [blame] | 85 | RAngleLoc, RequiresClause); |
Douglas Gregor | ded2d7b | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 86 | } |
| 87 | |
Douglas Gregor | f8f8683 | 2009-02-11 18:16:40 +0000 | [diff] [blame] | 88 | unsigned TemplateParameterList::getMinRequiredArguments() const { |
Douglas Gregor | 0231d8d | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 89 | unsigned NumRequiredArgs = 0; |
David Majnemer | dfecf1a | 2016-07-06 04:19:16 +0000 | [diff] [blame] | 90 | for (const NamedDecl *P : asArray()) { |
| 91 | if (P->isTemplateParameterPack()) { |
| 92 | if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(P)) |
Douglas Gregor | 0231d8d | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 93 | if (NTTP->isExpandedParameterPack()) { |
| 94 | NumRequiredArgs += NTTP->getNumExpansionTypes(); |
| 95 | continue; |
| 96 | } |
David Majnemer | dfecf1a | 2016-07-06 04:19:16 +0000 | [diff] [blame] | 97 | |
Douglas Gregor | f8f8683 | 2009-02-11 18:16:40 +0000 | [diff] [blame] | 98 | break; |
Douglas Gregor | 0231d8d | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 99 | } |
David Majnemer | dfecf1a | 2016-07-06 04:19:16 +0000 | [diff] [blame] | 100 | |
| 101 | if (const auto *TTP = dyn_cast<TemplateTypeParmDecl>(P)) { |
Douglas Gregor | 0231d8d | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 102 | if (TTP->hasDefaultArgument()) |
| 103 | break; |
David Majnemer | dfecf1a | 2016-07-06 04:19:16 +0000 | [diff] [blame] | 104 | } else if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(P)) { |
Douglas Gregor | 0231d8d | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 105 | if (NTTP->hasDefaultArgument()) |
| 106 | break; |
David Majnemer | dfecf1a | 2016-07-06 04:19:16 +0000 | [diff] [blame] | 107 | } else if (cast<TemplateTemplateParmDecl>(P)->hasDefaultArgument()) |
Douglas Gregor | 0231d8d | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 108 | break; |
David Majnemer | dfecf1a | 2016-07-06 04:19:16 +0000 | [diff] [blame] | 109 | |
Douglas Gregor | 0231d8d | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 110 | ++NumRequiredArgs; |
Douglas Gregor | f8f8683 | 2009-02-11 18:16:40 +0000 | [diff] [blame] | 111 | } |
David Majnemer | dfecf1a | 2016-07-06 04:19:16 +0000 | [diff] [blame] | 112 | |
Douglas Gregor | f8f8683 | 2009-02-11 18:16:40 +0000 | [diff] [blame] | 113 | return NumRequiredArgs; |
| 114 | } |
| 115 | |
Douglas Gregor | 2161038 | 2009-10-29 00:04:11 +0000 | [diff] [blame] | 116 | unsigned TemplateParameterList::getDepth() const { |
| 117 | if (size() == 0) |
| 118 | return 0; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 119 | |
Douglas Gregor | 2161038 | 2009-10-29 00:04:11 +0000 | [diff] [blame] | 120 | const NamedDecl *FirstParm = getParam(0); |
Eugene Zelenko | 309e29d | 2018-03-29 20:51:59 +0000 | [diff] [blame] | 121 | if (const auto *TTP = dyn_cast<TemplateTypeParmDecl>(FirstParm)) |
Douglas Gregor | 2161038 | 2009-10-29 00:04:11 +0000 | [diff] [blame] | 122 | return TTP->getDepth(); |
Eugene Zelenko | 309e29d | 2018-03-29 20:51:59 +0000 | [diff] [blame] | 123 | else if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(FirstParm)) |
Douglas Gregor | 2161038 | 2009-10-29 00:04:11 +0000 | [diff] [blame] | 124 | return NTTP->getDepth(); |
| 125 | else |
| 126 | return cast<TemplateTemplateParmDecl>(FirstParm)->getDepth(); |
| 127 | } |
| 128 | |
Douglas Gregor | 3c41bf7 | 2011-03-04 18:32:38 +0000 | [diff] [blame] | 129 | static void AdoptTemplateParameterList(TemplateParameterList *Params, |
| 130 | DeclContext *Owner) { |
David Majnemer | dfecf1a | 2016-07-06 04:19:16 +0000 | [diff] [blame] | 131 | for (NamedDecl *P : *Params) { |
| 132 | P->setDeclContext(Owner); |
| 133 | |
Eugene Zelenko | 309e29d | 2018-03-29 20:51:59 +0000 | [diff] [blame] | 134 | if (const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(P)) |
Douglas Gregor | 3c41bf7 | 2011-03-04 18:32:38 +0000 | [diff] [blame] | 135 | AdoptTemplateParameterList(TTP->getTemplateParameters(), Owner); |
| 136 | } |
| 137 | } |
| 138 | |
Richard Smith | e7bd6de | 2015-06-10 20:30:23 +0000 | [diff] [blame] | 139 | namespace clang { |
Eugene Zelenko | 421e890 | 2017-11-29 22:39:22 +0000 | [diff] [blame] | 140 | |
Richard Smith | e7bd6de | 2015-06-10 20:30:23 +0000 | [diff] [blame] | 141 | void *allocateDefaultArgStorageChain(const ASTContext &C) { |
| 142 | return new (C) char[sizeof(void*) * 2]; |
| 143 | } |
Eugene Zelenko | 421e890 | 2017-11-29 22:39:22 +0000 | [diff] [blame] | 144 | |
| 145 | } // namespace clang |
Richard Smith | e7bd6de | 2015-06-10 20:30:23 +0000 | [diff] [blame] | 146 | |
Douglas Gregor | ded2d7b | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 147 | //===----------------------------------------------------------------------===// |
Peter Collingbourne | 91b25b7 | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 148 | // RedeclarableTemplateDecl Implementation |
| 149 | //===----------------------------------------------------------------------===// |
| 150 | |
Richard Trieu | b3e902f | 2018-12-29 02:02:30 +0000 | [diff] [blame] | 151 | void RedeclarableTemplateDecl::anchor() {} |
| 152 | |
Dmitri Gribenko | b53f37c | 2013-01-23 16:52:57 +0000 | [diff] [blame] | 153 | RedeclarableTemplateDecl::CommonBase *RedeclarableTemplateDecl::getCommonPtr() const { |
Rafael Espindola | cb444fe | 2013-10-19 02:28:17 +0000 | [diff] [blame] | 154 | if (Common) |
| 155 | return Common; |
| 156 | |
| 157 | // Walk the previous-declaration chain until we either find a declaration |
| 158 | // with a common pointer or we run out of previous declarations. |
| 159 | SmallVector<const RedeclarableTemplateDecl *, 2> PrevDecls; |
| 160 | for (const RedeclarableTemplateDecl *Prev = getPreviousDecl(); Prev; |
| 161 | Prev = Prev->getPreviousDecl()) { |
| 162 | if (Prev->Common) { |
| 163 | Common = Prev->Common; |
| 164 | break; |
Douglas Gregor | 68444de | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 165 | } |
Peter Collingbourne | 91b25b7 | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 166 | |
Rafael Espindola | cb444fe | 2013-10-19 02:28:17 +0000 | [diff] [blame] | 167 | PrevDecls.push_back(Prev); |
Peter Collingbourne | 91b25b7 | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 168 | } |
Peter Collingbourne | 91b25b7 | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 169 | |
Rafael Espindola | cb444fe | 2013-10-19 02:28:17 +0000 | [diff] [blame] | 170 | // If we never found a common pointer, allocate one now. |
| 171 | if (!Common) { |
| 172 | // FIXME: If any of the declarations is from an AST file, we probably |
| 173 | // need an update record to add the common data. |
| 174 | |
| 175 | Common = newCommon(getASTContext()); |
| 176 | } |
| 177 | |
| 178 | // Update any previous declarations we saw with the common pointer. |
David Majnemer | dfecf1a | 2016-07-06 04:19:16 +0000 | [diff] [blame] | 179 | for (const RedeclarableTemplateDecl *Prev : PrevDecls) |
| 180 | Prev->Common = Common; |
Rafael Espindola | cb444fe | 2013-10-19 02:28:17 +0000 | [diff] [blame] | 181 | |
Douglas Gregor | 68444de | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 182 | return Common; |
Peter Collingbourne | 029fd69 | 2010-07-29 16:12:09 +0000 | [diff] [blame] | 183 | } |
| 184 | |
Vassil Vassilev | 61f6429 | 2017-12-14 23:30:18 +0000 | [diff] [blame] | 185 | void RedeclarableTemplateDecl::loadLazySpecializationsImpl() const { |
| 186 | // Grab the most recent declaration to ensure we've loaded any lazy |
| 187 | // redeclarations of this template. |
| 188 | CommonBase *CommonBasePtr = getMostRecentDecl()->getCommonPtr(); |
| 189 | if (CommonBasePtr->LazySpecializations) { |
| 190 | ASTContext &Context = getASTContext(); |
| 191 | uint32_t *Specs = CommonBasePtr->LazySpecializations; |
| 192 | CommonBasePtr->LazySpecializations = nullptr; |
| 193 | for (uint32_t I = 0, N = *Specs++; I != N; ++I) |
| 194 | (void)Context.getExternalSource()->GetExternalDecl(Specs[I]); |
| 195 | } |
| 196 | } |
| 197 | |
Richard Smith | e977e51 | 2015-02-24 01:23:23 +0000 | [diff] [blame] | 198 | template<class EntryType> |
| 199 | typename RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::DeclType * |
Peter Collingbourne | b498ed6 | 2010-07-30 17:09:04 +0000 | [diff] [blame] | 200 | RedeclarableTemplateDecl::findSpecializationImpl( |
Richard Smith | e977e51 | 2015-02-24 01:23:23 +0000 | [diff] [blame] | 201 | llvm::FoldingSetVector<EntryType> &Specs, ArrayRef<TemplateArgument> Args, |
| 202 | void *&InsertPos) { |
Eugene Zelenko | 421e890 | 2017-11-29 22:39:22 +0000 | [diff] [blame] | 203 | using SETraits = SpecEntryTraits<EntryType>; |
| 204 | |
Peter Collingbourne | b498ed6 | 2010-07-30 17:09:04 +0000 | [diff] [blame] | 205 | llvm::FoldingSetNodeID ID; |
Vassil Vassilev | 61f6429 | 2017-12-14 23:30:18 +0000 | [diff] [blame] | 206 | EntryType::Profile(ID, Args, getASTContext()); |
Peter Collingbourne | b498ed6 | 2010-07-30 17:09:04 +0000 | [diff] [blame] | 207 | EntryType *Entry = Specs.FindNodeOrInsertPos(ID, InsertPos); |
Richard Smith | e977e51 | 2015-02-24 01:23:23 +0000 | [diff] [blame] | 208 | return Entry ? SETraits::getDecl(Entry)->getMostRecentDecl() : nullptr; |
| 209 | } |
| 210 | |
| 211 | template<class Derived, class EntryType> |
| 212 | void RedeclarableTemplateDecl::addSpecializationImpl( |
| 213 | llvm::FoldingSetVector<EntryType> &Specializations, EntryType *Entry, |
| 214 | void *InsertPos) { |
Eugene Zelenko | 421e890 | 2017-11-29 22:39:22 +0000 | [diff] [blame] | 215 | using SETraits = SpecEntryTraits<EntryType>; |
| 216 | |
Richard Smith | e977e51 | 2015-02-24 01:23:23 +0000 | [diff] [blame] | 217 | if (InsertPos) { |
| 218 | #ifndef NDEBUG |
| 219 | void *CorrectInsertPos; |
| 220 | assert(!findSpecializationImpl(Specializations, |
| 221 | SETraits::getTemplateArgs(Entry), |
| 222 | CorrectInsertPos) && |
| 223 | InsertPos == CorrectInsertPos && |
| 224 | "given incorrect InsertPos for specialization"); |
| 225 | #endif |
| 226 | Specializations.InsertNode(Entry, InsertPos); |
| 227 | } else { |
| 228 | EntryType *Existing = Specializations.GetOrInsertNode(Entry); |
| 229 | (void)Existing; |
| 230 | assert(SETraits::getDecl(Existing)->isCanonicalDecl() && |
| 231 | "non-canonical specialization?"); |
| 232 | } |
| 233 | |
| 234 | if (ASTMutationListener *L = getASTMutationListener()) |
| 235 | L->AddedCXXTemplateSpecialization(cast<Derived>(this), |
| 236 | SETraits::getDecl(Entry)); |
Peter Collingbourne | b498ed6 | 2010-07-30 17:09:04 +0000 | [diff] [blame] | 237 | } |
| 238 | |
Peter Collingbourne | 91b25b7 | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 239 | //===----------------------------------------------------------------------===// |
Douglas Gregor | ded2d7b | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 240 | // FunctionTemplateDecl Implementation |
| 241 | //===----------------------------------------------------------------------===// |
| 242 | |
| 243 | FunctionTemplateDecl *FunctionTemplateDecl::Create(ASTContext &C, |
| 244 | DeclContext *DC, |
| 245 | SourceLocation L, |
| 246 | DeclarationName Name, |
Douglas Gregor | 8f5d442 | 2009-06-29 20:59:39 +0000 | [diff] [blame] | 247 | TemplateParameterList *Params, |
Douglas Gregor | ded2d7b | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 248 | NamedDecl *Decl) { |
Douglas Gregor | 3c41bf7 | 2011-03-04 18:32:38 +0000 | [diff] [blame] | 249 | AdoptTemplateParameterList(Params, cast<DeclContext>(Decl)); |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 250 | return new (C, DC) FunctionTemplateDecl(C, DC, L, Name, Params, Decl); |
Douglas Gregor | ded2d7b | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 251 | } |
| 252 | |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 253 | FunctionTemplateDecl *FunctionTemplateDecl::CreateDeserialized(ASTContext &C, |
| 254 | unsigned ID) { |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 255 | return new (C, ID) FunctionTemplateDecl(C, nullptr, SourceLocation(), |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 256 | DeclarationName(), nullptr, nullptr); |
Douglas Gregor | fd7c225 | 2011-03-04 17:52:15 +0000 | [diff] [blame] | 257 | } |
| 258 | |
Argyrios Kyrtzidis | f4bc0d8 | 2010-09-08 19:31:22 +0000 | [diff] [blame] | 259 | RedeclarableTemplateDecl::CommonBase * |
Dmitri Gribenko | b53f37c | 2013-01-23 16:52:57 +0000 | [diff] [blame] | 260 | FunctionTemplateDecl::newCommon(ASTContext &C) const { |
Eugene Zelenko | 309e29d | 2018-03-29 20:51:59 +0000 | [diff] [blame] | 261 | auto *CommonPtr = new (C) Common; |
George Burgess IV | b61bfbd | 2017-02-14 05:37:36 +0000 | [diff] [blame] | 262 | C.addDestruction(CommonPtr); |
Peter Collingbourne | 91b25b7 | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 263 | return CommonPtr; |
| 264 | } |
| 265 | |
Richard Smith | feb3e1a | 2013-06-28 04:37:53 +0000 | [diff] [blame] | 266 | void FunctionTemplateDecl::LoadLazySpecializations() const { |
Vassil Vassilev | 61f6429 | 2017-12-14 23:30:18 +0000 | [diff] [blame] | 267 | loadLazySpecializationsImpl(); |
Richard Smith | feb3e1a | 2013-06-28 04:37:53 +0000 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | llvm::FoldingSetVector<FunctionTemplateSpecializationInfo> & |
| 271 | FunctionTemplateDecl::getSpecializations() const { |
| 272 | LoadLazySpecializations(); |
| 273 | return getCommonPtr()->Specializations; |
| 274 | } |
| 275 | |
Argyrios Kyrtzidis | dde5790 | 2010-07-20 13:59:58 +0000 | [diff] [blame] | 276 | FunctionDecl * |
Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 277 | FunctionTemplateDecl::findSpecialization(ArrayRef<TemplateArgument> Args, |
| 278 | void *&InsertPos) { |
| 279 | return findSpecializationImpl(getSpecializations(), Args, InsertPos); |
Argyrios Kyrtzidis | dde5790 | 2010-07-20 13:59:58 +0000 | [diff] [blame] | 280 | } |
| 281 | |
Sebastian Redl | 9ab988f | 2011-04-14 14:07:59 +0000 | [diff] [blame] | 282 | void FunctionTemplateDecl::addSpecialization( |
| 283 | FunctionTemplateSpecializationInfo *Info, void *InsertPos) { |
Richard Smith | e977e51 | 2015-02-24 01:23:23 +0000 | [diff] [blame] | 284 | addSpecializationImpl<FunctionTemplateDecl>(getSpecializations(), Info, |
| 285 | InsertPos); |
Sebastian Redl | 9ab988f | 2011-04-14 14:07:59 +0000 | [diff] [blame] | 286 | } |
| 287 | |
Richard Smith | 841d8b2 | 2013-05-17 03:04:50 +0000 | [diff] [blame] | 288 | ArrayRef<TemplateArgument> FunctionTemplateDecl::getInjectedTemplateArgs() { |
Douglas Gregor | 43669f8 | 2011-03-05 17:54:25 +0000 | [diff] [blame] | 289 | TemplateParameterList *Params = getTemplateParameters(); |
| 290 | Common *CommonPtr = getCommonPtr(); |
| 291 | if (!CommonPtr->InjectedArgs) { |
Richard Smith | 43e14d2 | 2016-12-23 02:10:11 +0000 | [diff] [blame] | 292 | auto &Context = getASTContext(); |
| 293 | SmallVector<TemplateArgument, 16> TemplateArgs; |
| 294 | Context.getInjectedTemplateArgs(Params, TemplateArgs); |
| 295 | CommonPtr->InjectedArgs = |
| 296 | new (Context) TemplateArgument[TemplateArgs.size()]; |
| 297 | std::copy(TemplateArgs.begin(), TemplateArgs.end(), |
| 298 | CommonPtr->InjectedArgs); |
Douglas Gregor | 43669f8 | 2011-03-05 17:54:25 +0000 | [diff] [blame] | 299 | } |
Richard Smith | 841d8b2 | 2013-05-17 03:04:50 +0000 | [diff] [blame] | 300 | |
| 301 | return llvm::makeArrayRef(CommonPtr->InjectedArgs, Params->size()); |
Douglas Gregor | 43669f8 | 2011-03-05 17:54:25 +0000 | [diff] [blame] | 302 | } |
| 303 | |
Erik Pilkington | d1a184f | 2018-10-10 17:17:51 +0000 | [diff] [blame] | 304 | void FunctionTemplateDecl::mergePrevDecl(FunctionTemplateDecl *Prev) { |
| 305 | using Base = RedeclarableTemplateDecl; |
| 306 | |
| 307 | // If we haven't created a common pointer yet, then it can just be created |
| 308 | // with the usual method. |
| 309 | if (!Base::Common) |
| 310 | return; |
| 311 | |
| 312 | Common *ThisCommon = static_cast<Common *>(Base::Common); |
| 313 | Common *PrevCommon = nullptr; |
| 314 | SmallVector<FunctionTemplateDecl *, 8> PreviousDecls; |
| 315 | for (; Prev; Prev = Prev->getPreviousDecl()) { |
| 316 | if (Prev->Base::Common) { |
| 317 | PrevCommon = static_cast<Common *>(Prev->Base::Common); |
| 318 | break; |
| 319 | } |
| 320 | PreviousDecls.push_back(Prev); |
| 321 | } |
| 322 | |
| 323 | // If the previous redecl chain hasn't created a common pointer yet, then just |
| 324 | // use this common pointer. |
| 325 | if (!PrevCommon) { |
| 326 | for (auto *D : PreviousDecls) |
| 327 | D->Base::Common = ThisCommon; |
| 328 | return; |
| 329 | } |
| 330 | |
| 331 | // Ensure we don't leak any important state. |
| 332 | assert(ThisCommon->Specializations.size() == 0 && |
Erik Pilkington | d1a184f | 2018-10-10 17:17:51 +0000 | [diff] [blame] | 333 | "Can't merge incompatible declarations!"); |
| 334 | |
| 335 | Base::Common = PrevCommon; |
| 336 | } |
| 337 | |
Douglas Gregor | ded2d7b | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 338 | //===----------------------------------------------------------------------===// |
| 339 | // ClassTemplateDecl Implementation |
| 340 | //===----------------------------------------------------------------------===// |
| 341 | |
| 342 | ClassTemplateDecl *ClassTemplateDecl::Create(ASTContext &C, |
| 343 | DeclContext *DC, |
| 344 | SourceLocation L, |
| 345 | DeclarationName Name, |
| 346 | TemplateParameterList *Params, |
Hubert Tong | 5a8ec4e | 2017-02-10 02:46:19 +0000 | [diff] [blame] | 347 | NamedDecl *Decl, |
| 348 | Expr *AssociatedConstraints) { |
Douglas Gregor | 3c41bf7 | 2011-03-04 18:32:38 +0000 | [diff] [blame] | 349 | AdoptTemplateParameterList(Params, cast<DeclContext>(Decl)); |
Hubert Tong | 5a8ec4e | 2017-02-10 02:46:19 +0000 | [diff] [blame] | 350 | |
| 351 | if (!AssociatedConstraints) { |
| 352 | return new (C, DC) ClassTemplateDecl(C, DC, L, Name, Params, Decl); |
| 353 | } |
| 354 | |
Eugene Zelenko | 309e29d | 2018-03-29 20:51:59 +0000 | [diff] [blame] | 355 | auto *const CTDI = new (C) ConstrainedTemplateDeclInfo; |
| 356 | auto *const New = |
Hubert Tong | 5a8ec4e | 2017-02-10 02:46:19 +0000 | [diff] [blame] | 357 | new (C, DC) ClassTemplateDecl(CTDI, C, DC, L, Name, Params, Decl); |
| 358 | New->setAssociatedConstraints(AssociatedConstraints); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 359 | return New; |
Douglas Gregor | 90a1a65 | 2009-03-19 17:26:29 +0000 | [diff] [blame] | 360 | } |
| 361 | |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 362 | ClassTemplateDecl *ClassTemplateDecl::CreateDeserialized(ASTContext &C, |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 363 | unsigned ID) { |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 364 | return new (C, ID) ClassTemplateDecl(C, nullptr, SourceLocation(), |
| 365 | DeclarationName(), nullptr, nullptr); |
Douglas Gregor | fd7c225 | 2011-03-04 17:52:15 +0000 | [diff] [blame] | 366 | } |
| 367 | |
Dmitri Gribenko | 81f2575 | 2013-02-14 13:20:36 +0000 | [diff] [blame] | 368 | void ClassTemplateDecl::LoadLazySpecializations() const { |
Vassil Vassilev | 61f6429 | 2017-12-14 23:30:18 +0000 | [diff] [blame] | 369 | loadLazySpecializationsImpl(); |
Douglas Gregor | 7e8c4e0 | 2010-10-27 22:21:36 +0000 | [diff] [blame] | 370 | } |
| 371 | |
Chandler Carruth | b41171b | 2012-05-03 23:49:05 +0000 | [diff] [blame] | 372 | llvm::FoldingSetVector<ClassTemplateSpecializationDecl> & |
Dmitri Gribenko | 81f2575 | 2013-02-14 13:20:36 +0000 | [diff] [blame] | 373 | ClassTemplateDecl::getSpecializations() const { |
Douglas Gregor | 7e8c4e0 | 2010-10-27 22:21:36 +0000 | [diff] [blame] | 374 | LoadLazySpecializations(); |
| 375 | return getCommonPtr()->Specializations; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 376 | } |
Douglas Gregor | 7e8c4e0 | 2010-10-27 22:21:36 +0000 | [diff] [blame] | 377 | |
Chandler Carruth | b41171b | 2012-05-03 23:49:05 +0000 | [diff] [blame] | 378 | llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> & |
Douglas Gregor | 7e8c4e0 | 2010-10-27 22:21:36 +0000 | [diff] [blame] | 379 | ClassTemplateDecl::getPartialSpecializations() { |
| 380 | LoadLazySpecializations(); |
| 381 | return getCommonPtr()->PartialSpecializations; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 382 | } |
Douglas Gregor | 7e8c4e0 | 2010-10-27 22:21:36 +0000 | [diff] [blame] | 383 | |
Argyrios Kyrtzidis | f4bc0d8 | 2010-09-08 19:31:22 +0000 | [diff] [blame] | 384 | RedeclarableTemplateDecl::CommonBase * |
Dmitri Gribenko | b53f37c | 2013-01-23 16:52:57 +0000 | [diff] [blame] | 385 | ClassTemplateDecl::newCommon(ASTContext &C) const { |
Eugene Zelenko | 309e29d | 2018-03-29 20:51:59 +0000 | [diff] [blame] | 386 | auto *CommonPtr = new (C) Common; |
George Burgess IV | b61bfbd | 2017-02-14 05:37:36 +0000 | [diff] [blame] | 387 | C.addDestruction(CommonPtr); |
Peter Collingbourne | 91b25b7 | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 388 | return CommonPtr; |
| 389 | } |
| 390 | |
Argyrios Kyrtzidis | 47470f2 | 2010-07-20 13:59:28 +0000 | [diff] [blame] | 391 | ClassTemplateSpecializationDecl * |
Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 392 | ClassTemplateDecl::findSpecialization(ArrayRef<TemplateArgument> Args, |
| 393 | void *&InsertPos) { |
| 394 | return findSpecializationImpl(getSpecializations(), Args, InsertPos); |
Argyrios Kyrtzidis | 47470f2 | 2010-07-20 13:59:28 +0000 | [diff] [blame] | 395 | } |
| 396 | |
Argyrios Kyrtzidis | 402dbbb | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 397 | void ClassTemplateDecl::AddSpecialization(ClassTemplateSpecializationDecl *D, |
| 398 | void *InsertPos) { |
Richard Smith | e977e51 | 2015-02-24 01:23:23 +0000 | [diff] [blame] | 399 | addSpecializationImpl<ClassTemplateDecl>(getSpecializations(), D, InsertPos); |
Argyrios Kyrtzidis | 402dbbb | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 400 | } |
| 401 | |
Argyrios Kyrtzidis | 47470f2 | 2010-07-20 13:59:28 +0000 | [diff] [blame] | 402 | ClassTemplatePartialSpecializationDecl * |
Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 403 | ClassTemplateDecl::findPartialSpecialization(ArrayRef<TemplateArgument> Args, |
Argyrios Kyrtzidis | 47470f2 | 2010-07-20 13:59:28 +0000 | [diff] [blame] | 404 | void *&InsertPos) { |
Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 405 | return findSpecializationImpl(getPartialSpecializations(), Args, InsertPos); |
Argyrios Kyrtzidis | 47470f2 | 2010-07-20 13:59:28 +0000 | [diff] [blame] | 406 | } |
| 407 | |
Argyrios Kyrtzidis | 402dbbb | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 408 | void ClassTemplateDecl::AddPartialSpecialization( |
| 409 | ClassTemplatePartialSpecializationDecl *D, |
| 410 | void *InsertPos) { |
Douglas Gregor | ce9978f | 2012-03-28 14:34:23 +0000 | [diff] [blame] | 411 | if (InsertPos) |
| 412 | getPartialSpecializations().InsertNode(D, InsertPos); |
| 413 | else { |
| 414 | ClassTemplatePartialSpecializationDecl *Existing |
| 415 | = getPartialSpecializations().GetOrInsertNode(D); |
| 416 | (void)Existing; |
| 417 | assert(Existing->isCanonicalDecl() && "Non-canonical specialization?"); |
| 418 | } |
| 419 | |
Argyrios Kyrtzidis | 402dbbb | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 420 | if (ASTMutationListener *L = getASTMutationListener()) |
| 421 | L->AddedCXXTemplateSpecialization(this, D); |
| 422 | } |
| 423 | |
Douglas Gregor | 407e961 | 2010-04-30 05:56:50 +0000 | [diff] [blame] | 424 | void ClassTemplateDecl::getPartialSpecializations( |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 425 | SmallVectorImpl<ClassTemplatePartialSpecializationDecl *> &PS) { |
Chandler Carruth | b41171b | 2012-05-03 23:49:05 +0000 | [diff] [blame] | 426 | llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> &PartialSpecs |
Argyrios Kyrtzidis | a35c8e4 | 2010-06-21 10:57:41 +0000 | [diff] [blame] | 427 | = getPartialSpecializations(); |
Douglas Gregor | 407e961 | 2010-04-30 05:56:50 +0000 | [diff] [blame] | 428 | PS.clear(); |
Richard Smith | b2f61b4 | 2013-08-22 23:27:37 +0000 | [diff] [blame] | 429 | PS.reserve(PartialSpecs.size()); |
David Majnemer | dfecf1a | 2016-07-06 04:19:16 +0000 | [diff] [blame] | 430 | for (ClassTemplatePartialSpecializationDecl &P : PartialSpecs) |
| 431 | PS.push_back(P.getMostRecentDecl()); |
Douglas Gregor | 407e961 | 2010-04-30 05:56:50 +0000 | [diff] [blame] | 432 | } |
| 433 | |
Douglas Gregor | 1530138 | 2009-07-30 17:40:51 +0000 | [diff] [blame] | 434 | ClassTemplatePartialSpecializationDecl * |
| 435 | ClassTemplateDecl::findPartialSpecialization(QualType T) { |
| 436 | ASTContext &Context = getASTContext(); |
David Majnemer | dfecf1a | 2016-07-06 04:19:16 +0000 | [diff] [blame] | 437 | for (ClassTemplatePartialSpecializationDecl &P : |
| 438 | getPartialSpecializations()) { |
| 439 | if (Context.hasSameType(P.getInjectedSpecializationType(), T)) |
| 440 | return P.getMostRecentDecl(); |
Argyrios Kyrtzidis | 47470f2 | 2010-07-20 13:59:28 +0000 | [diff] [blame] | 441 | } |
| 442 | |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 443 | return nullptr; |
Argyrios Kyrtzidis | 47470f2 | 2010-07-20 13:59:28 +0000 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | ClassTemplatePartialSpecializationDecl * |
| 447 | ClassTemplateDecl::findPartialSpecInstantiatedFromMember( |
| 448 | ClassTemplatePartialSpecializationDecl *D) { |
| 449 | Decl *DCanon = D->getCanonicalDecl(); |
David Majnemer | dfecf1a | 2016-07-06 04:19:16 +0000 | [diff] [blame] | 450 | for (ClassTemplatePartialSpecializationDecl &P : getPartialSpecializations()) { |
| 451 | if (P.getInstantiatedFromMember()->getCanonicalDecl() == DCanon) |
| 452 | return P.getMostRecentDecl(); |
Douglas Gregor | 1530138 | 2009-07-30 17:40:51 +0000 | [diff] [blame] | 453 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 454 | |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 455 | return nullptr; |
Douglas Gregor | 1530138 | 2009-07-30 17:40:51 +0000 | [diff] [blame] | 456 | } |
| 457 | |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 458 | QualType |
Douglas Gregor | 9961ce9 | 2010-07-08 18:37:38 +0000 | [diff] [blame] | 459 | ClassTemplateDecl::getInjectedClassNameSpecialization() { |
Argyrios Kyrtzidis | a35c8e4 | 2010-06-21 10:57:41 +0000 | [diff] [blame] | 460 | Common *CommonPtr = getCommonPtr(); |
Douglas Gregor | e362cea | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 461 | if (!CommonPtr->InjectedClassNameType.isNull()) |
| 462 | return CommonPtr->InjectedClassNameType; |
| 463 | |
Douglas Gregor | 8092e80 | 2010-12-23 16:00:30 +0000 | [diff] [blame] | 464 | // C++0x [temp.dep.type]p2: |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 465 | // The template argument list of a primary template is a template argument |
Douglas Gregor | 8092e80 | 2010-12-23 16:00:30 +0000 | [diff] [blame] | 466 | // list in which the nth template argument has the value of the nth template |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 467 | // parameter of the class template. If the nth template parameter is a |
| 468 | // template parameter pack (14.5.3), the nth template argument is a pack |
| 469 | // expansion (14.5.3) whose pattern is the name of the template parameter |
Douglas Gregor | 8092e80 | 2010-12-23 16:00:30 +0000 | [diff] [blame] | 470 | // pack. |
Douglas Gregor | 9961ce9 | 2010-07-08 18:37:38 +0000 | [diff] [blame] | 471 | ASTContext &Context = getASTContext(); |
Douglas Gregor | e362cea | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 472 | TemplateParameterList *Params = getTemplateParameters(); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 473 | SmallVector<TemplateArgument, 16> TemplateArgs; |
Richard Smith | 43e14d2 | 2016-12-23 02:10:11 +0000 | [diff] [blame] | 474 | Context.getInjectedTemplateArgs(Params, TemplateArgs); |
Douglas Gregor | e362cea | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 475 | CommonPtr->InjectedClassNameType |
Douglas Gregor | a8e02e7 | 2009-07-28 23:00:59 +0000 | [diff] [blame] | 476 | = Context.getTemplateSpecializationType(TemplateName(this), |
David Majnemer | 6fbeee3 | 2016-07-07 04:43:07 +0000 | [diff] [blame] | 477 | TemplateArgs); |
Douglas Gregor | e362cea | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 478 | return CommonPtr->InjectedClassNameType; |
| 479 | } |
| 480 | |
Douglas Gregor | ded2d7b | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 481 | //===----------------------------------------------------------------------===// |
| 482 | // TemplateTypeParm Allocation/Deallocation Method Implementations |
| 483 | //===----------------------------------------------------------------------===// |
| 484 | |
| 485 | TemplateTypeParmDecl * |
Jay Foad | 39c7980 | 2011-01-12 09:06:06 +0000 | [diff] [blame] | 486 | TemplateTypeParmDecl::Create(const ASTContext &C, DeclContext *DC, |
Abramo Bagnara | b3185b0 | 2011-03-06 15:48:19 +0000 | [diff] [blame] | 487 | SourceLocation KeyLoc, SourceLocation NameLoc, |
| 488 | unsigned D, unsigned P, IdentifierInfo *Id, |
| 489 | bool Typename, bool ParameterPack) { |
Eugene Zelenko | 309e29d | 2018-03-29 20:51:59 +0000 | [diff] [blame] | 490 | auto *TTPDecl = |
| 491 | new (C, DC) TemplateTypeParmDecl(DC, KeyLoc, NameLoc, Id, Typename); |
Chandler Carruth | 0883632 | 2011-05-01 00:51:33 +0000 | [diff] [blame] | 492 | QualType TTPType = C.getTemplateTypeParmType(D, P, ParameterPack, TTPDecl); |
Richard Smith | 5b21db8 | 2014-04-23 18:20:42 +0000 | [diff] [blame] | 493 | TTPDecl->setTypeForDecl(TTPType.getTypePtr()); |
Chandler Carruth | 0883632 | 2011-05-01 00:51:33 +0000 | [diff] [blame] | 494 | return TTPDecl; |
Douglas Gregor | ded2d7b | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 495 | } |
| 496 | |
Argyrios Kyrtzidis | 39f0e30 | 2010-07-02 11:54:55 +0000 | [diff] [blame] | 497 | TemplateTypeParmDecl * |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 498 | TemplateTypeParmDecl::CreateDeserialized(const ASTContext &C, unsigned ID) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 499 | return new (C, ID) TemplateTypeParmDecl(nullptr, SourceLocation(), |
| 500 | SourceLocation(), nullptr, false); |
Argyrios Kyrtzidis | 39f0e30 | 2010-07-02 11:54:55 +0000 | [diff] [blame] | 501 | } |
| 502 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 503 | SourceLocation TemplateTypeParmDecl::getDefaultArgumentLoc() const { |
Abramo Bagnara | 23485e0 | 2011-03-04 12:42:03 +0000 | [diff] [blame] | 504 | return hasDefaultArgument() |
Richard Smith | 1469b91 | 2015-06-10 00:29:03 +0000 | [diff] [blame] | 505 | ? getDefaultArgumentInfo()->getTypeLoc().getBeginLoc() |
| 506 | : SourceLocation(); |
Abramo Bagnara | 23485e0 | 2011-03-04 12:42:03 +0000 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | SourceRange TemplateTypeParmDecl::getSourceRange() const { |
| 510 | if (hasDefaultArgument() && !defaultArgumentWasInherited()) |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 511 | return SourceRange(getBeginLoc(), |
Richard Smith | 1469b91 | 2015-06-10 00:29:03 +0000 | [diff] [blame] | 512 | getDefaultArgumentInfo()->getTypeLoc().getEndLoc()); |
Abramo Bagnara | 23485e0 | 2011-03-04 12:42:03 +0000 | [diff] [blame] | 513 | else |
Abramo Bagnara | b3185b0 | 2011-03-06 15:48:19 +0000 | [diff] [blame] | 514 | return TypeDecl::getSourceRange(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 515 | } |
| 516 | |
Douglas Gregor | 2161038 | 2009-10-29 00:04:11 +0000 | [diff] [blame] | 517 | unsigned TemplateTypeParmDecl::getDepth() const { |
Richard Smith | 5b21db8 | 2014-04-23 18:20:42 +0000 | [diff] [blame] | 518 | return getTypeForDecl()->getAs<TemplateTypeParmType>()->getDepth(); |
Douglas Gregor | 2161038 | 2009-10-29 00:04:11 +0000 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | unsigned TemplateTypeParmDecl::getIndex() const { |
Richard Smith | 5b21db8 | 2014-04-23 18:20:42 +0000 | [diff] [blame] | 522 | return getTypeForDecl()->getAs<TemplateTypeParmType>()->getIndex(); |
Douglas Gregor | 2161038 | 2009-10-29 00:04:11 +0000 | [diff] [blame] | 523 | } |
| 524 | |
Chandler Carruth | 0883632 | 2011-05-01 00:51:33 +0000 | [diff] [blame] | 525 | bool TemplateTypeParmDecl::isParameterPack() const { |
Richard Smith | 5b21db8 | 2014-04-23 18:20:42 +0000 | [diff] [blame] | 526 | return getTypeForDecl()->getAs<TemplateTypeParmType>()->isParameterPack(); |
Chandler Carruth | 0883632 | 2011-05-01 00:51:33 +0000 | [diff] [blame] | 527 | } |
| 528 | |
Douglas Gregor | ded2d7b | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 529 | //===----------------------------------------------------------------------===// |
| 530 | // NonTypeTemplateParmDecl Method Implementations |
| 531 | //===----------------------------------------------------------------------===// |
| 532 | |
David Majnemer | dfecf1a | 2016-07-06 04:19:16 +0000 | [diff] [blame] | 533 | NonTypeTemplateParmDecl::NonTypeTemplateParmDecl( |
| 534 | DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, unsigned D, |
| 535 | unsigned P, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, |
| 536 | ArrayRef<QualType> ExpandedTypes, ArrayRef<TypeSourceInfo *> ExpandedTInfos) |
| 537 | : DeclaratorDecl(NonTypeTemplateParm, DC, IdLoc, Id, T, TInfo, StartLoc), |
| 538 | TemplateParmPosition(D, P), ParameterPack(true), |
| 539 | ExpandedParameterPack(true), NumExpandedTypes(ExpandedTypes.size()) { |
| 540 | if (!ExpandedTypes.empty() && !ExpandedTInfos.empty()) { |
James Y Knight | 7a22b24 | 2015-08-06 20:26:32 +0000 | [diff] [blame] | 541 | auto TypesAndInfos = |
| 542 | getTrailingObjects<std::pair<QualType, TypeSourceInfo *>>(); |
Douglas Gregor | 0231d8d | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 543 | for (unsigned I = 0; I != NumExpandedTypes; ++I) { |
James Y Knight | 7a22b24 | 2015-08-06 20:26:32 +0000 | [diff] [blame] | 544 | new (&TypesAndInfos[I].first) QualType(ExpandedTypes[I]); |
| 545 | TypesAndInfos[I].second = ExpandedTInfos[I]; |
Douglas Gregor | 0231d8d | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 546 | } |
| 547 | } |
| 548 | } |
| 549 | |
Douglas Gregor | ded2d7b | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 550 | NonTypeTemplateParmDecl * |
Jay Foad | 39c7980 | 2011-01-12 09:06:06 +0000 | [diff] [blame] | 551 | NonTypeTemplateParmDecl::Create(const ASTContext &C, DeclContext *DC, |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 552 | SourceLocation StartLoc, SourceLocation IdLoc, |
| 553 | unsigned D, unsigned P, IdentifierInfo *Id, |
| 554 | QualType T, bool ParameterPack, |
| 555 | TypeSourceInfo *TInfo) { |
Richard Smith | f798172 | 2013-11-22 09:01:48 +0000 | [diff] [blame] | 556 | return new (C, DC) NonTypeTemplateParmDecl(DC, StartLoc, IdLoc, D, P, Id, |
| 557 | T, ParameterPack, TInfo); |
Douglas Gregor | ded2d7b | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 558 | } |
| 559 | |
David Majnemer | dfecf1a | 2016-07-06 04:19:16 +0000 | [diff] [blame] | 560 | NonTypeTemplateParmDecl *NonTypeTemplateParmDecl::Create( |
| 561 | const ASTContext &C, DeclContext *DC, SourceLocation StartLoc, |
| 562 | SourceLocation IdLoc, unsigned D, unsigned P, IdentifierInfo *Id, |
| 563 | QualType T, TypeSourceInfo *TInfo, ArrayRef<QualType> ExpandedTypes, |
| 564 | ArrayRef<TypeSourceInfo *> ExpandedTInfos) { |
James Y Knight | 7a22b24 | 2015-08-06 20:26:32 +0000 | [diff] [blame] | 565 | return new (C, DC, |
| 566 | additionalSizeToAlloc<std::pair<QualType, TypeSourceInfo *>>( |
David Majnemer | dfecf1a | 2016-07-06 04:19:16 +0000 | [diff] [blame] | 567 | ExpandedTypes.size())) |
James Y Knight | 7a22b24 | 2015-08-06 20:26:32 +0000 | [diff] [blame] | 568 | NonTypeTemplateParmDecl(DC, StartLoc, IdLoc, D, P, Id, T, TInfo, |
David Majnemer | dfecf1a | 2016-07-06 04:19:16 +0000 | [diff] [blame] | 569 | ExpandedTypes, ExpandedTInfos); |
Douglas Gregor | 0231d8d | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 570 | } |
| 571 | |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 572 | NonTypeTemplateParmDecl * |
| 573 | NonTypeTemplateParmDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 574 | return new (C, ID) NonTypeTemplateParmDecl(nullptr, SourceLocation(), |
| 575 | SourceLocation(), 0, 0, nullptr, |
| 576 | QualType(), false, nullptr); |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | NonTypeTemplateParmDecl * |
| 580 | NonTypeTemplateParmDecl::CreateDeserialized(ASTContext &C, unsigned ID, |
| 581 | unsigned NumExpandedTypes) { |
David Majnemer | dfecf1a | 2016-07-06 04:19:16 +0000 | [diff] [blame] | 582 | auto *NTTP = |
| 583 | new (C, ID, additionalSizeToAlloc<std::pair<QualType, TypeSourceInfo *>>( |
| 584 | NumExpandedTypes)) |
| 585 | NonTypeTemplateParmDecl(nullptr, SourceLocation(), SourceLocation(), |
| 586 | 0, 0, nullptr, QualType(), nullptr, None, |
| 587 | None); |
| 588 | NTTP->NumExpandedTypes = NumExpandedTypes; |
| 589 | return NTTP; |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 590 | } |
| 591 | |
John McCall | f4cd4f9 | 2011-02-09 01:13:10 +0000 | [diff] [blame] | 592 | SourceRange NonTypeTemplateParmDecl::getSourceRange() const { |
Abramo Bagnara | e15d553 | 2011-03-04 11:03:48 +0000 | [diff] [blame] | 593 | if (hasDefaultArgument() && !defaultArgumentWasInherited()) |
Abramo Bagnara | ea94788 | 2011-03-08 16:41:52 +0000 | [diff] [blame] | 594 | return SourceRange(getOuterLocStart(), |
| 595 | getDefaultArgument()->getSourceRange().getEnd()); |
| 596 | return DeclaratorDecl::getSourceRange(); |
John McCall | f4cd4f9 | 2011-02-09 01:13:10 +0000 | [diff] [blame] | 597 | } |
| 598 | |
Douglas Gregor | dba3263 | 2009-02-10 19:49:53 +0000 | [diff] [blame] | 599 | SourceLocation NonTypeTemplateParmDecl::getDefaultArgumentLoc() const { |
Abramo Bagnara | 656e300 | 2010-06-09 09:26:05 +0000 | [diff] [blame] | 600 | return hasDefaultArgument() |
| 601 | ? getDefaultArgument()->getSourceRange().getBegin() |
| 602 | : SourceLocation(); |
Douglas Gregor | dba3263 | 2009-02-10 19:49:53 +0000 | [diff] [blame] | 603 | } |
| 604 | |
Douglas Gregor | ded2d7b | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 605 | //===----------------------------------------------------------------------===// |
| 606 | // TemplateTemplateParmDecl Method Implementations |
| 607 | //===----------------------------------------------------------------------===// |
| 608 | |
Eugene Zelenko | 421e890 | 2017-11-29 22:39:22 +0000 | [diff] [blame] | 609 | void TemplateTemplateParmDecl::anchor() {} |
David Blaikie | 68e081d | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 610 | |
Richard Smith | 1fde8ec | 2012-09-07 02:06:42 +0000 | [diff] [blame] | 611 | TemplateTemplateParmDecl::TemplateTemplateParmDecl( |
| 612 | DeclContext *DC, SourceLocation L, unsigned D, unsigned P, |
| 613 | IdentifierInfo *Id, TemplateParameterList *Params, |
David Majnemer | dfecf1a | 2016-07-06 04:19:16 +0000 | [diff] [blame] | 614 | ArrayRef<TemplateParameterList *> Expansions) |
| 615 | : TemplateDecl(TemplateTemplateParm, DC, L, Id, Params), |
| 616 | TemplateParmPosition(D, P), ParameterPack(true), |
| 617 | ExpandedParameterPack(true), NumExpandedParams(Expansions.size()) { |
| 618 | if (!Expansions.empty()) |
| 619 | std::uninitialized_copy(Expansions.begin(), Expansions.end(), |
James Y Knight | 7a22b24 | 2015-08-06 20:26:32 +0000 | [diff] [blame] | 620 | getTrailingObjects<TemplateParameterList *>()); |
Richard Smith | 1fde8ec | 2012-09-07 02:06:42 +0000 | [diff] [blame] | 621 | } |
| 622 | |
Douglas Gregor | ded2d7b | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 623 | TemplateTemplateParmDecl * |
Jay Foad | 39c7980 | 2011-01-12 09:06:06 +0000 | [diff] [blame] | 624 | TemplateTemplateParmDecl::Create(const ASTContext &C, DeclContext *DC, |
Douglas Gregor | ded2d7b | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 625 | SourceLocation L, unsigned D, unsigned P, |
Douglas Gregor | f550077 | 2011-01-05 15:48:55 +0000 | [diff] [blame] | 626 | bool ParameterPack, IdentifierInfo *Id, |
Douglas Gregor | ded2d7b | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 627 | TemplateParameterList *Params) { |
Richard Smith | f798172 | 2013-11-22 09:01:48 +0000 | [diff] [blame] | 628 | return new (C, DC) TemplateTemplateParmDecl(DC, L, D, P, ParameterPack, Id, |
| 629 | Params); |
Douglas Gregor | ded2d7b | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 630 | } |
| 631 | |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 632 | TemplateTemplateParmDecl * |
Richard Smith | 1fde8ec | 2012-09-07 02:06:42 +0000 | [diff] [blame] | 633 | TemplateTemplateParmDecl::Create(const ASTContext &C, DeclContext *DC, |
| 634 | SourceLocation L, unsigned D, unsigned P, |
| 635 | IdentifierInfo *Id, |
| 636 | TemplateParameterList *Params, |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 637 | ArrayRef<TemplateParameterList *> Expansions) { |
James Y Knight | 7a22b24 | 2015-08-06 20:26:32 +0000 | [diff] [blame] | 638 | return new (C, DC, |
| 639 | additionalSizeToAlloc<TemplateParameterList *>(Expansions.size())) |
David Majnemer | dfecf1a | 2016-07-06 04:19:16 +0000 | [diff] [blame] | 640 | TemplateTemplateParmDecl(DC, L, D, P, Id, Params, Expansions); |
Richard Smith | 1fde8ec | 2012-09-07 02:06:42 +0000 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | TemplateTemplateParmDecl * |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 644 | TemplateTemplateParmDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 645 | return new (C, ID) TemplateTemplateParmDecl(nullptr, SourceLocation(), 0, 0, |
| 646 | false, nullptr, nullptr); |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 647 | } |
| 648 | |
Richard Smith | 1fde8ec | 2012-09-07 02:06:42 +0000 | [diff] [blame] | 649 | TemplateTemplateParmDecl * |
| 650 | TemplateTemplateParmDecl::CreateDeserialized(ASTContext &C, unsigned ID, |
| 651 | unsigned NumExpansions) { |
David Majnemer | dfecf1a | 2016-07-06 04:19:16 +0000 | [diff] [blame] | 652 | auto *TTP = |
| 653 | new (C, ID, additionalSizeToAlloc<TemplateParameterList *>(NumExpansions)) |
| 654 | TemplateTemplateParmDecl(nullptr, SourceLocation(), 0, 0, nullptr, |
| 655 | nullptr, None); |
| 656 | TTP->NumExpandedParams = NumExpansions; |
| 657 | return TTP; |
Richard Smith | 1fde8ec | 2012-09-07 02:06:42 +0000 | [diff] [blame] | 658 | } |
| 659 | |
Richard Smith | 35c1df5 | 2015-06-17 20:16:32 +0000 | [diff] [blame] | 660 | SourceLocation TemplateTemplateParmDecl::getDefaultArgumentLoc() const { |
| 661 | return hasDefaultArgument() ? getDefaultArgument().getLocation() |
| 662 | : SourceLocation(); |
| 663 | } |
| 664 | |
Richard Smith | 1469b91 | 2015-06-10 00:29:03 +0000 | [diff] [blame] | 665 | void TemplateTemplateParmDecl::setDefaultArgument( |
| 666 | const ASTContext &C, const TemplateArgumentLoc &DefArg) { |
| 667 | if (DefArg.getArgument().isNull()) |
| 668 | DefaultArgument.set(nullptr); |
| 669 | else |
| 670 | DefaultArgument.set(new (C) TemplateArgumentLoc(DefArg)); |
| 671 | } |
| 672 | |
Douglas Gregor | 264ec4f | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 673 | //===----------------------------------------------------------------------===// |
Douglas Gregor | d002c7b | 2009-05-11 23:53:27 +0000 | [diff] [blame] | 674 | // TemplateArgumentList Implementation |
| 675 | //===----------------------------------------------------------------------===// |
David Majnemer | 8b62269 | 2016-07-03 21:17:51 +0000 | [diff] [blame] | 676 | TemplateArgumentList::TemplateArgumentList(ArrayRef<TemplateArgument> Args) |
| 677 | : Arguments(getTrailingObjects<TemplateArgument>()), |
| 678 | NumArguments(Args.size()) { |
| 679 | std::uninitialized_copy(Args.begin(), Args.end(), |
James Y Knight | 7a22b24 | 2015-08-06 20:26:32 +0000 | [diff] [blame] | 680 | getTrailingObjects<TemplateArgument>()); |
| 681 | } |
| 682 | |
Douglas Gregor | 1ccc841 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 683 | TemplateArgumentList * |
| 684 | TemplateArgumentList::CreateCopy(ASTContext &Context, |
David Majnemer | 8b62269 | 2016-07-03 21:17:51 +0000 | [diff] [blame] | 685 | ArrayRef<TemplateArgument> Args) { |
| 686 | void *Mem = Context.Allocate(totalSizeToAlloc<TemplateArgument>(Args.size())); |
| 687 | return new (Mem) TemplateArgumentList(Args); |
Argyrios Kyrtzidis | fe6ba88 | 2010-06-23 13:48:23 +0000 | [diff] [blame] | 688 | } |
| 689 | |
Argyrios Kyrtzidis | e9a2443 | 2011-09-22 20:07:09 +0000 | [diff] [blame] | 690 | FunctionTemplateSpecializationInfo * |
| 691 | FunctionTemplateSpecializationInfo::Create(ASTContext &C, FunctionDecl *FD, |
| 692 | FunctionTemplateDecl *Template, |
| 693 | TemplateSpecializationKind TSK, |
| 694 | const TemplateArgumentList *TemplateArgs, |
| 695 | const TemplateArgumentListInfo *TemplateArgsAsWritten, |
| 696 | SourceLocation POI) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 697 | const ASTTemplateArgumentListInfo *ArgsAsWritten = nullptr; |
Argyrios Kyrtzidis | e9a2443 | 2011-09-22 20:07:09 +0000 | [diff] [blame] | 698 | if (TemplateArgsAsWritten) |
| 699 | ArgsAsWritten = ASTTemplateArgumentListInfo::Create(C, |
| 700 | *TemplateArgsAsWritten); |
| 701 | |
| 702 | return new (C) FunctionTemplateSpecializationInfo(FD, Template, TSK, |
| 703 | TemplateArgs, |
| 704 | ArgsAsWritten, |
| 705 | POI); |
| 706 | } |
| 707 | |
Douglas Gregor | d002c7b | 2009-05-11 23:53:27 +0000 | [diff] [blame] | 708 | //===----------------------------------------------------------------------===// |
David Blaikie | 68e081d | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 709 | // TemplateDecl Implementation |
| 710 | //===----------------------------------------------------------------------===// |
| 711 | |
Eugene Zelenko | 421e890 | 2017-11-29 22:39:22 +0000 | [diff] [blame] | 712 | void TemplateDecl::anchor() {} |
David Blaikie | 68e081d | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 713 | |
| 714 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 264ec4f | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 715 | // ClassTemplateSpecializationDecl Implementation |
| 716 | //===----------------------------------------------------------------------===// |
Eugene Zelenko | 421e890 | 2017-11-29 22:39:22 +0000 | [diff] [blame] | 717 | |
Douglas Gregor | 264ec4f | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 718 | ClassTemplateSpecializationDecl:: |
Douglas Gregor | e902956 | 2010-05-06 00:28:52 +0000 | [diff] [blame] | 719 | ClassTemplateSpecializationDecl(ASTContext &Context, Kind DK, TagKind TK, |
Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 720 | DeclContext *DC, SourceLocation StartLoc, |
| 721 | SourceLocation IdLoc, |
Douglas Gregor | 264ec4f | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 722 | ClassTemplateDecl *SpecializedTemplate, |
David Majnemer | 8b62269 | 2016-07-03 21:17:51 +0000 | [diff] [blame] | 723 | ArrayRef<TemplateArgument> Args, |
Douglas Gregor | b6b8f9e | 2009-07-29 23:36:44 +0000 | [diff] [blame] | 724 | ClassTemplateSpecializationDecl *PrevDecl) |
Eugene Zelenko | 421e890 | 2017-11-29 22:39:22 +0000 | [diff] [blame] | 725 | : CXXRecordDecl(DK, TK, Context, DC, StartLoc, IdLoc, |
| 726 | SpecializedTemplate->getIdentifier(), PrevDecl), |
Douglas Gregor | 264ec4f | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 727 | SpecializedTemplate(SpecializedTemplate), |
David Majnemer | 8b62269 | 2016-07-03 21:17:51 +0000 | [diff] [blame] | 728 | TemplateArgs(TemplateArgumentList::CreateCopy(Context, Args)), |
Douglas Gregor | d002c7b | 2009-05-11 23:53:27 +0000 | [diff] [blame] | 729 | SpecializationKind(TSK_Undeclared) { |
Douglas Gregor | 264ec4f | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 730 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 731 | |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 732 | ClassTemplateSpecializationDecl::ClassTemplateSpecializationDecl(ASTContext &C, |
| 733 | Kind DK) |
| 734 | : CXXRecordDecl(DK, TTK_Struct, C, nullptr, SourceLocation(), |
| 735 | SourceLocation(), nullptr, nullptr), |
Eugene Zelenko | 421e890 | 2017-11-29 22:39:22 +0000 | [diff] [blame] | 736 | SpecializationKind(TSK_Undeclared) {} |
Argyrios Kyrtzidis | fe6ba88 | 2010-06-23 13:48:23 +0000 | [diff] [blame] | 737 | |
Douglas Gregor | 264ec4f | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 738 | ClassTemplateSpecializationDecl * |
Douglas Gregor | e902956 | 2010-05-06 00:28:52 +0000 | [diff] [blame] | 739 | ClassTemplateSpecializationDecl::Create(ASTContext &Context, TagKind TK, |
Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 740 | DeclContext *DC, |
| 741 | SourceLocation StartLoc, |
| 742 | SourceLocation IdLoc, |
Douglas Gregor | 264ec4f | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 743 | ClassTemplateDecl *SpecializedTemplate, |
David Majnemer | 8b62269 | 2016-07-03 21:17:51 +0000 | [diff] [blame] | 744 | ArrayRef<TemplateArgument> Args, |
Douglas Gregor | 67a6564 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 745 | ClassTemplateSpecializationDecl *PrevDecl) { |
Eugene Zelenko | 309e29d | 2018-03-29 20:51:59 +0000 | [diff] [blame] | 746 | auto *Result = |
Richard Smith | f798172 | 2013-11-22 09:01:48 +0000 | [diff] [blame] | 747 | new (Context, DC) ClassTemplateSpecializationDecl( |
| 748 | Context, ClassTemplateSpecialization, TK, DC, StartLoc, IdLoc, |
David Majnemer | 8b62269 | 2016-07-03 21:17:51 +0000 | [diff] [blame] | 749 | SpecializedTemplate, Args, PrevDecl); |
Erich Keane | f92f31c | 2018-08-01 20:48:16 +0000 | [diff] [blame] | 750 | Result->setMayHaveOutOfDateDef(false); |
Douglas Gregor | 7dab26b | 2013-02-09 01:35:03 +0000 | [diff] [blame] | 751 | |
Douglas Gregor | 67a6564 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 752 | Context.getTypeDeclType(Result, PrevDecl); |
| 753 | return Result; |
Douglas Gregor | 264ec4f | 2009-02-17 01:05:43 +0000 | [diff] [blame] | 754 | } |
Douglas Gregor | 2373c59 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 755 | |
Argyrios Kyrtzidis | fe6ba88 | 2010-06-23 13:48:23 +0000 | [diff] [blame] | 756 | ClassTemplateSpecializationDecl * |
Richard Smith | f798172 | 2013-11-22 09:01:48 +0000 | [diff] [blame] | 757 | ClassTemplateSpecializationDecl::CreateDeserialized(ASTContext &C, |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 758 | unsigned ID) { |
Eugene Zelenko | 309e29d | 2018-03-29 20:51:59 +0000 | [diff] [blame] | 759 | auto *Result = |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 760 | new (C, ID) ClassTemplateSpecializationDecl(C, ClassTemplateSpecialization); |
Erich Keane | f92f31c | 2018-08-01 20:48:16 +0000 | [diff] [blame] | 761 | Result->setMayHaveOutOfDateDef(false); |
Douglas Gregor | 7dab26b | 2013-02-09 01:35:03 +0000 | [diff] [blame] | 762 | return Result; |
Argyrios Kyrtzidis | fe6ba88 | 2010-06-23 13:48:23 +0000 | [diff] [blame] | 763 | } |
| 764 | |
Benjamin Kramer | 9170e91 | 2013-02-22 15:46:01 +0000 | [diff] [blame] | 765 | void ClassTemplateSpecializationDecl::getNameForDiagnostic( |
| 766 | raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const { |
| 767 | NamedDecl::getNameForDiagnostic(OS, Policy, Qualified); |
Douglas Gregor | b11aad8 | 2011-02-19 18:51:44 +0000 | [diff] [blame] | 768 | |
Eugene Zelenko | 309e29d | 2018-03-29 20:51:59 +0000 | [diff] [blame] | 769 | const auto *PS = dyn_cast<ClassTemplatePartialSpecializationDecl>(this); |
Richard Smith | 792c22d | 2016-12-24 04:09:05 +0000 | [diff] [blame] | 770 | if (const ASTTemplateArgumentListInfo *ArgsAsWritten = |
| 771 | PS ? PS->getTemplateArgsAsWritten() : nullptr) { |
Serge Pavlov | 03e672c | 2017-11-28 16:14:14 +0000 | [diff] [blame] | 772 | printTemplateArgumentList(OS, ArgsAsWritten->arguments(), Policy); |
Richard Smith | 792c22d | 2016-12-24 04:09:05 +0000 | [diff] [blame] | 773 | } else { |
| 774 | const TemplateArgumentList &TemplateArgs = getTemplateArgs(); |
Serge Pavlov | 03e672c | 2017-11-28 16:14:14 +0000 | [diff] [blame] | 775 | printTemplateArgumentList(OS, TemplateArgs.asArray(), Policy); |
Richard Smith | 792c22d | 2016-12-24 04:09:05 +0000 | [diff] [blame] | 776 | } |
Douglas Gregor | b11aad8 | 2011-02-19 18:51:44 +0000 | [diff] [blame] | 777 | } |
| 778 | |
Douglas Gregor | 9dc8bd3 | 2009-08-02 23:24:31 +0000 | [diff] [blame] | 779 | ClassTemplateDecl * |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 780 | ClassTemplateSpecializationDecl::getSpecializedTemplate() const { |
Eugene Zelenko | 309e29d | 2018-03-29 20:51:59 +0000 | [diff] [blame] | 781 | if (const auto *PartialSpec = |
| 782 | SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization*>()) |
Douglas Gregor | 9dc8bd3 | 2009-08-02 23:24:31 +0000 | [diff] [blame] | 783 | return PartialSpec->PartialSpecialization->getSpecializedTemplate(); |
| 784 | return SpecializedTemplate.get<ClassTemplateDecl*>(); |
| 785 | } |
| 786 | |
Abramo Bagnara | a093526 | 2011-03-04 14:20:30 +0000 | [diff] [blame] | 787 | SourceRange |
| 788 | ClassTemplateSpecializationDecl::getSourceRange() const { |
Abramo Bagnara | fd3a455 | 2011-10-03 20:34:03 +0000 | [diff] [blame] | 789 | if (ExplicitInfo) { |
Abramo Bagnara | c76dcbd | 2012-10-15 21:06:42 +0000 | [diff] [blame] | 790 | SourceLocation Begin = getTemplateKeywordLoc(); |
| 791 | if (Begin.isValid()) { |
| 792 | // Here we have an explicit (partial) specialization or instantiation. |
| 793 | assert(getSpecializationKind() == TSK_ExplicitSpecialization || |
| 794 | getSpecializationKind() == TSK_ExplicitInstantiationDeclaration || |
| 795 | getSpecializationKind() == TSK_ExplicitInstantiationDefinition); |
| 796 | if (getExternLoc().isValid()) |
| 797 | Begin = getExternLoc(); |
Argyrios Kyrtzidis | d798c05 | 2016-07-15 18:11:33 +0000 | [diff] [blame] | 798 | SourceLocation End = getBraceRange().getEnd(); |
Abramo Bagnara | c76dcbd | 2012-10-15 21:06:42 +0000 | [diff] [blame] | 799 | if (End.isInvalid()) |
| 800 | End = getTypeAsWritten()->getTypeLoc().getEndLoc(); |
| 801 | return SourceRange(Begin, End); |
| 802 | } |
| 803 | // An implicit instantiation of a class template partial specialization |
| 804 | // uses ExplicitInfo to record the TypeAsWritten, but the source |
| 805 | // locations should be retrieved from the instantiation pattern. |
Eugene Zelenko | 421e890 | 2017-11-29 22:39:22 +0000 | [diff] [blame] | 806 | using CTPSDecl = ClassTemplatePartialSpecializationDecl; |
Eugene Zelenko | 309e29d | 2018-03-29 20:51:59 +0000 | [diff] [blame] | 807 | auto *ctpsd = const_cast<CTPSDecl *>(cast<CTPSDecl>(this)); |
Abramo Bagnara | c76dcbd | 2012-10-15 21:06:42 +0000 | [diff] [blame] | 808 | CTPSDecl *inst_from = ctpsd->getInstantiatedFromMember(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 809 | assert(inst_from != nullptr); |
Abramo Bagnara | c76dcbd | 2012-10-15 21:06:42 +0000 | [diff] [blame] | 810 | return inst_from->getSourceRange(); |
Abramo Bagnara | fd3a455 | 2011-10-03 20:34:03 +0000 | [diff] [blame] | 811 | } |
| 812 | else { |
| 813 | // No explicit info available. |
| 814 | llvm::PointerUnion<ClassTemplateDecl *, |
| 815 | ClassTemplatePartialSpecializationDecl *> |
| 816 | inst_from = getInstantiatedFrom(); |
| 817 | if (inst_from.isNull()) |
| 818 | return getSpecializedTemplate()->getSourceRange(); |
Eugene Zelenko | 309e29d | 2018-03-29 20:51:59 +0000 | [diff] [blame] | 819 | if (const auto *ctd = inst_from.dyn_cast<ClassTemplateDecl *>()) |
Abramo Bagnara | fd3a455 | 2011-10-03 20:34:03 +0000 | [diff] [blame] | 820 | return ctd->getSourceRange(); |
Eugene Zelenko | 309e29d | 2018-03-29 20:51:59 +0000 | [diff] [blame] | 821 | return inst_from.get<ClassTemplatePartialSpecializationDecl *>() |
Abramo Bagnara | fd3a455 | 2011-10-03 20:34:03 +0000 | [diff] [blame] | 822 | ->getSourceRange(); |
| 823 | } |
Abramo Bagnara | a093526 | 2011-03-04 14:20:30 +0000 | [diff] [blame] | 824 | } |
| 825 | |
Douglas Gregor | 2373c59 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 826 | //===----------------------------------------------------------------------===// |
| 827 | // ClassTemplatePartialSpecializationDecl Implementation |
| 828 | //===----------------------------------------------------------------------===// |
Eugene Zelenko | 421e890 | 2017-11-29 22:39:22 +0000 | [diff] [blame] | 829 | void ClassTemplatePartialSpecializationDecl::anchor() {} |
David Blaikie | 68e081d | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 830 | |
Douglas Gregor | fd7c225 | 2011-03-04 17:52:15 +0000 | [diff] [blame] | 831 | ClassTemplatePartialSpecializationDecl:: |
| 832 | ClassTemplatePartialSpecializationDecl(ASTContext &Context, TagKind TK, |
Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 833 | DeclContext *DC, |
| 834 | SourceLocation StartLoc, |
| 835 | SourceLocation IdLoc, |
Douglas Gregor | fd7c225 | 2011-03-04 17:52:15 +0000 | [diff] [blame] | 836 | TemplateParameterList *Params, |
| 837 | ClassTemplateDecl *SpecializedTemplate, |
David Majnemer | 8b62269 | 2016-07-03 21:17:51 +0000 | [diff] [blame] | 838 | ArrayRef<TemplateArgument> Args, |
Enea Zaffanella | 6dbe187 | 2013-08-10 07:24:53 +0000 | [diff] [blame] | 839 | const ASTTemplateArgumentListInfo *ArgInfos, |
Richard Smith | b2f61b4 | 2013-08-22 23:27:37 +0000 | [diff] [blame] | 840 | ClassTemplatePartialSpecializationDecl *PrevDecl) |
Eugene Zelenko | 421e890 | 2017-11-29 22:39:22 +0000 | [diff] [blame] | 841 | : ClassTemplateSpecializationDecl(Context, |
| 842 | ClassTemplatePartialSpecialization, |
| 843 | TK, DC, StartLoc, IdLoc, |
| 844 | SpecializedTemplate, Args, PrevDecl), |
| 845 | TemplateParams(Params), ArgsAsWritten(ArgInfos), |
| 846 | InstantiatedFromMember(nullptr, false) { |
Douglas Gregor | 3c41bf7 | 2011-03-04 18:32:38 +0000 | [diff] [blame] | 847 | AdoptTemplateParameterList(Params, this); |
Douglas Gregor | fd7c225 | 2011-03-04 17:52:15 +0000 | [diff] [blame] | 848 | } |
| 849 | |
Douglas Gregor | 2373c59 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 850 | ClassTemplatePartialSpecializationDecl * |
| 851 | ClassTemplatePartialSpecializationDecl:: |
Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 852 | Create(ASTContext &Context, TagKind TK,DeclContext *DC, |
| 853 | SourceLocation StartLoc, SourceLocation IdLoc, |
Douglas Gregor | 2373c59 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 854 | TemplateParameterList *Params, |
| 855 | ClassTemplateDecl *SpecializedTemplate, |
David Majnemer | 8b62269 | 2016-07-03 21:17:51 +0000 | [diff] [blame] | 856 | ArrayRef<TemplateArgument> Args, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 857 | const TemplateArgumentListInfo &ArgInfos, |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 858 | QualType CanonInjectedType, |
Richard Smith | b2f61b4 | 2013-08-22 23:27:37 +0000 | [diff] [blame] | 859 | ClassTemplatePartialSpecializationDecl *PrevDecl) { |
Enea Zaffanella | 6dbe187 | 2013-08-10 07:24:53 +0000 | [diff] [blame] | 860 | const ASTTemplateArgumentListInfo *ASTArgInfos = |
| 861 | ASTTemplateArgumentListInfo::Create(Context, ArgInfos); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 862 | |
Eugene Zelenko | 309e29d | 2018-03-29 20:51:59 +0000 | [diff] [blame] | 863 | auto *Result = new (Context, DC) |
Richard Smith | f798172 | 2013-11-22 09:01:48 +0000 | [diff] [blame] | 864 | ClassTemplatePartialSpecializationDecl(Context, TK, DC, StartLoc, IdLoc, |
| 865 | Params, SpecializedTemplate, Args, |
David Majnemer | 8b62269 | 2016-07-03 21:17:51 +0000 | [diff] [blame] | 866 | ASTArgInfos, PrevDecl); |
Douglas Gregor | 2373c59 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 867 | Result->setSpecializationKind(TSK_ExplicitSpecialization); |
Erich Keane | f92f31c | 2018-08-01 20:48:16 +0000 | [diff] [blame] | 868 | Result->setMayHaveOutOfDateDef(false); |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 869 | |
| 870 | Context.getInjectedClassNameType(Result, CanonInjectedType); |
Douglas Gregor | 2373c59 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 871 | return Result; |
| 872 | } |
John McCall | 11083da | 2009-09-16 22:47:08 +0000 | [diff] [blame] | 873 | |
Argyrios Kyrtzidis | fe6ba88 | 2010-06-23 13:48:23 +0000 | [diff] [blame] | 874 | ClassTemplatePartialSpecializationDecl * |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 875 | ClassTemplatePartialSpecializationDecl::CreateDeserialized(ASTContext &C, |
| 876 | unsigned ID) { |
Eugene Zelenko | 309e29d | 2018-03-29 20:51:59 +0000 | [diff] [blame] | 877 | auto *Result = new (C, ID) ClassTemplatePartialSpecializationDecl(C); |
Erich Keane | f92f31c | 2018-08-01 20:48:16 +0000 | [diff] [blame] | 878 | Result->setMayHaveOutOfDateDef(false); |
Douglas Gregor | 7dab26b | 2013-02-09 01:35:03 +0000 | [diff] [blame] | 879 | return Result; |
Argyrios Kyrtzidis | fe6ba88 | 2010-06-23 13:48:23 +0000 | [diff] [blame] | 880 | } |
| 881 | |
John McCall | 11083da | 2009-09-16 22:47:08 +0000 | [diff] [blame] | 882 | //===----------------------------------------------------------------------===// |
| 883 | // FriendTemplateDecl Implementation |
| 884 | //===----------------------------------------------------------------------===// |
| 885 | |
Eugene Zelenko | 421e890 | 2017-11-29 22:39:22 +0000 | [diff] [blame] | 886 | void FriendTemplateDecl::anchor() {} |
David Blaikie | 68e081d | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 887 | |
David Majnemer | dfecf1a | 2016-07-06 04:19:16 +0000 | [diff] [blame] | 888 | FriendTemplateDecl * |
| 889 | FriendTemplateDecl::Create(ASTContext &Context, DeclContext *DC, |
| 890 | SourceLocation L, |
| 891 | MutableArrayRef<TemplateParameterList *> Params, |
| 892 | FriendUnion Friend, SourceLocation FLoc) { |
| 893 | return new (Context, DC) FriendTemplateDecl(DC, L, Params, Friend, FLoc); |
John McCall | 11083da | 2009-09-16 22:47:08 +0000 | [diff] [blame] | 894 | } |
Argyrios Kyrtzidis | 165b581 | 2010-07-22 16:04:10 +0000 | [diff] [blame] | 895 | |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 896 | FriendTemplateDecl *FriendTemplateDecl::CreateDeserialized(ASTContext &C, |
| 897 | unsigned ID) { |
Richard Smith | f798172 | 2013-11-22 09:01:48 +0000 | [diff] [blame] | 898 | return new (C, ID) FriendTemplateDecl(EmptyShell()); |
Argyrios Kyrtzidis | 165b581 | 2010-07-22 16:04:10 +0000 | [diff] [blame] | 899 | } |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 900 | |
| 901 | //===----------------------------------------------------------------------===// |
| 902 | // TypeAliasTemplateDecl Implementation |
| 903 | //===----------------------------------------------------------------------===// |
| 904 | |
| 905 | TypeAliasTemplateDecl *TypeAliasTemplateDecl::Create(ASTContext &C, |
| 906 | DeclContext *DC, |
| 907 | SourceLocation L, |
| 908 | DeclarationName Name, |
| 909 | TemplateParameterList *Params, |
| 910 | NamedDecl *Decl) { |
| 911 | AdoptTemplateParameterList(Params, DC); |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 912 | return new (C, DC) TypeAliasTemplateDecl(C, DC, L, Name, Params, Decl); |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 913 | } |
| 914 | |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 915 | TypeAliasTemplateDecl *TypeAliasTemplateDecl::CreateDeserialized(ASTContext &C, |
| 916 | unsigned ID) { |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 917 | return new (C, ID) TypeAliasTemplateDecl(C, nullptr, SourceLocation(), |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 918 | DeclarationName(), nullptr, nullptr); |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 919 | } |
| 920 | |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 921 | RedeclarableTemplateDecl::CommonBase * |
Dmitri Gribenko | b53f37c | 2013-01-23 16:52:57 +0000 | [diff] [blame] | 922 | TypeAliasTemplateDecl::newCommon(ASTContext &C) const { |
Eugene Zelenko | 309e29d | 2018-03-29 20:51:59 +0000 | [diff] [blame] | 923 | auto *CommonPtr = new (C) Common; |
George Burgess IV | b61bfbd | 2017-02-14 05:37:36 +0000 | [diff] [blame] | 924 | C.addDestruction(CommonPtr); |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 925 | return CommonPtr; |
| 926 | } |
| 927 | |
David Blaikie | 68e081d | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 928 | //===----------------------------------------------------------------------===// |
| 929 | // ClassScopeFunctionSpecializationDecl Implementation |
| 930 | //===----------------------------------------------------------------------===// |
| 931 | |
Eugene Zelenko | 421e890 | 2017-11-29 22:39:22 +0000 | [diff] [blame] | 932 | void ClassScopeFunctionSpecializationDecl::anchor() {} |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 933 | |
| 934 | ClassScopeFunctionSpecializationDecl * |
| 935 | ClassScopeFunctionSpecializationDecl::CreateDeserialized(ASTContext &C, |
| 936 | unsigned ID) { |
Richard Smith | f798172 | 2013-11-22 09:01:48 +0000 | [diff] [blame] | 937 | return new (C, ID) ClassScopeFunctionSpecializationDecl( |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 938 | nullptr, SourceLocation(), nullptr, false, TemplateArgumentListInfo()); |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 939 | } |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 940 | |
| 941 | //===----------------------------------------------------------------------===// |
| 942 | // VarTemplateDecl Implementation |
| 943 | //===----------------------------------------------------------------------===// |
| 944 | |
Larisse Voufo | a11bd8a | 2013-08-13 02:02:26 +0000 | [diff] [blame] | 945 | VarTemplateDecl *VarTemplateDecl::getDefinition() { |
| 946 | VarTemplateDecl *CurD = this; |
| 947 | while (CurD) { |
| 948 | if (CurD->isThisDeclarationADefinition()) |
| 949 | return CurD; |
| 950 | CurD = CurD->getPreviousDecl(); |
| 951 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 952 | return nullptr; |
Larisse Voufo | a11bd8a | 2013-08-13 02:02:26 +0000 | [diff] [blame] | 953 | } |
| 954 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 955 | VarTemplateDecl *VarTemplateDecl::Create(ASTContext &C, DeclContext *DC, |
| 956 | SourceLocation L, DeclarationName Name, |
| 957 | TemplateParameterList *Params, |
Richard Smith | beef345 | 2014-01-16 23:39:20 +0000 | [diff] [blame] | 958 | VarDecl *Decl) { |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 959 | return new (C, DC) VarTemplateDecl(C, DC, L, Name, Params, Decl); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | VarTemplateDecl *VarTemplateDecl::CreateDeserialized(ASTContext &C, |
| 963 | unsigned ID) { |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 964 | return new (C, ID) VarTemplateDecl(C, nullptr, SourceLocation(), |
| 965 | DeclarationName(), nullptr, nullptr); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 966 | } |
| 967 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 968 | void VarTemplateDecl::LoadLazySpecializations() const { |
Vassil Vassilev | 61f6429 | 2017-12-14 23:30:18 +0000 | [diff] [blame] | 969 | loadLazySpecializationsImpl(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 970 | } |
| 971 | |
| 972 | llvm::FoldingSetVector<VarTemplateSpecializationDecl> & |
| 973 | VarTemplateDecl::getSpecializations() const { |
| 974 | LoadLazySpecializations(); |
| 975 | return getCommonPtr()->Specializations; |
| 976 | } |
| 977 | |
| 978 | llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl> & |
| 979 | VarTemplateDecl::getPartialSpecializations() { |
| 980 | LoadLazySpecializations(); |
| 981 | return getCommonPtr()->PartialSpecializations; |
| 982 | } |
| 983 | |
| 984 | RedeclarableTemplateDecl::CommonBase * |
| 985 | VarTemplateDecl::newCommon(ASTContext &C) const { |
Eugene Zelenko | 309e29d | 2018-03-29 20:51:59 +0000 | [diff] [blame] | 986 | auto *CommonPtr = new (C) Common; |
George Burgess IV | b61bfbd | 2017-02-14 05:37:36 +0000 | [diff] [blame] | 987 | C.addDestruction(CommonPtr); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 988 | return CommonPtr; |
| 989 | } |
| 990 | |
| 991 | VarTemplateSpecializationDecl * |
Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 992 | VarTemplateDecl::findSpecialization(ArrayRef<TemplateArgument> Args, |
| 993 | void *&InsertPos) { |
| 994 | return findSpecializationImpl(getSpecializations(), Args, InsertPos); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 995 | } |
| 996 | |
| 997 | void VarTemplateDecl::AddSpecialization(VarTemplateSpecializationDecl *D, |
| 998 | void *InsertPos) { |
Richard Smith | e977e51 | 2015-02-24 01:23:23 +0000 | [diff] [blame] | 999 | addSpecializationImpl<VarTemplateDecl>(getSpecializations(), D, InsertPos); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1000 | } |
| 1001 | |
| 1002 | VarTemplatePartialSpecializationDecl * |
Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 1003 | VarTemplateDecl::findPartialSpecialization(ArrayRef<TemplateArgument> Args, |
| 1004 | void *&InsertPos) { |
| 1005 | return findSpecializationImpl(getPartialSpecializations(), Args, InsertPos); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | void VarTemplateDecl::AddPartialSpecialization( |
| 1009 | VarTemplatePartialSpecializationDecl *D, void *InsertPos) { |
| 1010 | if (InsertPos) |
| 1011 | getPartialSpecializations().InsertNode(D, InsertPos); |
| 1012 | else { |
| 1013 | VarTemplatePartialSpecializationDecl *Existing = |
| 1014 | getPartialSpecializations().GetOrInsertNode(D); |
| 1015 | (void)Existing; |
| 1016 | assert(Existing->isCanonicalDecl() && "Non-canonical specialization?"); |
| 1017 | } |
| 1018 | |
| 1019 | if (ASTMutationListener *L = getASTMutationListener()) |
| 1020 | L->AddedCXXTemplateSpecialization(this, D); |
| 1021 | } |
| 1022 | |
| 1023 | void VarTemplateDecl::getPartialSpecializations( |
| 1024 | SmallVectorImpl<VarTemplatePartialSpecializationDecl *> &PS) { |
| 1025 | llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl> &PartialSpecs = |
| 1026 | getPartialSpecializations(); |
| 1027 | PS.clear(); |
Richard Smith | b2f61b4 | 2013-08-22 23:27:37 +0000 | [diff] [blame] | 1028 | PS.reserve(PartialSpecs.size()); |
David Majnemer | dfecf1a | 2016-07-06 04:19:16 +0000 | [diff] [blame] | 1029 | for (VarTemplatePartialSpecializationDecl &P : PartialSpecs) |
| 1030 | PS.push_back(P.getMostRecentDecl()); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1031 | } |
| 1032 | |
| 1033 | VarTemplatePartialSpecializationDecl * |
| 1034 | VarTemplateDecl::findPartialSpecInstantiatedFromMember( |
| 1035 | VarTemplatePartialSpecializationDecl *D) { |
| 1036 | Decl *DCanon = D->getCanonicalDecl(); |
David Majnemer | dfecf1a | 2016-07-06 04:19:16 +0000 | [diff] [blame] | 1037 | for (VarTemplatePartialSpecializationDecl &P : getPartialSpecializations()) { |
| 1038 | if (P.getInstantiatedFromMember()->getCanonicalDecl() == DCanon) |
| 1039 | return P.getMostRecentDecl(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1040 | } |
| 1041 | |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1042 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1043 | } |
| 1044 | |
| 1045 | //===----------------------------------------------------------------------===// |
| 1046 | // VarTemplateSpecializationDecl Implementation |
| 1047 | //===----------------------------------------------------------------------===// |
Eugene Zelenko | 421e890 | 2017-11-29 22:39:22 +0000 | [diff] [blame] | 1048 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1049 | VarTemplateSpecializationDecl::VarTemplateSpecializationDecl( |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 1050 | Kind DK, ASTContext &Context, DeclContext *DC, SourceLocation StartLoc, |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1051 | SourceLocation IdLoc, VarTemplateDecl *SpecializedTemplate, QualType T, |
David Majnemer | 8b62269 | 2016-07-03 21:17:51 +0000 | [diff] [blame] | 1052 | TypeSourceInfo *TInfo, StorageClass S, ArrayRef<TemplateArgument> Args) |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 1053 | : VarDecl(DK, Context, DC, StartLoc, IdLoc, |
| 1054 | SpecializedTemplate->getIdentifier(), T, TInfo, S), |
Eugene Zelenko | 421e890 | 2017-11-29 22:39:22 +0000 | [diff] [blame] | 1055 | SpecializedTemplate(SpecializedTemplate), |
David Majnemer | 8b62269 | 2016-07-03 21:17:51 +0000 | [diff] [blame] | 1056 | TemplateArgs(TemplateArgumentList::CreateCopy(Context, Args)), |
Richard Smith | 435e647 | 2017-12-02 02:48:42 +0000 | [diff] [blame] | 1057 | SpecializationKind(TSK_Undeclared), IsCompleteDefinition(false) {} |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1058 | |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 1059 | VarTemplateSpecializationDecl::VarTemplateSpecializationDecl(Kind DK, |
| 1060 | ASTContext &C) |
| 1061 | : VarDecl(DK, C, nullptr, SourceLocation(), SourceLocation(), nullptr, |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1062 | QualType(), nullptr, SC_None), |
Richard Smith | 435e647 | 2017-12-02 02:48:42 +0000 | [diff] [blame] | 1063 | SpecializationKind(TSK_Undeclared), IsCompleteDefinition(false) {} |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1064 | |
| 1065 | VarTemplateSpecializationDecl *VarTemplateSpecializationDecl::Create( |
| 1066 | ASTContext &Context, DeclContext *DC, SourceLocation StartLoc, |
| 1067 | SourceLocation IdLoc, VarTemplateDecl *SpecializedTemplate, QualType T, |
David Majnemer | 8b62269 | 2016-07-03 21:17:51 +0000 | [diff] [blame] | 1068 | TypeSourceInfo *TInfo, StorageClass S, ArrayRef<TemplateArgument> Args) { |
Richard Smith | f798172 | 2013-11-22 09:01:48 +0000 | [diff] [blame] | 1069 | return new (Context, DC) VarTemplateSpecializationDecl( |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 1070 | VarTemplateSpecialization, Context, DC, StartLoc, IdLoc, |
David Majnemer | 8b62269 | 2016-07-03 21:17:51 +0000 | [diff] [blame] | 1071 | SpecializedTemplate, T, TInfo, S, Args); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1072 | } |
| 1073 | |
| 1074 | VarTemplateSpecializationDecl * |
| 1075 | VarTemplateSpecializationDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 1076 | return new (C, ID) |
| 1077 | VarTemplateSpecializationDecl(VarTemplateSpecialization, C); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1078 | } |
| 1079 | |
| 1080 | void VarTemplateSpecializationDecl::getNameForDiagnostic( |
| 1081 | raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const { |
| 1082 | NamedDecl::getNameForDiagnostic(OS, Policy, Qualified); |
| 1083 | |
Eugene Zelenko | 309e29d | 2018-03-29 20:51:59 +0000 | [diff] [blame] | 1084 | const auto *PS = dyn_cast<VarTemplatePartialSpecializationDecl>(this); |
Richard Smith | 792c22d | 2016-12-24 04:09:05 +0000 | [diff] [blame] | 1085 | if (const ASTTemplateArgumentListInfo *ArgsAsWritten = |
| 1086 | PS ? PS->getTemplateArgsAsWritten() : nullptr) { |
Serge Pavlov | 03e672c | 2017-11-28 16:14:14 +0000 | [diff] [blame] | 1087 | printTemplateArgumentList(OS, ArgsAsWritten->arguments(), Policy); |
Richard Smith | 792c22d | 2016-12-24 04:09:05 +0000 | [diff] [blame] | 1088 | } else { |
| 1089 | const TemplateArgumentList &TemplateArgs = getTemplateArgs(); |
Serge Pavlov | 03e672c | 2017-11-28 16:14:14 +0000 | [diff] [blame] | 1090 | printTemplateArgumentList(OS, TemplateArgs.asArray(), Policy); |
Richard Smith | 792c22d | 2016-12-24 04:09:05 +0000 | [diff] [blame] | 1091 | } |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1092 | } |
| 1093 | |
| 1094 | VarTemplateDecl *VarTemplateSpecializationDecl::getSpecializedTemplate() const { |
Eugene Zelenko | 309e29d | 2018-03-29 20:51:59 +0000 | [diff] [blame] | 1095 | if (const auto *PartialSpec = |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1096 | SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>()) |
| 1097 | return PartialSpec->PartialSpecialization->getSpecializedTemplate(); |
| 1098 | return SpecializedTemplate.get<VarTemplateDecl *>(); |
| 1099 | } |
| 1100 | |
| 1101 | void VarTemplateSpecializationDecl::setTemplateArgsInfo( |
| 1102 | const TemplateArgumentListInfo &ArgsInfo) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1103 | TemplateArgsInfo.setLAngleLoc(ArgsInfo.getLAngleLoc()); |
| 1104 | TemplateArgsInfo.setRAngleLoc(ArgsInfo.getRAngleLoc()); |
David Majnemer | dfecf1a | 2016-07-06 04:19:16 +0000 | [diff] [blame] | 1105 | for (const TemplateArgumentLoc &Loc : ArgsInfo.arguments()) |
| 1106 | TemplateArgsInfo.addArgument(Loc); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1107 | } |
| 1108 | |
| 1109 | //===----------------------------------------------------------------------===// |
| 1110 | // VarTemplatePartialSpecializationDecl Implementation |
| 1111 | //===----------------------------------------------------------------------===// |
Eugene Zelenko | 421e890 | 2017-11-29 22:39:22 +0000 | [diff] [blame] | 1112 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1113 | void VarTemplatePartialSpecializationDecl::anchor() {} |
| 1114 | |
| 1115 | VarTemplatePartialSpecializationDecl::VarTemplatePartialSpecializationDecl( |
| 1116 | ASTContext &Context, DeclContext *DC, SourceLocation StartLoc, |
| 1117 | SourceLocation IdLoc, TemplateParameterList *Params, |
| 1118 | VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo, |
David Majnemer | 8b62269 | 2016-07-03 21:17:51 +0000 | [diff] [blame] | 1119 | StorageClass S, ArrayRef<TemplateArgument> Args, |
Richard Smith | b2f61b4 | 2013-08-22 23:27:37 +0000 | [diff] [blame] | 1120 | const ASTTemplateArgumentListInfo *ArgInfos) |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 1121 | : VarTemplateSpecializationDecl(VarTemplatePartialSpecialization, Context, |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1122 | DC, StartLoc, IdLoc, SpecializedTemplate, T, |
David Majnemer | 8b62269 | 2016-07-03 21:17:51 +0000 | [diff] [blame] | 1123 | TInfo, S, Args), |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1124 | TemplateParams(Params), ArgsAsWritten(ArgInfos), |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1125 | InstantiatedFromMember(nullptr, false) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1126 | // TODO: The template parameters should be in DC by now. Verify. |
| 1127 | // AdoptTemplateParameterList(Params, DC); |
| 1128 | } |
| 1129 | |
| 1130 | VarTemplatePartialSpecializationDecl * |
| 1131 | VarTemplatePartialSpecializationDecl::Create( |
| 1132 | ASTContext &Context, DeclContext *DC, SourceLocation StartLoc, |
| 1133 | SourceLocation IdLoc, TemplateParameterList *Params, |
| 1134 | VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo, |
David Majnemer | 8b62269 | 2016-07-03 21:17:51 +0000 | [diff] [blame] | 1135 | StorageClass S, ArrayRef<TemplateArgument> Args, |
Richard Smith | b2f61b4 | 2013-08-22 23:27:37 +0000 | [diff] [blame] | 1136 | const TemplateArgumentListInfo &ArgInfos) { |
Enea Zaffanella | 6dbe187 | 2013-08-10 07:24:53 +0000 | [diff] [blame] | 1137 | const ASTTemplateArgumentListInfo *ASTArgInfos |
| 1138 | = ASTTemplateArgumentListInfo::Create(Context, ArgInfos); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1139 | |
Eugene Zelenko | 309e29d | 2018-03-29 20:51:59 +0000 | [diff] [blame] | 1140 | auto *Result = |
Richard Smith | f798172 | 2013-11-22 09:01:48 +0000 | [diff] [blame] | 1141 | new (Context, DC) VarTemplatePartialSpecializationDecl( |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1142 | Context, DC, StartLoc, IdLoc, Params, SpecializedTemplate, T, TInfo, |
David Majnemer | 8b62269 | 2016-07-03 21:17:51 +0000 | [diff] [blame] | 1143 | S, Args, ASTArgInfos); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1144 | Result->setSpecializationKind(TSK_ExplicitSpecialization); |
| 1145 | return Result; |
| 1146 | } |
| 1147 | |
| 1148 | VarTemplatePartialSpecializationDecl * |
| 1149 | VarTemplatePartialSpecializationDecl::CreateDeserialized(ASTContext &C, |
| 1150 | unsigned ID) { |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 1151 | return new (C, ID) VarTemplatePartialSpecializationDecl(C); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1152 | } |
David Majnemer | d9b1a4f | 2015-11-04 03:40:30 +0000 | [diff] [blame] | 1153 | |
| 1154 | static TemplateParameterList * |
| 1155 | createMakeIntegerSeqParameterList(const ASTContext &C, DeclContext *DC) { |
| 1156 | // typename T |
| 1157 | auto *T = TemplateTypeParmDecl::Create( |
| 1158 | C, DC, SourceLocation(), SourceLocation(), /*Depth=*/1, /*Position=*/0, |
| 1159 | /*Id=*/nullptr, /*Typename=*/true, /*ParameterPack=*/false); |
| 1160 | T->setImplicit(true); |
| 1161 | |
| 1162 | // T ...Ints |
| 1163 | TypeSourceInfo *TI = |
| 1164 | C.getTrivialTypeSourceInfo(QualType(T->getTypeForDecl(), 0)); |
| 1165 | auto *N = NonTypeTemplateParmDecl::Create( |
| 1166 | C, DC, SourceLocation(), SourceLocation(), /*Depth=*/0, /*Position=*/1, |
| 1167 | /*Id=*/nullptr, TI->getType(), /*ParameterPack=*/true, TI); |
| 1168 | N->setImplicit(true); |
| 1169 | |
| 1170 | // <typename T, T ...Ints> |
| 1171 | NamedDecl *P[2] = {T, N}; |
| 1172 | auto *TPL = TemplateParameterList::Create( |
Hubert Tong | e4a0c0e | 2016-07-30 22:33:34 +0000 | [diff] [blame] | 1173 | C, SourceLocation(), SourceLocation(), P, SourceLocation(), nullptr); |
David Majnemer | d9b1a4f | 2015-11-04 03:40:30 +0000 | [diff] [blame] | 1174 | |
| 1175 | // template <typename T, ...Ints> class IntSeq |
| 1176 | auto *TemplateTemplateParm = TemplateTemplateParmDecl::Create( |
| 1177 | C, DC, SourceLocation(), /*Depth=*/0, /*Position=*/0, |
| 1178 | /*ParameterPack=*/false, /*Id=*/nullptr, TPL); |
| 1179 | TemplateTemplateParm->setImplicit(true); |
| 1180 | |
| 1181 | // typename T |
| 1182 | auto *TemplateTypeParm = TemplateTypeParmDecl::Create( |
| 1183 | C, DC, SourceLocation(), SourceLocation(), /*Depth=*/0, /*Position=*/1, |
| 1184 | /*Id=*/nullptr, /*Typename=*/true, /*ParameterPack=*/false); |
| 1185 | TemplateTypeParm->setImplicit(true); |
| 1186 | |
| 1187 | // T N |
| 1188 | TypeSourceInfo *TInfo = C.getTrivialTypeSourceInfo( |
| 1189 | QualType(TemplateTypeParm->getTypeForDecl(), 0)); |
| 1190 | auto *NonTypeTemplateParm = NonTypeTemplateParmDecl::Create( |
| 1191 | C, DC, SourceLocation(), SourceLocation(), /*Depth=*/0, /*Position=*/2, |
| 1192 | /*Id=*/nullptr, TInfo->getType(), /*ParameterPack=*/false, TInfo); |
| 1193 | NamedDecl *Params[] = {TemplateTemplateParm, TemplateTypeParm, |
| 1194 | NonTypeTemplateParm}; |
| 1195 | |
| 1196 | // template <template <typename T, T ...Ints> class IntSeq, typename T, T N> |
| 1197 | return TemplateParameterList::Create(C, SourceLocation(), SourceLocation(), |
Hubert Tong | e4a0c0e | 2016-07-30 22:33:34 +0000 | [diff] [blame] | 1198 | Params, SourceLocation(), nullptr); |
David Majnemer | d9b1a4f | 2015-11-04 03:40:30 +0000 | [diff] [blame] | 1199 | } |
| 1200 | |
Eric Fiselier | 6ad6855 | 2016-07-01 01:24:09 +0000 | [diff] [blame] | 1201 | static TemplateParameterList * |
| 1202 | createTypePackElementParameterList(const ASTContext &C, DeclContext *DC) { |
| 1203 | // std::size_t Index |
| 1204 | TypeSourceInfo *TInfo = C.getTrivialTypeSourceInfo(C.getSizeType()); |
| 1205 | auto *Index = NonTypeTemplateParmDecl::Create( |
| 1206 | C, DC, SourceLocation(), SourceLocation(), /*Depth=*/0, /*Position=*/0, |
| 1207 | /*Id=*/nullptr, TInfo->getType(), /*ParameterPack=*/false, TInfo); |
| 1208 | |
| 1209 | // typename ...T |
| 1210 | auto *Ts = TemplateTypeParmDecl::Create( |
| 1211 | C, DC, SourceLocation(), SourceLocation(), /*Depth=*/0, /*Position=*/1, |
| 1212 | /*Id=*/nullptr, /*Typename=*/true, /*ParameterPack=*/true); |
| 1213 | Ts->setImplicit(true); |
| 1214 | |
| 1215 | // template <std::size_t Index, typename ...T> |
| 1216 | NamedDecl *Params[] = {Index, Ts}; |
| 1217 | return TemplateParameterList::Create(C, SourceLocation(), SourceLocation(), |
| 1218 | llvm::makeArrayRef(Params), |
Hubert Tong | e4a0c0e | 2016-07-30 22:33:34 +0000 | [diff] [blame] | 1219 | SourceLocation(), nullptr); |
Eric Fiselier | 6ad6855 | 2016-07-01 01:24:09 +0000 | [diff] [blame] | 1220 | } |
| 1221 | |
David Majnemer | d9b1a4f | 2015-11-04 03:40:30 +0000 | [diff] [blame] | 1222 | static TemplateParameterList *createBuiltinTemplateParameterList( |
| 1223 | const ASTContext &C, DeclContext *DC, BuiltinTemplateKind BTK) { |
| 1224 | switch (BTK) { |
| 1225 | case BTK__make_integer_seq: |
| 1226 | return createMakeIntegerSeqParameterList(C, DC); |
Eric Fiselier | 6ad6855 | 2016-07-01 01:24:09 +0000 | [diff] [blame] | 1227 | case BTK__type_pack_element: |
| 1228 | return createTypePackElementParameterList(C, DC); |
David Majnemer | d9b1a4f | 2015-11-04 03:40:30 +0000 | [diff] [blame] | 1229 | } |
| 1230 | |
| 1231 | llvm_unreachable("unhandled BuiltinTemplateKind!"); |
| 1232 | } |
| 1233 | |
| 1234 | void BuiltinTemplateDecl::anchor() {} |
| 1235 | |
| 1236 | BuiltinTemplateDecl::BuiltinTemplateDecl(const ASTContext &C, DeclContext *DC, |
| 1237 | DeclarationName Name, |
| 1238 | BuiltinTemplateKind BTK) |
| 1239 | : TemplateDecl(BuiltinTemplate, DC, SourceLocation(), Name, |
| 1240 | createBuiltinTemplateParameterList(C, DC, BTK)), |
| 1241 | BTK(BTK) {} |