resolver: Validate compound assignment statements
Reuse the logic for resolving binary operator result types that was
implemented for binary expressions. This validates that the LHS and
RHS are compatible for the target operator. We then try to match the
resolved result type against the LHS store type.
Bug: tint:1325
Change-Id: If80a883079bb71fa6c4eb5545654279fefffacb4
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/74362
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
diff --git a/src/tint/program_builder.h b/src/tint/program_builder.h
index 1d40cb1..eb87d3e 100644
--- a/src/tint/program_builder.h
+++ b/src/tint/program_builder.h
@@ -32,6 +32,7 @@
#include "src/tint/ast/call_expression.h"
#include "src/tint/ast/call_statement.h"
#include "src/tint/ast/case_statement.h"
+#include "src/tint/ast/compound_assignment_statement.h"
#include "src/tint/ast/continue_statement.h"
#include "src/tint/ast/depth_multisampled_texture.h"
#include "src/tint/ast/depth_texture.h"
@@ -2265,6 +2266,40 @@
Expr(std::forward<RhsExpressionInit>(rhs)));
}
+ /// Creates a ast::CompoundAssignmentStatement with input lhs and rhs
+ /// expressions, and a binary operator.
+ /// @param source the source information
+ /// @param lhs the left hand side expression initializer
+ /// @param rhs the right hand side expression initializer
+ /// @param op the binary operator
+ /// @returns the compound assignment statement pointer
+ template <typename LhsExpressionInit, typename RhsExpressionInit>
+ const ast::CompoundAssignmentStatement* CompoundAssign(
+ const Source& source,
+ LhsExpressionInit&& lhs,
+ RhsExpressionInit&& rhs,
+ ast::BinaryOp op) {
+ return create<ast::CompoundAssignmentStatement>(
+ source, Expr(std::forward<LhsExpressionInit>(lhs)),
+ Expr(std::forward<RhsExpressionInit>(rhs)), op);
+ }
+
+ /// Creates a ast::CompoundAssignmentStatement with input lhs and rhs
+ /// expressions, and a binary operator.
+ /// @param lhs the left hand side expression initializer
+ /// @param rhs the right hand side expression initializer
+ /// @param op the binary operator
+ /// @returns the compound assignment statement pointer
+ template <typename LhsExpressionInit, typename RhsExpressionInit>
+ const ast::CompoundAssignmentStatement* CompoundAssign(
+ LhsExpressionInit&& lhs,
+ RhsExpressionInit&& rhs,
+ ast::BinaryOp op) {
+ return create<ast::CompoundAssignmentStatement>(
+ Expr(std::forward<LhsExpressionInit>(lhs)),
+ Expr(std::forward<RhsExpressionInit>(rhs)), op);
+ }
+
/// Creates a ast::LoopStatement with input body and optional continuing
/// @param source the source information
/// @param body the loop body