From aec965e4a1cb513e9ca45c9747f221532797f75e Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Tue, 7 Apr 2020 12:54:29 +0000 Subject: [PATCH] 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 --- src/type_determiner.cc | 5 +++++ src/type_determiner_test.cc | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/type_determiner.cc b/src/type_determiner.cc index 841899861f..2e8ffbd3c3 100644 --- a/src/type_determiner.cc +++ b/src/type_determiner.cc @@ -17,6 +17,7 @@ #include "src/ast/assignment_statement.h" #include "src/ast/break_statement.h" #include "src/ast/case_statement.h" +#include "src/ast/continue_statement.h" #include "src/ast/scalar_constructor_expression.h" #include "src/ast/type_constructor_expression.h" @@ -85,6 +86,10 @@ bool TypeDeterminer::DetermineResultType(ast::Statement* stmt) { auto c = stmt->AsCase(); return DetermineResultType(c->body()); } + if (stmt->IsContinue()) { + auto c = stmt->AsContinue(); + return DetermineResultType(c->conditional()); + } error_ = "unknown statement type for type determination"; return false; diff --git a/src/type_determiner_test.cc b/src/type_determiner_test.cc index fb244d092f..f5c54f1026 100644 --- a/src/type_determiner_test.cc +++ b/src/type_determiner_test.cc @@ -21,6 +21,7 @@ #include "src/ast/assignment_statement.h" #include "src/ast/break_statement.h" #include "src/ast/case_statement.h" +#include "src/ast/continue_statement.h" #include "src/ast/float_literal.h" #include "src/ast/int_literal.h" #include "src/ast/scalar_constructor_expression.h" @@ -105,6 +106,20 @@ TEST_F(TypeDeterminerTest, Stmt_Case) { EXPECT_TRUE(rhs_ptr->result_type()->IsF32()); } +TEST_F(TypeDeterminerTest, Stmt_Continue) { + ast::type::I32Type i32; + + auto cond = std::make_unique( + std::make_unique(&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) { ast::type::F32Type f32; ast::ScalarConstructorExpression s(