| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | #ifndef LLVM_CLANG_AST_DECLTEMPLATE_H |
| 15 | #define LLVM_CLANG_AST_DECLTEMPLATE_H |
| 16 | |
| 17 | #include "clang/AST/Decl.h" |
| 18 | #include "clang/AST/DeclBase.h" |
| 19 | #include "clang/AST/DeclCXX.h" |
| 20 | #include "clang/AST/DeclarationName.h" |
| 21 | #include "clang/AST/Redeclarable.h" |
| 22 | #include "clang/AST/TemplateBase.h" |
| 23 | #include "clang/AST/Type.h" |
| 24 | #include "clang/Basic/LLVM.h" |
| 25 | #include "clang/Basic/SourceLocation.h" |
| 26 | #include "clang/Basic/Specifiers.h" |
| 27 | #include "llvm/ADT/ArrayRef.h" |
| 28 | #include "llvm/ADT/FoldingSet.h" |
| 29 | #include "llvm/ADT/PointerIntPair.h" |
| 30 | #include "llvm/ADT/PointerUnion.h" |
| 31 | #include "llvm/ADT/iterator.h" |
| 32 | #include "llvm/ADT/iterator_range.h" |
| 33 | #include "llvm/Support/Casting.h" |
| 34 | #include "llvm/Support/Compiler.h" |
| 35 | #include "llvm/Support/TrailingObjects.h" |
| 36 | #include <cassert> |
| 37 | #include <cstddef> |
| 38 | #include <cstdint> |
| 39 | #include <iterator> |
| 40 | #include <utility> |
| 41 | |
| 42 | namespace clang { |
| 43 | |
| 44 | enum BuiltinTemplateKind : int; |
| 45 | class ClassTemplateDecl; |
| 46 | class ClassTemplatePartialSpecializationDecl; |
| 47 | class Expr; |
| 48 | class FunctionTemplateDecl; |
| 49 | class IdentifierInfo; |
| 50 | class NonTypeTemplateParmDecl; |
| 51 | class TemplateDecl; |
| 52 | class TemplateTemplateParmDecl; |
| 53 | class TemplateTypeParmDecl; |
| 54 | class UnresolvedSetImpl; |
| 55 | class VarTemplateDecl; |
| 56 | class VarTemplatePartialSpecializationDecl; |
| 57 | |
| 58 | |
| 59 | using TemplateParameter = |
| 60 | llvm::PointerUnion3<TemplateTypeParmDecl *, NonTypeTemplateParmDecl *, |
| 61 | TemplateTemplateParmDecl *>; |
| 62 | |
| 63 | NamedDecl *getAsNamedDecl(TemplateParameter P); |
| 64 | |
| 65 | |
| 66 | |
| 67 | class TemplateParameterList final |
| 68 | : private llvm::TrailingObjects<TemplateParameterList, NamedDecl *, |
| 69 | Expr *> { |
| 70 | |
| 71 | SourceLocation TemplateLoc; |
| 72 | |
| 73 | |
| 74 | SourceLocation LAngleLoc, RAngleLoc; |
| 75 | |
| 76 | |
| 77 | |
| 78 | unsigned NumParams : 30; |
| 79 | |
| 80 | |
| 81 | |
| 82 | unsigned ContainsUnexpandedParameterPack : 1; |
| 83 | |
| 84 | |
| 85 | unsigned HasRequiresClause : 1; |
| 86 | |
| 87 | protected: |
| 88 | TemplateParameterList(SourceLocation TemplateLoc, SourceLocation LAngleLoc, |
| 89 | ArrayRef<NamedDecl *> Params, SourceLocation RAngleLoc, |
| 90 | Expr *RequiresClause); |
| 91 | |
| 92 | size_t numTrailingObjects(OverloadToken<NamedDecl *>) const { |
| 93 | return NumParams; |
| 94 | } |
| 95 | |
| 96 | size_t numTrailingObjects(OverloadToken<Expr *>) const { |
| 97 | return HasRequiresClause; |
| 98 | } |
| 99 | |
| 100 | public: |
| 101 | template <size_t N, bool HasRequiresClause> |
| 102 | friend class FixedSizeTemplateParameterListStorage; |
| 103 | friend TrailingObjects; |
| 104 | |
| 105 | static TemplateParameterList *Create(const ASTContext &C, |
| 106 | SourceLocation TemplateLoc, |
| 107 | SourceLocation LAngleLoc, |
| 108 | ArrayRef<NamedDecl *> Params, |
| 109 | SourceLocation RAngleLoc, |
| 110 | Expr *RequiresClause); |
| 111 | |
| 112 | |
| 113 | using iterator = NamedDecl **; |
| 114 | |
| 115 | |
| 116 | using const_iterator = NamedDecl * const *; |
| 117 | |
| 118 | iterator begin() { return getTrailingObjects<NamedDecl *>(); } |
| 119 | const_iterator begin() const { return getTrailingObjects<NamedDecl *>(); } |
| 120 | iterator end() { return begin() + NumParams; } |
| 121 | const_iterator end() const { return begin() + NumParams; } |
| 122 | |
| 123 | unsigned size() const { return NumParams; } |
| 124 | |
| 125 | ArrayRef<NamedDecl*> asArray() { |
| 126 | return llvm::makeArrayRef(begin(), end()); |
| 127 | } |
| 128 | ArrayRef<const NamedDecl*> asArray() const { |
| 129 | return llvm::makeArrayRef(begin(), size()); |
| 130 | } |
| 131 | |
| 132 | NamedDecl* getParam(unsigned Idx) { |
| 133 | (0) . __assert_fail ("Idx < size() && \"Template parameter index out-of-range\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 133, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(Idx < size() && "Template parameter index out-of-range"); |
| 134 | return begin()[Idx]; |
| 135 | } |
| 136 | const NamedDecl* getParam(unsigned Idx) const { |
| 137 | (0) . __assert_fail ("Idx < size() && \"Template parameter index out-of-range\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 137, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(Idx < size() && "Template parameter index out-of-range"); |
| 138 | return begin()[Idx]; |
| 139 | } |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | unsigned getMinRequiredArguments() const; |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | unsigned getDepth() const; |
| 154 | |
| 155 | |
| 156 | |
| 157 | bool containsUnexpandedParameterPack() const { |
| 158 | return ContainsUnexpandedParameterPack; |
| 159 | } |
| 160 | |
| 161 | |
| 162 | Expr *getRequiresClause() { |
| 163 | return HasRequiresClause ? *getTrailingObjects<Expr *>() : nullptr; |
| 164 | } |
| 165 | |
| 166 | |
| 167 | const Expr *getRequiresClause() const { |
| 168 | return HasRequiresClause ? *getTrailingObjects<Expr *>() : nullptr; |
| 169 | } |
| 170 | |
| 171 | SourceLocation getTemplateLoc() const { return TemplateLoc; } |
| 172 | SourceLocation getLAngleLoc() const { return LAngleLoc; } |
| 173 | SourceLocation getRAngleLoc() const { return RAngleLoc; } |
| 174 | |
| 175 | SourceRange getSourceRange() const LLVM_READONLY { |
| 176 | return SourceRange(TemplateLoc, RAngleLoc); |
| 177 | } |
| 178 | |
| 179 | public: |
| 180 | |
| 181 | using FixedSizeStorageOwner = TrailingObjects::FixedSizeStorageOwner; |
| 182 | }; |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | template <size_t N, bool HasRequiresClause> |
| 188 | class FixedSizeTemplateParameterListStorage |
| 189 | : public TemplateParameterList::FixedSizeStorageOwner { |
| 190 | typename TemplateParameterList::FixedSizeStorage< |
| 191 | NamedDecl *, Expr *>::with_counts< |
| 192 | N, HasRequiresClause ? 1u : 0u |
| 193 | >::type storage; |
| 194 | |
| 195 | public: |
| 196 | FixedSizeTemplateParameterListStorage(SourceLocation TemplateLoc, |
| 197 | SourceLocation LAngleLoc, |
| 198 | ArrayRef<NamedDecl *> Params, |
| 199 | SourceLocation RAngleLoc, |
| 200 | Expr *RequiresClause) |
| 201 | : FixedSizeStorageOwner( |
| 202 | (assert(N == Params.size()), |
| 203 | (RequiresClause)", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 203, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(HasRequiresClause == static_cast<bool>(RequiresClause)), |
| 204 | new (static_cast<void *>(&storage)) TemplateParameterList( |
| 205 | TemplateLoc, LAngleLoc, Params, RAngleLoc, RequiresClause))) {} |
| 206 | }; |
| 207 | |
| 208 | |
| 209 | class TemplateArgumentList final |
| 210 | : private llvm::TrailingObjects<TemplateArgumentList, TemplateArgument> { |
| 211 | |
| 212 | const TemplateArgument *Arguments; |
| 213 | |
| 214 | |
| 215 | |
| 216 | unsigned NumArguments; |
| 217 | |
| 218 | |
| 219 | |
| 220 | TemplateArgumentList(ArrayRef<TemplateArgument> Args); |
| 221 | |
| 222 | public: |
| 223 | friend TrailingObjects; |
| 224 | |
| 225 | TemplateArgumentList(const TemplateArgumentList &) = delete; |
| 226 | TemplateArgumentList &operator=(const TemplateArgumentList &) = delete; |
| 227 | |
| 228 | |
| 229 | |
| 230 | enum OnStackType { OnStack }; |
| 231 | |
| 232 | |
| 233 | |
| 234 | static TemplateArgumentList *CreateCopy(ASTContext &Context, |
| 235 | ArrayRef<TemplateArgument> Args); |
| 236 | |
| 237 | |
| 238 | |
| 239 | |
| 240 | |
| 241 | explicit TemplateArgumentList(OnStackType, ArrayRef<TemplateArgument> Args) |
| 242 | : Arguments(Args.data()), NumArguments(Args.size()) {} |
| 243 | |
| 244 | |
| 245 | |
| 246 | |
| 247 | |
| 248 | |
| 249 | |
| 250 | explicit TemplateArgumentList(const TemplateArgumentList *Other) |
| 251 | : Arguments(Other->data()), NumArguments(Other->size()) {} |
| 252 | |
| 253 | |
| 254 | const TemplateArgument &get(unsigned Idx) const { |
| 255 | (0) . __assert_fail ("Idx < NumArguments && \"Invalid template argument index\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 255, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(Idx < NumArguments && "Invalid template argument index"); |
| 256 | return data()[Idx]; |
| 257 | } |
| 258 | |
| 259 | |
| 260 | const TemplateArgument &operator[](unsigned Idx) const { return get(Idx); } |
| 261 | |
| 262 | |
| 263 | ArrayRef<TemplateArgument> asArray() const { |
| 264 | return llvm::makeArrayRef(data(), size()); |
| 265 | } |
| 266 | |
| 267 | |
| 268 | |
| 269 | unsigned size() const { return NumArguments; } |
| 270 | |
| 271 | |
| 272 | const TemplateArgument *data() const { return Arguments; } |
| 273 | }; |
| 274 | |
| 275 | void *allocateDefaultArgStorageChain(const ASTContext &C); |
| 276 | |
| 277 | |
| 278 | |
| 279 | |
| 280 | |
| 281 | |
| 282 | |
| 283 | |
| 284 | |
| 285 | template<typename ParmDecl, typename ArgType> |
| 286 | class DefaultArgStorage { |
| 287 | |
| 288 | |
| 289 | |
| 290 | struct Chain { |
| 291 | ParmDecl *PrevDeclWithDefaultArg; |
| 292 | ArgType Value; |
| 293 | }; |
| 294 | static_assert(sizeof(Chain) == sizeof(void *) * 2, |
| 295 | "non-pointer argument type?"); |
| 296 | |
| 297 | llvm::PointerUnion3<ArgType, ParmDecl*, Chain*> ValueOrInherited; |
| 298 | |
| 299 | static ParmDecl *getParmOwningDefaultArg(ParmDecl *Parm) { |
| 300 | const DefaultArgStorage &Storage = Parm->getDefaultArgStorage(); |
| 301 | if (auto *Prev = Storage.ValueOrInherited.template dyn_cast<ParmDecl *>()) |
| 302 | Parm = Prev; |
| 303 | (0) . __assert_fail ("!Parm->getDefaultArgStorage() .ValueOrInherited.template is() && \"should only be one level of indirection\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 305, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(!Parm->getDefaultArgStorage() |
| 304 | (0) . __assert_fail ("!Parm->getDefaultArgStorage() .ValueOrInherited.template is() && \"should only be one level of indirection\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 305, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> .ValueOrInherited.template is<ParmDecl *>() && |
| 305 | (0) . __assert_fail ("!Parm->getDefaultArgStorage() .ValueOrInherited.template is() && \"should only be one level of indirection\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 305, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "should only be one level of indirection"); |
| 306 | return Parm; |
| 307 | } |
| 308 | |
| 309 | public: |
| 310 | DefaultArgStorage() : ValueOrInherited(ArgType()) {} |
| 311 | |
| 312 | |
| 313 | bool isSet() const { return !ValueOrInherited.isNull(); } |
| 314 | |
| 315 | |
| 316 | |
| 317 | bool isInherited() const { return ValueOrInherited.template is<ParmDecl*>(); } |
| 318 | |
| 319 | |
| 320 | |
| 321 | ArgType get() const { |
| 322 | const DefaultArgStorage *Storage = this; |
| 323 | if (const auto *Prev = ValueOrInherited.template dyn_cast<ParmDecl *>()) |
| 324 | Storage = &Prev->getDefaultArgStorage(); |
| 325 | if (const auto *C = Storage->ValueOrInherited.template dyn_cast<Chain *>()) |
| 326 | return C->Value; |
| 327 | return Storage->ValueOrInherited.template get<ArgType>(); |
| 328 | } |
| 329 | |
| 330 | |
| 331 | |
| 332 | const ParmDecl *getInheritedFrom() const { |
| 333 | if (const auto *D = ValueOrInherited.template dyn_cast<ParmDecl *>()) |
| 334 | return D; |
| 335 | if (const auto *C = ValueOrInherited.template dyn_cast<Chain *>()) |
| 336 | return C->PrevDeclWithDefaultArg; |
| 337 | return nullptr; |
| 338 | } |
| 339 | |
| 340 | |
| 341 | void set(ArgType Arg) { |
| 342 | (0) . __assert_fail ("!isSet() && \"default argument already set\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 342, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(!isSet() && "default argument already set"); |
| 343 | ValueOrInherited = Arg; |
| 344 | } |
| 345 | |
| 346 | |
| 347 | void setInherited(const ASTContext &C, ParmDecl *InheritedFrom) { |
| 348 | (0) . __assert_fail ("!isInherited() && \"default argument already inherited\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 348, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(!isInherited() && "default argument already inherited"); |
| 349 | InheritedFrom = getParmOwningDefaultArg(InheritedFrom); |
| 350 | if (!isSet()) |
| 351 | ValueOrInherited = InheritedFrom; |
| 352 | else |
| 353 | ValueOrInherited = new (allocateDefaultArgStorageChain(C)) |
| 354 | Chain{InheritedFrom, ValueOrInherited.template get<ArgType>()}; |
| 355 | } |
| 356 | |
| 357 | |
| 358 | void clear() { |
| 359 | ValueOrInherited = ArgType(); |
| 360 | } |
| 361 | }; |
| 362 | |
| 363 | |
| 364 | |
| 365 | |
| 366 | |
| 367 | |
| 368 | |
| 369 | class ConstrainedTemplateDeclInfo { |
| 370 | friend TemplateDecl; |
| 371 | |
| 372 | public: |
| 373 | ConstrainedTemplateDeclInfo() = default; |
| 374 | |
| 375 | TemplateParameterList *getTemplateParameters() const { |
| 376 | return TemplateParams; |
| 377 | } |
| 378 | |
| 379 | Expr *getAssociatedConstraints() const { return AssociatedConstraints; } |
| 380 | |
| 381 | protected: |
| 382 | void setTemplateParameters(TemplateParameterList *TParams) { |
| 383 | TemplateParams = TParams; |
| 384 | } |
| 385 | |
| 386 | void setAssociatedConstraints(Expr *AC) { AssociatedConstraints = AC; } |
| 387 | |
| 388 | TemplateParameterList *TemplateParams = nullptr; |
| 389 | Expr *AssociatedConstraints = nullptr; |
| 390 | }; |
| 391 | |
| 392 | |
| 393 | |
| 394 | |
| 395 | |
| 396 | |
| 397 | |
| 398 | class TemplateDecl : public NamedDecl { |
| 399 | void anchor() override; |
| 400 | |
| 401 | protected: |
| 402 | |
| 403 | |
| 404 | TemplateDecl(ConstrainedTemplateDeclInfo *CTDI, Kind DK, DeclContext *DC, |
| 405 | SourceLocation L, DeclarationName Name, |
| 406 | TemplateParameterList *Params) |
| 407 | : NamedDecl(DK, DC, L, Name), TemplatedDecl(nullptr), |
| 408 | TemplateParams(CTDI) { |
| 409 | this->setTemplateParameters(Params); |
| 410 | } |
| 411 | |
| 412 | TemplateDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName Name, |
| 413 | TemplateParameterList *Params) |
| 414 | : TemplateDecl(nullptr, DK, DC, L, Name, Params) {} |
| 415 | |
| 416 | |
| 417 | TemplateDecl(ConstrainedTemplateDeclInfo *CTDI, Kind DK, DeclContext *DC, |
| 418 | SourceLocation L, DeclarationName Name, |
| 419 | TemplateParameterList *Params, NamedDecl *Decl) |
| 420 | : NamedDecl(DK, DC, L, Name), TemplatedDecl(Decl), |
| 421 | TemplateParams(CTDI) { |
| 422 | this->setTemplateParameters(Params); |
| 423 | } |
| 424 | |
| 425 | TemplateDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName Name, |
| 426 | TemplateParameterList *Params, NamedDecl *Decl) |
| 427 | : TemplateDecl(nullptr, DK, DC, L, Name, Params, Decl) {} |
| 428 | |
| 429 | public: |
| 430 | |
| 431 | TemplateParameterList *getTemplateParameters() const { |
| 432 | const auto *const CTDI = |
| 433 | TemplateParams.dyn_cast<ConstrainedTemplateDeclInfo *>(); |
| 434 | return CTDI ? CTDI->getTemplateParameters() |
| 435 | : TemplateParams.get<TemplateParameterList *>(); |
| 436 | } |
| 437 | |
| 438 | |
| 439 | const Expr *getRequiresClause() const { |
| 440 | const TemplateParameterList *const TP = getTemplateParameters(); |
| 441 | return TP ? TP->getRequiresClause() : nullptr; |
| 442 | } |
| 443 | |
| 444 | Expr *getAssociatedConstraints() const { |
| 445 | const auto *const C = cast<TemplateDecl>(getCanonicalDecl()); |
| 446 | const auto *const CTDI = |
| 447 | C->TemplateParams.dyn_cast<ConstrainedTemplateDeclInfo *>(); |
| 448 | return CTDI ? CTDI->getAssociatedConstraints() : nullptr; |
| 449 | } |
| 450 | |
| 451 | |
| 452 | NamedDecl *getTemplatedDecl() const { return TemplatedDecl; } |
| 453 | |
| 454 | |
| 455 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 456 | |
| 457 | static bool classofKind(Kind K) { |
| 458 | return K >= firstTemplate && K <= lastTemplate; |
| 459 | } |
| 460 | |
| 461 | SourceRange getSourceRange() const override LLVM_READONLY { |
| 462 | return SourceRange(getTemplateParameters()->getTemplateLoc(), |
| 463 | TemplatedDecl->getSourceRange().getEnd()); |
| 464 | } |
| 465 | |
| 466 | protected: |
| 467 | NamedDecl *TemplatedDecl; |
| 468 | |
| 469 | |
| 470 | |
| 471 | |
| 472 | |
| 473 | llvm::PointerUnion<TemplateParameterList *, |
| 474 | ConstrainedTemplateDeclInfo *> |
| 475 | TemplateParams; |
| 476 | |
| 477 | void setTemplateParameters(TemplateParameterList *TParams) { |
| 478 | if (auto *const CTDI = |
| 479 | TemplateParams.dyn_cast<ConstrainedTemplateDeclInfo *>()) { |
| 480 | CTDI->setTemplateParameters(TParams); |
| 481 | } else { |
| 482 | TemplateParams = TParams; |
| 483 | } |
| 484 | } |
| 485 | |
| 486 | void setAssociatedConstraints(Expr *AC) { |
| 487 | (0) . __assert_fail ("isCanonicalDecl() && \"Attaching associated constraints to non-canonical Decl\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 488, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(isCanonicalDecl() && |
| 488 | (0) . __assert_fail ("isCanonicalDecl() && \"Attaching associated constraints to non-canonical Decl\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 488, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "Attaching associated constraints to non-canonical Decl"); |
| 489 | TemplateParams.get<ConstrainedTemplateDeclInfo *>() |
| 490 | ->setAssociatedConstraints(AC); |
| 491 | } |
| 492 | |
| 493 | public: |
| 494 | |
| 495 | |
| 496 | void init(NamedDecl *templatedDecl, TemplateParameterList* templateParams) { |
| 497 | (0) . __assert_fail ("!TemplatedDecl && \"TemplatedDecl already set!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 497, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(!TemplatedDecl && "TemplatedDecl already set!"); |
| 498 | (0) . __assert_fail ("!TemplateParams && \"TemplateParams already set!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 498, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(!TemplateParams && "TemplateParams already set!"); |
| 499 | TemplatedDecl = templatedDecl; |
| 500 | TemplateParams = templateParams; |
| 501 | } |
| 502 | }; |
| 503 | |
| 504 | |
| 505 | |
| 506 | |
| 507 | class FunctionTemplateSpecializationInfo : public llvm::FoldingSetNode { |
| 508 | FunctionTemplateSpecializationInfo(FunctionDecl *FD, |
| 509 | FunctionTemplateDecl *Template, |
| 510 | TemplateSpecializationKind TSK, |
| 511 | const TemplateArgumentList *TemplateArgs, |
| 512 | const ASTTemplateArgumentListInfo *TemplateArgsAsWritten, |
| 513 | SourceLocation POI) |
| 514 | : Function(FD), Template(Template, TSK - 1), |
| 515 | TemplateArguments(TemplateArgs), |
| 516 | TemplateArgumentsAsWritten(TemplateArgsAsWritten), |
| 517 | PointOfInstantiation(POI) {} |
| 518 | |
| 519 | public: |
| 520 | static FunctionTemplateSpecializationInfo * |
| 521 | Create(ASTContext &C, FunctionDecl *FD, FunctionTemplateDecl *Template, |
| 522 | TemplateSpecializationKind TSK, |
| 523 | const TemplateArgumentList *TemplateArgs, |
| 524 | const TemplateArgumentListInfo *TemplateArgsAsWritten, |
| 525 | SourceLocation POI); |
| 526 | |
| 527 | |
| 528 | |
| 529 | FunctionDecl *Function; |
| 530 | |
| 531 | |
| 532 | |
| 533 | |
| 534 | |
| 535 | llvm::PointerIntPair<FunctionTemplateDecl *, 2> Template; |
| 536 | |
| 537 | |
| 538 | |
| 539 | const TemplateArgumentList *TemplateArguments; |
| 540 | |
| 541 | |
| 542 | const ASTTemplateArgumentListInfo *TemplateArgumentsAsWritten; |
| 543 | |
| 544 | |
| 545 | |
| 546 | SourceLocation PointOfInstantiation; |
| 547 | |
| 548 | |
| 549 | FunctionTemplateDecl *getTemplate() const { return Template.getPointer(); } |
| 550 | |
| 551 | |
| 552 | TemplateSpecializationKind getTemplateSpecializationKind() const { |
| 553 | return (TemplateSpecializationKind)(Template.getInt() + 1); |
| 554 | } |
| 555 | |
| 556 | bool isExplicitSpecialization() const { |
| 557 | return getTemplateSpecializationKind() == TSK_ExplicitSpecialization; |
| 558 | } |
| 559 | |
| 560 | |
| 561 | |
| 562 | |
| 563 | bool isExplicitInstantiationOrSpecialization() const { |
| 564 | return isTemplateExplicitInstantiationOrSpecialization( |
| 565 | getTemplateSpecializationKind()); |
| 566 | } |
| 567 | |
| 568 | |
| 569 | void setTemplateSpecializationKind(TemplateSpecializationKind TSK) { |
| 570 | (0) . __assert_fail ("TSK != TSK_Undeclared && \"Cannot encode TSK_Undeclared for a function template specialization\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 571, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(TSK != TSK_Undeclared && |
| 571 | (0) . __assert_fail ("TSK != TSK_Undeclared && \"Cannot encode TSK_Undeclared for a function template specialization\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 571, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "Cannot encode TSK_Undeclared for a function template specialization"); |
| 572 | Template.setInt(TSK - 1); |
| 573 | } |
| 574 | |
| 575 | |
| 576 | |
| 577 | |
| 578 | |
| 579 | |
| 580 | SourceLocation getPointOfInstantiation() const { |
| 581 | return PointOfInstantiation; |
| 582 | } |
| 583 | |
| 584 | |
| 585 | |
| 586 | void setPointOfInstantiation(SourceLocation POI) { |
| 587 | PointOfInstantiation = POI; |
| 588 | } |
| 589 | |
| 590 | void Profile(llvm::FoldingSetNodeID &ID) { |
| 591 | Profile(ID, TemplateArguments->asArray(), |
| 592 | Function->getASTContext()); |
| 593 | } |
| 594 | |
| 595 | static void |
| 596 | Profile(llvm::FoldingSetNodeID &ID, ArrayRef<TemplateArgument> TemplateArgs, |
| 597 | ASTContext &Context) { |
| 598 | ID.AddInteger(TemplateArgs.size()); |
| 599 | for (const TemplateArgument &TemplateArg : TemplateArgs) |
| 600 | TemplateArg.Profile(ID, Context); |
| 601 | } |
| 602 | }; |
| 603 | |
| 604 | |
| 605 | |
| 606 | |
| 607 | class MemberSpecializationInfo { |
| 608 | |
| 609 | |
| 610 | llvm::PointerIntPair<NamedDecl *, 2> MemberAndTSK; |
| 611 | |
| 612 | |
| 613 | SourceLocation PointOfInstantiation; |
| 614 | |
| 615 | public: |
| 616 | explicit |
| 617 | MemberSpecializationInfo(NamedDecl *IF, TemplateSpecializationKind TSK, |
| 618 | SourceLocation POI = SourceLocation()) |
| 619 | : MemberAndTSK(IF, TSK - 1), PointOfInstantiation(POI) { |
| 620 | (0) . __assert_fail ("TSK != TSK_Undeclared && \"Cannot encode undeclared template specializations for members\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 621, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(TSK != TSK_Undeclared && |
| 621 | (0) . __assert_fail ("TSK != TSK_Undeclared && \"Cannot encode undeclared template specializations for members\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 621, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "Cannot encode undeclared template specializations for members"); |
| 622 | } |
| 623 | |
| 624 | |
| 625 | |
| 626 | NamedDecl *getInstantiatedFrom() const { return MemberAndTSK.getPointer(); } |
| 627 | |
| 628 | |
| 629 | TemplateSpecializationKind getTemplateSpecializationKind() const { |
| 630 | return (TemplateSpecializationKind)(MemberAndTSK.getInt() + 1); |
| 631 | } |
| 632 | |
| 633 | bool isExplicitSpecialization() const { |
| 634 | return getTemplateSpecializationKind() == TSK_ExplicitSpecialization; |
| 635 | } |
| 636 | |
| 637 | |
| 638 | void setTemplateSpecializationKind(TemplateSpecializationKind TSK) { |
| 639 | (0) . __assert_fail ("TSK != TSK_Undeclared && \"Cannot encode undeclared template specializations for members\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 640, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(TSK != TSK_Undeclared && |
| 640 | (0) . __assert_fail ("TSK != TSK_Undeclared && \"Cannot encode undeclared template specializations for members\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 640, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "Cannot encode undeclared template specializations for members"); |
| 641 | MemberAndTSK.setInt(TSK - 1); |
| 642 | } |
| 643 | |
| 644 | |
| 645 | |
| 646 | |
| 647 | SourceLocation getPointOfInstantiation() const { |
| 648 | return PointOfInstantiation; |
| 649 | } |
| 650 | |
| 651 | |
| 652 | void setPointOfInstantiation(SourceLocation POI) { |
| 653 | PointOfInstantiation = POI; |
| 654 | } |
| 655 | }; |
| 656 | |
| 657 | |
| 658 | |
| 659 | |
| 660 | |
| 661 | |
| 662 | |
| 663 | |
| 664 | |
| 665 | |
| 666 | |
| 667 | |
| 668 | |
| 669 | |
| 670 | |
| 671 | class DependentFunctionTemplateSpecializationInfo final |
| 672 | : private llvm::TrailingObjects<DependentFunctionTemplateSpecializationInfo, |
| 673 | TemplateArgumentLoc, |
| 674 | FunctionTemplateDecl *> { |
| 675 | |
| 676 | unsigned NumTemplates; |
| 677 | |
| 678 | |
| 679 | unsigned NumArgs; |
| 680 | |
| 681 | |
| 682 | SourceRange AngleLocs; |
| 683 | |
| 684 | size_t numTrailingObjects(OverloadToken<TemplateArgumentLoc>) const { |
| 685 | return NumArgs; |
| 686 | } |
| 687 | size_t numTrailingObjects(OverloadToken<FunctionTemplateDecl *>) const { |
| 688 | return NumTemplates; |
| 689 | } |
| 690 | |
| 691 | DependentFunctionTemplateSpecializationInfo( |
| 692 | const UnresolvedSetImpl &Templates, |
| 693 | const TemplateArgumentListInfo &TemplateArgs); |
| 694 | |
| 695 | public: |
| 696 | friend TrailingObjects; |
| 697 | |
| 698 | static DependentFunctionTemplateSpecializationInfo * |
| 699 | Create(ASTContext &Context, const UnresolvedSetImpl &Templates, |
| 700 | const TemplateArgumentListInfo &TemplateArgs); |
| 701 | |
| 702 | |
| 703 | |
| 704 | unsigned getNumTemplates() const { return NumTemplates; } |
| 705 | |
| 706 | |
| 707 | FunctionTemplateDecl *getTemplate(unsigned I) const { |
| 708 | (0) . __assert_fail ("I < getNumTemplates() && \"template index out of range\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 708, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(I < getNumTemplates() && "template index out of range"); |
| 709 | return getTrailingObjects<FunctionTemplateDecl *>()[I]; |
| 710 | } |
| 711 | |
| 712 | |
| 713 | const TemplateArgumentLoc *getTemplateArgs() const { |
| 714 | return getTrailingObjects<TemplateArgumentLoc>(); |
| 715 | } |
| 716 | |
| 717 | |
| 718 | unsigned getNumTemplateArgs() const { return NumArgs; } |
| 719 | |
| 720 | |
| 721 | const TemplateArgumentLoc &getTemplateArg(unsigned I) const { |
| 722 | (0) . __assert_fail ("I < getNumTemplateArgs() && \"template arg index out of range\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 722, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(I < getNumTemplateArgs() && "template arg index out of range"); |
| 723 | return getTemplateArgs()[I]; |
| 724 | } |
| 725 | |
| 726 | SourceLocation getLAngleLoc() const { |
| 727 | return AngleLocs.getBegin(); |
| 728 | } |
| 729 | |
| 730 | SourceLocation getRAngleLoc() const { |
| 731 | return AngleLocs.getEnd(); |
| 732 | } |
| 733 | }; |
| 734 | |
| 735 | |
| 736 | class RedeclarableTemplateDecl : public TemplateDecl, |
| 737 | public Redeclarable<RedeclarableTemplateDecl> |
| 738 | { |
| 739 | using redeclarable_base = Redeclarable<RedeclarableTemplateDecl>; |
| 740 | |
| 741 | RedeclarableTemplateDecl *getNextRedeclarationImpl() override { |
| 742 | return getNextRedeclaration(); |
| 743 | } |
| 744 | |
| 745 | RedeclarableTemplateDecl *getPreviousDeclImpl() override { |
| 746 | return getPreviousDecl(); |
| 747 | } |
| 748 | |
| 749 | RedeclarableTemplateDecl *getMostRecentDeclImpl() override { |
| 750 | return getMostRecentDecl(); |
| 751 | } |
| 752 | |
| 753 | void anchor() override; |
| 754 | protected: |
| 755 | template <typename EntryType> struct SpecEntryTraits { |
| 756 | using DeclType = EntryType; |
| 757 | |
| 758 | static DeclType *getDecl(EntryType *D) { |
| 759 | return D; |
| 760 | } |
| 761 | |
| 762 | static ArrayRef<TemplateArgument> getTemplateArgs(EntryType *D) { |
| 763 | return D->getTemplateArgs().asArray(); |
| 764 | } |
| 765 | }; |
| 766 | |
| 767 | template <typename EntryType, typename SETraits = SpecEntryTraits<EntryType>, |
| 768 | typename DeclType = typename SETraits::DeclType> |
| 769 | struct SpecIterator |
| 770 | : llvm::iterator_adaptor_base< |
| 771 | SpecIterator<EntryType, SETraits, DeclType>, |
| 772 | typename llvm::FoldingSetVector<EntryType>::iterator, |
| 773 | typename std::iterator_traits<typename llvm::FoldingSetVector< |
| 774 | EntryType>::iterator>::iterator_category, |
| 775 | DeclType *, ptrdiff_t, DeclType *, DeclType *> { |
| 776 | SpecIterator() = default; |
| 777 | explicit SpecIterator( |
| 778 | typename llvm::FoldingSetVector<EntryType>::iterator SetIter) |
| 779 | : SpecIterator::iterator_adaptor_base(std::move(SetIter)) {} |
| 780 | |
| 781 | DeclType *operator*() const { |
| 782 | return SETraits::getDecl(&*this->I)->getMostRecentDecl(); |
| 783 | } |
| 784 | |
| 785 | DeclType *operator->() const { return **this; } |
| 786 | }; |
| 787 | |
| 788 | template <typename EntryType> |
| 789 | static SpecIterator<EntryType> |
| 790 | makeSpecIterator(llvm::FoldingSetVector<EntryType> &Specs, bool isEnd) { |
| 791 | return SpecIterator<EntryType>(isEnd ? Specs.end() : Specs.begin()); |
| 792 | } |
| 793 | |
| 794 | void loadLazySpecializationsImpl() const; |
| 795 | |
| 796 | template <class EntryType> typename SpecEntryTraits<EntryType>::DeclType* |
| 797 | findSpecializationImpl(llvm::FoldingSetVector<EntryType> &Specs, |
| 798 | ArrayRef<TemplateArgument> Args, void *&InsertPos); |
| 799 | |
| 800 | template <class Derived, class EntryType> |
| 801 | void addSpecializationImpl(llvm::FoldingSetVector<EntryType> &Specs, |
| 802 | EntryType *Entry, void *InsertPos); |
| 803 | |
| 804 | struct CommonBase { |
| 805 | CommonBase() : InstantiatedFromMember(nullptr, false) {} |
| 806 | |
| 807 | |
| 808 | |
| 809 | |
| 810 | |
| 811 | |
| 812 | llvm::PointerIntPair<RedeclarableTemplateDecl*, 1, bool> |
| 813 | InstantiatedFromMember; |
| 814 | |
| 815 | |
| 816 | |
| 817 | |
| 818 | |
| 819 | |
| 820 | uint32_t *LazySpecializations = nullptr; |
| 821 | }; |
| 822 | |
| 823 | |
| 824 | |
| 825 | mutable CommonBase *Common = nullptr; |
| 826 | |
| 827 | |
| 828 | |
| 829 | |
| 830 | CommonBase *getCommonPtr() const; |
| 831 | |
| 832 | virtual CommonBase *newCommon(ASTContext &C) const = 0; |
| 833 | |
| 834 | |
| 835 | RedeclarableTemplateDecl(ConstrainedTemplateDeclInfo *CTDI, Kind DK, |
| 836 | ASTContext &C, DeclContext *DC, SourceLocation L, |
| 837 | DeclarationName Name, TemplateParameterList *Params, |
| 838 | NamedDecl *Decl) |
| 839 | : TemplateDecl(CTDI, DK, DC, L, Name, Params, Decl), redeclarable_base(C) |
| 840 | {} |
| 841 | |
| 842 | RedeclarableTemplateDecl(Kind DK, ASTContext &C, DeclContext *DC, |
| 843 | SourceLocation L, DeclarationName Name, |
| 844 | TemplateParameterList *Params, NamedDecl *Decl) |
| 845 | : RedeclarableTemplateDecl(nullptr, DK, C, DC, L, Name, Params, Decl) {} |
| 846 | |
| 847 | public: |
| 848 | friend class ASTDeclReader; |
| 849 | friend class ASTDeclWriter; |
| 850 | friend class ASTReader; |
| 851 | template <class decl_type> friend class RedeclarableTemplate; |
| 852 | |
| 853 | |
| 854 | RedeclarableTemplateDecl *getCanonicalDecl() override { |
| 855 | return getFirstDecl(); |
| 856 | } |
| 857 | const RedeclarableTemplateDecl *getCanonicalDecl() const { |
| 858 | return getFirstDecl(); |
| 859 | } |
| 860 | |
| 861 | |
| 862 | |
| 863 | |
| 864 | |
| 865 | |
| 866 | |
| 867 | |
| 868 | |
| 869 | |
| 870 | |
| 871 | |
| 872 | |
| 873 | |
| 874 | |
| 875 | |
| 876 | |
| 877 | |
| 878 | |
| 879 | bool isMemberSpecialization() const { |
| 880 | return getCommonPtr()->InstantiatedFromMember.getInt(); |
| 881 | } |
| 882 | |
| 883 | |
| 884 | void setMemberSpecialization() { |
| 885 | (0) . __assert_fail ("getCommonPtr()->InstantiatedFromMember.getPointer() && \"Only member templates can be member template specializations\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 886, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(getCommonPtr()->InstantiatedFromMember.getPointer() && |
| 886 | (0) . __assert_fail ("getCommonPtr()->InstantiatedFromMember.getPointer() && \"Only member templates can be member template specializations\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 886, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "Only member templates can be member template specializations"); |
| 887 | getCommonPtr()->InstantiatedFromMember.setInt(true); |
| 888 | } |
| 889 | |
| 890 | |
| 891 | |
| 892 | |
| 893 | |
| 894 | |
| 895 | |
| 896 | |
| 897 | |
| 898 | |
| 899 | |
| 900 | |
| 901 | |
| 902 | |
| 903 | |
| 904 | |
| 905 | |
| 906 | |
| 907 | |
| 908 | |
| 909 | |
| 910 | |
| 911 | |
| 912 | |
| 913 | |
| 914 | |
| 915 | |
| 916 | |
| 917 | |
| 918 | |
| 919 | |
| 920 | |
| 921 | |
| 922 | |
| 923 | |
| 924 | |
| 925 | |
| 926 | RedeclarableTemplateDecl *getInstantiatedFromMemberTemplate() const { |
| 927 | return getCommonPtr()->InstantiatedFromMember.getPointer(); |
| 928 | } |
| 929 | |
| 930 | void setInstantiatedFromMemberTemplate(RedeclarableTemplateDecl *TD) { |
| 931 | InstantiatedFromMember.getPointer()", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 931, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(!getCommonPtr()->InstantiatedFromMember.getPointer()); |
| 932 | getCommonPtr()->InstantiatedFromMember.setPointer(TD); |
| 933 | } |
| 934 | |
| 935 | using redecl_range = redeclarable_base::redecl_range; |
| 936 | using redecl_iterator = redeclarable_base::redecl_iterator; |
| 937 | |
| 938 | using redeclarable_base::redecls_begin; |
| 939 | using redeclarable_base::redecls_end; |
| 940 | using redeclarable_base::redecls; |
| 941 | using redeclarable_base::getPreviousDecl; |
| 942 | using redeclarable_base::getMostRecentDecl; |
| 943 | using redeclarable_base::isFirstDecl; |
| 944 | |
| 945 | |
| 946 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 947 | |
| 948 | static bool classofKind(Kind K) { |
| 949 | return K >= firstRedeclarableTemplate && K <= lastRedeclarableTemplate; |
| 950 | } |
| 951 | }; |
| 952 | |
| 953 | template <> struct RedeclarableTemplateDecl:: |
| 954 | SpecEntryTraits<FunctionTemplateSpecializationInfo> { |
| 955 | using DeclType = FunctionDecl; |
| 956 | |
| 957 | static DeclType *getDecl(FunctionTemplateSpecializationInfo *I) { |
| 958 | return I->Function; |
| 959 | } |
| 960 | |
| 961 | static ArrayRef<TemplateArgument> |
| 962 | getTemplateArgs(FunctionTemplateSpecializationInfo *I) { |
| 963 | return I->TemplateArguments->asArray(); |
| 964 | } |
| 965 | }; |
| 966 | |
| 967 | |
| 968 | class FunctionTemplateDecl : public RedeclarableTemplateDecl { |
| 969 | protected: |
| 970 | friend class FunctionDecl; |
| 971 | |
| 972 | |
| 973 | |
| 974 | struct Common : CommonBase { |
| 975 | |
| 976 | |
| 977 | llvm::FoldingSetVector<FunctionTemplateSpecializationInfo> Specializations; |
| 978 | |
| 979 | |
| 980 | |
| 981 | |
| 982 | |
| 983 | |
| 984 | |
| 985 | |
| 986 | TemplateArgument *InjectedArgs = nullptr; |
| 987 | |
| 988 | Common() = default; |
| 989 | }; |
| 990 | |
| 991 | FunctionTemplateDecl(ASTContext &C, DeclContext *DC, SourceLocation L, |
| 992 | DeclarationName Name, TemplateParameterList *Params, |
| 993 | NamedDecl *Decl) |
| 994 | : RedeclarableTemplateDecl(FunctionTemplate, C, DC, L, Name, Params, |
| 995 | Decl) {} |
| 996 | |
| 997 | CommonBase *newCommon(ASTContext &C) const override; |
| 998 | |
| 999 | Common *getCommonPtr() const { |
| 1000 | return static_cast<Common *>(RedeclarableTemplateDecl::getCommonPtr()); |
| 1001 | } |
| 1002 | |
| 1003 | |
| 1004 | |
| 1005 | llvm::FoldingSetVector<FunctionTemplateSpecializationInfo> & |
| 1006 | getSpecializations() const; |
| 1007 | |
| 1008 | |
| 1009 | |
| 1010 | |
| 1011 | |
| 1012 | void addSpecialization(FunctionTemplateSpecializationInfo* Info, |
| 1013 | void *InsertPos); |
| 1014 | |
| 1015 | public: |
| 1016 | friend class ASTDeclReader; |
| 1017 | friend class ASTDeclWriter; |
| 1018 | |
| 1019 | |
| 1020 | void LoadLazySpecializations() const; |
| 1021 | |
| 1022 | |
| 1023 | FunctionDecl *getTemplatedDecl() const { |
| 1024 | return static_cast<FunctionDecl *>(TemplatedDecl); |
| 1025 | } |
| 1026 | |
| 1027 | |
| 1028 | |
| 1029 | bool isThisDeclarationADefinition() const { |
| 1030 | return getTemplatedDecl()->isThisDeclarationADefinition(); |
| 1031 | } |
| 1032 | |
| 1033 | |
| 1034 | |
| 1035 | FunctionDecl *findSpecialization(ArrayRef<TemplateArgument> Args, |
| 1036 | void *&InsertPos); |
| 1037 | |
| 1038 | FunctionTemplateDecl *getCanonicalDecl() override { |
| 1039 | return cast<FunctionTemplateDecl>( |
| 1040 | RedeclarableTemplateDecl::getCanonicalDecl()); |
| 1041 | } |
| 1042 | const FunctionTemplateDecl *getCanonicalDecl() const { |
| 1043 | return cast<FunctionTemplateDecl>( |
| 1044 | RedeclarableTemplateDecl::getCanonicalDecl()); |
| 1045 | } |
| 1046 | |
| 1047 | |
| 1048 | |
| 1049 | FunctionTemplateDecl *getPreviousDecl() { |
| 1050 | return cast_or_null<FunctionTemplateDecl>( |
| 1051 | static_cast<RedeclarableTemplateDecl *>(this)->getPreviousDecl()); |
| 1052 | } |
| 1053 | const FunctionTemplateDecl *getPreviousDecl() const { |
| 1054 | return cast_or_null<FunctionTemplateDecl>( |
| 1055 | static_cast<const RedeclarableTemplateDecl *>(this)->getPreviousDecl()); |
| 1056 | } |
| 1057 | |
| 1058 | FunctionTemplateDecl *getMostRecentDecl() { |
| 1059 | return cast<FunctionTemplateDecl>( |
| 1060 | static_cast<RedeclarableTemplateDecl *>(this) |
| 1061 | ->getMostRecentDecl()); |
| 1062 | } |
| 1063 | const FunctionTemplateDecl *getMostRecentDecl() const { |
| 1064 | return const_cast<FunctionTemplateDecl*>(this)->getMostRecentDecl(); |
| 1065 | } |
| 1066 | |
| 1067 | FunctionTemplateDecl *getInstantiatedFromMemberTemplate() const { |
| 1068 | return cast_or_null<FunctionTemplateDecl>( |
| 1069 | RedeclarableTemplateDecl::getInstantiatedFromMemberTemplate()); |
| 1070 | } |
| 1071 | |
| 1072 | using spec_iterator = SpecIterator<FunctionTemplateSpecializationInfo>; |
| 1073 | using spec_range = llvm::iterator_range<spec_iterator>; |
| 1074 | |
| 1075 | spec_range specializations() const { |
| 1076 | return spec_range(spec_begin(), spec_end()); |
| 1077 | } |
| 1078 | |
| 1079 | spec_iterator spec_begin() const { |
| 1080 | return makeSpecIterator(getSpecializations(), false); |
| 1081 | } |
| 1082 | |
| 1083 | spec_iterator spec_end() const { |
| 1084 | return makeSpecIterator(getSpecializations(), true); |
| 1085 | } |
| 1086 | |
| 1087 | |
| 1088 | |
| 1089 | |
| 1090 | |
| 1091 | |
| 1092 | |
| 1093 | |
| 1094 | ArrayRef<TemplateArgument> getInjectedTemplateArgs(); |
| 1095 | |
| 1096 | |
| 1097 | void mergePrevDecl(FunctionTemplateDecl *Prev); |
| 1098 | |
| 1099 | |
| 1100 | static FunctionTemplateDecl *Create(ASTContext &C, DeclContext *DC, |
| 1101 | SourceLocation L, |
| 1102 | DeclarationName Name, |
| 1103 | TemplateParameterList *Params, |
| 1104 | NamedDecl *Decl); |
| 1105 | |
| 1106 | |
| 1107 | static FunctionTemplateDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
| 1108 | |
| 1109 | |
| 1110 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 1111 | static bool classofKind(Kind K) { return K == FunctionTemplate; } |
| 1112 | }; |
| 1113 | |
| 1114 | |
| 1115 | |
| 1116 | |
| 1117 | |
| 1118 | |
| 1119 | |
| 1120 | |
| 1121 | |
| 1122 | |
| 1123 | |
| 1124 | |
| 1125 | |
| 1126 | |
| 1127 | class TemplateParmPosition { |
| 1128 | protected: |
| 1129 | |
| 1130 | |
| 1131 | unsigned Depth; |
| 1132 | unsigned Position; |
| 1133 | |
| 1134 | TemplateParmPosition(unsigned D, unsigned P) : Depth(D), Position(P) {} |
| 1135 | |
| 1136 | public: |
| 1137 | TemplateParmPosition() = delete; |
| 1138 | |
| 1139 | |
| 1140 | unsigned getDepth() const { return Depth; } |
| 1141 | void setDepth(unsigned D) { Depth = D; } |
| 1142 | |
| 1143 | |
| 1144 | unsigned getPosition() const { return Position; } |
| 1145 | void setPosition(unsigned P) { Position = P; } |
| 1146 | |
| 1147 | |
| 1148 | unsigned getIndex() const { return Position; } |
| 1149 | }; |
| 1150 | |
| 1151 | |
| 1152 | |
| 1153 | |
| 1154 | |
| 1155 | |
| 1156 | |
| 1157 | class TemplateTypeParmDecl : public TypeDecl { |
| 1158 | |
| 1159 | friend class Sema; |
| 1160 | |
| 1161 | |
| 1162 | |
| 1163 | |
| 1164 | |
| 1165 | bool Typename : 1; |
| 1166 | |
| 1167 | |
| 1168 | using DefArgStorage = |
| 1169 | DefaultArgStorage<TemplateTypeParmDecl, TypeSourceInfo *>; |
| 1170 | DefArgStorage DefaultArgument; |
| 1171 | |
| 1172 | TemplateTypeParmDecl(DeclContext *DC, SourceLocation KeyLoc, |
| 1173 | SourceLocation IdLoc, IdentifierInfo *Id, |
| 1174 | bool Typename) |
| 1175 | : TypeDecl(TemplateTypeParm, DC, IdLoc, Id, KeyLoc), Typename(Typename) {} |
| 1176 | |
| 1177 | public: |
| 1178 | static TemplateTypeParmDecl *Create(const ASTContext &C, DeclContext *DC, |
| 1179 | SourceLocation KeyLoc, |
| 1180 | SourceLocation NameLoc, |
| 1181 | unsigned D, unsigned P, |
| 1182 | IdentifierInfo *Id, bool Typename, |
| 1183 | bool ParameterPack); |
| 1184 | static TemplateTypeParmDecl *CreateDeserialized(const ASTContext &C, |
| 1185 | unsigned ID); |
| 1186 | |
| 1187 | |
| 1188 | |
| 1189 | |
| 1190 | |
| 1191 | bool wasDeclaredWithTypename() const { return Typename; } |
| 1192 | |
| 1193 | const DefArgStorage &getDefaultArgStorage() const { return DefaultArgument; } |
| 1194 | |
| 1195 | |
| 1196 | |
| 1197 | bool hasDefaultArgument() const { return DefaultArgument.isSet(); } |
| 1198 | |
| 1199 | |
| 1200 | QualType getDefaultArgument() const { |
| 1201 | return DefaultArgument.get()->getType(); |
| 1202 | } |
| 1203 | |
| 1204 | |
| 1205 | TypeSourceInfo *getDefaultArgumentInfo() const { |
| 1206 | return DefaultArgument.get(); |
| 1207 | } |
| 1208 | |
| 1209 | |
| 1210 | SourceLocation getDefaultArgumentLoc() const; |
| 1211 | |
| 1212 | |
| 1213 | |
| 1214 | bool defaultArgumentWasInherited() const { |
| 1215 | return DefaultArgument.isInherited(); |
| 1216 | } |
| 1217 | |
| 1218 | |
| 1219 | void setDefaultArgument(TypeSourceInfo *DefArg) { |
| 1220 | DefaultArgument.set(DefArg); |
| 1221 | } |
| 1222 | |
| 1223 | |
| 1224 | |
| 1225 | void setInheritedDefaultArgument(const ASTContext &C, |
| 1226 | TemplateTypeParmDecl *Prev) { |
| 1227 | DefaultArgument.setInherited(C, Prev); |
| 1228 | } |
| 1229 | |
| 1230 | |
| 1231 | void removeDefaultArgument() { |
| 1232 | DefaultArgument.clear(); |
| 1233 | } |
| 1234 | |
| 1235 | |
| 1236 | |
| 1237 | void setDeclaredWithTypename(bool withTypename) { Typename = withTypename; } |
| 1238 | |
| 1239 | |
| 1240 | unsigned getDepth() const; |
| 1241 | |
| 1242 | |
| 1243 | unsigned getIndex() const; |
| 1244 | |
| 1245 | |
| 1246 | bool isParameterPack() const; |
| 1247 | |
| 1248 | SourceRange getSourceRange() const override LLVM_READONLY; |
| 1249 | |
| 1250 | |
| 1251 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 1252 | static bool classofKind(Kind K) { return K == TemplateTypeParm; } |
| 1253 | }; |
| 1254 | |
| 1255 | |
| 1256 | |
| 1257 | |
| 1258 | |
| 1259 | |
| 1260 | class NonTypeTemplateParmDecl final |
| 1261 | : public DeclaratorDecl, |
| 1262 | protected TemplateParmPosition, |
| 1263 | private llvm::TrailingObjects<NonTypeTemplateParmDecl, |
| 1264 | std::pair<QualType, TypeSourceInfo *>> { |
| 1265 | friend class ASTDeclReader; |
| 1266 | friend TrailingObjects; |
| 1267 | |
| 1268 | |
| 1269 | |
| 1270 | using DefArgStorage = DefaultArgStorage<NonTypeTemplateParmDecl, Expr *>; |
| 1271 | DefArgStorage DefaultArgument; |
| 1272 | |
| 1273 | |
| 1274 | |
| 1275 | |
| 1276 | |
| 1277 | bool ParameterPack; |
| 1278 | |
| 1279 | |
| 1280 | |
| 1281 | |
| 1282 | bool ExpandedParameterPack = false; |
| 1283 | |
| 1284 | |
| 1285 | unsigned NumExpandedTypes = 0; |
| 1286 | |
| 1287 | size_t numTrailingObjects( |
| 1288 | OverloadToken<std::pair<QualType, TypeSourceInfo *>>) const { |
| 1289 | return NumExpandedTypes; |
| 1290 | } |
| 1291 | |
| 1292 | NonTypeTemplateParmDecl(DeclContext *DC, SourceLocation StartLoc, |
| 1293 | SourceLocation IdLoc, unsigned D, unsigned P, |
| 1294 | IdentifierInfo *Id, QualType T, |
| 1295 | bool ParameterPack, TypeSourceInfo *TInfo) |
| 1296 | : DeclaratorDecl(NonTypeTemplateParm, DC, IdLoc, Id, T, TInfo, StartLoc), |
| 1297 | TemplateParmPosition(D, P), ParameterPack(ParameterPack) {} |
| 1298 | |
| 1299 | NonTypeTemplateParmDecl(DeclContext *DC, SourceLocation StartLoc, |
| 1300 | SourceLocation IdLoc, unsigned D, unsigned P, |
| 1301 | IdentifierInfo *Id, QualType T, |
| 1302 | TypeSourceInfo *TInfo, |
| 1303 | ArrayRef<QualType> ExpandedTypes, |
| 1304 | ArrayRef<TypeSourceInfo *> ExpandedTInfos); |
| 1305 | |
| 1306 | public: |
| 1307 | static NonTypeTemplateParmDecl * |
| 1308 | Create(const ASTContext &C, DeclContext *DC, SourceLocation StartLoc, |
| 1309 | SourceLocation IdLoc, unsigned D, unsigned P, IdentifierInfo *Id, |
| 1310 | QualType T, bool ParameterPack, TypeSourceInfo *TInfo); |
| 1311 | |
| 1312 | static NonTypeTemplateParmDecl * |
| 1313 | Create(const ASTContext &C, DeclContext *DC, SourceLocation StartLoc, |
| 1314 | SourceLocation IdLoc, unsigned D, unsigned P, IdentifierInfo *Id, |
| 1315 | QualType T, TypeSourceInfo *TInfo, ArrayRef<QualType> ExpandedTypes, |
| 1316 | ArrayRef<TypeSourceInfo *> ExpandedTInfos); |
| 1317 | |
| 1318 | static NonTypeTemplateParmDecl *CreateDeserialized(ASTContext &C, |
| 1319 | unsigned ID); |
| 1320 | static NonTypeTemplateParmDecl *CreateDeserialized(ASTContext &C, |
| 1321 | unsigned ID, |
| 1322 | unsigned NumExpandedTypes); |
| 1323 | |
| 1324 | using TemplateParmPosition::getDepth; |
| 1325 | using TemplateParmPosition::setDepth; |
| 1326 | using TemplateParmPosition::getPosition; |
| 1327 | using TemplateParmPosition::setPosition; |
| 1328 | using TemplateParmPosition::getIndex; |
| 1329 | |
| 1330 | SourceRange getSourceRange() const override LLVM_READONLY; |
| 1331 | |
| 1332 | const DefArgStorage &getDefaultArgStorage() const { return DefaultArgument; } |
| 1333 | |
| 1334 | |
| 1335 | |
| 1336 | bool hasDefaultArgument() const { return DefaultArgument.isSet(); } |
| 1337 | |
| 1338 | |
| 1339 | Expr *getDefaultArgument() const { return DefaultArgument.get(); } |
| 1340 | |
| 1341 | |
| 1342 | SourceLocation getDefaultArgumentLoc() const; |
| 1343 | |
| 1344 | |
| 1345 | |
| 1346 | bool defaultArgumentWasInherited() const { |
| 1347 | return DefaultArgument.isInherited(); |
| 1348 | } |
| 1349 | |
| 1350 | |
| 1351 | |
| 1352 | |
| 1353 | void setDefaultArgument(Expr *DefArg) { DefaultArgument.set(DefArg); } |
| 1354 | void setInheritedDefaultArgument(const ASTContext &C, |
| 1355 | NonTypeTemplateParmDecl *Parm) { |
| 1356 | DefaultArgument.setInherited(C, Parm); |
| 1357 | } |
| 1358 | |
| 1359 | |
| 1360 | void removeDefaultArgument() { DefaultArgument.clear(); } |
| 1361 | |
| 1362 | |
| 1363 | |
| 1364 | |
| 1365 | |
| 1366 | |
| 1367 | |
| 1368 | |
| 1369 | |
| 1370 | |
| 1371 | bool isParameterPack() const { return ParameterPack; } |
| 1372 | |
| 1373 | |
| 1374 | |
| 1375 | |
| 1376 | |
| 1377 | |
| 1378 | bool isPackExpansion() const { |
| 1379 | return ParameterPack && getType()->getAs<PackExpansionType>(); |
| 1380 | } |
| 1381 | |
| 1382 | |
| 1383 | |
| 1384 | |
| 1385 | |
| 1386 | |
| 1387 | |
| 1388 | |
| 1389 | |
| 1390 | |
| 1391 | |
| 1392 | |
| 1393 | |
| 1394 | |
| 1395 | |
| 1396 | |
| 1397 | |
| 1398 | |
| 1399 | |
| 1400 | |
| 1401 | |
| 1402 | |
| 1403 | |
| 1404 | |
| 1405 | |
| 1406 | bool isExpandedParameterPack() const { return ExpandedParameterPack; } |
| 1407 | |
| 1408 | |
| 1409 | |
| 1410 | unsigned getNumExpansionTypes() const { |
| 1411 | (0) . __assert_fail ("ExpandedParameterPack && \"Not an expansion parameter pack\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 1411, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(ExpandedParameterPack && "Not an expansion parameter pack"); |
| 1412 | return NumExpandedTypes; |
| 1413 | } |
| 1414 | |
| 1415 | |
| 1416 | |
| 1417 | QualType getExpansionType(unsigned I) const { |
| 1418 | (0) . __assert_fail ("I < NumExpandedTypes && \"Out-of-range expansion type index\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 1418, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(I < NumExpandedTypes && "Out-of-range expansion type index"); |
| 1419 | auto TypesAndInfos = |
| 1420 | getTrailingObjects<std::pair<QualType, TypeSourceInfo *>>(); |
| 1421 | return TypesAndInfos[I].first; |
| 1422 | } |
| 1423 | |
| 1424 | |
| 1425 | |
| 1426 | TypeSourceInfo *getExpansionTypeSourceInfo(unsigned I) const { |
| 1427 | (0) . __assert_fail ("I < NumExpandedTypes && \"Out-of-range expansion type index\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 1427, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(I < NumExpandedTypes && "Out-of-range expansion type index"); |
| 1428 | auto TypesAndInfos = |
| 1429 | getTrailingObjects<std::pair<QualType, TypeSourceInfo *>>(); |
| 1430 | return TypesAndInfos[I].second; |
| 1431 | } |
| 1432 | |
| 1433 | |
| 1434 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 1435 | static bool classofKind(Kind K) { return K == NonTypeTemplateParm; } |
| 1436 | }; |
| 1437 | |
| 1438 | |
| 1439 | |
| 1440 | |
| 1441 | |
| 1442 | |
| 1443 | |
| 1444 | |
| 1445 | class TemplateTemplateParmDecl final |
| 1446 | : public TemplateDecl, |
| 1447 | protected TemplateParmPosition, |
| 1448 | private llvm::TrailingObjects<TemplateTemplateParmDecl, |
| 1449 | TemplateParameterList *> { |
| 1450 | |
| 1451 | using DefArgStorage = |
| 1452 | DefaultArgStorage<TemplateTemplateParmDecl, TemplateArgumentLoc *>; |
| 1453 | DefArgStorage DefaultArgument; |
| 1454 | |
| 1455 | |
| 1456 | bool ParameterPack; |
| 1457 | |
| 1458 | |
| 1459 | |
| 1460 | |
| 1461 | bool ExpandedParameterPack = false; |
| 1462 | |
| 1463 | |
| 1464 | unsigned NumExpandedParams = 0; |
| 1465 | |
| 1466 | TemplateTemplateParmDecl(DeclContext *DC, SourceLocation L, |
| 1467 | unsigned D, unsigned P, bool ParameterPack, |
| 1468 | IdentifierInfo *Id, TemplateParameterList *Params) |
| 1469 | : TemplateDecl(TemplateTemplateParm, DC, L, Id, Params), |
| 1470 | TemplateParmPosition(D, P), ParameterPack(ParameterPack) {} |
| 1471 | |
| 1472 | TemplateTemplateParmDecl(DeclContext *DC, SourceLocation L, |
| 1473 | unsigned D, unsigned P, |
| 1474 | IdentifierInfo *Id, TemplateParameterList *Params, |
| 1475 | ArrayRef<TemplateParameterList *> Expansions); |
| 1476 | |
| 1477 | void anchor() override; |
| 1478 | |
| 1479 | public: |
| 1480 | friend class ASTDeclReader; |
| 1481 | friend class ASTDeclWriter; |
| 1482 | friend TrailingObjects; |
| 1483 | |
| 1484 | static TemplateTemplateParmDecl *Create(const ASTContext &C, DeclContext *DC, |
| 1485 | SourceLocation L, unsigned D, |
| 1486 | unsigned P, bool ParameterPack, |
| 1487 | IdentifierInfo *Id, |
| 1488 | TemplateParameterList *Params); |
| 1489 | static TemplateTemplateParmDecl *Create(const ASTContext &C, DeclContext *DC, |
| 1490 | SourceLocation L, unsigned D, |
| 1491 | unsigned P, |
| 1492 | IdentifierInfo *Id, |
| 1493 | TemplateParameterList *Params, |
| 1494 | ArrayRef<TemplateParameterList *> Expansions); |
| 1495 | |
| 1496 | static TemplateTemplateParmDecl *CreateDeserialized(ASTContext &C, |
| 1497 | unsigned ID); |
| 1498 | static TemplateTemplateParmDecl *CreateDeserialized(ASTContext &C, |
| 1499 | unsigned ID, |
| 1500 | unsigned NumExpansions); |
| 1501 | |
| 1502 | using TemplateParmPosition::getDepth; |
| 1503 | using TemplateParmPosition::setDepth; |
| 1504 | using TemplateParmPosition::getPosition; |
| 1505 | using TemplateParmPosition::setPosition; |
| 1506 | using TemplateParmPosition::getIndex; |
| 1507 | |
| 1508 | |
| 1509 | |
| 1510 | |
| 1511 | |
| 1512 | |
| 1513 | |
| 1514 | bool isParameterPack() const { return ParameterPack; } |
| 1515 | |
| 1516 | |
| 1517 | |
| 1518 | |
| 1519 | |
| 1520 | bool isPackExpansion() const { |
| 1521 | return ParameterPack && |
| 1522 | getTemplateParameters()->containsUnexpandedParameterPack(); |
| 1523 | } |
| 1524 | |
| 1525 | |
| 1526 | |
| 1527 | |
| 1528 | |
| 1529 | |
| 1530 | |
| 1531 | |
| 1532 | |
| 1533 | |
| 1534 | |
| 1535 | |
| 1536 | |
| 1537 | |
| 1538 | |
| 1539 | |
| 1540 | |
| 1541 | |
| 1542 | |
| 1543 | bool isExpandedParameterPack() const { return ExpandedParameterPack; } |
| 1544 | |
| 1545 | |
| 1546 | |
| 1547 | unsigned getNumExpansionTemplateParameters() const { |
| 1548 | (0) . __assert_fail ("ExpandedParameterPack && \"Not an expansion parameter pack\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 1548, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(ExpandedParameterPack && "Not an expansion parameter pack"); |
| 1549 | return NumExpandedParams; |
| 1550 | } |
| 1551 | |
| 1552 | |
| 1553 | |
| 1554 | TemplateParameterList *getExpansionTemplateParameters(unsigned I) const { |
| 1555 | (0) . __assert_fail ("I < NumExpandedParams && \"Out-of-range expansion type index\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 1555, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(I < NumExpandedParams && "Out-of-range expansion type index"); |
| 1556 | return getTrailingObjects<TemplateParameterList *>()[I]; |
| 1557 | } |
| 1558 | |
| 1559 | const DefArgStorage &getDefaultArgStorage() const { return DefaultArgument; } |
| 1560 | |
| 1561 | |
| 1562 | |
| 1563 | bool hasDefaultArgument() const { return DefaultArgument.isSet(); } |
| 1564 | |
| 1565 | |
| 1566 | const TemplateArgumentLoc &getDefaultArgument() const { |
| 1567 | static const TemplateArgumentLoc None; |
| 1568 | return DefaultArgument.isSet() ? *DefaultArgument.get() : None; |
| 1569 | } |
| 1570 | |
| 1571 | |
| 1572 | SourceLocation getDefaultArgumentLoc() const; |
| 1573 | |
| 1574 | |
| 1575 | |
| 1576 | bool defaultArgumentWasInherited() const { |
| 1577 | return DefaultArgument.isInherited(); |
| 1578 | } |
| 1579 | |
| 1580 | |
| 1581 | |
| 1582 | |
| 1583 | void setDefaultArgument(const ASTContext &C, |
| 1584 | const TemplateArgumentLoc &DefArg); |
| 1585 | void setInheritedDefaultArgument(const ASTContext &C, |
| 1586 | TemplateTemplateParmDecl *Prev) { |
| 1587 | DefaultArgument.setInherited(C, Prev); |
| 1588 | } |
| 1589 | |
| 1590 | |
| 1591 | void removeDefaultArgument() { DefaultArgument.clear(); } |
| 1592 | |
| 1593 | SourceRange getSourceRange() const override LLVM_READONLY { |
| 1594 | SourceLocation End = getLocation(); |
| 1595 | if (hasDefaultArgument() && !defaultArgumentWasInherited()) |
| 1596 | End = getDefaultArgument().getSourceRange().getEnd(); |
| 1597 | return SourceRange(getTemplateParameters()->getTemplateLoc(), End); |
| 1598 | } |
| 1599 | |
| 1600 | |
| 1601 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 1602 | static bool classofKind(Kind K) { return K == TemplateTemplateParm; } |
| 1603 | }; |
| 1604 | |
| 1605 | |
| 1606 | |
| 1607 | |
| 1608 | class BuiltinTemplateDecl : public TemplateDecl { |
| 1609 | BuiltinTemplateKind BTK; |
| 1610 | |
| 1611 | BuiltinTemplateDecl(const ASTContext &C, DeclContext *DC, |
| 1612 | DeclarationName Name, BuiltinTemplateKind BTK); |
| 1613 | |
| 1614 | void anchor() override; |
| 1615 | |
| 1616 | public: |
| 1617 | |
| 1618 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 1619 | static bool classofKind(Kind K) { return K == BuiltinTemplate; } |
| 1620 | |
| 1621 | static BuiltinTemplateDecl *Create(const ASTContext &C, DeclContext *DC, |
| 1622 | DeclarationName Name, |
| 1623 | BuiltinTemplateKind BTK) { |
| 1624 | return new (C, DC) BuiltinTemplateDecl(C, DC, Name, BTK); |
| 1625 | } |
| 1626 | |
| 1627 | SourceRange getSourceRange() const override LLVM_READONLY { |
| 1628 | return {}; |
| 1629 | } |
| 1630 | |
| 1631 | BuiltinTemplateKind getBuiltinTemplateKind() const { return BTK; } |
| 1632 | }; |
| 1633 | |
| 1634 | |
| 1635 | |
| 1636 | |
| 1637 | |
| 1638 | |
| 1639 | |
| 1640 | |
| 1641 | |
| 1642 | |
| 1643 | |
| 1644 | |
| 1645 | |
| 1646 | |
| 1647 | class ClassTemplateSpecializationDecl |
| 1648 | : public CXXRecordDecl, public llvm::FoldingSetNode { |
| 1649 | |
| 1650 | |
| 1651 | |
| 1652 | struct SpecializedPartialSpecialization { |
| 1653 | |
| 1654 | |
| 1655 | ClassTemplatePartialSpecializationDecl *PartialSpecialization; |
| 1656 | |
| 1657 | |
| 1658 | |
| 1659 | const TemplateArgumentList *TemplateArgs; |
| 1660 | }; |
| 1661 | |
| 1662 | |
| 1663 | llvm::PointerUnion<ClassTemplateDecl *, SpecializedPartialSpecialization *> |
| 1664 | SpecializedTemplate; |
| 1665 | |
| 1666 | |
| 1667 | struct ExplicitSpecializationInfo { |
| 1668 | |
| 1669 | TypeSourceInfo *TypeAsWritten = nullptr; |
| 1670 | |
| 1671 | |
| 1672 | SourceLocation ExternLoc; |
| 1673 | |
| 1674 | |
| 1675 | SourceLocation TemplateKeywordLoc; |
| 1676 | |
| 1677 | ExplicitSpecializationInfo() = default; |
| 1678 | }; |
| 1679 | |
| 1680 | |
| 1681 | |
| 1682 | ExplicitSpecializationInfo *ExplicitInfo = nullptr; |
| 1683 | |
| 1684 | |
| 1685 | const TemplateArgumentList *TemplateArgs; |
| 1686 | |
| 1687 | |
| 1688 | SourceLocation PointOfInstantiation; |
| 1689 | |
| 1690 | |
| 1691 | |
| 1692 | unsigned SpecializationKind : 3; |
| 1693 | |
| 1694 | protected: |
| 1695 | ClassTemplateSpecializationDecl(ASTContext &Context, Kind DK, TagKind TK, |
| 1696 | DeclContext *DC, SourceLocation StartLoc, |
| 1697 | SourceLocation IdLoc, |
| 1698 | ClassTemplateDecl *SpecializedTemplate, |
| 1699 | ArrayRef<TemplateArgument> Args, |
| 1700 | ClassTemplateSpecializationDecl *PrevDecl); |
| 1701 | |
| 1702 | explicit ClassTemplateSpecializationDecl(ASTContext &C, Kind DK); |
| 1703 | |
| 1704 | public: |
| 1705 | friend class ASTDeclReader; |
| 1706 | friend class ASTDeclWriter; |
| 1707 | |
| 1708 | static ClassTemplateSpecializationDecl * |
| 1709 | Create(ASTContext &Context, TagKind TK, DeclContext *DC, |
| 1710 | SourceLocation StartLoc, SourceLocation IdLoc, |
| 1711 | ClassTemplateDecl *SpecializedTemplate, |
| 1712 | ArrayRef<TemplateArgument> Args, |
| 1713 | ClassTemplateSpecializationDecl *PrevDecl); |
| 1714 | static ClassTemplateSpecializationDecl * |
| 1715 | CreateDeserialized(ASTContext &C, unsigned ID); |
| 1716 | |
| 1717 | void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy, |
| 1718 | bool Qualified) const override; |
| 1719 | |
| 1720 | |
| 1721 | |
| 1722 | |
| 1723 | |
| 1724 | |
| 1725 | ClassTemplateSpecializationDecl *getMostRecentDecl() { |
| 1726 | return cast<ClassTemplateSpecializationDecl>( |
| 1727 | getMostRecentNonInjectedDecl()); |
| 1728 | } |
| 1729 | |
| 1730 | |
| 1731 | ClassTemplateDecl *getSpecializedTemplate() const; |
| 1732 | |
| 1733 | |
| 1734 | |
| 1735 | const TemplateArgumentList &getTemplateArgs() const { |
| 1736 | return *TemplateArgs; |
| 1737 | } |
| 1738 | |
| 1739 | |
| 1740 | |
| 1741 | TemplateSpecializationKind getSpecializationKind() const { |
| 1742 | return static_cast<TemplateSpecializationKind>(SpecializationKind); |
| 1743 | } |
| 1744 | |
| 1745 | bool isExplicitSpecialization() const { |
| 1746 | return getSpecializationKind() == TSK_ExplicitSpecialization; |
| 1747 | } |
| 1748 | |
| 1749 | |
| 1750 | |
| 1751 | |
| 1752 | bool isExplicitInstantiationOrSpecialization() const { |
| 1753 | return isTemplateExplicitInstantiationOrSpecialization( |
| 1754 | getTemplateSpecializationKind()); |
| 1755 | } |
| 1756 | |
| 1757 | void setSpecializationKind(TemplateSpecializationKind TSK) { |
| 1758 | SpecializationKind = TSK; |
| 1759 | } |
| 1760 | |
| 1761 | |
| 1762 | SourceLocation getPointOfInstantiation() const { |
| 1763 | return PointOfInstantiation; |
| 1764 | } |
| 1765 | |
| 1766 | void setPointOfInstantiation(SourceLocation Loc) { |
| 1767 | (0) . __assert_fail ("Loc.isValid() && \"point of instantiation must be valid!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 1767, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(Loc.isValid() && "point of instantiation must be valid!"); |
| 1768 | PointOfInstantiation = Loc; |
| 1769 | } |
| 1770 | |
| 1771 | |
| 1772 | |
| 1773 | |
| 1774 | |
| 1775 | llvm::PointerUnion<ClassTemplateDecl *, |
| 1776 | ClassTemplatePartialSpecializationDecl *> |
| 1777 | getInstantiatedFrom() const { |
| 1778 | if (!isTemplateInstantiation(getSpecializationKind())) |
| 1779 | return llvm::PointerUnion<ClassTemplateDecl *, |
| 1780 | ClassTemplatePartialSpecializationDecl *>(); |
| 1781 | |
| 1782 | return getSpecializedTemplateOrPartial(); |
| 1783 | } |
| 1784 | |
| 1785 | |
| 1786 | |
| 1787 | llvm::PointerUnion<ClassTemplateDecl *, |
| 1788 | ClassTemplatePartialSpecializationDecl *> |
| 1789 | getSpecializedTemplateOrPartial() const { |
| 1790 | if (const auto *PartialSpec = |
| 1791 | SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>()) |
| 1792 | return PartialSpec->PartialSpecialization; |
| 1793 | |
| 1794 | return SpecializedTemplate.get<ClassTemplateDecl*>(); |
| 1795 | } |
| 1796 | |
| 1797 | |
| 1798 | |
| 1799 | |
| 1800 | |
| 1801 | |
| 1802 | |
| 1803 | |
| 1804 | |
| 1805 | |
| 1806 | |
| 1807 | |
| 1808 | const TemplateArgumentList &getTemplateInstantiationArgs() const { |
| 1809 | if (const auto *PartialSpec = |
| 1810 | SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>()) |
| 1811 | return *PartialSpec->TemplateArgs; |
| 1812 | |
| 1813 | return getTemplateArgs(); |
| 1814 | } |
| 1815 | |
| 1816 | |
| 1817 | |
| 1818 | |
| 1819 | void setInstantiationOf(ClassTemplatePartialSpecializationDecl *PartialSpec, |
| 1820 | const TemplateArgumentList *TemplateArgs) { |
| 1821 | (0) . __assert_fail ("!SpecializedTemplate.is() && \"Already set to a class template partial specialization!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 1822, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(!SpecializedTemplate.is<SpecializedPartialSpecialization*>() && |
| 1822 | (0) . __assert_fail ("!SpecializedTemplate.is() && \"Already set to a class template partial specialization!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 1822, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "Already set to a class template partial specialization!"); |
| 1823 | auto *PS = new (getASTContext()) SpecializedPartialSpecialization(); |
| 1824 | PS->PartialSpecialization = PartialSpec; |
| 1825 | PS->TemplateArgs = TemplateArgs; |
| 1826 | SpecializedTemplate = PS; |
| 1827 | } |
| 1828 | |
| 1829 | |
| 1830 | |
| 1831 | void setInstantiationOf(ClassTemplateDecl *TemplDecl) { |
| 1832 | (0) . __assert_fail ("!SpecializedTemplate.is() && \"Previously set to a class template partial specialization!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 1833, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(!SpecializedTemplate.is<SpecializedPartialSpecialization*>() && |
| 1833 | (0) . __assert_fail ("!SpecializedTemplate.is() && \"Previously set to a class template partial specialization!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 1833, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "Previously set to a class template partial specialization!"); |
| 1834 | SpecializedTemplate = TemplDecl; |
| 1835 | } |
| 1836 | |
| 1837 | |
| 1838 | |
| 1839 | void setTypeAsWritten(TypeSourceInfo *T) { |
| 1840 | if (!ExplicitInfo) |
| 1841 | ExplicitInfo = new (getASTContext()) ExplicitSpecializationInfo; |
| 1842 | ExplicitInfo->TypeAsWritten = T; |
| 1843 | } |
| 1844 | |
| 1845 | |
| 1846 | |
| 1847 | TypeSourceInfo *getTypeAsWritten() const { |
| 1848 | return ExplicitInfo ? ExplicitInfo->TypeAsWritten : nullptr; |
| 1849 | } |
| 1850 | |
| 1851 | |
| 1852 | SourceLocation getExternLoc() const { |
| 1853 | return ExplicitInfo ? ExplicitInfo->ExternLoc : SourceLocation(); |
| 1854 | } |
| 1855 | |
| 1856 | |
| 1857 | void setExternLoc(SourceLocation Loc) { |
| 1858 | if (!ExplicitInfo) |
| 1859 | ExplicitInfo = new (getASTContext()) ExplicitSpecializationInfo; |
| 1860 | ExplicitInfo->ExternLoc = Loc; |
| 1861 | } |
| 1862 | |
| 1863 | |
| 1864 | void setTemplateKeywordLoc(SourceLocation Loc) { |
| 1865 | if (!ExplicitInfo) |
| 1866 | ExplicitInfo = new (getASTContext()) ExplicitSpecializationInfo; |
| 1867 | ExplicitInfo->TemplateKeywordLoc = Loc; |
| 1868 | } |
| 1869 | |
| 1870 | |
| 1871 | SourceLocation getTemplateKeywordLoc() const { |
| 1872 | return ExplicitInfo ? ExplicitInfo->TemplateKeywordLoc : SourceLocation(); |
| 1873 | } |
| 1874 | |
| 1875 | SourceRange getSourceRange() const override LLVM_READONLY; |
| 1876 | |
| 1877 | void Profile(llvm::FoldingSetNodeID &ID) const { |
| 1878 | Profile(ID, TemplateArgs->asArray(), getASTContext()); |
| 1879 | } |
| 1880 | |
| 1881 | static void |
| 1882 | Profile(llvm::FoldingSetNodeID &ID, ArrayRef<TemplateArgument> TemplateArgs, |
| 1883 | ASTContext &Context) { |
| 1884 | ID.AddInteger(TemplateArgs.size()); |
| 1885 | for (const TemplateArgument &TemplateArg : TemplateArgs) |
| 1886 | TemplateArg.Profile(ID, Context); |
| 1887 | } |
| 1888 | |
| 1889 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 1890 | |
| 1891 | static bool classofKind(Kind K) { |
| 1892 | return K >= firstClassTemplateSpecialization && |
| 1893 | K <= lastClassTemplateSpecialization; |
| 1894 | } |
| 1895 | }; |
| 1896 | |
| 1897 | class ClassTemplatePartialSpecializationDecl |
| 1898 | : public ClassTemplateSpecializationDecl { |
| 1899 | |
| 1900 | TemplateParameterList* TemplateParams = nullptr; |
| 1901 | |
| 1902 | |
| 1903 | |
| 1904 | const ASTTemplateArgumentListInfo *ArgsAsWritten = nullptr; |
| 1905 | |
| 1906 | |
| 1907 | |
| 1908 | |
| 1909 | |
| 1910 | |
| 1911 | llvm::PointerIntPair<ClassTemplatePartialSpecializationDecl *, 1, bool> |
| 1912 | InstantiatedFromMember; |
| 1913 | |
| 1914 | ClassTemplatePartialSpecializationDecl(ASTContext &Context, TagKind TK, |
| 1915 | DeclContext *DC, |
| 1916 | SourceLocation StartLoc, |
| 1917 | SourceLocation IdLoc, |
| 1918 | TemplateParameterList *Params, |
| 1919 | ClassTemplateDecl *SpecializedTemplate, |
| 1920 | ArrayRef<TemplateArgument> Args, |
| 1921 | const ASTTemplateArgumentListInfo *ArgsAsWritten, |
| 1922 | ClassTemplatePartialSpecializationDecl *PrevDecl); |
| 1923 | |
| 1924 | ClassTemplatePartialSpecializationDecl(ASTContext &C) |
| 1925 | : ClassTemplateSpecializationDecl(C, ClassTemplatePartialSpecialization), |
| 1926 | InstantiatedFromMember(nullptr, false) {} |
| 1927 | |
| 1928 | void anchor() override; |
| 1929 | |
| 1930 | public: |
| 1931 | friend class ASTDeclReader; |
| 1932 | friend class ASTDeclWriter; |
| 1933 | |
| 1934 | static ClassTemplatePartialSpecializationDecl * |
| 1935 | Create(ASTContext &Context, TagKind TK, DeclContext *DC, |
| 1936 | SourceLocation StartLoc, SourceLocation IdLoc, |
| 1937 | TemplateParameterList *Params, |
| 1938 | ClassTemplateDecl *SpecializedTemplate, |
| 1939 | ArrayRef<TemplateArgument> Args, |
| 1940 | const TemplateArgumentListInfo &ArgInfos, |
| 1941 | QualType CanonInjectedType, |
| 1942 | ClassTemplatePartialSpecializationDecl *PrevDecl); |
| 1943 | |
| 1944 | static ClassTemplatePartialSpecializationDecl * |
| 1945 | CreateDeserialized(ASTContext &C, unsigned ID); |
| 1946 | |
| 1947 | ClassTemplatePartialSpecializationDecl *getMostRecentDecl() { |
| 1948 | return cast<ClassTemplatePartialSpecializationDecl>( |
| 1949 | static_cast<ClassTemplateSpecializationDecl *>( |
| 1950 | this)->getMostRecentDecl()); |
| 1951 | } |
| 1952 | |
| 1953 | |
| 1954 | TemplateParameterList *getTemplateParameters() const { |
| 1955 | return TemplateParams; |
| 1956 | } |
| 1957 | |
| 1958 | |
| 1959 | const ASTTemplateArgumentListInfo *getTemplateArgsAsWritten() const { |
| 1960 | return ArgsAsWritten; |
| 1961 | } |
| 1962 | |
| 1963 | |
| 1964 | |
| 1965 | |
| 1966 | |
| 1967 | |
| 1968 | |
| 1969 | |
| 1970 | |
| 1971 | |
| 1972 | |
| 1973 | |
| 1974 | |
| 1975 | |
| 1976 | |
| 1977 | |
| 1978 | |
| 1979 | |
| 1980 | |
| 1981 | |
| 1982 | |
| 1983 | ClassTemplatePartialSpecializationDecl *getInstantiatedFromMember() const { |
| 1984 | const auto *First = |
| 1985 | cast<ClassTemplatePartialSpecializationDecl>(getFirstDecl()); |
| 1986 | return First->InstantiatedFromMember.getPointer(); |
| 1987 | } |
| 1988 | ClassTemplatePartialSpecializationDecl * |
| 1989 | getInstantiatedFromMemberTemplate() const { |
| 1990 | return getInstantiatedFromMember(); |
| 1991 | } |
| 1992 | |
| 1993 | void setInstantiatedFromMember( |
| 1994 | ClassTemplatePartialSpecializationDecl *PartialSpec) { |
| 1995 | auto *First = cast<ClassTemplatePartialSpecializationDecl>(getFirstDecl()); |
| 1996 | First->InstantiatedFromMember.setPointer(PartialSpec); |
| 1997 | } |
| 1998 | |
| 1999 | |
| 2000 | |
| 2001 | |
| 2002 | |
| 2003 | |
| 2004 | |
| 2005 | |
| 2006 | |
| 2007 | |
| 2008 | |
| 2009 | |
| 2010 | |
| 2011 | |
| 2012 | |
| 2013 | |
| 2014 | |
| 2015 | bool isMemberSpecialization() { |
| 2016 | const auto *First = |
| 2017 | cast<ClassTemplatePartialSpecializationDecl>(getFirstDecl()); |
| 2018 | return First->InstantiatedFromMember.getInt(); |
| 2019 | } |
| 2020 | |
| 2021 | |
| 2022 | void setMemberSpecialization() { |
| 2023 | auto *First = cast<ClassTemplatePartialSpecializationDecl>(getFirstDecl()); |
| 2024 | (0) . __assert_fail ("First->InstantiatedFromMember.getPointer() && \"Only member templates can be member template specializations\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 2025, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(First->InstantiatedFromMember.getPointer() && |
| 2025 | (0) . __assert_fail ("First->InstantiatedFromMember.getPointer() && \"Only member templates can be member template specializations\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 2025, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "Only member templates can be member template specializations"); |
| 2026 | return First->InstantiatedFromMember.setInt(true); |
| 2027 | } |
| 2028 | |
| 2029 | |
| 2030 | |
| 2031 | |
| 2032 | QualType getInjectedSpecializationType() const { |
| 2033 | (0) . __assert_fail ("getTypeForDecl() && \"partial specialization has no type set!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 2033, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(getTypeForDecl() && "partial specialization has no type set!"); |
| 2034 | return cast<InjectedClassNameType>(getTypeForDecl()) |
| 2035 | ->getInjectedSpecializationType(); |
| 2036 | } |
| 2037 | |
| 2038 | |
| 2039 | |
| 2040 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 2041 | |
| 2042 | static bool classofKind(Kind K) { |
| 2043 | return K == ClassTemplatePartialSpecialization; |
| 2044 | } |
| 2045 | }; |
| 2046 | |
| 2047 | |
| 2048 | class ClassTemplateDecl : public RedeclarableTemplateDecl { |
| 2049 | protected: |
| 2050 | |
| 2051 | |
| 2052 | struct Common : CommonBase { |
| 2053 | |
| 2054 | |
| 2055 | llvm::FoldingSetVector<ClassTemplateSpecializationDecl> Specializations; |
| 2056 | |
| 2057 | |
| 2058 | |
| 2059 | llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> |
| 2060 | PartialSpecializations; |
| 2061 | |
| 2062 | |
| 2063 | QualType InjectedClassNameType; |
| 2064 | |
| 2065 | Common() = default; |
| 2066 | }; |
| 2067 | |
| 2068 | |
| 2069 | llvm::FoldingSetVector<ClassTemplateSpecializationDecl> & |
| 2070 | getSpecializations() const; |
| 2071 | |
| 2072 | |
| 2073 | |
| 2074 | llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> & |
| 2075 | getPartialSpecializations(); |
| 2076 | |
| 2077 | ClassTemplateDecl(ConstrainedTemplateDeclInfo *CTDI, ASTContext &C, |
| 2078 | DeclContext *DC, SourceLocation L, DeclarationName Name, |
| 2079 | TemplateParameterList *Params, NamedDecl *Decl) |
| 2080 | : RedeclarableTemplateDecl(CTDI, ClassTemplate, C, DC, L, Name, Params, |
| 2081 | Decl) {} |
| 2082 | |
| 2083 | ClassTemplateDecl(ASTContext &C, DeclContext *DC, SourceLocation L, |
| 2084 | DeclarationName Name, TemplateParameterList *Params, |
| 2085 | NamedDecl *Decl) |
| 2086 | : ClassTemplateDecl(nullptr, C, DC, L, Name, Params, Decl) {} |
| 2087 | |
| 2088 | CommonBase *newCommon(ASTContext &C) const override; |
| 2089 | |
| 2090 | Common *getCommonPtr() const { |
| 2091 | return static_cast<Common *>(RedeclarableTemplateDecl::getCommonPtr()); |
| 2092 | } |
| 2093 | |
| 2094 | public: |
| 2095 | friend class ASTDeclReader; |
| 2096 | friend class ASTDeclWriter; |
| 2097 | |
| 2098 | |
| 2099 | void LoadLazySpecializations() const; |
| 2100 | |
| 2101 | |
| 2102 | CXXRecordDecl *getTemplatedDecl() const { |
| 2103 | return static_cast<CXXRecordDecl *>(TemplatedDecl); |
| 2104 | } |
| 2105 | |
| 2106 | |
| 2107 | |
| 2108 | bool isThisDeclarationADefinition() const { |
| 2109 | return getTemplatedDecl()->isThisDeclarationADefinition(); |
| 2110 | } |
| 2111 | |
| 2112 | |
| 2113 | |
| 2114 | static ClassTemplateDecl *Create(ASTContext &C, DeclContext *DC, |
| 2115 | SourceLocation L, |
| 2116 | DeclarationName Name, |
| 2117 | TemplateParameterList *Params, |
| 2118 | NamedDecl *Decl, |
| 2119 | Expr *AssociatedConstraints = nullptr); |
| 2120 | |
| 2121 | |
| 2122 | static ClassTemplateDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
| 2123 | |
| 2124 | |
| 2125 | |
| 2126 | ClassTemplateSpecializationDecl * |
| 2127 | findSpecialization(ArrayRef<TemplateArgument> Args, void *&InsertPos); |
| 2128 | |
| 2129 | |
| 2130 | |
| 2131 | void AddSpecialization(ClassTemplateSpecializationDecl *D, void *InsertPos); |
| 2132 | |
| 2133 | ClassTemplateDecl *getCanonicalDecl() override { |
| 2134 | return cast<ClassTemplateDecl>( |
| 2135 | RedeclarableTemplateDecl::getCanonicalDecl()); |
| 2136 | } |
| 2137 | const ClassTemplateDecl *getCanonicalDecl() const { |
| 2138 | return cast<ClassTemplateDecl>( |
| 2139 | RedeclarableTemplateDecl::getCanonicalDecl()); |
| 2140 | } |
| 2141 | |
| 2142 | |
| 2143 | |
| 2144 | ClassTemplateDecl *getPreviousDecl() { |
| 2145 | return cast_or_null<ClassTemplateDecl>( |
| 2146 | static_cast<RedeclarableTemplateDecl *>(this)->getPreviousDecl()); |
| 2147 | } |
| 2148 | const ClassTemplateDecl *getPreviousDecl() const { |
| 2149 | return cast_or_null<ClassTemplateDecl>( |
| 2150 | static_cast<const RedeclarableTemplateDecl *>( |
| 2151 | this)->getPreviousDecl()); |
| 2152 | } |
| 2153 | |
| 2154 | ClassTemplateDecl *getMostRecentDecl() { |
| 2155 | return cast<ClassTemplateDecl>( |
| 2156 | static_cast<RedeclarableTemplateDecl *>(this)->getMostRecentDecl()); |
| 2157 | } |
| 2158 | const ClassTemplateDecl *getMostRecentDecl() const { |
| 2159 | return const_cast<ClassTemplateDecl*>(this)->getMostRecentDecl(); |
| 2160 | } |
| 2161 | |
| 2162 | ClassTemplateDecl *getInstantiatedFromMemberTemplate() const { |
| 2163 | return cast_or_null<ClassTemplateDecl>( |
| 2164 | RedeclarableTemplateDecl::getInstantiatedFromMemberTemplate()); |
| 2165 | } |
| 2166 | |
| 2167 | |
| 2168 | |
| 2169 | ClassTemplatePartialSpecializationDecl * |
| 2170 | findPartialSpecialization(ArrayRef<TemplateArgument> Args, void *&InsertPos); |
| 2171 | |
| 2172 | |
| 2173 | |
| 2174 | void AddPartialSpecialization(ClassTemplatePartialSpecializationDecl *D, |
| 2175 | void *InsertPos); |
| 2176 | |
| 2177 | |
| 2178 | void getPartialSpecializations( |
| 2179 | SmallVectorImpl<ClassTemplatePartialSpecializationDecl *> &PS); |
| 2180 | |
| 2181 | |
| 2182 | |
| 2183 | |
| 2184 | |
| 2185 | |
| 2186 | |
| 2187 | |
| 2188 | |
| 2189 | ClassTemplatePartialSpecializationDecl *findPartialSpecialization(QualType T); |
| 2190 | |
| 2191 | |
| 2192 | |
| 2193 | |
| 2194 | |
| 2195 | |
| 2196 | |
| 2197 | |
| 2198 | |
| 2199 | ClassTemplatePartialSpecializationDecl * |
| 2200 | findPartialSpecInstantiatedFromMember( |
| 2201 | ClassTemplatePartialSpecializationDecl *D); |
| 2202 | |
| 2203 | |
| 2204 | |
| 2205 | |
| 2206 | |
| 2207 | |
| 2208 | |
| 2209 | |
| 2210 | |
| 2211 | |
| 2212 | |
| 2213 | |
| 2214 | |
| 2215 | |
| 2216 | |
| 2217 | QualType getInjectedClassNameSpecialization(); |
| 2218 | |
| 2219 | using spec_iterator = SpecIterator<ClassTemplateSpecializationDecl>; |
| 2220 | using spec_range = llvm::iterator_range<spec_iterator>; |
| 2221 | |
| 2222 | spec_range specializations() const { |
| 2223 | return spec_range(spec_begin(), spec_end()); |
| 2224 | } |
| 2225 | |
| 2226 | spec_iterator spec_begin() const { |
| 2227 | return makeSpecIterator(getSpecializations(), false); |
| 2228 | } |
| 2229 | |
| 2230 | spec_iterator spec_end() const { |
| 2231 | return makeSpecIterator(getSpecializations(), true); |
| 2232 | } |
| 2233 | |
| 2234 | |
| 2235 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 2236 | static bool classofKind(Kind K) { return K == ClassTemplate; } |
| 2237 | }; |
| 2238 | |
| 2239 | |
| 2240 | |
| 2241 | |
| 2242 | |
| 2243 | |
| 2244 | |
| 2245 | |
| 2246 | |
| 2247 | |
| 2248 | |
| 2249 | |
| 2250 | |
| 2251 | |
| 2252 | class FriendTemplateDecl : public Decl { |
| 2253 | virtual void anchor(); |
| 2254 | |
| 2255 | public: |
| 2256 | using FriendUnion = llvm::PointerUnion<NamedDecl *,TypeSourceInfo *>; |
| 2257 | |
| 2258 | private: |
| 2259 | |
| 2260 | unsigned NumParams = 0; |
| 2261 | |
| 2262 | |
| 2263 | TemplateParameterList **Params = nullptr; |
| 2264 | |
| 2265 | |
| 2266 | FriendUnion Friend; |
| 2267 | |
| 2268 | |
| 2269 | SourceLocation FriendLoc; |
| 2270 | |
| 2271 | FriendTemplateDecl(DeclContext *DC, SourceLocation Loc, |
| 2272 | MutableArrayRef<TemplateParameterList *> Params, |
| 2273 | FriendUnion Friend, SourceLocation FriendLoc) |
| 2274 | : Decl(Decl::FriendTemplate, DC, Loc), NumParams(Params.size()), |
| 2275 | Params(Params.data()), Friend(Friend), FriendLoc(FriendLoc) {} |
| 2276 | |
| 2277 | FriendTemplateDecl(EmptyShell Empty) : Decl(Decl::FriendTemplate, Empty) {} |
| 2278 | |
| 2279 | public: |
| 2280 | friend class ASTDeclReader; |
| 2281 | |
| 2282 | static FriendTemplateDecl * |
| 2283 | Create(ASTContext &Context, DeclContext *DC, SourceLocation Loc, |
| 2284 | MutableArrayRef<TemplateParameterList *> Params, FriendUnion Friend, |
| 2285 | SourceLocation FriendLoc); |
| 2286 | |
| 2287 | static FriendTemplateDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
| 2288 | |
| 2289 | |
| 2290 | |
| 2291 | |
| 2292 | TypeSourceInfo *getFriendType() const { |
| 2293 | return Friend.dyn_cast<TypeSourceInfo*>(); |
| 2294 | } |
| 2295 | |
| 2296 | |
| 2297 | |
| 2298 | |
| 2299 | NamedDecl *getFriendDecl() const { |
| 2300 | return Friend.dyn_cast<NamedDecl*>(); |
| 2301 | } |
| 2302 | |
| 2303 | |
| 2304 | SourceLocation getFriendLoc() const { |
| 2305 | return FriendLoc; |
| 2306 | } |
| 2307 | |
| 2308 | TemplateParameterList *getTemplateParameterList(unsigned i) const { |
| 2309 | assert(i <= NumParams); |
| 2310 | return Params[i]; |
| 2311 | } |
| 2312 | |
| 2313 | unsigned getNumTemplateParameters() const { |
| 2314 | return NumParams; |
| 2315 | } |
| 2316 | |
| 2317 | |
| 2318 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 2319 | static bool classofKind(Kind K) { return K == Decl::FriendTemplate; } |
| 2320 | }; |
| 2321 | |
| 2322 | |
| 2323 | |
| 2324 | |
| 2325 | |
| 2326 | |
| 2327 | |
| 2328 | class TypeAliasTemplateDecl : public RedeclarableTemplateDecl { |
| 2329 | protected: |
| 2330 | using Common = CommonBase; |
| 2331 | |
| 2332 | TypeAliasTemplateDecl(ASTContext &C, DeclContext *DC, SourceLocation L, |
| 2333 | DeclarationName Name, TemplateParameterList *Params, |
| 2334 | NamedDecl *Decl) |
| 2335 | : RedeclarableTemplateDecl(TypeAliasTemplate, C, DC, L, Name, Params, |
| 2336 | Decl) {} |
| 2337 | |
| 2338 | CommonBase *newCommon(ASTContext &C) const override; |
| 2339 | |
| 2340 | Common *getCommonPtr() { |
| 2341 | return static_cast<Common *>(RedeclarableTemplateDecl::getCommonPtr()); |
| 2342 | } |
| 2343 | |
| 2344 | public: |
| 2345 | friend class ASTDeclReader; |
| 2346 | friend class ASTDeclWriter; |
| 2347 | |
| 2348 | |
| 2349 | TypeAliasDecl *getTemplatedDecl() const { |
| 2350 | return static_cast<TypeAliasDecl *>(TemplatedDecl); |
| 2351 | } |
| 2352 | |
| 2353 | |
| 2354 | TypeAliasTemplateDecl *getCanonicalDecl() override { |
| 2355 | return cast<TypeAliasTemplateDecl>( |
| 2356 | RedeclarableTemplateDecl::getCanonicalDecl()); |
| 2357 | } |
| 2358 | const TypeAliasTemplateDecl *getCanonicalDecl() const { |
| 2359 | return cast<TypeAliasTemplateDecl>( |
| 2360 | RedeclarableTemplateDecl::getCanonicalDecl()); |
| 2361 | } |
| 2362 | |
| 2363 | |
| 2364 | |
| 2365 | TypeAliasTemplateDecl *getPreviousDecl() { |
| 2366 | return cast_or_null<TypeAliasTemplateDecl>( |
| 2367 | static_cast<RedeclarableTemplateDecl *>(this)->getPreviousDecl()); |
| 2368 | } |
| 2369 | const TypeAliasTemplateDecl *getPreviousDecl() const { |
| 2370 | return cast_or_null<TypeAliasTemplateDecl>( |
| 2371 | static_cast<const RedeclarableTemplateDecl *>( |
| 2372 | this)->getPreviousDecl()); |
| 2373 | } |
| 2374 | |
| 2375 | TypeAliasTemplateDecl *getInstantiatedFromMemberTemplate() const { |
| 2376 | return cast_or_null<TypeAliasTemplateDecl>( |
| 2377 | RedeclarableTemplateDecl::getInstantiatedFromMemberTemplate()); |
| 2378 | } |
| 2379 | |
| 2380 | |
| 2381 | static TypeAliasTemplateDecl *Create(ASTContext &C, DeclContext *DC, |
| 2382 | SourceLocation L, |
| 2383 | DeclarationName Name, |
| 2384 | TemplateParameterList *Params, |
| 2385 | NamedDecl *Decl); |
| 2386 | |
| 2387 | |
| 2388 | static TypeAliasTemplateDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
| 2389 | |
| 2390 | |
| 2391 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 2392 | static bool classofKind(Kind K) { return K == TypeAliasTemplate; } |
| 2393 | }; |
| 2394 | |
| 2395 | |
| 2396 | |
| 2397 | |
| 2398 | |
| 2399 | |
| 2400 | |
| 2401 | |
| 2402 | |
| 2403 | |
| 2404 | |
| 2405 | |
| 2406 | |
| 2407 | |
| 2408 | |
| 2409 | |
| 2410 | |
| 2411 | class ClassScopeFunctionSpecializationDecl : public Decl { |
| 2412 | CXXMethodDecl *Specialization; |
| 2413 | bool HasExplicitTemplateArgs; |
| 2414 | TemplateArgumentListInfo TemplateArgs; |
| 2415 | |
| 2416 | ClassScopeFunctionSpecializationDecl(DeclContext *DC, SourceLocation Loc, |
| 2417 | CXXMethodDecl *FD, bool Args, |
| 2418 | TemplateArgumentListInfo TemplArgs) |
| 2419 | : Decl(Decl::ClassScopeFunctionSpecialization, DC, Loc), |
| 2420 | Specialization(FD), HasExplicitTemplateArgs(Args), |
| 2421 | TemplateArgs(std::move(TemplArgs)) {} |
| 2422 | |
| 2423 | ClassScopeFunctionSpecializationDecl(EmptyShell Empty) |
| 2424 | : Decl(Decl::ClassScopeFunctionSpecialization, Empty) {} |
| 2425 | |
| 2426 | virtual void anchor(); |
| 2427 | |
| 2428 | public: |
| 2429 | friend class ASTDeclReader; |
| 2430 | friend class ASTDeclWriter; |
| 2431 | |
| 2432 | CXXMethodDecl *getSpecialization() const { return Specialization; } |
| 2433 | bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; } |
| 2434 | const TemplateArgumentListInfo& templateArgs() const { return TemplateArgs; } |
| 2435 | |
| 2436 | static ClassScopeFunctionSpecializationDecl *Create(ASTContext &C, |
| 2437 | DeclContext *DC, |
| 2438 | SourceLocation Loc, |
| 2439 | CXXMethodDecl *FD, |
| 2440 | bool HasExplicitTemplateArgs, |
| 2441 | TemplateArgumentListInfo TemplateArgs) { |
| 2442 | return new (C, DC) ClassScopeFunctionSpecializationDecl( |
| 2443 | DC, Loc, FD, HasExplicitTemplateArgs, std::move(TemplateArgs)); |
| 2444 | } |
| 2445 | |
| 2446 | static ClassScopeFunctionSpecializationDecl * |
| 2447 | CreateDeserialized(ASTContext &Context, unsigned ID); |
| 2448 | |
| 2449 | |
| 2450 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 2451 | |
| 2452 | static bool classofKind(Kind K) { |
| 2453 | return K == Decl::ClassScopeFunctionSpecialization; |
| 2454 | } |
| 2455 | }; |
| 2456 | |
| 2457 | |
| 2458 | inline AnyFunctionDecl::AnyFunctionDecl(FunctionTemplateDecl *FTD) |
| 2459 | : Function(FTD) {} |
| 2460 | |
| 2461 | |
| 2462 | |
| 2463 | |
| 2464 | |
| 2465 | |
| 2466 | |
| 2467 | |
| 2468 | |
| 2469 | |
| 2470 | |
| 2471 | |
| 2472 | |
| 2473 | |
| 2474 | class VarTemplateSpecializationDecl : public VarDecl, |
| 2475 | public llvm::FoldingSetNode { |
| 2476 | |
| 2477 | |
| 2478 | |
| 2479 | |
| 2480 | struct SpecializedPartialSpecialization { |
| 2481 | |
| 2482 | |
| 2483 | VarTemplatePartialSpecializationDecl *PartialSpecialization; |
| 2484 | |
| 2485 | |
| 2486 | |
| 2487 | const TemplateArgumentList *TemplateArgs; |
| 2488 | }; |
| 2489 | |
| 2490 | |
| 2491 | llvm::PointerUnion<VarTemplateDecl *, SpecializedPartialSpecialization *> |
| 2492 | SpecializedTemplate; |
| 2493 | |
| 2494 | |
| 2495 | struct ExplicitSpecializationInfo { |
| 2496 | |
| 2497 | TypeSourceInfo *TypeAsWritten = nullptr; |
| 2498 | |
| 2499 | |
| 2500 | SourceLocation ExternLoc; |
| 2501 | |
| 2502 | |
| 2503 | SourceLocation TemplateKeywordLoc; |
| 2504 | |
| 2505 | ExplicitSpecializationInfo() = default; |
| 2506 | }; |
| 2507 | |
| 2508 | |
| 2509 | |
| 2510 | ExplicitSpecializationInfo *ExplicitInfo = nullptr; |
| 2511 | |
| 2512 | |
| 2513 | const TemplateArgumentList *TemplateArgs; |
| 2514 | TemplateArgumentListInfo TemplateArgsInfo; |
| 2515 | |
| 2516 | |
| 2517 | SourceLocation PointOfInstantiation; |
| 2518 | |
| 2519 | |
| 2520 | |
| 2521 | unsigned SpecializationKind : 3; |
| 2522 | |
| 2523 | |
| 2524 | |
| 2525 | |
| 2526 | |
| 2527 | unsigned IsCompleteDefinition : 1; |
| 2528 | |
| 2529 | protected: |
| 2530 | VarTemplateSpecializationDecl(Kind DK, ASTContext &Context, DeclContext *DC, |
| 2531 | SourceLocation StartLoc, SourceLocation IdLoc, |
| 2532 | VarTemplateDecl *SpecializedTemplate, |
| 2533 | QualType T, TypeSourceInfo *TInfo, |
| 2534 | StorageClass S, |
| 2535 | ArrayRef<TemplateArgument> Args); |
| 2536 | |
| 2537 | explicit VarTemplateSpecializationDecl(Kind DK, ASTContext &Context); |
| 2538 | |
| 2539 | public: |
| 2540 | friend class ASTDeclReader; |
| 2541 | friend class ASTDeclWriter; |
| 2542 | friend class VarDecl; |
| 2543 | |
| 2544 | static VarTemplateSpecializationDecl * |
| 2545 | Create(ASTContext &Context, DeclContext *DC, SourceLocation StartLoc, |
| 2546 | SourceLocation IdLoc, VarTemplateDecl *SpecializedTemplate, QualType T, |
| 2547 | TypeSourceInfo *TInfo, StorageClass S, |
| 2548 | ArrayRef<TemplateArgument> Args); |
| 2549 | static VarTemplateSpecializationDecl *CreateDeserialized(ASTContext &C, |
| 2550 | unsigned ID); |
| 2551 | |
| 2552 | void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy, |
| 2553 | bool Qualified) const override; |
| 2554 | |
| 2555 | VarTemplateSpecializationDecl *getMostRecentDecl() { |
| 2556 | VarDecl *Recent = static_cast<VarDecl *>(this)->getMostRecentDecl(); |
| 2557 | return cast<VarTemplateSpecializationDecl>(Recent); |
| 2558 | } |
| 2559 | |
| 2560 | |
| 2561 | VarTemplateDecl *getSpecializedTemplate() const; |
| 2562 | |
| 2563 | |
| 2564 | |
| 2565 | const TemplateArgumentList &getTemplateArgs() const { return *TemplateArgs; } |
| 2566 | |
| 2567 | |
| 2568 | void setTemplateArgsInfo(const TemplateArgumentListInfo &ArgsInfo); |
| 2569 | |
| 2570 | const TemplateArgumentListInfo &getTemplateArgsInfo() const { |
| 2571 | return TemplateArgsInfo; |
| 2572 | } |
| 2573 | |
| 2574 | |
| 2575 | |
| 2576 | TemplateSpecializationKind getSpecializationKind() const { |
| 2577 | return static_cast<TemplateSpecializationKind>(SpecializationKind); |
| 2578 | } |
| 2579 | |
| 2580 | bool isExplicitSpecialization() const { |
| 2581 | return getSpecializationKind() == TSK_ExplicitSpecialization; |
| 2582 | } |
| 2583 | |
| 2584 | |
| 2585 | |
| 2586 | |
| 2587 | bool isExplicitInstantiationOrSpecialization() const { |
| 2588 | return isTemplateExplicitInstantiationOrSpecialization( |
| 2589 | getTemplateSpecializationKind()); |
| 2590 | } |
| 2591 | |
| 2592 | void setSpecializationKind(TemplateSpecializationKind TSK) { |
| 2593 | SpecializationKind = TSK; |
| 2594 | } |
| 2595 | |
| 2596 | |
| 2597 | SourceLocation getPointOfInstantiation() const { |
| 2598 | return PointOfInstantiation; |
| 2599 | } |
| 2600 | |
| 2601 | void setPointOfInstantiation(SourceLocation Loc) { |
| 2602 | (0) . __assert_fail ("Loc.isValid() && \"point of instantiation must be valid!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 2602, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(Loc.isValid() && "point of instantiation must be valid!"); |
| 2603 | PointOfInstantiation = Loc; |
| 2604 | } |
| 2605 | |
| 2606 | void setCompleteDefinition() { IsCompleteDefinition = true; } |
| 2607 | |
| 2608 | |
| 2609 | |
| 2610 | |
| 2611 | |
| 2612 | llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *> |
| 2613 | getInstantiatedFrom() const { |
| 2614 | if (!isTemplateInstantiation(getSpecializationKind())) |
| 2615 | return llvm::PointerUnion<VarTemplateDecl *, |
| 2616 | VarTemplatePartialSpecializationDecl *>(); |
| 2617 | |
| 2618 | return getSpecializedTemplateOrPartial(); |
| 2619 | } |
| 2620 | |
| 2621 | |
| 2622 | |
| 2623 | llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *> |
| 2624 | getSpecializedTemplateOrPartial() const { |
| 2625 | if (const auto *PartialSpec = |
| 2626 | SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>()) |
| 2627 | return PartialSpec->PartialSpecialization; |
| 2628 | |
| 2629 | return SpecializedTemplate.get<VarTemplateDecl *>(); |
| 2630 | } |
| 2631 | |
| 2632 | |
| 2633 | |
| 2634 | |
| 2635 | |
| 2636 | |
| 2637 | |
| 2638 | |
| 2639 | |
| 2640 | |
| 2641 | |
| 2642 | |
| 2643 | const TemplateArgumentList &getTemplateInstantiationArgs() const { |
| 2644 | if (const auto *PartialSpec = |
| 2645 | SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>()) |
| 2646 | return *PartialSpec->TemplateArgs; |
| 2647 | |
| 2648 | return getTemplateArgs(); |
| 2649 | } |
| 2650 | |
| 2651 | |
| 2652 | |
| 2653 | |
| 2654 | void setInstantiationOf(VarTemplatePartialSpecializationDecl *PartialSpec, |
| 2655 | const TemplateArgumentList *TemplateArgs) { |
| 2656 | (0) . __assert_fail ("!SpecializedTemplate.is() && \"Already set to a variable template partial specialization!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 2657, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(!SpecializedTemplate.is<SpecializedPartialSpecialization *>() && |
| 2657 | (0) . __assert_fail ("!SpecializedTemplate.is() && \"Already set to a variable template partial specialization!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 2657, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "Already set to a variable template partial specialization!"); |
| 2658 | auto *PS = new (getASTContext()) SpecializedPartialSpecialization(); |
| 2659 | PS->PartialSpecialization = PartialSpec; |
| 2660 | PS->TemplateArgs = TemplateArgs; |
| 2661 | SpecializedTemplate = PS; |
| 2662 | } |
| 2663 | |
| 2664 | |
| 2665 | |
| 2666 | void setInstantiationOf(VarTemplateDecl *TemplDecl) { |
| 2667 | (0) . __assert_fail ("!SpecializedTemplate.is() && \"Previously set to a variable template partial specialization!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 2668, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(!SpecializedTemplate.is<SpecializedPartialSpecialization *>() && |
| 2668 | (0) . __assert_fail ("!SpecializedTemplate.is() && \"Previously set to a variable template partial specialization!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 2668, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "Previously set to a variable template partial specialization!"); |
| 2669 | SpecializedTemplate = TemplDecl; |
| 2670 | } |
| 2671 | |
| 2672 | |
| 2673 | |
| 2674 | void setTypeAsWritten(TypeSourceInfo *T) { |
| 2675 | if (!ExplicitInfo) |
| 2676 | ExplicitInfo = new (getASTContext()) ExplicitSpecializationInfo; |
| 2677 | ExplicitInfo->TypeAsWritten = T; |
| 2678 | } |
| 2679 | |
| 2680 | |
| 2681 | |
| 2682 | TypeSourceInfo *getTypeAsWritten() const { |
| 2683 | return ExplicitInfo ? ExplicitInfo->TypeAsWritten : nullptr; |
| 2684 | } |
| 2685 | |
| 2686 | |
| 2687 | SourceLocation getExternLoc() const { |
| 2688 | return ExplicitInfo ? ExplicitInfo->ExternLoc : SourceLocation(); |
| 2689 | } |
| 2690 | |
| 2691 | |
| 2692 | void setExternLoc(SourceLocation Loc) { |
| 2693 | if (!ExplicitInfo) |
| 2694 | ExplicitInfo = new (getASTContext()) ExplicitSpecializationInfo; |
| 2695 | ExplicitInfo->ExternLoc = Loc; |
| 2696 | } |
| 2697 | |
| 2698 | |
| 2699 | void setTemplateKeywordLoc(SourceLocation Loc) { |
| 2700 | if (!ExplicitInfo) |
| 2701 | ExplicitInfo = new (getASTContext()) ExplicitSpecializationInfo; |
| 2702 | ExplicitInfo->TemplateKeywordLoc = Loc; |
| 2703 | } |
| 2704 | |
| 2705 | |
| 2706 | SourceLocation getTemplateKeywordLoc() const { |
| 2707 | return ExplicitInfo ? ExplicitInfo->TemplateKeywordLoc : SourceLocation(); |
| 2708 | } |
| 2709 | |
| 2710 | void Profile(llvm::FoldingSetNodeID &ID) const { |
| 2711 | Profile(ID, TemplateArgs->asArray(), getASTContext()); |
| 2712 | } |
| 2713 | |
| 2714 | static void Profile(llvm::FoldingSetNodeID &ID, |
| 2715 | ArrayRef<TemplateArgument> TemplateArgs, |
| 2716 | ASTContext &Context) { |
| 2717 | ID.AddInteger(TemplateArgs.size()); |
| 2718 | for (const TemplateArgument &TemplateArg : TemplateArgs) |
| 2719 | TemplateArg.Profile(ID, Context); |
| 2720 | } |
| 2721 | |
| 2722 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 2723 | |
| 2724 | static bool classofKind(Kind K) { |
| 2725 | return K >= firstVarTemplateSpecialization && |
| 2726 | K <= lastVarTemplateSpecialization; |
| 2727 | } |
| 2728 | }; |
| 2729 | |
| 2730 | class VarTemplatePartialSpecializationDecl |
| 2731 | : public VarTemplateSpecializationDecl { |
| 2732 | |
| 2733 | TemplateParameterList *TemplateParams = nullptr; |
| 2734 | |
| 2735 | |
| 2736 | |
| 2737 | const ASTTemplateArgumentListInfo *ArgsAsWritten = nullptr; |
| 2738 | |
| 2739 | |
| 2740 | |
| 2741 | |
| 2742 | |
| 2743 | |
| 2744 | llvm::PointerIntPair<VarTemplatePartialSpecializationDecl *, 1, bool> |
| 2745 | InstantiatedFromMember; |
| 2746 | |
| 2747 | VarTemplatePartialSpecializationDecl( |
| 2748 | ASTContext &Context, DeclContext *DC, SourceLocation StartLoc, |
| 2749 | SourceLocation IdLoc, TemplateParameterList *Params, |
| 2750 | VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo, |
| 2751 | StorageClass S, ArrayRef<TemplateArgument> Args, |
| 2752 | const ASTTemplateArgumentListInfo *ArgInfos); |
| 2753 | |
| 2754 | VarTemplatePartialSpecializationDecl(ASTContext &Context) |
| 2755 | : VarTemplateSpecializationDecl(VarTemplatePartialSpecialization, |
| 2756 | Context), |
| 2757 | InstantiatedFromMember(nullptr, false) {} |
| 2758 | |
| 2759 | void anchor() override; |
| 2760 | |
| 2761 | public: |
| 2762 | friend class ASTDeclReader; |
| 2763 | friend class ASTDeclWriter; |
| 2764 | |
| 2765 | static VarTemplatePartialSpecializationDecl * |
| 2766 | Create(ASTContext &Context, DeclContext *DC, SourceLocation StartLoc, |
| 2767 | SourceLocation IdLoc, TemplateParameterList *Params, |
| 2768 | VarTemplateDecl *SpecializedTemplate, QualType T, |
| 2769 | TypeSourceInfo *TInfo, StorageClass S, ArrayRef<TemplateArgument> Args, |
| 2770 | const TemplateArgumentListInfo &ArgInfos); |
| 2771 | |
| 2772 | static VarTemplatePartialSpecializationDecl *CreateDeserialized(ASTContext &C, |
| 2773 | unsigned ID); |
| 2774 | |
| 2775 | VarTemplatePartialSpecializationDecl *getMostRecentDecl() { |
| 2776 | return cast<VarTemplatePartialSpecializationDecl>( |
| 2777 | static_cast<VarTemplateSpecializationDecl *>( |
| 2778 | this)->getMostRecentDecl()); |
| 2779 | } |
| 2780 | |
| 2781 | |
| 2782 | TemplateParameterList *getTemplateParameters() const { |
| 2783 | return TemplateParams; |
| 2784 | } |
| 2785 | |
| 2786 | |
| 2787 | const ASTTemplateArgumentListInfo *getTemplateArgsAsWritten() const { |
| 2788 | return ArgsAsWritten; |
| 2789 | } |
| 2790 | |
| 2791 | |
| 2792 | |
| 2793 | |
| 2794 | |
| 2795 | |
| 2796 | |
| 2797 | |
| 2798 | |
| 2799 | |
| 2800 | |
| 2801 | |
| 2802 | |
| 2803 | |
| 2804 | |
| 2805 | |
| 2806 | |
| 2807 | |
| 2808 | |
| 2809 | |
| 2810 | |
| 2811 | VarTemplatePartialSpecializationDecl *getInstantiatedFromMember() const { |
| 2812 | const auto *First = |
| 2813 | cast<VarTemplatePartialSpecializationDecl>(getFirstDecl()); |
| 2814 | return First->InstantiatedFromMember.getPointer(); |
| 2815 | } |
| 2816 | |
| 2817 | void |
| 2818 | setInstantiatedFromMember(VarTemplatePartialSpecializationDecl *PartialSpec) { |
| 2819 | auto *First = cast<VarTemplatePartialSpecializationDecl>(getFirstDecl()); |
| 2820 | First->InstantiatedFromMember.setPointer(PartialSpec); |
| 2821 | } |
| 2822 | |
| 2823 | |
| 2824 | |
| 2825 | |
| 2826 | |
| 2827 | |
| 2828 | |
| 2829 | |
| 2830 | |
| 2831 | |
| 2832 | |
| 2833 | |
| 2834 | |
| 2835 | |
| 2836 | |
| 2837 | |
| 2838 | |
| 2839 | bool isMemberSpecialization() { |
| 2840 | const auto *First = |
| 2841 | cast<VarTemplatePartialSpecializationDecl>(getFirstDecl()); |
| 2842 | return First->InstantiatedFromMember.getInt(); |
| 2843 | } |
| 2844 | |
| 2845 | |
| 2846 | void setMemberSpecialization() { |
| 2847 | auto *First = cast<VarTemplatePartialSpecializationDecl>(getFirstDecl()); |
| 2848 | (0) . __assert_fail ("First->InstantiatedFromMember.getPointer() && \"Only member templates can be member template specializations\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 2849, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(First->InstantiatedFromMember.getPointer() && |
| 2849 | (0) . __assert_fail ("First->InstantiatedFromMember.getPointer() && \"Only member templates can be member template specializations\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 2849, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "Only member templates can be member template specializations"); |
| 2850 | return First->InstantiatedFromMember.setInt(true); |
| 2851 | } |
| 2852 | |
| 2853 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 2854 | |
| 2855 | static bool classofKind(Kind K) { |
| 2856 | return K == VarTemplatePartialSpecialization; |
| 2857 | } |
| 2858 | }; |
| 2859 | |
| 2860 | |
| 2861 | class VarTemplateDecl : public RedeclarableTemplateDecl { |
| 2862 | protected: |
| 2863 | |
| 2864 | |
| 2865 | struct Common : CommonBase { |
| 2866 | |
| 2867 | |
| 2868 | llvm::FoldingSetVector<VarTemplateSpecializationDecl> Specializations; |
| 2869 | |
| 2870 | |
| 2871 | |
| 2872 | llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl> |
| 2873 | PartialSpecializations; |
| 2874 | |
| 2875 | Common() = default; |
| 2876 | }; |
| 2877 | |
| 2878 | |
| 2879 | llvm::FoldingSetVector<VarTemplateSpecializationDecl> & |
| 2880 | getSpecializations() const; |
| 2881 | |
| 2882 | |
| 2883 | |
| 2884 | llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl> & |
| 2885 | getPartialSpecializations(); |
| 2886 | |
| 2887 | VarTemplateDecl(ASTContext &C, DeclContext *DC, SourceLocation L, |
| 2888 | DeclarationName Name, TemplateParameterList *Params, |
| 2889 | NamedDecl *Decl) |
| 2890 | : RedeclarableTemplateDecl(VarTemplate, C, DC, L, Name, Params, Decl) {} |
| 2891 | |
| 2892 | CommonBase *newCommon(ASTContext &C) const override; |
| 2893 | |
| 2894 | Common *getCommonPtr() const { |
| 2895 | return static_cast<Common *>(RedeclarableTemplateDecl::getCommonPtr()); |
| 2896 | } |
| 2897 | |
| 2898 | public: |
| 2899 | friend class ASTDeclReader; |
| 2900 | friend class ASTDeclWriter; |
| 2901 | |
| 2902 | |
| 2903 | void LoadLazySpecializations() const; |
| 2904 | |
| 2905 | |
| 2906 | VarDecl *getTemplatedDecl() const { |
| 2907 | return static_cast<VarDecl *>(TemplatedDecl); |
| 2908 | } |
| 2909 | |
| 2910 | |
| 2911 | |
| 2912 | bool isThisDeclarationADefinition() const { |
| 2913 | return getTemplatedDecl()->isThisDeclarationADefinition(); |
| 2914 | } |
| 2915 | |
| 2916 | VarTemplateDecl *getDefinition(); |
| 2917 | |
| 2918 | |
| 2919 | static VarTemplateDecl *Create(ASTContext &C, DeclContext *DC, |
| 2920 | SourceLocation L, DeclarationName Name, |
| 2921 | TemplateParameterList *Params, |
| 2922 | VarDecl *Decl); |
| 2923 | |
| 2924 | |
| 2925 | static VarTemplateDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
| 2926 | |
| 2927 | |
| 2928 | |
| 2929 | VarTemplateSpecializationDecl * |
| 2930 | findSpecialization(ArrayRef<TemplateArgument> Args, void *&InsertPos); |
| 2931 | |
| 2932 | |
| 2933 | |
| 2934 | void AddSpecialization(VarTemplateSpecializationDecl *D, void *InsertPos); |
| 2935 | |
| 2936 | VarTemplateDecl *getCanonicalDecl() override { |
| 2937 | return cast<VarTemplateDecl>(RedeclarableTemplateDecl::getCanonicalDecl()); |
| 2938 | } |
| 2939 | const VarTemplateDecl *getCanonicalDecl() const { |
| 2940 | return cast<VarTemplateDecl>(RedeclarableTemplateDecl::getCanonicalDecl()); |
| 2941 | } |
| 2942 | |
| 2943 | |
| 2944 | |
| 2945 | VarTemplateDecl *getPreviousDecl() { |
| 2946 | return cast_or_null<VarTemplateDecl>( |
| 2947 | static_cast<RedeclarableTemplateDecl *>(this)->getPreviousDecl()); |
| 2948 | } |
| 2949 | const VarTemplateDecl *getPreviousDecl() const { |
| 2950 | return cast_or_null<VarTemplateDecl>( |
| 2951 | static_cast<const RedeclarableTemplateDecl *>( |
| 2952 | this)->getPreviousDecl()); |
| 2953 | } |
| 2954 | |
| 2955 | VarTemplateDecl *getMostRecentDecl() { |
| 2956 | return cast<VarTemplateDecl>( |
| 2957 | static_cast<RedeclarableTemplateDecl *>(this)->getMostRecentDecl()); |
| 2958 | } |
| 2959 | const VarTemplateDecl *getMostRecentDecl() const { |
| 2960 | return const_cast<VarTemplateDecl *>(this)->getMostRecentDecl(); |
| 2961 | } |
| 2962 | |
| 2963 | VarTemplateDecl *getInstantiatedFromMemberTemplate() const { |
| 2964 | return cast_or_null<VarTemplateDecl>( |
| 2965 | RedeclarableTemplateDecl::getInstantiatedFromMemberTemplate()); |
| 2966 | } |
| 2967 | |
| 2968 | |
| 2969 | |
| 2970 | VarTemplatePartialSpecializationDecl * |
| 2971 | findPartialSpecialization(ArrayRef<TemplateArgument> Args, void *&InsertPos); |
| 2972 | |
| 2973 | |
| 2974 | |
| 2975 | void AddPartialSpecialization(VarTemplatePartialSpecializationDecl *D, |
| 2976 | void *InsertPos); |
| 2977 | |
| 2978 | |
| 2979 | void getPartialSpecializations( |
| 2980 | SmallVectorImpl<VarTemplatePartialSpecializationDecl *> &PS); |
| 2981 | |
| 2982 | |
| 2983 | |
| 2984 | |
| 2985 | |
| 2986 | |
| 2987 | |
| 2988 | |
| 2989 | |
| 2990 | |
| 2991 | |
| 2992 | VarTemplatePartialSpecializationDecl *findPartialSpecInstantiatedFromMember( |
| 2993 | VarTemplatePartialSpecializationDecl *D); |
| 2994 | |
| 2995 | using spec_iterator = SpecIterator<VarTemplateSpecializationDecl>; |
| 2996 | using spec_range = llvm::iterator_range<spec_iterator>; |
| 2997 | |
| 2998 | spec_range specializations() const { |
| 2999 | return spec_range(spec_begin(), spec_end()); |
| 3000 | } |
| 3001 | |
| 3002 | spec_iterator spec_begin() const { |
| 3003 | return makeSpecIterator(getSpecializations(), false); |
| 3004 | } |
| 3005 | |
| 3006 | spec_iterator spec_end() const { |
| 3007 | return makeSpecIterator(getSpecializations(), true); |
| 3008 | } |
| 3009 | |
| 3010 | |
| 3011 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 3012 | static bool classofKind(Kind K) { return K == VarTemplate; } |
| 3013 | }; |
| 3014 | |
| 3015 | inline NamedDecl *getAsNamedDecl(TemplateParameter P) { |
| 3016 | if (auto *PD = P.dyn_cast<TemplateTypeParmDecl *>()) |
| 3017 | return PD; |
| 3018 | if (auto *PD = P.dyn_cast<NonTypeTemplateParmDecl *>()) |
| 3019 | return PD; |
| 3020 | return P.get<TemplateTemplateParmDecl *>(); |
| 3021 | } |
| 3022 | |
| 3023 | inline TemplateDecl *getAsTypeTemplateDecl(Decl *D) { |
| 3024 | auto *TD = dyn_cast<TemplateDecl>(D); |
| 3025 | return TD && (isa<ClassTemplateDecl>(TD) || |
| 3026 | isa<ClassTemplatePartialSpecializationDecl>(TD) || |
| 3027 | isa<TypeAliasTemplateDecl>(TD) || |
| 3028 | isa<TemplateTemplateParmDecl>(TD)) |
| 3029 | ? TD |
| 3030 | : nullptr; |
| 3031 | } |
| 3032 | |
| 3033 | } |
| 3034 | |
| 3035 | #endif |
| 3036 | |