16
16
#include < mrdox/Platform.hpp>
17
17
#include < mrdox/ADT/Optional.hpp>
18
18
#include < mrdox/Metadata/Type.hpp>
19
+ #include < mrdox/Support/TypeTraits.hpp>
19
20
#include < optional>
20
21
#include < string>
21
22
#include < vector>
22
23
23
24
namespace clang {
24
25
namespace mrdox {
25
26
27
+ enum class TArgKind : int
28
+ {
29
+ // type arguments
30
+ Type = 1 , // for bitstream
31
+ // non-type arguments, i.e. expressions
32
+ NonType,
33
+ // template template arguments, i.e. template names
34
+ Template
35
+ };
36
+
37
+ MRDOX_DECL dom::String toString (TArgKind kind) noexcept ;
38
+
39
+ struct TArg
40
+ {
41
+ /* * The kind of template argument this is. */
42
+ TArgKind Kind;
43
+
44
+ /* * Whether this template argument is a parameter expansion. */
45
+ bool IsPackExpansion = false ;
46
+
47
+ constexpr virtual ~TArg () = default ;
48
+
49
+ constexpr bool isType () const noexcept { return Kind == TArgKind::Type; }
50
+ constexpr bool isNonType () const noexcept { return Kind == TArgKind::NonType; }
51
+ constexpr bool isTemplate () const noexcept { return Kind == TArgKind::Template; }
52
+
53
+ protected:
54
+ constexpr
55
+ TArg (
56
+ TArgKind kind) noexcept
57
+ : Kind(kind)
58
+ {
59
+ }
60
+ };
61
+
62
+ template <TArgKind K>
63
+ struct IsTArg : TArg
64
+ {
65
+ static constexpr TArgKind kind_id = K;
66
+
67
+ static constexpr bool isType () noexcept { return K == TArgKind::Type; }
68
+ static constexpr bool isNonType () noexcept { return K == TArgKind::NonType; }
69
+ static constexpr bool isTemplate () noexcept { return K == TArgKind::Template; }
70
+
71
+ protected:
72
+ constexpr
73
+ IsTArg () noexcept
74
+ : TArg(K)
75
+ {
76
+ }
77
+ };
78
+
79
+ struct TypeTArg
80
+ : IsTArg<TArgKind::Type>
81
+ {
82
+ /* * Template argument type. */
83
+ std::unique_ptr<TypeInfo> Type;
84
+ };
85
+
86
+ struct NonTypeTArg
87
+ : IsTArg<TArgKind::NonType>
88
+ {
89
+ /* * Template argument expression. */
90
+ ExprInfo Value;
91
+ };
92
+
93
+ struct TemplateTArg
94
+ : IsTArg<TArgKind::Template>
95
+ {
96
+ /* * SymbolID of the referenced template. */
97
+ SymbolID Template;
98
+
99
+ /* * Name of the referenced template. */
100
+ std::string Name;
101
+ };
102
+
103
+ template <
104
+ typename TArgTy,
105
+ typename F,
106
+ typename ... Args>
107
+ requires std::derived_from<TArgTy, TArg>
108
+ constexpr
109
+ decltype (auto )
110
+ visit (
111
+ TArgTy& A,
112
+ F&& f,
113
+ Args&&... args)
114
+ {
115
+ switch (A.Kind )
116
+ {
117
+ case TArgKind::Type:
118
+ return f (static_cast <add_cv_from_t <
119
+ TArgTy, TypeTArg>&>(A),
120
+ std::forward<Args>(args)...);
121
+ case TArgKind::NonType:
122
+ return f (static_cast <add_cv_from_t <
123
+ TArgTy, NonTypeTArg>&>(A),
124
+ std::forward<Args>(args)...);
125
+ case TArgKind::Template:
126
+ return f (static_cast <add_cv_from_t <
127
+ TArgTy, TemplateTArg>&>(A),
128
+ std::forward<Args>(args)...);
129
+ default :
130
+ MRDOX_UNREACHABLE ();
131
+ }
132
+ }
133
+
134
+ // ----------------------------------------------------------------
135
+
26
136
enum class TParamKind : int
27
137
{
28
138
// template type parameter, e.g. "typename T" or "class T"
@@ -103,48 +213,31 @@ struct TemplateTParam
103
213
Optional<std::string> Default;
104
214
};
105
215
106
- template <typename F, typename ... Args>
216
+ template <
217
+ typename TParamTy,
218
+ typename F,
219
+ typename ... Args>
220
+ requires std::derived_from<TParamTy, TParam>
107
221
constexpr
108
222
decltype (auto )
109
223
visit (
110
- TParam & P,
224
+ TParamTy & P,
111
225
F&& f,
112
226
Args&&... args)
113
227
{
114
228
switch (P.Kind )
115
229
{
116
230
case TParamKind::Type:
117
- return f (static_cast <TypeTParam&>(P),
231
+ return f (static_cast <add_cv_from_t <
232
+ TParamTy, TypeTParam>&>(P),
118
233
std::forward<Args>(args)...);
119
234
case TParamKind::NonType:
120
- return f (static_cast <NonTypeTParam&>(P),
235
+ return f (static_cast <add_cv_from_t <
236
+ TParamTy, NonTypeTParam>&>(P),
121
237
std::forward<Args>(args)...);
122
238
case TParamKind::Template:
123
- return f (static_cast <TemplateTParam&>(P),
124
- std::forward<Args>(args)...);
125
- default :
126
- MRDOX_UNREACHABLE ();
127
- }
128
- }
129
-
130
- template <typename F, typename ... Args>
131
- constexpr
132
- decltype (auto )
133
- visit (
134
- const TParam& P,
135
- F&& f,
136
- Args&&... args)
137
- {
138
- switch (P.Kind )
139
- {
140
- case TParamKind::Type:
141
- return f (static_cast <const TypeTParam&>(P),
142
- std::forward<Args>(args)...);
143
- case TParamKind::NonType:
144
- return f (static_cast <const NonTypeTParam&>(P),
145
- std::forward<Args>(args)...);
146
- case TParamKind::Template:
147
- return f (static_cast <const TemplateTParam&>(P),
239
+ return f (static_cast <add_cv_from_t <
240
+ TParamTy, TemplateTParam>&>(P),
148
241
std::forward<Args>(args)...);
149
242
default :
150
243
MRDOX_UNREACHABLE ();
@@ -153,6 +246,7 @@ visit(
153
246
154
247
// ----------------------------------------------------------------
155
248
249
+ #if 0
156
250
struct TArg
157
251
{
158
252
std::string Value;
@@ -162,6 +256,7 @@ struct TArg
162
256
MRDOX_DECL
163
257
TArg(std::string&& value);
164
258
};
259
+ #endif
165
260
166
261
// ----------------------------------------------------------------
167
262
@@ -191,7 +286,7 @@ struct TemplateInfo
191
286
once in Args outside of a non-deduced context
192
287
*/
193
288
std::vector<std::unique_ptr<TParam>> Params;
194
- std::vector<TArg> Args;
289
+ std::vector<std::unique_ptr< TArg> > Args;
195
290
196
291
/* * Primary template ID for partial and explicit specializations.
197
292
*/
0 commit comments