clang
20.0.0git
include
clang
AST
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
16
#include "
clang/AST/DependenceFlags.h
"
17
#include "
clang/AST/NestedNameSpecifier.h
"
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
26
namespace
clang
{
27
28
class
ASTContext;
29
class
Decl
;
30
class
DependentTemplateName;
31
class
IdentifierInfo;
32
class
NamedDecl;
33
class
NestedNameSpecifier;
34
enum
OverloadedOperatorKind
:
int
;
35
class
OverloadedTemplateStorage;
36
class
AssumedTemplateStorage;
37
class
DeducedTemplateStorage;
38
struct
PrintingPolicy;
39
class
QualifiedTemplateName;
40
class
SubstTemplateTemplateParmPackStorage;
41
class
SubstTemplateTemplateParmStorage;
42
class
TemplateArgument;
43
class
TemplateDecl;
44
class
TemplateTemplateParmDecl;
45
class
UsingShadowDecl;
46
47
/// Implementation class used to describe either a set of overloaded
48
/// template names or an already-substituted template template parameter pack.
49
class
UncommonTemplateNameStorage
{
50
protected
:
51
enum
Kind
{
52
Overloaded
,
53
Assumed
,
// defined in DeclarationName.h
54
Deduced
,
55
SubstTemplateTemplateParm
,
56
SubstTemplateTemplateParmPack
57
};
58
59
struct
BitsTag
{
60
LLVM_PREFERRED_TYPE(
Kind
)
61
unsigned
Kind
: 3;
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
;
73
void
*
PointerAlignment
;
74
};
75
76
UncommonTemplateNameStorage
(
Kind
Kind
,
unsigned
Index
,
unsigned
Data
) {
77
Bits
.
Kind
=
Kind
;
78
Bits
.
Index
=
Index
;
79
Bits
.
Data
=
Data
;
80
}
81
82
public
:
83
OverloadedTemplateStorage
*
getAsOverloadedStorage
() {
84
return
Bits
.
Kind
==
Overloaded
85
?
reinterpret_cast<
OverloadedTemplateStorage
*
>
(
this
)
86
:
nullptr
;
87
}
88
89
AssumedTemplateStorage
*
getAsAssumedTemplateName
() {
90
return
Bits
.
Kind
==
Assumed
91
?
reinterpret_cast<
AssumedTemplateStorage
*
>
(
this
)
92
:
nullptr
;
93
}
94
95
DeducedTemplateStorage
*
getAsDeducedTemplateName
() {
96
return
Bits
.
Kind
==
Deduced
97
?
reinterpret_cast<
DeducedTemplateStorage
*
>
(
this
)
98
:
nullptr
;
99
}
100
101
SubstTemplateTemplateParmStorage
*
getAsSubstTemplateTemplateParm
() {
102
return
Bits
.
Kind
==
SubstTemplateTemplateParm
103
?
reinterpret_cast<
SubstTemplateTemplateParmStorage
*
>
(
this
)
104
:
nullptr
;
105
}
106
107
SubstTemplateTemplateParmPackStorage
*
getAsSubstTemplateTemplateParmPack
() {
108
return
Bits
.
Kind
==
SubstTemplateTemplateParmPack
109
?
reinterpret_cast<
SubstTemplateTemplateParmPackStorage
*
>
(
this
)
110
:
nullptr
;
111
}
112
};
113
114
/// A structure for storing the information associated with an
115
/// overloaded template name.
116
class
OverloadedTemplateStorage
:
public
UncommonTemplateNameStorage
{
117
friend
class
ASTContext
;
118
119
OverloadedTemplateStorage
(
unsigned
size)
120
:
UncommonTemplateNameStorage
(Overloaded, 0, size) {}
121
122
NamedDecl
**
getStorage
() {
123
return
reinterpret_cast<
NamedDecl
**
>
(
this
+ 1);
124
}
125
NamedDecl *
const
*
getStorage
()
const
{
126
return
reinterpret_cast<
NamedDecl *
const
*
>
(
this
+ 1);
127
}
128
129
public
:
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
137
llvm::ArrayRef<NamedDecl*>
decls
()
const
{
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.
148
class
SubstTemplateTemplateParmPackStorage
:
public
UncommonTemplateNameStorage
,
149
public
llvm::FoldingSetNode {
150
const
TemplateArgument
*Arguments;
151
llvm::PointerIntPair<Decl *, 1, bool> AssociatedDeclAndFinal;
152
153
public
:
154
SubstTemplateTemplateParmPackStorage
(
ArrayRef<TemplateArgument>
ArgPack,
155
Decl
*AssociatedDecl,
unsigned
Index,