clang 20.0.0git
TemplateName.h
Go to the documentation of this file.
1//===- TemplateName.h - C++ Template Name Representation --------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the TemplateName interface and subclasses.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_AST_TEMPLATENAME_H
14#define LLVM_CLANG_AST_TEMPLATENAME_H
15
18#include "clang/Basic/LLVM.h"
19#include "llvm/ADT/FoldingSet.h"
20#include "llvm/ADT/PointerIntPair.h"
21#include "llvm/ADT/PointerUnion.h"
22#include "llvm/Support/PointerLikeTypeTraits.h"
23#include <cassert>
24#include <optional>
25
26namespace clang {
27
28class ASTContext;
29class Decl;
30class DependentTemplateName;
31class IdentifierInfo;
32class NamedDecl;
33class NestedNameSpecifier;
35class OverloadedTemplateStorage;
36class AssumedTemplateStorage;
37class DeducedTemplateStorage;
38struct PrintingPolicy;
39class QualifiedTemplateName;
40class SubstTemplateTemplateParmPackStorage;
41class SubstTemplateTemplateParmStorage;
42class TemplateArgument;
43class TemplateDecl;
44class TemplateTemplateParmDecl;
45class UsingShadowDecl;
46
47/// Implementation class used to describe either a set of overloaded
48/// template names or an already-substituted template template parameter pack.
50protected:
51 enum Kind {
53 Assumed, // defined in DeclarationName.h
57 };
58
59 struct BitsTag {
60 LLVM_PREFERRED_TYPE(Kind)
62
63 // The template parameter index.
64 unsigned Index : 14;
65
66 /// The pack index, or the number of stored templates
67 /// or template arguments, depending on which subclass we have.
68 unsigned Data : 15;
69 };
70
71 union {
72 struct BitsTag Bits;
74 };
75
77 Bits.Kind = Kind;
79 Bits.Data = Data;
80 }
81
82public:
84 return Bits.Kind == Overloaded
85 ? reinterpret_cast<OverloadedTemplateStorage *>(this)
86 : nullptr;
87 }
88
90 return Bits.Kind == Assumed
91 ? reinterpret_cast<AssumedTemplateStorage *>(this)
92 : nullptr;
93 }
94
96 return Bits.Kind == Deduced
97 ? reinterpret_cast<DeducedTemplateStorage *>(this)
98 : nullptr;
99 }
100
103 ? reinterpret_cast<SubstTemplateTemplateParmStorage *>(this)
104 : nullptr;
105 }
106
109 ? reinterpret_cast<SubstTemplateTemplateParmPackStorage *>(this)
110 : nullptr;
111 }
112};
113
114/// A structure for storing the information associated with an
115/// overloaded template name.
117 friend class ASTContext;
118
119 OverloadedTemplateStorage(unsigned size)
120 : UncommonTemplateNameStorage(Overloaded, 0, size) {}
121
123 return reinterpret_cast<NamedDecl **>(this + 1);
124 }
125 NamedDecl * const *getStorage() const {
126 return reinterpret_cast<NamedDecl *const *>(this + 1);
127 }
128
129public:
130 unsigned size() const { return Bits.Data; }
131
132 using iterator = NamedDecl *const *;
133
134 iterator begin() const { return getStorage(); }
135 iterator end() const { return getStorage() + Bits.Data; }
136
138 return llvm::ArrayRef(begin(), end());
139 }
140};
141
142/// A structure for storing an already-substituted template template
143/// parameter pack.
144///
145/// This kind of template names occurs when the parameter pack has been
146/// provided with a template template argument pack in a context where its
147/// enclosing pack expansion could not be fully expanded.
149 public llvm::FoldingSetNode {
150 const TemplateArgument *Arguments;
151 llvm::PointerIntPair<Decl *, 1, bool> AssociatedDeclAndFinal;
152
153public:
155 Decl *AssociatedDecl, unsigned Index,