[type-determiner] Determine call parameter types.

This CL adds type determination for the call parameters.

Bug: tint:5
Change-Id: I488718bd7a4c1f2304a1c17554b8354d184dc159
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/19760
Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
dan sinclair 2020-04-20 14:18:54 +00:00 committed by dan sinclair
parent 6ad9f5d1ed
commit ccb52dc547
2 changed files with 32 additions and 0 deletions

View File

@ -284,6 +284,12 @@ bool TypeDeterminer::DetermineAs(ast::AsExpression* expr) {
}
bool TypeDeterminer::DetermineCall(ast::CallExpression* expr) {
for (const auto& param : expr->params()) {
if (!DetermineResultType(param.get())) {
return false;
}
}
if (!DetermineResultType(expr->func())) {
return false;
}

View File

@ -545,6 +545,32 @@ TEST_F(TypeDeterminerTest, Expr_Call) {
EXPECT_TRUE(call.result_type()->IsF32());
}
TEST_F(TypeDeterminerTest, Expr_Call_WithParams) {
ast::type::F32Type f32;
ast::VariableList params;
auto func =
std::make_unique<ast::Function>("my_func", std::move(params), &f32);
ast::Module m;
m.AddFunction(std::move(func));
// Register the function
EXPECT_TRUE(td()->Determine(&m));
ast::ExpressionList call_params;
call_params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 2.4)));
auto* param_ptr = call_params.back().get();
ast::CallExpression call(
std::make_unique<ast::IdentifierExpression>("my_func"),
std::move(call_params));
EXPECT_TRUE(td()->DetermineResultType(&call));
ASSERT_NE(param_ptr->result_type(), nullptr);
EXPECT_TRUE(param_ptr->result_type()->IsF32());
}
TEST_F(TypeDeterminerTest, Expr_Cast) {
ast::type::F32Type f32;
ast::CastExpression cast(&f32,