Add break statement type determination.

This CL adds type determination for break statements.

Bug: tint:5
Change-Id: I5ca74a848ffd12fe404676910b08ea7518451eaf
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/18829
Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
dan sinclair 2020-04-07 12:54:10 +00:00 committed by dan sinclair
parent 6c498fc0f8
commit b7ea6e2f72
2 changed files with 20 additions and 0 deletions

View File

@ -15,6 +15,7 @@
#include "src/type_determiner.h"
#include "src/ast/assignment_statement.h"
#include "src/ast/break_statement.h"
#include "src/ast/scalar_constructor_expression.h"
#include "src/ast/type_constructor_expression.h"
@ -75,6 +76,10 @@ bool TypeDeterminer::DetermineResultType(ast::Statement* stmt) {
auto a = stmt->AsAssign();
return DetermineResultType(a->lhs()) && DetermineResultType(a->rhs());
}
if (stmt->IsBreak()) {
auto b = stmt->AsBreak();
return DetermineResultType(b->conditional());
}
error_ = "unknown statement type for type determination";
return false;

View File

@ -19,6 +19,7 @@
#include "gtest/gtest.h"
#include "src/ast/assignment_statement.h"
#include "src/ast/break_statement.h"
#include "src/ast/float_literal.h"
#include "src/ast/int_literal.h"
#include "src/ast/scalar_constructor_expression.h"
@ -63,6 +64,20 @@ TEST_F(TypeDeterminerTest, Stmt_Assign) {
EXPECT_TRUE(rhs_ptr->result_type()->IsF32());
}
TEST_F(TypeDeterminerTest, Stmt_Break) {
ast::type::I32Type i32;
auto cond = std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::IntLiteral>(&i32, 2));
auto cond_ptr = cond.get();
ast::BreakStatement brk(ast::StatementCondition::kIf, std::move(cond));
EXPECT_TRUE(td()->DetermineResultType(&brk));
ASSERT_NE(cond_ptr->result_type(), nullptr);
EXPECT_TRUE(cond_ptr->result_type()->IsI32());
}
TEST_F(TypeDeterminerTest, Expr_Constructor_Scalar) {
ast::type::F32Type f32;
ast::ScalarConstructorExpression s(