From 45540b9dbddb1f7e99eff9a1ca89b5f2b32ed625 Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Tue, 7 Apr 2020 12:56:08 +0000 Subject: [PATCH] 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 --- src/type_determiner.cc | 6 ++++++ src/type_determiner_test.cc | 31 +++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/type_determiner.cc b/src/type_determiner.cc index 86e35570b4..9048b2f3ee 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 @@ bool TypeDeterminer::DetermineResultType(ast::Statement* stmt) { 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 75fb75ac34..6c591b4161 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 @@ TEST_F(TypeDeterminerTest, Stmt_Loop) { 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( + std::make_unique(&i32, 2)); + auto lhs_ptr = lhs.get(); + + auto rhs = std::make_unique( + std::make_unique(&f32, 2.3f)); + auto rhs_ptr = rhs.get(); + + ast::StatementList body; + body.push_back(std::make_unique(std::move(lhs), + std::move(rhs))); + + ast::RegardlessStatement regardless( + std::make_unique( + std::make_unique(&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(