Type determine the call statement.

This CL adds type determination for the call statement.

Bug: tint:45
Change-Id: I2460fe6c6103bdf7e5d0367cded1d78ca5d671d6
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/25321
Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
dan sinclair 2020-07-21 13:42:13 +00:00 committed by dan sinclair
parent 2e40491467
commit 50080b74e1
2 changed files with 28 additions and 0 deletions

View File

@ -24,6 +24,7 @@
#include "src/ast/binary_expression.h"
#include "src/ast/break_statement.h"
#include "src/ast/call_expression.h"
#include "src/ast/call_statement.h"
#include "src/ast/case_statement.h"
#include "src/ast/cast_expression.h"
#include "src/ast/continue_statement.h"
@ -284,6 +285,9 @@ bool TypeDeterminer::DetermineResultType(ast::Statement* stmt) {
if (stmt->IsBreak()) {
return true;
}
if (stmt->IsCall()) {
return DetermineResultType(stmt->AsCall()->expr());
}
if (stmt->IsCase()) {
auto* c = stmt->AsCase();
return DetermineStatements(c->body());

View File

@ -26,6 +26,7 @@
#include "src/ast/binary_expression.h"
#include "src/ast/break_statement.h"
#include "src/ast/call_expression.h"
#include "src/ast/call_statement.h"
#include "src/ast/case_statement.h"
#include "src/ast/cast_expression.h"
#include "src/ast/continue_statement.h"
@ -338,6 +339,29 @@ TEST_F(TypeDeterminerTest, Stmt_Switch) {
EXPECT_TRUE(rhs_ptr->result_type()->IsF32());
}
TEST_F(TypeDeterminerTest, Stmt_Call) {
ast::type::F32Type f32;
ast::VariableList params;
auto func =
std::make_unique<ast::Function>("my_func", std::move(params), &f32);
mod()->AddFunction(std::move(func));
// Register the function
EXPECT_TRUE(td()->Determine());
ast::ExpressionList call_params;
auto expr = std::make_unique<ast::CallExpression>(
std::make_unique<ast::IdentifierExpression>("my_func"),
std::move(call_params));
auto* expr_ptr = expr.get();
ast::CallStatement call(std::move(expr));
EXPECT_TRUE(td()->DetermineResultType(&call));
ASSERT_NE(expr_ptr->result_type(), nullptr);
EXPECT_TRUE(expr_ptr->result_type()->IsF32());
}
TEST_F(TypeDeterminerTest, Stmt_VariableDecl) {
ast::type::I32Type i32;
auto var =