blob: 14758e48b8ba9fbdb596510eeed708b12bbfec03 [file] [log] [blame]
Ben Claytona6b9a8e2021-01-26 16:57:10 +00001// Copyright 2021 The Tint Authors.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef SRC_PROGRAM_BUILDER_H_
16#define SRC_PROGRAM_BUILDER_H_
17
18#include <string>
19#include <utility>
20
21#include "src/ast/array_accessor_expression.h"
22#include "src/ast/binary_expression.h"
23#include "src/ast/bool_literal.h"
24#include "src/ast/call_expression.h"
25#include "src/ast/expression.h"
26#include "src/ast/float_literal.h"
27#include "src/ast/identifier_expression.h"
28#include "src/ast/member_accessor_expression.h"
29#include "src/ast/module.h"
30#include "src/ast/scalar_constructor_expression.h"
31#include "src/ast/sint_literal.h"
Ben Claytonbab31972021-02-08 21:16:21 +000032#include "src/ast/stride_decoration.h"
Ben Claytona6b9a8e2021-01-26 16:57:10 +000033#include "src/ast/struct.h"
34#include "src/ast/struct_member.h"
35#include "src/ast/struct_member_offset_decoration.h"
36#include "src/ast/type_constructor_expression.h"
37#include "src/ast/uint_literal.h"
38#include "src/ast/variable.h"
Ben Clayton844217f2021-01-27 18:49:05 +000039#include "src/diagnostic/diagnostic.h"
Ben Claytona6b9a8e2021-01-26 16:57:10 +000040#include "src/program.h"
Ben Claytondd1b6fc2021-01-29 10:55:40 +000041#include "src/semantic/info.h"
Ben Clayton7fdfff12021-01-29 15:17:30 +000042#include "src/semantic/node.h"
Ben Claytona6b9a8e2021-01-26 16:57:10 +000043#include "src/symbol_table.h"
44#include "src/type/alias_type.h"
45#include "src/type/array_type.h"
46#include "src/type/bool_type.h"
47#include "src/type/f32_type.h"
48#include "src/type/i32_type.h"
49#include "src/type/matrix_type.h"
50#include "src/type/pointer_type.h"
51#include "src/type/struct_type.h"
52#include "src/type/type_manager.h"
53#include "src/type/u32_type.h"
54#include "src/type/vector_type.h"
55#include "src/type/void_type.h"
56
57namespace tint {
58
Ben Clayton401b96b2021-02-03 17:19:59 +000059// Forward declarations
60namespace ast {
61class VariableDeclStatement;
62} // namespace ast
63
Ben Claytona6b9a8e2021-01-26 16:57:10 +000064class CloneContext;
65
66/// ProgramBuilder is a mutable builder for a Program.
67/// To construct a Program, populate the builder and then `std::move` it to a
68/// Program.
69class ProgramBuilder {
70 public:
Ben Clayton7fdfff12021-01-29 15:17:30 +000071 /// ASTNodeAllocator is an alias to BlockAllocator<ast::Node>
72 using ASTNodeAllocator = BlockAllocator<ast::Node>;
73
74 /// SemNodeAllocator is an alias to BlockAllocator<semantic::Node>
75 using SemNodeAllocator = BlockAllocator<semantic::Node>;
Ben Claytona6b9a8e2021-01-26 16:57:10 +000076
77 /// `i32` is a type alias to `int`.
78 /// Useful for passing to template methods such as `vec2<i32>()` to imitate
79 /// WGSL syntax.
80 /// Note: this is intentionally not aliased to uint32_t as we want integer
81 /// literals passed to the builder to match WGSL's integer literal types.
82 using i32 = decltype(1);
83 /// `u32` is a type alias to `unsigned int`.
84 /// Useful for passing to template methods such as `vec2<u32>()` to imitate
85 /// WGSL syntax.
86 /// Note: this is intentionally not aliased to uint32_t as we want integer
87 /// literals passed to the builder to match WGSL's integer literal types.
88 using u32 = decltype(1u);
89 /// `f32` is a type alias to `float`
90 /// Useful for passing to template methods such as `vec2<f32>()` to imitate
91 /// WGSL syntax.
92 using f32 = float;
93
94 /// Constructor
95 ProgramBuilder();
96
97 /// Move constructor
98 /// @param rhs the builder to move
99 ProgramBuilder(ProgramBuilder&& rhs);
100
101 /// Destructor
102 virtual ~ProgramBuilder();
103
104 /// Move assignment operator
105 /// @param rhs the builder to move
106 /// @return this builder
107 ProgramBuilder& operator=(ProgramBuilder&& rhs);
108
Ben Claytone43c8302021-01-29 11:59:32 +0000109 /// Wrap returns a new ProgramBuilder wrapping the Program `program` without
110 /// making a deep clone of the Program contents.
111 /// ProgramBuilder returned by Wrap() is intended to temporarily extend an
112 /// existing immutable program.
113 /// As the returned ProgramBuilder wraps `program`, `program` must not be
114 /// destructed or assigned while using the returned ProgramBuilder.
115 /// TODO(bclayton) - Evaluate whether there are safer alternatives to this
116 /// function. See crbug.com/tint/460.
117 /// @param program the immutable Program to wrap
118 /// @return the ProgramBuilder that wraps `program`
119 static ProgramBuilder Wrap(const Program* program);
120
Ben Claytona6b9a8e2021-01-26 16:57:10 +0000121 /// @returns a reference to the program's types
122 type::Manager& Types() {
123 AssertNotMoved();
124 return types_;
125 }
126
Ben Claytondd1b6fc2021-01-29 10:55:40 +0000127 /// @returns a reference to the program's types
128 const type::Manager& Types() const {
129 AssertNotMoved();
130 return types_;
131 }
132
Ben Claytona6b9a8e2021-01-26 16:57:10 +0000133 /// @returns a reference to the program's AST nodes storage
Ben Clayton7fdfff12021-01-29 15:17:30 +0000134 ASTNodeAllocator& ASTNodes() {
Ben Claytona6b9a8e2021-01-26 16:57:10 +0000135 AssertNotMoved();
Ben Clayton7fdfff12021-01-29 15:17:30 +0000136 return ast_nodes_;
Ben Claytona6b9a8e2021-01-26 16:57:10 +0000137 }
138
Ben Claytondd1b6fc2021-01-29 10:55:40 +0000139 /// @returns a reference to the program's AST nodes storage
Ben Clayton7fdfff12021-01-29 15:17:30 +0000140 const ASTNodeAllocator& ASTNodes() const {
Ben Claytondd1b6fc2021-01-29 10:55:40 +0000141 AssertNotMoved();
Ben Clayton7fdfff12021-01-29 15:17:30 +0000142 return ast_nodes_;
143 }
144
145 /// @returns a reference to the program's semantic nodes storage
146 SemNodeAllocator& SemNodes() {
147 AssertNotMoved();
148 return sem_nodes_;
149 }
150
151 /// @returns a reference to the program's semantic nodes storage
152 const SemNodeAllocator& SemNodes() const {
153 AssertNotMoved();
154 return sem_nodes_;
Ben Claytondd1b6fc2021-01-29 10:55:40 +0000155 }
156
Ben Claytona6b9a8e2021-01-26 16:57:10 +0000157 /// @returns a reference to the program's AST root Module
158 ast::Module& AST() {
159 AssertNotMoved();
160 return *ast_;
161 }
162
Ben Claytondd1b6fc2021-01-29 10:55:40 +0000163 /// @returns a reference to the program's AST root Module
164 const ast::Module& AST() const {
165 AssertNotMoved();
166 return *ast_;
167 }
168
169 /// @returns a reference to the program's semantic info
170 semantic::Info& Sem() {
171 AssertNotMoved();
172 return sem_;
173 }
174
175 /// @returns a reference to the program's semantic info
176 const semantic::Info& Sem() const {
177 AssertNotMoved();
178 return sem_;
179 }
180
Ben Claytona6b9a8e2021-01-26 16:57:10 +0000181 /// @returns a reference to the program's SymbolTable
182 SymbolTable& Symbols() {
183 AssertNotMoved();
184 return symbols_;
185 }
186
Ben Clayton708dc2d2021-01-29 11:22:40 +0000187 /// @returns a reference to the program's SymbolTable
188 const SymbolTable& Symbols() const {
189 AssertNotMoved();
190 return symbols_;
191 }
192
Ben Clayton844217f2021-01-27 18:49:05 +0000193 /// @returns a reference to the program's diagnostics
194 diag::List& Diagnostics() {
195 AssertNotMoved();
196 return diagnostics_;
197 }
198
Ben Claytondd1b6fc2021-01-29 10:55:40 +0000199 /// @returns a reference to the program's diagnostics
200 const diag::List& Diagnostics() const {
201 AssertNotMoved();
202 return diagnostics_;
203 }
204
Ben Claytondd69ac32021-01-27 19:23:55 +0000205 /// Controls whether the TypeDeterminer will be run on the program when it is
206 /// built.
207 /// @param enable the new flag value (defaults to true)
208 void SetResolveOnBuild(bool enable) { resolve_on_build_ = enable; }
209
210 /// @return true if the TypeDeterminer will be run on the program when it is
211 /// built.
212 bool ResolveOnBuild() const { return resolve_on_build_; }
213
Ben Clayton844217f2021-01-27 18:49:05 +0000214 /// @returns true if the program has no error diagnostics and is not missing
215 /// information
Ben Claytona6b9a8e2021-01-26 16:57:10 +0000216 bool IsValid() const;
217
Ben Clayton708dc2d2021-01-29 11:22:40 +0000218 /// Writes a representation of the node to the output stream
219 /// @note unlike str(), to_str() does not automatically demangle the string.
220 /// @param node the AST node
221 /// @param out the stream to write to
222 /// @param indent number of spaces to indent the node when writing
223 void to_str(const ast::Node* node, std::ostream& out, size_t indent) const {
224 node->to_str(Sem(), out, indent);
225 }
226
227 /// Returns a demangled, string representation of `node`.
228 /// @param node the AST node
229 /// @returns a string representation of the node
230 std::string str(const ast::Node* node) const;
231
Ben Clayton7fdfff12021-01-29 15:17:30 +0000232 /// Creates a new ast::Node owned by the ProgramBuilder. When the
233 /// ProgramBuilder is destructed, the ast::Node will also be destructed.
Ben Claytona6b9a8e2021-01-26 16:57:10 +0000234 /// @param source the Source of the node
235 /// @param args the arguments to pass to the type constructor
236 /// @returns the node pointer
237 template <typename T, typename... ARGS>
238 traits::EnableIfIsType<T, ast::Node>* create(const Source& source,
239 ARGS&&... args) {
240 AssertNotMoved();
Ben Clayton7fdfff12021-01-29 15:17:30 +0000241 return ast_nodes_.Create<T>(source, std::forward<ARGS>(args)...);
Ben Claytona6b9a8e2021-01-26 16:57:10 +0000242 }
243
Ben Clayton7fdfff12021-01-29 15:17:30 +0000244 /// Creates a new ast::Node owned by the ProgramBuilder, injecting the current
245 /// Source as set by the last call to SetSource() as the only argument to the
Ben Claytona6b9a8e2021-01-26 16:57:10 +0000246 /// constructor.
Ben Clayton7fdfff12021-01-29 15:17:30 +0000247 /// When the ProgramBuilder is destructed, the ast::Node will also be
248 /// destructed.
Ben Claytona6b9a8e2021-01-26 16:57:10 +0000249 /// @returns the node pointer
250 template <typename T>
251 traits::EnableIfIsType<T, ast::Node>* create() {
252 AssertNotMoved();
Ben Clayton7fdfff12021-01-29 15:17:30 +0000253 return ast_nodes_.Create<T>(source_);
Ben Claytona6b9a8e2021-01-26 16:57:10 +0000254 }
255
Ben Clayton7fdfff12021-01-29 15:17:30 +0000256 /// Creates a new ast::Node owned by the ProgramBuilder, injecting the current
257 /// Source as set by the last call to SetSource() as the first argument to the
Ben Claytona6b9a8e2021-01-26 16:57:10 +0000258 /// constructor.
Ben Clayton7fdfff12021-01-29 15:17:30 +0000259 /// When the ProgramBuilder is destructed, the ast::Node will also be
260 /// destructed.
Ben Claytona6b9a8e2021-01-26 16:57:10 +0000261 /// @param arg0 the first arguments to pass to the type constructor
262 /// @param args the remaining arguments to pass to the type constructor
263 /// @returns the node pointer
264 template <typename T, typename ARG0, typename... ARGS>
265 traits::EnableIf</* T is ast::Node and ARG0 is not Source */
266 traits::IsTypeOrDerived<T, ast::Node>::value &&
267 !traits::IsTypeOrDerived<ARG0, Source>::value,
268 T>*
269 create(ARG0&& arg0, ARGS&&... args) {
270 AssertNotMoved();
Ben Clayton7fdfff12021-01-29 15:17:30 +0000271 return ast_nodes_.Create<T>(source_, std::forward<ARG0>(arg0),
272 std::forward<ARGS>(args)...);
Ben Claytona6b9a8e2021-01-26 16:57:10 +0000273 }
274
Ben Clayton7fdfff12021-01-29 15:17:30 +0000275 /// Creates a new semantic::Node owned by the ProgramBuilder.
276 /// When the ProgramBuilder is destructed, the semantic::Node will also be
277 /// destructed.
278 /// @param args the arguments to pass to the type constructor
279 /// @returns the node pointer
280 template <typename T, typename... ARGS>
281 traits::EnableIfIsType<T, semantic::Node>* create(ARGS&&... args) {
282 AssertNotMoved();
283 return sem_nodes_.Create<T>(std::forward<ARGS>(args)...);
284 }
285
286 /// Creates a new type::Type owned by the ProgramBuilder.
287 /// When the ProgramBuilder is destructed, owned ProgramBuilder and the
288 /// returned`Type` will also be destructed.
Ben Claytona6b9a8e2021-01-26 16:57:10 +0000289 /// Types are unique (de-aliased), and so calling create() for the same `T`
290 /// and arguments will return the same pointer.
291 /// @warning Use this method to acquire a type only if all of its type
292 /// information is provided in the constructor arguments `args`.<br>
293 /// If the type requires additional configuration after construction that
294 /// affect its fundamental type, build the type with `std::make_unique`, make
295 /// any necessary alterations and then call unique_type() instead.
296 /// @param args the arguments to pass to the type constructor
297 /// @returns the de-aliased type pointer
298 template <typename T, typename... ARGS>
299 traits::EnableIfIsType<T, type::Type>* create(ARGS&&... args) {
300 static_assert(std::is_base_of<type::Type, T>::value,
301 "T does not derive from type::Type");
302 AssertNotMoved();
303 return types_.Get<T>(std::forward<ARGS>(args)...);
304 }
305
306 /// Marks this builder as moved, preventing any further use of the builder.
307 void MarkAsMoved();
308
309 //////////////////////////////////////////////////////////////////////////////
310 // TypesBuilder
311 //////////////////////////////////////////////////////////////////////////////
312
313 /// TypesBuilder holds basic `tint` types and methods for constructing
314 /// complex types.
315 class TypesBuilder {
316 public:
317 /// Constructor
318 /// @param builder the program builder
319 explicit TypesBuilder(ProgramBuilder* builder);
320
321 /// @return the tint AST type for the C type `T`.
322 template <typename T>
323 type::Type* Of() const {
324 return CToAST<T>::get(this);
325 }
326
327 /// @returns a boolean type
328 type::Bool* bool_() const { return builder->create<type::Bool>(); }
329
330 /// @returns a f32 type
331 type::F32* f32() const { return builder->create<type::F32>(); }
332
333 /// @returns a i32 type
334 type::I32* i32() const { return builder->create<type::I32>(); }
335
336 /// @returns a u32 type
337 type::U32* u32() const { return builder->create<type::U32>(); }
338
339 /// @returns a void type
340 type::Void* void_() const { return builder->create<type::Void>(); }
341
342 /// @return the tint AST type for a 2-element vector of the C type `T`.
343 template <typename T>
344 type::Vector* vec2() const {
345 return builder->create<type::Vector>(Of<T>(), 2);
346 }
347
348 /// @return the tint AST type for a 3-element vector of the C type `T`.
349 template <typename T>
350 type::Vector* vec3() const {
351 return builder->create<type::Vector>(Of<T>(), 3);
352 }
353
354 /// @return the tint AST type for a 4-element vector of the C type `T`.
355 template <typename T>
356 type::Type* vec4() const {
357 return builder->create<type::Vector>(Of<T>(), 4);
358 }
359
360 /// @return the tint AST type for a 2x3 matrix of the C type `T`.
361 template <typename T>
362 type::Matrix* mat2x2() const {
363 return builder->create<type::Matrix>(Of<T>(), 2, 2);
364 }
365
366 /// @return the tint AST type for a 2x3 matrix of the C type `T`.
367 template <typename T>
368 type::Matrix* mat2x3() const {
369 return builder->create<type::Matrix>(Of<T>(), 3, 2);
370 }
371
372 /// @return the tint AST type for a 2x4 matrix of the C type `T`.
373 template <typename T>
374 type::Matrix* mat2x4() const {
375 return builder->create<type::Matrix>(Of<T>(), 4, 2);
376 }
377
378 /// @return the tint AST type for a 3x2 matrix of the C type `T`.
379 template <typename T>
380 type::Matrix* mat3x2() const {
381 return builder->create<type::Matrix>(Of<T>(), 2, 3);
382 }
383
384 /// @return the tint AST type for a 3x3 matrix of the C type `T`.
385 template <typename T>
386 type::Matrix* mat3x3() const {
387 return builder->create<type::Matrix>(Of<T>(), 3, 3);
388 }
389
390 /// @return the tint AST type for a 3x4 matrix of the C type `T`.
391 template <typename T>
392 type::Matrix* mat3x4() const {
393 return builder->create<type::Matrix>(Of<T>(), 4, 3);
394 }
395
396 /// @return the tint AST type for a 4x2 matrix of the C type `T`.
397 template <typename T>
398 type::Matrix* mat4x2() const {
399 return builder->create<type::Matrix>(Of<T>(), 2, 4);
400 }
401
402 /// @return the tint AST type for a 4x3 matrix of the C type `T`.
403 template <typename T>
404 type::Matrix* mat4x3() const {
405 return builder->create<type::Matrix>(Of<T>(), 3, 4);
406 }
407
408 /// @return the tint AST type for a 4x4 matrix of the C type `T`.
409 template <typename T>
410 type::Matrix* mat4x4() const {
411 return builder->create<type::Matrix>(Of<T>(), 4, 4);
412 }
413
414 /// @param subtype the array element type
415 /// @param n the array size. 0 represents a runtime-array.
416 /// @return the tint AST type for a array of size `n` of type `T`
417 type::Array* array(type::Type* subtype, uint32_t n) const {
418 return builder->create<type::Array>(subtype, n,
419 ast::ArrayDecorationList{});
420 }
421
Ben Claytonbab31972021-02-08 21:16:21 +0000422 /// @param subtype the array element type
423 /// @param n the array size. 0 represents a runtime-array.
424 /// @param stride the array stride.
425 /// @return the tint AST type for a array of size `n` of type `T`
426 type::Array* array(type::Type* subtype, uint32_t n, uint32_t stride) const {
427 return builder->create<type::Array>(
428 subtype, n,
429 ast::ArrayDecorationList{
430 builder->create<ast::StrideDecoration>(stride),
431 });
432 }
433
Ben Claytona6b9a8e2021-01-26 16:57:10 +0000434 /// @return the tint AST type for an array of size `N` of type `T`
435 template <typename T, int N = 0>
436 type::Array* array() const {
437 return array(Of<T>(), N);
438 }
439
Ben Claytonbab31972021-02-08 21:16:21 +0000440 /// @param stride the array stride
441 /// @return the tint AST type for an array of size `N` of type `T`
442 template <typename T, int N = 0>
443 type::Array* array(uint32_t stride) const {
444 return array(Of<T>(), N, stride);
445 }
Ben Clayton42d1e092021-02-02 14:29:15 +0000446 /// Creates an alias type
Ben Claytona6b9a8e2021-01-26 16:57:10 +0000447 /// @param name the alias name
448 /// @param type the alias type
449 /// @returns the alias pointer
450 type::Alias* alias(const std::string& name, type::Type* type) const {
451 return builder->create<type::Alias>(builder->Symbols().Register(name),
452 type);
453 }
454
455 /// @return the tint AST pointer to type `T` with the given
456 /// ast::StorageClass.
457 /// @param storage_class the storage class of the pointer
458 template <typename T>
459 type::Pointer* pointer(ast::StorageClass storage_class) const {
460 return builder->create<type::Pointer>(Of<T>(), storage_class);
461 }
462
463 /// @param name the struct name
464 /// @param impl the struct implementation
465 /// @returns a struct pointer
466 type::Struct* struct_(const std::string& name, ast::Struct* impl) const {
467 return builder->create<type::Struct>(builder->Symbols().Register(name),
468 impl);
469 }
470
471 private:
472 /// CToAST<T> is specialized for various `T` types and each specialization
473 /// contains a single static `get()` method for obtaining the corresponding
474 /// AST type for the C type `T`.
475 /// `get()` has the signature:
476 /// `static type::Type* get(Types* t)`
477 template <typename T>
478 struct CToAST {};
479
480 ProgramBuilder* builder;
481 };
482
483 //////////////////////////////////////////////////////////////////////////////
484 // AST helper methods
485 //////////////////////////////////////////////////////////////////////////////
486
487 /// @param expr the expression
488 /// @return expr
489 ast::Expression* Expr(ast::Expression* expr) { return expr; }
490
491 /// @param name the identifier name
492 /// @return an ast::IdentifierExpression with the given name
493 ast::IdentifierExpression* Expr(const std::string& name) {
494 return create<ast::IdentifierExpression>(Symbols().Register(name));
495 }
496
497 /// @param source the source information
498 /// @param name the identifier name
499 /// @return an ast::IdentifierExpression with the given name
500 ast::IdentifierExpression* Expr(const Source& source,
501 const std::string& name) {
502 return create<ast::IdentifierExpression>(source, Symbols().Register(name));
503 }
504
505 /// @param name the identifier name
506 /// @return an ast::IdentifierExpression with the given name
507 ast::IdentifierExpression* Expr(const char* name) {
508 return create<ast::IdentifierExpression>(Symbols().Register(name));
509 }
510
511 /// @param value the boolean value
512 /// @return a Scalar constructor for the given value
513 ast::ScalarConstructorExpression* Expr(bool value) {
514 return create<ast::ScalarConstructorExpression>(Literal(value));
515 }
516
517 /// @param value the float value
518 /// @return a Scalar constructor for the given value
519 ast::ScalarConstructorExpression* Expr(f32 value) {
520 return create<ast::ScalarConstructorExpression>(Literal(value));
521 }
522
523 /// @param value the integer value
524 /// @return a Scalar constructor for the given value
525 ast::ScalarConstructorExpression* Expr(i32 value) {
526 return create<ast::ScalarConstructorExpression>(Literal(value));
527 }
528
529 /// @param value the unsigned int value
530 /// @return a Scalar constructor for the given value
531 ast::ScalarConstructorExpression* Expr(u32 value) {
532 return create<ast::ScalarConstructorExpression>(Literal(value));
533 }
534
535 /// Converts `arg` to an `ast::Expression` using `Expr()`, then appends it to
536 /// `list`.
537 /// @param list the list to append too
538 /// @param arg the arg to create
539 template <typename ARG>
540 void Append(ast::ExpressionList& list, ARG&& arg) {
541 list.emplace_back(Expr(std::forward<ARG>(arg)));
542 }
543
544 /// Converts `arg0` and `args` to `ast::Expression`s using `Expr()`,
545 /// then appends them to `list`.
546 /// @param list the list to append too
547 /// @param arg0 the first argument
548 /// @param args the rest of the arguments
549 template <typename ARG0, typename... ARGS>
550 void Append(ast::ExpressionList& list, ARG0&& arg0, ARGS&&... args) {
551 Append(list, std::forward<ARG0>(arg0));
552 Append(list, std::forward<ARGS>(args)...);
553 }
554
555 /// @return an empty list of expressions
556 ast::ExpressionList ExprList() { return {}; }
557
558 /// @param args the list of expressions
559 /// @return the list of expressions converted to `ast::Expression`s using
560 /// `Expr()`,
561 template <typename... ARGS>
562 ast::ExpressionList ExprList(ARGS&&... args) {
563 ast::ExpressionList list;
564 list.reserve(sizeof...(args));
565 Append(list, std::forward<ARGS>(args)...);
566 return list;
567 }
568
569 /// @param list the list of expressions
570 /// @return `list`
571 ast::ExpressionList ExprList(ast::ExpressionList list) { return list; }
572
573 /// @param val the boolan value
574 /// @return a boolean literal with the given value
575 ast::BoolLiteral* Literal(bool val) {
576 return create<ast::BoolLiteral>(ty.bool_(), val);
577 }
578
579 /// @param val the float value
580 /// @return a float literal with the given value
581 ast::FloatLiteral* Literal(f32 val) {
582 return create<ast::FloatLiteral>(ty.f32(), val);
583 }
584
585 /// @param val the unsigned int value
586 /// @return a ast::UintLiteral with the given value
587 ast::UintLiteral* Literal(u32 val) {
588 return create<ast::UintLiteral>(ty.u32(), val);
589 }
590
591 /// @param val the integer value
592 /// @return the ast::SintLiteral with the given value
593 ast::SintLiteral* Literal(i32 val) {
594 return create<ast::SintLiteral>(ty.i32(), val);
595 }
596
597 /// @param args the arguments for the type constructor
598 /// @return an `ast::TypeConstructorExpression` of type `ty`, with the values
599 /// of `args` converted to `ast::Expression`s using `Expr()`
600 template <typename T, typename... ARGS>
601 ast::TypeConstructorExpression* Construct(ARGS&&... args) {
602 return create<ast::TypeConstructorExpression>(
603 ty.Of<T>(), ExprList(std::forward<ARGS>(args)...));
604 }
605
606 /// @param type the type to construct
607 /// @param args the arguments for the constructor
608 /// @return an `ast::TypeConstructorExpression` of `type` constructed with the
609 /// values `args`.
610 template <typename... ARGS>
611 ast::TypeConstructorExpression* Construct(type::Type* type, ARGS&&... args) {
612 return create<ast::TypeConstructorExpression>(
613 type, ExprList(std::forward<ARGS>(args)...));
614 }
615
616 /// @param args the arguments for the vector constructor
617 /// @return an `ast::TypeConstructorExpression` of a 2-element vector of type
618 /// `T`, constructed with the values `args`.
619 template <typename T, typename... ARGS>
620 ast::TypeConstructorExpression* vec2(ARGS&&... args) {
621 return create<ast::TypeConstructorExpression>(
622 ty.vec2<T>(), ExprList(std::forward<ARGS>(args)...));
623 }
624
625 /// @param args the arguments for the vector constructor
626 /// @return an `ast::TypeConstructorExpression` of a 3-element vector of type
627 /// `T`, constructed with the values `args`.
628 template <typename T, typename... ARGS>
629 ast::TypeConstructorExpression* vec3(ARGS&&... args) {
630 return create<ast::TypeConstructorExpression>(
631 ty.vec3<T>(), ExprList(std::forward<ARGS>(args)...));
632 }
633
634 /// @param args the arguments for the vector constructor
635 /// @return an `ast::TypeConstructorExpression` of a 4-element vector of type
636 /// `T`, constructed with the values `args`.
637 template <typename T, typename... ARGS>
638 ast::TypeConstructorExpression* vec4(ARGS&&... args) {
639 return create<ast::TypeConstructorExpression>(
640 ty.vec4<T>(), ExprList(std::forward<ARGS>(args)...));
641 }
642
643 /// @param args the arguments for the matrix constructor
644 /// @return an `ast::TypeConstructorExpression` of a 2x2 matrix of type
645 /// `T`, constructed with the values `args`.
646 template <typename T, typename... ARGS>
647 ast::TypeConstructorExpression* mat2x2(ARGS&&... args) {
648 return create<ast::TypeConstructorExpression>(
649 ty.mat2x2<T>(), ExprList(std::forward<ARGS>(args)...));
650 }
651
652 /// @param args the arguments for the matrix constructor
653 /// @return an `ast::TypeConstructorExpression` of a 2x3 matrix of type
654 /// `T`, constructed with the values `args`.
655 template <typename T, typename... ARGS>
656 ast::TypeConstructorExpression* mat2x3(ARGS&&... args) {
657 return create<ast::TypeConstructorExpression>(
658 ty.mat2x3<T>(), ExprList(std::forward<ARGS>(args)...));
659 }
660
661 /// @param args the arguments for the matrix constructor
662 /// @return an `ast::TypeConstructorExpression` of a 2x4 matrix of type
663 /// `T`, constructed with the values `args`.
664 template <typename T, typename... ARGS>
665 ast::TypeConstructorExpression* mat2x4(ARGS&&... args) {
666 return create<ast::TypeConstructorExpression>(
667 ty.mat2x4<T>(), ExprList(std::forward<ARGS>(args)...));
668 }
669
670 /// @param args the arguments for the matrix constructor
671 /// @return an `ast::TypeConstructorExpression` of a 3x2 matrix of type
672 /// `T`, constructed with the values `args`.
673 template <typename T, typename... ARGS>
674 ast::TypeConstructorExpression* mat3x2(ARGS&&... args) {
675 return create<ast::TypeConstructorExpression>(
676 ty.mat3x2<T>(), ExprList(std::forward<ARGS>(args)...));
677 }
678
679 /// @param args the arguments for the matrix constructor
680 /// @return an `ast::TypeConstructorExpression` of a 3x3 matrix of type
681 /// `T`, constructed with the values `args`.
682 template <typename T, typename... ARGS>
683 ast::TypeConstructorExpression* mat3x3(ARGS&&... args) {
684 return create<ast::TypeConstructorExpression>(
685 ty.mat3x3<T>(), ExprList(std::forward<ARGS>(args)...));
686 }
687
688 /// @param args the arguments for the matrix constructor
689 /// @return an `ast::TypeConstructorExpression` of a 3x4 matrix of type
690 /// `T`, constructed with the values `args`.
691 template <typename T, typename... ARGS>
692 ast::TypeConstructorExpression* mat3x4(ARGS&&... args) {
693 return create<ast::TypeConstructorExpression>(
694 ty.mat3x4<T>(), ExprList(std::forward<ARGS>(args)...));
695 }
696
697 /// @param args the arguments for the matrix constructor
698 /// @return an `ast::TypeConstructorExpression` of a 4x2 matrix of type
699 /// `T`, constructed with the values `args`.
700 template <typename T, typename... ARGS>
701 ast::TypeConstructorExpression* mat4x2(ARGS&&... args) {
702 return create<ast::TypeConstructorExpression>(
703 ty.mat4x2<T>(), ExprList(std::forward<ARGS>(args)...));
704 }
705
706 /// @param args the arguments for the matrix constructor
707 /// @return an `ast::TypeConstructorExpression` of a 4x3 matrix of type
708 /// `T`, constructed with the values `args`.
709 template <typename T, typename... ARGS>
710 ast::TypeConstructorExpression* mat4x3(ARGS&&... args) {
711 return create<ast::TypeConstructorExpression>(
712 ty.mat4x3<T>(), ExprList(std::forward<ARGS>(args)...));
713 }
714
715 /// @param args the arguments for the matrix constructor
716 /// @return an `ast::TypeConstructorExpression` of a 4x4 matrix of type
717 /// `T`, constructed with the values `args`.
718 template <typename T, typename... ARGS>
719 ast::TypeConstructorExpression* mat4x4(ARGS&&... args) {
720 return create<ast::TypeConstructorExpression>(
721 ty.mat4x4<T>(), ExprList(std::forward<ARGS>(args)...));
722 }
723
724 /// @param args the arguments for the array constructor
725 /// @return an `ast::TypeConstructorExpression` of an array with element type
726 /// `T`, constructed with the values `args`.
727 template <typename T, int N = 0, typename... ARGS>
728 ast::TypeConstructorExpression* array(ARGS&&... args) {
729 return create<ast::TypeConstructorExpression>(
730 ty.array<T, N>(), ExprList(std::forward<ARGS>(args)...));
731 }
732
733 /// @param subtype the array element type
734 /// @param n the array size. 0 represents a runtime-array.
735 /// @param args the arguments for the array constructor
736 /// @return an `ast::TypeConstructorExpression` of an array with element type
737 /// `subtype`, constructed with the values `args`.
738 template <typename... ARGS>
739 ast::TypeConstructorExpression* array(type::Type* subtype,
740 uint32_t n,
741 ARGS&&... args) {
742 return create<ast::TypeConstructorExpression>(
743 ty.array(subtype, n), ExprList(std::forward<ARGS>(args)...));
744 }
745
746 /// @param name the variable name
747 /// @param storage the variable storage class
748 /// @param type the variable type
749 /// @returns a `ast::Variable` with the given name, storage and type. The
750 /// variable will be built with a nullptr constructor and no decorations.
751 ast::Variable* Var(const std::string& name,
752 ast::StorageClass storage,
753 type::Type* type);
754
755 /// @param name the variable name
756 /// @param storage the variable storage class
757 /// @param type the variable type
758 /// @param constructor constructor expression
759 /// @param decorations variable decorations
760 /// @returns a `ast::Variable` with the given name, storage and type
761 ast::Variable* Var(const std::string& name,
762 ast::StorageClass storage,
763 type::Type* type,
764 ast::Expression* constructor,
765 ast::VariableDecorationList decorations);
766
767 /// @param source the variable source
768 /// @param name the variable name
769 /// @param storage the variable storage class
770 /// @param type the variable type
771 /// @param constructor constructor expression
772 /// @param decorations variable decorations
773 /// @returns a `ast::Variable` with the given name, storage and type
774 ast::Variable* Var(const Source& source,
775 const std::string& name,
776 ast::StorageClass storage,
777 type::Type* type,
778 ast::Expression* constructor,
779 ast::VariableDecorationList decorations);
780
781 /// @param name the variable name
782 /// @param storage the variable storage class
783 /// @param type the variable type
784 /// @returns a constant `ast::Variable` with the given name, storage and type.
785 /// The variable will be built with a nullptr constructor and no decorations.
786 ast::Variable* Const(const std::string& name,
787 ast::StorageClass storage,
788 type::Type* type);
789
790 /// @param name the variable name
791 /// @param storage the variable storage class
792 /// @param type the variable type
793 /// @param constructor optional constructor expression
794 /// @param decorations optional variable decorations
795 /// @returns a constant `ast::Variable` with the given name, storage and type
796 ast::Variable* Const(const std::string& name,
797 ast::StorageClass storage,
798 type::Type* type,
799 ast::Expression* constructor,
800 ast::VariableDecorationList decorations);
801
802 /// @param source the variable source
803 /// @param name the variable name
804 /// @param storage the variable storage class
805 /// @param type the variable type
806 /// @param constructor optional constructor expression
807 /// @param decorations optional variable decorations
808 /// @returns a constant `ast::Variable` with the given name, storage and type
809 ast::Variable* Const(const Source& source,
810 const std::string& name,
811 ast::StorageClass storage,
812 type::Type* type,
813 ast::Expression* constructor,
814 ast::VariableDecorationList decorations);
815
Ben Clayton401b96b2021-02-03 17:19:59 +0000816 /// @param args the arguments to pass to Var()
817 /// @returns a `ast::Variable` constructed by calling Var() with the arguments
818 /// of `args`, which is automatically registered as a global variable with the
819 /// ast::Module.
820 template <typename... ARGS>
821 ast::Variable* Global(ARGS&&... args) {
822 auto* var = Var(std::forward<ARGS>(args)...);
823 AST().AddGlobalVariable(var);
824 return var;
825 }
826
827 /// @param args the arguments to pass to Const()
828 /// @returns a const `ast::Variable` constructed by calling Var() with the
829 /// arguments of `args`, which is automatically registered as a global
830 /// variable with the ast::Module.
831 template <typename... ARGS>
832 ast::Variable* GlobalConst(ARGS&&... args) {
833 auto* var = Const(std::forward<ARGS>(args)...);
834 AST().AddGlobalVariable(var);
835 return var;
836 }
837
Ben Claytona6b9a8e2021-01-26 16:57:10 +0000838 /// @param func the function name
839 /// @param args the function call arguments
840 /// @returns a `ast::CallExpression` to the function `func`, with the
841 /// arguments of `args` converted to `ast::Expression`s using `Expr()`.
842 template <typename NAME, typename... ARGS>
843 ast::CallExpression* Call(NAME&& func, ARGS&&... args) {
844 return create<ast::CallExpression>(Expr(func),
845 ExprList(std::forward<ARGS>(args)...));
846 }
847
848 /// @param lhs the left hand argument to the addition operation
849 /// @param rhs the right hand argument to the addition operation
850 /// @returns a `ast::BinaryExpression` summing the arguments `lhs` and `rhs`
851 template <typename LHS, typename RHS>
852 ast::Expression* Add(LHS&& lhs, RHS&& rhs) {
853 return create<ast::BinaryExpression>(ast::BinaryOp::kAdd,
854 Expr(std::forward<LHS>(lhs)),
855 Expr(std::forward<RHS>(rhs)));
856 }
857
858 /// @param lhs the left hand argument to the subtraction operation
859 /// @param rhs the right hand argument to the subtraction operation
860 /// @returns a `ast::BinaryExpression` subtracting `rhs` from `lhs`
861 template <typename LHS, typename RHS>
862 ast::Expression* Sub(LHS&& lhs, RHS&& rhs) {
863 return create<ast::BinaryExpression>(ast::BinaryOp::kSubtract,
864 Expr(std::forward<LHS>(lhs)),
865 Expr(std::forward<RHS>(rhs)));
866 }
867
868 /// @param lhs the left hand argument to the multiplication operation
869 /// @param rhs the right hand argument to the multiplication operation
870 /// @returns a `ast::BinaryExpression` multiplying `rhs` from `lhs`
871 template <typename LHS, typename RHS>
872 ast::Expression* Mul(LHS&& lhs, RHS&& rhs) {
873 return create<ast::BinaryExpression>(ast::BinaryOp::kMultiply,
874 Expr(std::forward<LHS>(lhs)),
875 Expr(std::forward<RHS>(rhs)));
876 }
877
878 /// @param arr the array argument for the array accessor expression
879 /// @param idx the index argument for the array accessor expression
880 /// @returns a `ast::ArrayAccessorExpression` that indexes `arr` with `idx`
881 template <typename ARR, typename IDX>
882 ast::Expression* IndexAccessor(ARR&& arr, IDX&& idx) {
883 return create<ast::ArrayAccessorExpression>(Expr(std::forward<ARR>(arr)),
884 Expr(std::forward<IDX>(idx)));
885 }
886
887 /// @param obj the object for the member accessor expression
888 /// @param idx the index argument for the array accessor expression
889 /// @returns a `ast::MemberAccessorExpression` that indexes `obj` with `idx`
890 template <typename OBJ, typename IDX>
891 ast::Expression* MemberAccessor(OBJ&& obj, IDX&& idx) {
892 return create<ast::MemberAccessorExpression>(Expr(std::forward<OBJ>(obj)),
893 Expr(std::forward<IDX>(idx)));
894 }
895
Ben Clayton42d1e092021-02-02 14:29:15 +0000896 /// Creates a ast::StructMemberOffsetDecoration
Ben Claytona6b9a8e2021-01-26 16:57:10 +0000897 /// @param val the offset value
898 /// @returns the offset decoration pointer
899 ast::StructMemberOffsetDecoration* MemberOffset(uint32_t val) {
900 return create<ast::StructMemberOffsetDecoration>(source_, val);
901 }
902
Ben Clayton42d1e092021-02-02 14:29:15 +0000903 /// Creates an ast::Function and registers it with the ast::Module.
Ben Claytona6b9a8e2021-01-26 16:57:10 +0000904 /// @param source the source information
905 /// @param name the function name
906 /// @param params the function parameters
907 /// @param type the function return type
908 /// @param body the function body
909 /// @param decorations the function decorations
910 /// @returns the function pointer
911 ast::Function* Func(Source source,
912 std::string name,
913 ast::VariableList params,
914 type::Type* type,
915 ast::StatementList body,
916 ast::FunctionDecorationList decorations) {
Ben Clayton42d1e092021-02-02 14:29:15 +0000917 auto* func =
918 create<ast::Function>(source, Symbols().Register(name), params, type,
919 create<ast::BlockStatement>(body), decorations);
920 AST().Functions().Add(func);
921 return func;
Ben Claytona6b9a8e2021-01-26 16:57:10 +0000922 }
923
Ben Clayton42d1e092021-02-02 14:29:15 +0000924 /// Creates an ast::Function and registers it with the ast::Module.
Ben Claytona6b9a8e2021-01-26 16:57:10 +0000925 /// @param name the function name
926 /// @param params the function parameters
927 /// @param type the function return type
928 /// @param body the function body
929 /// @param decorations the function decorations
930 /// @returns the function pointer
931 ast::Function* Func(std::string name,
932 ast::VariableList params,
933 type::Type* type,
934 ast::StatementList body,
935 ast::FunctionDecorationList decorations) {
Ben Clayton42d1e092021-02-02 14:29:15 +0000936 auto* func =
937 create<ast::Function>(Symbols().Register(name), params, type,
938 create<ast::BlockStatement>(body), decorations);
939 AST().Functions().Add(func);
940 return func;
Ben Claytona6b9a8e2021-01-26 16:57:10 +0000941 }
942
Ben Clayton42d1e092021-02-02 14:29:15 +0000943 /// Creates a ast::StructMember
Ben Claytona6b9a8e2021-01-26 16:57:10 +0000944 /// @param source the source information
945 /// @param name the struct member name
946 /// @param type the struct member type
947 /// @returns the struct member pointer
948 ast::StructMember* Member(const Source& source,
949 const std::string& name,
950 type::Type* type) {
951 return create<ast::StructMember>(source, Symbols().Register(name), type,
952 ast::StructMemberDecorationList{});
953 }
954
Ben Clayton42d1e092021-02-02 14:29:15 +0000955 /// Creates a ast::StructMember
Ben Claytona6b9a8e2021-01-26 16:57:10 +0000956 /// @param name the struct member name
957 /// @param type the struct member type
958 /// @returns the struct member pointer
959 ast::StructMember* Member(const std::string& name, type::Type* type) {
960 return create<ast::StructMember>(source_, Symbols().Register(name), type,
961 ast::StructMemberDecorationList{});
962 }
963
Ben Clayton42d1e092021-02-02 14:29:15 +0000964 /// Creates a ast::StructMember
Ben Claytona6b9a8e2021-01-26 16:57:10 +0000965 /// @param name the struct member name
966 /// @param type the struct member type
967 /// @param decorations the struct member decorations
968 /// @returns the struct member pointer
969 ast::StructMember* Member(const std::string& name,
970 type::Type* type,
971 ast::StructMemberDecorationList decorations) {
972 return create<ast::StructMember>(source_, Symbols().Register(name), type,
973 decorations);
974 }
975
Ben Claytonbab31972021-02-08 21:16:21 +0000976 /// Creates a ast::StructMember with the given byte offset
977 /// @param offset the offset to use in the StructMemberOffsetDecoration
978 /// @param name the struct member name
979 /// @param type the struct member type
980 /// @returns the struct member pointer
981 ast::StructMember* Member(uint32_t offset,
982 const std::string& name,
983 type::Type* type) {
984 return create<ast::StructMember>(
985 source_, Symbols().Register(name), type,
986 ast::StructMemberDecorationList{
987 create<ast::StructMemberOffsetDecoration>(offset),
988 });
989 }
990
Ben Claytona6b9a8e2021-01-26 16:57:10 +0000991 /// Sets the current builder source to `src`
992 /// @param src the Source used for future create() calls
993 void SetSource(const Source& src) {
994 AssertNotMoved();
995 source_ = src;
996 }
997
998 /// Sets the current builder source to `loc`
999 /// @param loc the Source used for future create() calls
1000 void SetSource(const Source::Location& loc) {
1001 AssertNotMoved();
1002 source_ = Source(loc);
1003 }
1004
Ben Clayton33352542021-01-29 16:43:41 +00001005 /// Helper for returning the resolved semantic type of the expression `expr`.
1006 /// @note As the TypeDeterminator is run when the Program is built, this will
1007 /// only be useful for the TypeDeterminer itself and tests that use their own
1008 /// TypeDeterminer.
1009 /// @param expr the AST expression
1010 /// @return the resolved semantic type for the expression, or nullptr if the
1011 /// expression has no resolved type.
1012 type::Type* TypeOf(ast::Expression* expr) const;
1013
Ben Clayton401b96b2021-02-03 17:19:59 +00001014 /// Wraps the ast::Expression in a statement. This is used by tests that
1015 /// construct a partial AST and require the TypeDeterminer to reach these
1016 /// nodes.
1017 /// @param expr the ast::Expression to be wrapped by an ast::Statement
1018 /// @return the ast::Statement that wraps the ast::Expression
1019 ast::Statement* WrapInStatement(ast::Expression* expr);
1020 /// Wraps the ast::Variable in a ast::VariableDeclStatement. This is used by
1021 /// tests that construct a partial AST and require the TypeDeterminer to reach
1022 /// these nodes.
1023 /// @param v the ast::Variable to be wrapped by an ast::VariableDeclStatement
1024 /// @return the ast::VariableDeclStatement that wraps the ast::Variable
1025 ast::VariableDeclStatement* WrapInStatement(ast::Variable* v);
1026 /// Returns the statement argument. Used as a passthrough-overload by
1027 /// WrapInFunction().
1028 /// @param stmt the ast::Statement
1029 /// @return `stmt`
1030 ast::Statement* WrapInStatement(ast::Statement* stmt);
1031 /// Wraps the list of arguments in a simple function so that each is reachable
1032 /// by the TypeDeterminer.
1033 /// @param args a mix of ast::Expression, ast::Statement, ast::Variables.
1034 template <typename... ARGS>
1035 void WrapInFunction(ARGS&&... args) {
1036 ast::StatementList stmts{WrapInStatement(std::forward<ARGS>(args))...};
1037 WrapInFunction(stmts);
1038 }
1039 /// @param stmts a list of ast::Statement that will be wrapped by a function,
1040 /// so that each statement is reachable by the TypeDeterminer.
1041 void WrapInFunction(ast::StatementList stmts);
1042
Ben Claytona6b9a8e2021-01-26 16:57:10 +00001043 /// The builder types
1044 TypesBuilder ty;
1045
1046 protected:
1047 /// Asserts that the builder has not been moved.
1048 void AssertNotMoved() const;
1049
Ben Claytona6b9a8e2021-01-26 16:57:10 +00001050 private:
1051 type::Manager types_;
Ben Clayton7fdfff12021-01-29 15:17:30 +00001052 ASTNodeAllocator ast_nodes_;
1053 SemNodeAllocator sem_nodes_;
Ben Claytona6b9a8e2021-01-26 16:57:10 +00001054 ast::Module* ast_;
Ben Claytondd1b6fc2021-01-29 10:55:40 +00001055 semantic::Info sem_;
Ben Claytona6b9a8e2021-01-26 16:57:10 +00001056 SymbolTable symbols_;
Ben Clayton844217f2021-01-27 18:49:05 +00001057 diag::List diagnostics_;
Ben Claytona6b9a8e2021-01-26 16:57:10 +00001058
1059 /// The source to use when creating AST nodes without providing a Source as
1060 /// the first argument.
1061 Source source_;
1062
Ben Claytondd69ac32021-01-27 19:23:55 +00001063 /// Set by SetResolveOnBuild(). If set, the TypeDeterminer will be run on the
1064 /// program when built.
1065 bool resolve_on_build_ = true;
1066
Ben Claytona6b9a8e2021-01-26 16:57:10 +00001067 /// Set by MarkAsMoved(). Once set, no methods may be called on this builder.
1068 bool moved_ = false;
1069};
1070
1071//! @cond Doxygen_Suppress
1072// Various template specializations for ProgramBuilder::TypesBuilder::CToAST.
1073template <>
1074struct ProgramBuilder::TypesBuilder::CToAST<ProgramBuilder::i32> {
1075 static type::Type* get(const ProgramBuilder::TypesBuilder* t) {
1076 return t->i32();
1077 }
1078};
1079template <>
1080struct ProgramBuilder::TypesBuilder::CToAST<ProgramBuilder::u32> {
1081 static type::Type* get(const ProgramBuilder::TypesBuilder* t) {
1082 return t->u32();
1083 }
1084};
1085template <>
1086struct ProgramBuilder::TypesBuilder::CToAST<ProgramBuilder::f32> {
1087 static type::Type* get(const ProgramBuilder::TypesBuilder* t) {
1088 return t->f32();
1089 }
1090};
1091template <>
1092struct ProgramBuilder::TypesBuilder::CToAST<bool> {
1093 static type::Type* get(const ProgramBuilder::TypesBuilder* t) {
1094 return t->bool_();
1095 }
1096};
1097template <>
1098struct ProgramBuilder::TypesBuilder::CToAST<void> {
1099 static type::Type* get(const ProgramBuilder::TypesBuilder* t) {
1100 return t->void_();
1101 }
1102};
1103//! @endcond
1104
1105} // namespace tint
1106
1107#endif // SRC_PROGRAM_BUILDER_H_