mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-06-05 06:03:34 +00:00
Determine types for module scoped variable constructors.
This CL updates the type determination code to determine the types of module scoped variable constructors. Bug: tint:89 Change-Id: Icd5d65409fcf17a0cbf0b34b9919f8d9e1577354 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23220 Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
parent
c7d1ac3361
commit
7be237aa8f
@ -65,6 +65,12 @@ void TypeDeterminer::set_error(const Source& src, const std::string& msg) {
|
|||||||
bool TypeDeterminer::Determine() {
|
bool TypeDeterminer::Determine() {
|
||||||
for (const auto& var : mod_->global_variables()) {
|
for (const auto& var : mod_->global_variables()) {
|
||||||
variable_stack_.set_global(var->name(), var.get());
|
variable_stack_.set_global(var->name(), var.get());
|
||||||
|
|
||||||
|
if (var->has_constructor()) {
|
||||||
|
if (!DetermineResultType(var->constructor())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto& func : mod_->functions()) {
|
for (const auto& func : mod_->functions()) {
|
||||||
|
@ -353,6 +353,21 @@ TEST_F(TypeDeterminerTest, Stmt_VariableDecl) {
|
|||||||
EXPECT_TRUE(init_ptr->result_type()->IsI32());
|
EXPECT_TRUE(init_ptr->result_type()->IsI32());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(TypeDeterminerTest, Stmt_VariableDecl_ModuleScope) {
|
||||||
|
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::SintLiteral>(&i32, 2)));
|
||||||
|
auto* init_ptr = var->constructor();
|
||||||
|
|
||||||
|
mod()->AddGlobalVariable(std::move(var));
|
||||||
|
|
||||||
|
EXPECT_TRUE(td()->Determine());
|
||||||
|
ASSERT_NE(init_ptr->result_type(), nullptr);
|
||||||
|
EXPECT_TRUE(init_ptr->result_type()->IsI32());
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(TypeDeterminerTest, Expr_Error_Unknown) {
|
TEST_F(TypeDeterminerTest, Expr_Error_Unknown) {
|
||||||
FakeExpr e;
|
FakeExpr e;
|
||||||
e.set_source(Source{2, 30});
|
e.set_source(Source{2, 30});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user