Add while statement parsing.
This CL adds parsing for the WGSL `while` statement.
Bug: tint:1425
Change-Id: Ibce5e28568935ca4f51b5ac33e7a60af7a916b4a
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/93540
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
diff --git a/src/tint/program_builder.h b/src/tint/program_builder.h
index 960f3d7..5f17d1d 100644
--- a/src/tint/program_builder.h
+++ b/src/tint/program_builder.h
@@ -76,6 +76,7 @@
#include "src/tint/ast/variable_decl_statement.h"
#include "src/tint/ast/vector.h"
#include "src/tint/ast/void.h"
+#include "src/tint/ast/while_statement.h"
#include "src/tint/ast/workgroup_attribute.h"
#include "src/tint/number.h"
#include "src/tint/program.h"
@@ -2339,6 +2340,27 @@
return create<ast::ForLoopStatement>(init, Expr(std::forward<COND>(cond)), cont, body);
}
+ /// Creates a ast::WhileStatement with input body and condition.
+ /// @param source the source information
+ /// @param cond the loop condition
+ /// @param body the loop body
+ /// @returns the while statement pointer
+ template <typename COND>
+ const ast::WhileStatement* While(const Source& source,
+ COND&& cond,
+ const ast::BlockStatement* body) {
+ return create<ast::WhileStatement>(source, Expr(std::forward<COND>(cond)), body);
+ }
+
+ /// Creates a ast::WhileStatement with given condition and body.
+ /// @param cond the condition
+ /// @param body the loop body
+ /// @returns the while loop statement pointer
+ template <typename COND>
+ const ast::WhileStatement* While(COND&& cond, const ast::BlockStatement* body) {
+ return create<ast::WhileStatement>(Expr(std::forward<COND>(cond)), body);
+ }
+
/// Creates a ast::VariableDeclStatement for the input variable
/// @param source the source information
/// @param var the variable to wrap in a decl statement