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>
This commit is contained in:
dan sinclair 2020-04-07 12:56:08 +00:00 committed by dan sinclair
parent bc71edaab3
commit 45540b9dbd
2 changed files with 37 additions and 0 deletions

View File

@ -21,6 +21,7 @@
#include "src/ast/else_statement.h" #include "src/ast/else_statement.h"
#include "src/ast/if_statement.h" #include "src/ast/if_statement.h"
#include "src/ast/loop_statement.h" #include "src/ast/loop_statement.h"
#include "src/ast/regardless_statement.h"
#include "src/ast/scalar_constructor_expression.h" #include "src/ast/scalar_constructor_expression.h"
#include "src/ast/type_constructor_expression.h" #include "src/ast/type_constructor_expression.h"
@ -123,6 +124,11 @@ bool TypeDeterminer::DetermineResultType(ast::Statement* stmt) {
return DetermineResultType(l->body()) && return DetermineResultType(l->body()) &&
DetermineResultType(l->continuing()); DetermineResultType(l->continuing());
} }
if (stmt->IsRegardless()) {
auto r = stmt->AsRegardless();
return DetermineResultType(r->condition()) &&
DetermineResultType(r->body());
}
if (stmt->IsNop()) { if (stmt->IsNop()) {
return true; return true;
} }

View File

@ -27,6 +27,7 @@
#include "src/ast/if_statement.h" #include "src/ast/if_statement.h"
#include "src/ast/int_literal.h" #include "src/ast/int_literal.h"
#include "src/ast/loop_statement.h" #include "src/ast/loop_statement.h"
#include "src/ast/regardless_statement.h"
#include "src/ast/scalar_constructor_expression.h" #include "src/ast/scalar_constructor_expression.h"
#include "src/ast/type/f32_type.h" #include "src/ast/type/f32_type.h"
#include "src/ast/type/i32_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()); 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(&regardless));
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) { TEST_F(TypeDeterminerTest, Expr_Constructor_Scalar) {
ast::type::F32Type f32; ast::type::F32Type f32;
ast::ScalarConstructorExpression s( ast::ScalarConstructorExpression s(