blob: 4769a3c609758c1f7dbb392a807972b71029d8bc [file] [log] [blame]
Ben Claytonb85e6922022-02-02 23:07:11 +00001{{- /*
2--------------------------------------------------------------------------------
Ben Claytonbccd87c2022-10-12 09:42:00 +00003Template file for use with tools/src/cmd/gen to generate intrinsic_table.inl
Ben Claytonb85e6922022-02-02 23:07:11 +00004Used by BuiltinTable.cc for builtin overload resolution.
5
Ben Claytona123b892022-07-27 16:36:35 +00006To update the generated file, run:
7 ./tools/run gen
8
Ben Claytonb85e6922022-02-02 23:07:11 +00009See:
Ben Claytoncde50092022-07-26 15:46:44 +000010* tools/src/cmd/gen for structures used by this template
Ben Claytonb85e6922022-02-02 23:07:11 +000011* https://golang.org/pkg/text/template/ for documentation on the template syntax
12--------------------------------------------------------------------------------
13*/ -}}
14
15// clang-format off
16
Ben Claytoncde50092022-07-26 15:46:44 +000017{{ with Sem -}}
Ben Claytonb85e6922022-02-02 23:07:11 +000018{{ range .Types -}}
19{{ template "Type" . }}
20{{ end -}}
21{{ range .TypeMatchers -}}
22{{ template "TypeMatcher" . }}
23{{ end -}}
24{{ range .EnumMatchers -}}
25{{ template "EnumMatcher" . }}
26{{ end -}}
27{{- end -}}
28
Ben Claytone6e96de2022-05-09 18:08:23 +000029{{- with IntrinsicTable -}}
Ben Claytonb85e6922022-02-02 23:07:11 +000030{{- template "Matchers" . }}
31
32constexpr MatcherIndex kMatcherIndices[] = {
33{{- range $i, $idx := .MatcherIndices }}
34 /* [{{$i}}] */ {{$idx}},
35{{- end }}
36};
37
38// Assert that the MatcherIndex is big enough to index all the matchers, plus
39// kNoMatcher.
40static_assert(static_cast<int>(sizeof(kMatcherIndices) / sizeof(kMatcherIndices[0])) <
41 static_cast<int>(std::numeric_limits<MatcherIndex>::max() - 1),
42 "MatcherIndex is not large enough to index kMatcherIndices");
43
44constexpr ParameterInfo kParameters[] = {
45{{- range $i, $p := .Parameters }}
46 {
47 /* [{{$i}}] */
48 /* usage */ ParameterUsage::
49{{- if $p.Usage }}k{{PascalCase $p.Usage}}
50{{- else }}kNone
51{{- end }},
52 /* matcher indices */ &kMatcherIndices[{{$p.MatcherIndicesOffset}}],
53 },
54{{- end }}
55};
56
Ben Clayton4c9ed742022-05-17 22:42:32 +000057constexpr TemplateTypeInfo kTemplateTypes[] = {
58{{- range $i, $o := .TemplateTypes }}
Ben Claytonb85e6922022-02-02 23:07:11 +000059 {
60 /* [{{$i}}] */
61 /* name */ "{{$o.Name}}",
62 /* matcher index */
63{{- if ge $o.MatcherIndex 0 }} {{$o.MatcherIndex}}
64{{- else }} kNoMatcher
65{{- end }},
66 },
67{{- end }}
68};
69
Ben Clayton4c9ed742022-05-17 22:42:32 +000070constexpr TemplateNumberInfo kTemplateNumbers[] = {
71{{- range $i, $o := .TemplateNumbers }}
Ben Claytonb85e6922022-02-02 23:07:11 +000072 {
73 /* [{{$i}}] */
74 /* name */ "{{$o.Name}}",
75 /* matcher index */
76{{- if ge $o.MatcherIndex 0 }} {{$o.MatcherIndex}}
77{{- else }} kNoMatcher
78{{- end }},
79 },
80{{- end }}
81};
82
83constexpr OverloadInfo kOverloads[] = {
84{{- range $i, $o := .Overloads }}
85 {
86 /* [{{$i}}] */
87 /* num parameters */ {{$o.NumParameters}},
Ben Clayton4c9ed742022-05-17 22:42:32 +000088 /* num template types */ {{$o.NumTemplateTypes}},
89 /* num template numbers */ {{$o.NumTemplateNumbers}},
90 /* template types */
91{{- if $o.TemplateTypesOffset }} &kTemplateTypes[{{$o.TemplateTypesOffset}}],
Ben Clayton451eee02022-06-01 23:57:20 +000092{{- else }} nullptr,
Ben Claytonb85e6922022-02-02 23:07:11 +000093{{- end }}
Ben Clayton4c9ed742022-05-17 22:42:32 +000094 /* template numbers */
95{{- if $o.TemplateNumbersOffset }} &kTemplateNumbers[{{$o.TemplateNumbersOffset}}]
Ben Clayton451eee02022-06-01 23:57:20 +000096{{- else }} nullptr
Ben Claytonb85e6922022-02-02 23:07:11 +000097{{- end }},
98 /* parameters */ &kParameters[{{$o.ParametersOffset}}],
99 /* return matcher indices */
100{{- if $o.ReturnMatcherIndicesOffset }} &kMatcherIndices[{{$o.ReturnMatcherIndicesOffset}}]
101{{- else }} nullptr
102{{- end }},
Ben Clayton59e23942022-05-13 16:14:17 +0000103 /* flags */ OverloadFlags(OverloadFlag::kIs{{Title $o.Kind}}
Ben Claytonb85e6922022-02-02 23:07:11 +0000104{{- range $i, $u := $o.CanBeUsedInStage.List -}}
Ben Clayton59e23942022-05-13 16:14:17 +0000105 , OverloadFlag::kSupports{{Title $u}}Pipeline
106{{- end }}
Ben Claytond8490322023-02-22 13:52:21 +0000107{{- if $o.MustUse}}, OverloadFlag::kMustUse{{end}}
108{{- if $o.IsDeprecated}}, OverloadFlag::kIsDeprecated{{end -}}
109 ),
Ben Clayton451eee02022-06-01 23:57:20 +0000110 /* const eval */
Ben Claytonac660c22022-07-15 23:54:10 +0000111{{- if $o.ConstEvalFunction }} {{template "ConstEvalFn" $o}},
Ben Clayton451eee02022-06-01 23:57:20 +0000112{{- else }} nullptr,
113{{- end }}
Ben Claytonb85e6922022-02-02 23:07:11 +0000114 },
115{{- end }}
116};
117
Ben Claytone6e96de2022-05-09 18:08:23 +0000118constexpr IntrinsicInfo kBuiltins[] = {
119{{- range $i, $b := .Builtins }}
Ben Claytonb85e6922022-02-02 23:07:11 +0000120 {
121 /* [{{$i}}] */
Ben Claytone6e96de2022-05-09 18:08:23 +0000122{{- range $b.OverloadDescriptions }}
Ben Claytonb85e6922022-02-02 23:07:11 +0000123 /* {{.}} */
124{{- end }}
Ben Claytone6e96de2022-05-09 18:08:23 +0000125 /* num overloads */ {{$b.NumOverloads}},
126 /* overloads */ &kOverloads[{{$b.OverloadsOffset}}],
Ben Claytonb85e6922022-02-02 23:07:11 +0000127 },
128{{- end }}
129};
130
Ben Clayton77473b42022-05-13 14:35:37 +0000131constexpr IntrinsicInfo kUnaryOperators[] = {
132{{- range $i, $o := .UnaryOperators }}
Ben Clayton9fb29a32022-05-09 20:00:13 +0000133 {
134 /* [{{$i}}] */
135{{- range $o.OverloadDescriptions }}
136 /* {{.}} */
137{{- end }}
138 /* num overloads */ {{$o.NumOverloads}},
139 /* overloads */ &kOverloads[{{$o.OverloadsOffset}}],
140 },
141{{- end }}
142};
143
Ben Clayton77473b42022-05-13 14:35:37 +0000144{{- range $i, $o := .UnaryOperators }}
Ben Claytonac660c22022-07-15 23:54:10 +0000145constexpr uint8_t kUnaryOperator{{ template "ExpandName" $o.Name}} = {{$i}};
Ben Clayton77473b42022-05-13 14:35:37 +0000146{{- end }}
147
148constexpr IntrinsicInfo kBinaryOperators[] = {
149{{- range $i, $o := .BinaryOperators }}
150 {
151 /* [{{$i}}] */
152{{- range $o.OverloadDescriptions }}
153 /* {{.}} */
154{{- end }}
155 /* num overloads */ {{$o.NumOverloads}},
156 /* overloads */ &kOverloads[{{$o.OverloadsOffset}}],
157 },
158{{- end }}
159};
160
161{{- range $i, $o := .BinaryOperators }}
Ben Claytonac660c22022-07-15 23:54:10 +0000162constexpr uint8_t kBinaryOperator{{ template "ExpandName" $o.Name}} = {{$i}};
Ben Clayton9fb29a32022-05-09 20:00:13 +0000163{{- end }}
164
Ben Clayton54a104e2023-02-22 20:04:40 +0000165constexpr IntrinsicInfo kConstructorsAndConverters[] = {
166{{- range $i, $o := .ConstructorsAndConverters }}
Ben Clayton6ae608c2022-05-16 20:54:42 +0000167 {
168 /* [{{$i}}] */
169{{- range $o.OverloadDescriptions }}
170 /* {{.}} */
171{{- end }}
172 /* num overloads */ {{$o.NumOverloads}},
173 /* overloads */ &kOverloads[{{$o.OverloadsOffset}}],
174 },
175{{- end }}
176};
177
Ben Claytonb85e6922022-02-02 23:07:11 +0000178// clang-format on
179{{ end -}}
180
181{{- /* ------------------------------------------------------------------ */ -}}
182{{- define "Type" -}}
183{{- /* ------------------------------------------------------------------ */ -}}
184{{- $class := PascalCase .Name -}}
185/// TypeMatcher for 'type {{.Name}}'
186{{- if .Decl.Source.S.Filepath }}
Ben Claytonb85e6922022-02-02 23:07:11 +0000187{{- end }}
188class {{$class}} : public TypeMatcher {
189 public:
190 /// Checks whether the given type matches the matcher rules.
Ben Clayton23696b12022-05-18 21:56:28 +0000191 /// Match may define and refine the template types and numbers in state.
Ben Claytonb85e6922022-02-02 23:07:11 +0000192 /// @param state the MatchState
193 /// @param type the type to match
194 /// @returns the canonicalized type on match, otherwise nullptr
dan sinclair5f764d82022-12-08 00:32:27 +0000195 const type::Type* Match(MatchState& state,
196 const type::Type* type) const override;
Ben Claytonb85e6922022-02-02 23:07:11 +0000197 /// @param state the MatchState
198 /// @return a string representation of the matcher.
Ben Claytonb1fa4572022-05-19 18:26:09 +0000199 std::string String(MatchState* state) const override;
Ben Claytonb85e6922022-02-02 23:07:11 +0000200};
201
dan sinclair5f764d82022-12-08 00:32:27 +0000202const type::Type* {{$class}}::Match(MatchState& state, const type::Type* ty) const {
Ben Claytonb85e6922022-02-02 23:07:11 +0000203{{- range .TemplateParams }}
204{{- template "DeclareLocalTemplateParam" . }}
205{{- end }}
Antonio Maioranofc7994b2022-10-04 22:19:48 +0000206 if (!match_{{TrimLeft .Name "_"}}(state, ty{{range .TemplateParams}}, {{.GetName}}{{end}})) {
Ben Claytonb85e6922022-02-02 23:07:11 +0000207 return nullptr;
208 }
209{{- range .TemplateParams }}
210 {{.Name}} = {{ template "MatchTemplateParam" .}}({{.Name}});
211 if ({{ template "IsTemplateParamInvalid" .}}) {
212 return nullptr;
213 }
214{{- end }}
215 return build_{{TrimLeft .Name "_"}}(state{{range .TemplateParams}}, {{.GetName}}{{end}});
216}
217
Ben Claytonb1fa4572022-05-19 18:26:09 +0000218std::string {{$class}}::String(MatchState*{{if .TemplateParams}} state{{end}}) const {
Ben Claytonb85e6922022-02-02 23:07:11 +0000219{{- range .TemplateParams }}
220{{- template "DeclareLocalTemplateParamName" . }}
221{{- end }}
222
223{{- if .DisplayName }}
dan sinclairb23cda42023-02-28 17:31:54 +0000224 utils::StringStream ss;
Ben Claytonb85e6922022-02-02 23:07:11 +0000225 ss{{range SplitDisplayName .DisplayName}} << {{.}}{{end}};
226 return ss.str();
227{{- else if .TemplateParams }}
228 return "{{.Name}}<"{{template "AppendTemplateParamNames" .TemplateParams}} + ">";
229{{- else }}
230 return "{{.Name}}";
231{{- end }}
232}
233{{ end -}}
234
235{{- /* ------------------------------------------------------------------ */ -}}
236{{- define "TypeMatcher" -}}
237{{- /* ------------------------------------------------------------------ */ -}}
238{{- $class := PascalCase .Name -}}
239/// TypeMatcher for 'match {{.Name}}'
240{{- if .Decl.Source.S.Filepath }}
Ben Claytonb85e6922022-02-02 23:07:11 +0000241{{- end }}
242class {{$class}} : public TypeMatcher {
243 public:
244 /// Checks whether the given type matches the matcher rules, and returns the
245 /// expected, canonicalized type on success.
Ben Clayton23696b12022-05-18 21:56:28 +0000246 /// Match may define and refine the template types and numbers in state.
Ben Claytonb85e6922022-02-02 23:07:11 +0000247 /// @param state the MatchState
248 /// @param type the type to match
249 /// @returns the canonicalized type on match, otherwise nullptr
dan sinclair5f764d82022-12-08 00:32:27 +0000250 const type::Type* Match(MatchState& state,
251 const type::Type* type) const override;
Ben Claytonb85e6922022-02-02 23:07:11 +0000252 /// @param state the MatchState
253 /// @return a string representation of the matcher.
Ben Claytonb1fa4572022-05-19 18:26:09 +0000254 std::string String(MatchState* state) const override;
Ben Claytonb85e6922022-02-02 23:07:11 +0000255};
256
dan sinclair5f764d82022-12-08 00:32:27 +0000257const type::Type* {{$class}}::Match(MatchState& state, const type::Type* ty) const {
Ben Claytonc6700182022-05-18 18:56:58 +0000258{{- range .PrecedenceSortedTypes }}
Antonio Maioranofc7994b2022-10-04 22:19:48 +0000259 if (match_{{.Name}}(state, ty)) {
Ben Claytonb85e6922022-02-02 23:07:11 +0000260 return build_{{.Name}}(state);
261 }
262{{- end }}
263 return nullptr;
264}
265
Ben Claytonb1fa4572022-05-19 18:26:09 +0000266std::string {{$class}}::String(MatchState*) const {
dan sinclairb23cda42023-02-28 17:31:54 +0000267 utils::StringStream ss;
Ben Claytonb1fa4572022-05-19 18:26:09 +0000268 // Note: We pass nullptr to the TypeMatcher::String() functions, as 'matcher's do not support
269 // template arguments, nor can they match sub-types. As such, they have no use for the MatchState.
270 ss
Ben Claytonb85e6922022-02-02 23:07:11 +0000271{{- range .Types -}}
Ben Claytonb1fa4572022-05-19 18:26:09 +0000272{{- if IsFirstIn . $.Types }} << {{PascalCase .Name}}().String(nullptr)
273{{- else if IsLastIn . $.Types }} << " or " << {{PascalCase .Name}}().String(nullptr)
274{{- else }} << ", " << {{PascalCase .Name}}().String(nullptr)
Ben Claytonb85e6922022-02-02 23:07:11 +0000275{{- end -}}
Ben Claytonb1fa4572022-05-19 18:26:09 +0000276{{- end -}};
277 return ss.str();
Ben Claytonb85e6922022-02-02 23:07:11 +0000278}
279{{ end -}}
280
281{{- /* ------------------------------------------------------------------ */ -}}
282{{- define "EnumMatcher" -}}
283{{- /* ------------------------------------------------------------------ */ -}}
284{{- $class := PascalCase .Name -}}
285{{- $enum := PascalCase .Enum.Name -}}
286/// EnumMatcher for 'match {{.Name}}'
287{{- if .Decl.Source.S.Filepath }}
Ben Claytonb85e6922022-02-02 23:07:11 +0000288{{- end }}
289class {{$class}} : public NumberMatcher {
290 public:
291 /// Checks whether the given number matches the enum matcher rules.
Ben Clayton23696b12022-05-18 21:56:28 +0000292 /// Match may define template numbers in state.
Ben Claytonb85e6922022-02-02 23:07:11 +0000293 /// @param state the MatchState
294 /// @param number the enum value as a Number
295 /// @return true if the enum value matches the set
296 Number Match(MatchState& state, Number number) const override;
297 /// @param state the MatchState
298 /// @return a string representation of the matcher.
Ben Claytonb1fa4572022-05-19 18:26:09 +0000299 std::string String(MatchState* state) const override;
Ben Claytonb85e6922022-02-02 23:07:11 +0000300};
301
302{{ if eq 1 (len .Options) -}}
303{{- $option := index .Options 0 }}
304{{- $entry := printf "k%v" (PascalCase $option.Name) -}}
305Number {{$class}}::Match(MatchState&, Number number) const {
306 if (number.IsAny() || number.Value() == static_cast<uint32_t>({{$enum}}::{{$entry}})) {
307 return Number(static_cast<uint32_t>({{$enum}}::{{$entry}}));
308 }
309 return Number::invalid;
310}
311{{- else -}}
312Number {{$class}}::Match(MatchState&, Number number) const {
313 switch (static_cast<{{$enum}}>(number.Value())) {
314{{- range .Options }}
315 case {{$enum}}::k{{PascalCase .Name}}:
316{{- end }}
317 return number;
318 default:
319 return Number::invalid;
320 }
321}
322{{- end }}
323
Ben Claytonb1fa4572022-05-19 18:26:09 +0000324std::string {{$class}}::String(MatchState*) const {
Ben Claytonb85e6922022-02-02 23:07:11 +0000325 return "
326{{- range .Options -}}
327{{- if IsFirstIn . $.Options }}{{.Name}}
328{{- else if IsLastIn . $.Options }} or {{.Name}}
329{{- else }}, {{.Name}}
330{{- end -}}
331{{- end -}}
332";
333}
334{{ end -}}
335
336{{- /* ------------------------------------------------------------------ */ -}}
337{{- define "Matchers" -}}
338{{- /* ------------------------------------------------------------------ */ -}}
339/// Matchers holds type and number matchers
340class Matchers {
341 private:
342{{- $t_names := Map -}}
343{{- $n_names := Map -}}
Ben Claytoncde50092022-07-26 15:46:44 +0000344{{- range Iterate Sem.MaxTemplateTypes -}}
Ben Clayton4c9ed742022-05-17 22:42:32 +0000345{{- $name := printf "template_type_%v" . -}}
Ben Claytonb85e6922022-02-02 23:07:11 +0000346{{- $t_names.Put . $name }}
Ben Clayton4c9ed742022-05-17 22:42:32 +0000347 TemplateTypeMatcher {{$name}}_{ {{- . -}} };
Ben Claytonb85e6922022-02-02 23:07:11 +0000348{{- end }}
Ben Claytoncde50092022-07-26 15:46:44 +0000349{{- range Iterate Sem.MaxTemplateNumbers -}}
Ben Clayton4c9ed742022-05-17 22:42:32 +0000350{{- $name := printf "template_number_%v" . -}}
Ben Claytonb85e6922022-02-02 23:07:11 +0000351{{- $n_names.Put . $name }}
Ben Clayton4c9ed742022-05-17 22:42:32 +0000352 TemplateNumberMatcher {{$name}}_{ {{- . -}} };
Ben Claytonb85e6922022-02-02 23:07:11 +0000353{{- end }}
Ben Claytoncde50092022-07-26 15:46:44 +0000354{{- range Sem.Types -}}
Ben Claytonb85e6922022-02-02 23:07:11 +0000355{{- $name := PascalCase .Name -}}
356{{- $t_names.Put . $name }}
357 {{$name}} {{$name}}_;
358{{- end }}
Ben Claytoncde50092022-07-26 15:46:44 +0000359{{- range Sem.TypeMatchers -}}
Ben Claytonb85e6922022-02-02 23:07:11 +0000360{{- $name := PascalCase .Name -}}
361{{- $t_names.Put . $name }}
362 {{$name}} {{$name}}_;
363{{- end }}
Ben Claytoncde50092022-07-26 15:46:44 +0000364{{- range Sem.EnumMatchers -}}
Ben Claytonb85e6922022-02-02 23:07:11 +0000365{{- $name := PascalCase .Name -}}
366{{- $n_names.Put . $name }}
367 {{$name}} {{$name}}_;
368{{- end }}
369
370 public:
371 /// Constructor
372 Matchers();
373 /// Destructor
374 ~Matchers();
375
Ben Clayton4c9ed742022-05-17 22:42:32 +0000376 /// The template types, types, and type matchers
Ben Claytonb85e6922022-02-02 23:07:11 +0000377 TypeMatcher const* const type[{{len .TMatchers}}] = {
378{{- range $i, $m := .TMatchers }}
379 /* [{{$i}}] */
380{{- if $m }} &{{$t_names.Get $m}}_,
381{{- else }} &{{$t_names.Get $i}}_,
382{{- end }}
383{{- end }}
384 };
385
Ben Clayton4c9ed742022-05-17 22:42:32 +0000386 /// The template numbers, and number matchers
Ben Claytonb85e6922022-02-02 23:07:11 +0000387 NumberMatcher const* const number[{{len .NMatchers}}] = {
388{{- range $i, $m := .NMatchers }}
389 /* [{{$i}}] */
390{{- if $m }} &{{$n_names.Get $m}}_,
391{{- else }} &{{$n_names.Get $i}}_,
392{{- end }}
393{{- end }}
394 };
395};
396
397Matchers::Matchers() = default;
398Matchers::~Matchers() = default;
399{{- end -}}
400
401{{- /* ------------------------------------------------------------------ */ -}}
402{{- define "DeclareLocalTemplateParam" -}}
403{{- /* ------------------------------------------------------------------ */ -}}
404{{- if IsTemplateTypeParam . }}
dan sinclair5f764d82022-12-08 00:32:27 +0000405 const type::Type* {{.Name}} = nullptr;
Ben Claytonb85e6922022-02-02 23:07:11 +0000406{{- else if IsTemplateNumberParam . }}
407 Number {{.Name}} = Number::invalid;
408{{- else if IsTemplateEnumParam . }}
409 Number {{.Name}} = Number::invalid;
410{{- end -}}
411{{- end -}}
412
413{{- /* ------------------------------------------------------------------ */ -}}
414{{- define "DeclareLocalTemplateParamName" -}}
415{{- /* ------------------------------------------------------------------ */ -}}
416{{- if IsTemplateTypeParam . }}
Ben Claytonb1fa4572022-05-19 18:26:09 +0000417 const std::string {{.Name}} = state->TypeName();
Ben Claytonb85e6922022-02-02 23:07:11 +0000418{{- else if IsTemplateNumberParam . }}
Ben Claytonb1fa4572022-05-19 18:26:09 +0000419 const std::string {{.Name}} = state->NumName();
Ben Claytonb85e6922022-02-02 23:07:11 +0000420{{- else if IsTemplateEnumParam . }}
Ben Claytonb1fa4572022-05-19 18:26:09 +0000421 const std::string {{.Name}} = state->NumName();
Ben Claytonb85e6922022-02-02 23:07:11 +0000422{{- end -}}
423{{- end -}}
424
425{{- /* ------------------------------------------------------------------ */ -}}
426{{- define "MatchTemplateParam" -}}
427{{- /* ------------------------------------------------------------------ */ -}}
428{{- if IsTemplateTypeParam . -}}
429 state.Type
430{{- else if IsTemplateNumberParam . -}}
431 state.Num
432{{- else if IsTemplateEnumParam . -}}
433 state.Num
434{{- end -}}
435{{- end -}}
436
437{{- /* ------------------------------------------------------------------ */ -}}
438{{- define "IsTemplateParamInvalid" -}}
439{{- /* ------------------------------------------------------------------ */ -}}
440{{- if IsTemplateTypeParam . -}}
441 {{.Name}} == nullptr
442{{- else if IsTemplateNumberParam . -}}
443 !{{.Name}}.IsValid()
444{{- else if IsTemplateEnumParam . -}}
445 !{{.Name}}.IsValid()
446{{- end -}}
447{{- end -}}
448
449{{- /* ------------------------------------------------------------------ */ -}}
450{{- define "AppendTemplateParamNames" -}}
451{{- /* ------------------------------------------------------------------ */ -}}
452{{- range $i, $ := . -}}
453{{- if $i }} + ", " + {{.Name}}
454{{- else }} + {{.Name}}
455{{- end -}}
456{{- end -}}
457{{- end -}}
Ben Clayton9fb29a32022-05-09 20:00:13 +0000458
459{{- /* ------------------------------------------------------------------ */ -}}
Ben Claytonac660c22022-07-15 23:54:10 +0000460{{- define "ExpandName" -}}
Ben Clayton9fb29a32022-05-09 20:00:13 +0000461{{- /* ------------------------------------------------------------------ */ -}}
462{{- if eq . "<<" -}}ShiftLeft
463{{- else if eq . "&" -}}And
464{{- else if eq . "|" -}}Or
465{{- else if eq . "^" -}}Xor
466{{- else if eq . "&&" -}}LogicalAnd
467{{- else if eq . "||" -}}LogicalOr
468{{- else if eq . "==" -}}Equal
Ben Claytonb61e0452022-05-09 21:22:24 +0000469{{- else if eq . "!" -}}Not
Ben Clayton9fb29a32022-05-09 20:00:13 +0000470{{- else if eq . "!=" -}}NotEqual
Ben Claytonb61e0452022-05-09 21:22:24 +0000471{{- else if eq . "~" -}}Complement
Ben Clayton9fb29a32022-05-09 20:00:13 +0000472{{- else if eq . "<" -}}LessThan
473{{- else if eq . ">" -}}GreaterThan
474{{- else if eq . "<=" -}}LessThanEqual
475{{- else if eq . ">=" -}}GreaterThanEqual
476{{- else if eq . "<<" -}}ShiftLeft
477{{- else if eq . ">>" -}}ShiftRight
478{{- else if eq . "+" -}}Plus
479{{- else if eq . "-" -}}Minus
480{{- else if eq . "*" -}}Star
481{{- else if eq . "/" -}}Divide
482{{- else if eq . "%" -}}Modulo
Ben Claytonac660c22022-07-15 23:54:10 +0000483{{- else -}}{{.}}
Ben Clayton9fb29a32022-05-09 20:00:13 +0000484{{- end -}}
485{{- end -}}
Ben Claytonac660c22022-07-15 23:54:10 +0000486
487
488{{- /* ------------------------------------------------------------------ */ -}}
489{{- define "ConstEvalFn" -}}
490{{- /* ------------------------------------------------------------------ */ -}}
491 &ConstEval::
492{{- if eq .Kind "operator" -}}Op{{end -}}
493 {{template "ExpandName" .ConstEvalFunction}}
494{{- end -}}
495