Add type determination for the regardless statement.
This CL adds the type determination code for the Regardless statement.
Bug: tint:5
Change-Id: I8485800f3e19130101917d8175e8111aa196828c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/18836
Reviewed-by: David Neto <dneto@google.com>
diff --git a/src/type_determiner.cc b/src/type_determiner.cc
index 86e3557..9048b2f 100644
--- a/src/type_determiner.cc
+++ b/src/type_determiner.cc
@@ -21,6 +21,7 @@
#include "src/ast/else_statement.h"
#include "src/ast/if_statement.h"
#include "src/ast/loop_statement.h"
+#include "src/ast/regardless_statement.h"
#include "src/ast/scalar_constructor_expression.h"
#include "src/ast/type_constructor_expression.h"
@@ -123,6 +124,11 @@
return DetermineResultType(l->body()) &&
DetermineResultType(l->continuing());
}
+ if (stmt->IsRegardless()) {
+ auto r = stmt->AsRegardless();
+ return DetermineResultType(r->condition()) &&
+ DetermineResultType(r->body());
+ }
if (stmt->IsNop()) {
return true;
}
diff --git a/src/type_determiner_test.cc b/src/type_determiner_test.cc
index 75fb75a..6c591b4 100644
--- a/src/type_determiner_test.cc
+++ b/src/type_determiner_test.cc
@@ -27,6 +27,7 @@
#include "src/ast/if_statement.h"
#include "src/ast/int_literal.h"
#include "src/ast/loop_statement.h"
+#include "src/ast/regardless_statement.h"
#include "src/ast/scalar_constructor_expression.h"
#include "src/ast/type/f32_type.h"
#include "src/ast/type/i32_type.h"
@@ -247,6 +248,36 @@
EXPECT_TRUE(continuing_rhs_ptr->result_type()->IsF32());
}
+TEST_F(TypeDeterminerTest, Stmt_Regardless) {
+ ast::type::I32Type i32;
+ ast::type::F32Type f32;
+
+ auto lhs = std::make_unique<ast::ScalarConstructorExpression>(
+ std::make_unique<ast::IntLiteral>(&i32, 2));
+ auto lhs_ptr = lhs.get();
+
+ auto rhs = std::make_unique<ast::ScalarConstructorExpression>(
+ std::make_unique<ast::FloatLiteral>(&f32, 2.3f));
+ auto rhs_ptr = rhs.get();
+
+ ast::StatementList body;
+ body.push_back(std::make_unique<ast::AssignmentStatement>(std::move(lhs),
+ std::move(rhs)));
+
+ ast::RegardlessStatement regardless(
+ std::make_unique<ast::ScalarConstructorExpression>(
+ std::make_unique<ast::IntLiteral>(&i32, 3)),
+ std::move(body));
+
+ EXPECT_TRUE(td()->DetermineResultType(®ardless));
+ ASSERT_NE(regardless.condition()->result_type(), nullptr);
+ ASSERT_NE(lhs_ptr->result_type(), nullptr);
+ ASSERT_NE(rhs_ptr->result_type(), nullptr);
+ EXPECT_TRUE(regardless.condition()->result_type()->IsI32());
+ EXPECT_TRUE(lhs_ptr->result_type()->IsI32());
+ EXPECT_TRUE(rhs_ptr->result_type()->IsF32());
+}
+
TEST_F(TypeDeterminerTest, Expr_Constructor_Scalar) {
ast::type::F32Type f32;
ast::ScalarConstructorExpression s(