This CL adds type determination for the variable declaration statements.
This Cl adds variable declaration type determination. Bug: tint:5 Change-Id: I3dc19af470f9403dadc230f1bf2b597bb1fe4fee Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/18840 Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
parent
9a84e5eb47
commit
ca893e3200
|
@ -27,6 +27,7 @@
|
|||
#include "src/ast/switch_statement.h"
|
||||
#include "src/ast/type_constructor_expression.h"
|
||||
#include "src/ast/unless_statement.h"
|
||||
#include "src/ast/variable_decl_statement.h"
|
||||
|
||||
namespace tint {
|
||||
|
||||
|
@ -156,6 +157,11 @@ bool TypeDeterminer::DetermineResultType(ast::Statement* stmt) {
|
|||
return DetermineResultType(u->condition()) &&
|
||||
DetermineResultType(u->body());
|
||||
}
|
||||
if (stmt->IsVariableDecl()) {
|
||||
auto v = stmt->AsVariableDecl();
|
||||
variable_stack_.set(v->variable()->name(), v->variable());
|
||||
return DetermineResultType(v->variable()->constructor());
|
||||
}
|
||||
|
||||
error_ = "unknown statement type for type determination";
|
||||
return false;
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include "src/ast/type/vector_type.h"
|
||||
#include "src/ast/type_constructor_expression.h"
|
||||
#include "src/ast/unless_statement.h"
|
||||
#include "src/ast/variable_decl_statement.h"
|
||||
|
||||
namespace tint {
|
||||
namespace {
|
||||
|
@ -359,6 +360,21 @@ TEST_F(TypeDeterminerTest, Stmt_Unless) {
|
|||
EXPECT_TRUE(rhs_ptr->result_type()->IsF32());
|
||||
}
|
||||
|
||||
TEST_F(TypeDeterminerTest, Stmt_VariableDecl) {
|
||||
ast::type::I32Type i32;
|
||||
auto var =
|
||||
std::make_unique<ast::Variable>("my_var", ast::StorageClass::kNone, &i32);
|
||||
var->set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::IntLiteral>(&i32, 2)));
|
||||
auto init_ptr = var->constructor();
|
||||
|
||||
ast::VariableDeclStatement decl(std::move(var));
|
||||
|
||||
EXPECT_TRUE(td()->DetermineResultType(&decl));
|
||||
ASSERT_NE(init_ptr->result_type(), nullptr);
|
||||
EXPECT_TRUE(init_ptr->result_type()->IsI32());
|
||||
}
|
||||
|
||||
TEST_F(TypeDeterminerTest, Expr_Constructor_Scalar) {
|
||||
ast::type::F32Type f32;
|
||||
ast::ScalarConstructorExpression s(
|
||||
|
|
Loading…
Reference in New Issue