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>
diff --git a/src/type_determiner.cc b/src/type_determiner.cc
index 8418998..2e8ffbd 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 @@
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 fb244d0..f5c54f1 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 @@
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) {
ast::type::F32Type f32;
ast::ScalarConstructorExpression s(