Add continue statement type determination.

This CL adds type determination for the continue statement.

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

View File

@ -17,6 +17,7 @@
#include "src/ast/assignment_statement.h" #include "src/ast/assignment_statement.h"
#include "src/ast/break_statement.h" #include "src/ast/break_statement.h"
#include "src/ast/case_statement.h" #include "src/ast/case_statement.h"
#include "src/ast/continue_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"
@ -85,6 +86,10 @@ bool TypeDeterminer::DetermineResultType(ast::Statement* stmt) {
auto c = stmt->AsCase(); auto c = stmt->AsCase();
return DetermineResultType(c->body()); return DetermineResultType(c->body());
} }
if (stmt->IsContinue()) {
auto c = stmt->AsContinue();
return DetermineResultType(c->conditional());
}
error_ = "unknown statement type for type determination"; error_ = "unknown statement type for type determination";
return false; return false;

View File

@ -21,6 +21,7 @@
#include "src/ast/assignment_statement.h" #include "src/ast/assignment_statement.h"
#include "src/ast/break_statement.h" #include "src/ast/break_statement.h"
#include "src/ast/case_statement.h" #include "src/ast/case_statement.h"
#include "src/ast/continue_statement.h"
#include "src/ast/float_literal.h" #include "src/ast/float_literal.h"
#include "src/ast/int_literal.h" #include "src/ast/int_literal.h"
#include "src/ast/scalar_constructor_expression.h" #include "src/ast/scalar_constructor_expression.h"
@ -105,6 +106,20 @@ TEST_F(TypeDeterminerTest, Stmt_Case) {
EXPECT_TRUE(rhs_ptr->result_type()->IsF32()); EXPECT_TRUE(rhs_ptr->result_type()->IsF32());
} }
TEST_F(TypeDeterminerTest, Stmt_Continue) {
ast::type::I32Type i32;
auto cond = std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::IntLiteral>(&i32, 2));
auto cond_ptr = cond.get();
ast::ContinueStatement stmt(ast::StatementCondition::kIf, std::move(cond));
EXPECT_TRUE(td()->DetermineResultType(&stmt));
ASSERT_NE(cond_ptr->result_type(), nullptr);
EXPECT_TRUE(cond_ptr->result_type()->IsI32());
}
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(