Add cast expression type determination.
This CL adds the type determination for cast expressions. Bug: tint:5 Change-Id: I35ae28e3b70c554cd48c6abcd78d95c2ba7211fa Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/18845 Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
parent
3ca8746ebd
commit
4e8079544a
|
@ -22,6 +22,7 @@
|
||||||
#include "src/ast/break_statement.h"
|
#include "src/ast/break_statement.h"
|
||||||
#include "src/ast/call_expression.h"
|
#include "src/ast/call_expression.h"
|
||||||
#include "src/ast/case_statement.h"
|
#include "src/ast/case_statement.h"
|
||||||
|
#include "src/ast/cast_expression.h"
|
||||||
#include "src/ast/continue_statement.h"
|
#include "src/ast/continue_statement.h"
|
||||||
#include "src/ast/else_statement.h"
|
#include "src/ast/else_statement.h"
|
||||||
#include "src/ast/identifier_expression.h"
|
#include "src/ast/identifier_expression.h"
|
||||||
|
@ -197,6 +198,9 @@ bool TypeDeterminer::DetermineResultType(ast::Expression* expr) {
|
||||||
if (expr->IsCall()) {
|
if (expr->IsCall()) {
|
||||||
return DetermineCall(expr->AsCall());
|
return DetermineCall(expr->AsCall());
|
||||||
}
|
}
|
||||||
|
if (expr->IsCast()) {
|
||||||
|
return DetermineCast(expr->AsCast());
|
||||||
|
}
|
||||||
if (expr->IsConstructor()) {
|
if (expr->IsConstructor()) {
|
||||||
return DetermineConstructor(expr->AsConstructor());
|
return DetermineConstructor(expr->AsConstructor());
|
||||||
}
|
}
|
||||||
|
@ -245,6 +249,11 @@ bool TypeDeterminer::DetermineCall(ast::CallExpression* expr) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TypeDeterminer::DetermineCast(ast::CastExpression* expr) {
|
||||||
|
expr->set_result_type(expr->type());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool TypeDeterminer::DetermineConstructor(ast::ConstructorExpression* expr) {
|
bool TypeDeterminer::DetermineConstructor(ast::ConstructorExpression* expr) {
|
||||||
if (expr->IsTypeConstructor()) {
|
if (expr->IsTypeConstructor()) {
|
||||||
expr->set_result_type(expr->AsTypeConstructor()->type());
|
expr->set_result_type(expr->AsTypeConstructor()->type());
|
||||||
|
|
|
@ -28,6 +28,7 @@ namespace ast {
|
||||||
class ArrayAccessorExpression;
|
class ArrayAccessorExpression;
|
||||||
class AsExpression;
|
class AsExpression;
|
||||||
class CallExpression;
|
class CallExpression;
|
||||||
|
class CastExpression;
|
||||||
class ConstructorExpression;
|
class ConstructorExpression;
|
||||||
class IdentifierExpression;
|
class IdentifierExpression;
|
||||||
class Function;
|
class Function;
|
||||||
|
@ -79,6 +80,7 @@ class TypeDeterminer {
|
||||||
bool DetermineArrayAccessor(ast::ArrayAccessorExpression* expr);
|
bool DetermineArrayAccessor(ast::ArrayAccessorExpression* expr);
|
||||||
bool DetermineAs(ast::AsExpression* expr);
|
bool DetermineAs(ast::AsExpression* expr);
|
||||||
bool DetermineCall(ast::CallExpression* expr);
|
bool DetermineCall(ast::CallExpression* expr);
|
||||||
|
bool DetermineCast(ast::CastExpression* expr);
|
||||||
bool DetermineConstructor(ast::ConstructorExpression* expr);
|
bool DetermineConstructor(ast::ConstructorExpression* expr);
|
||||||
bool DetermineIdentifier(ast::IdentifierExpression* expr);
|
bool DetermineIdentifier(ast::IdentifierExpression* expr);
|
||||||
Context& ctx_;
|
Context& ctx_;
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include "src/ast/break_statement.h"
|
#include "src/ast/break_statement.h"
|
||||||
#include "src/ast/call_expression.h"
|
#include "src/ast/call_expression.h"
|
||||||
#include "src/ast/case_statement.h"
|
#include "src/ast/case_statement.h"
|
||||||
|
#include "src/ast/cast_expression.h"
|
||||||
#include "src/ast/continue_statement.h"
|
#include "src/ast/continue_statement.h"
|
||||||
#include "src/ast/else_statement.h"
|
#include "src/ast/else_statement.h"
|
||||||
#include "src/ast/float_literal.h"
|
#include "src/ast/float_literal.h"
|
||||||
|
@ -550,6 +551,16 @@ TEST_F(TypeDeterminerTest, Expr_Call_WithParams) {
|
||||||
EXPECT_TRUE(b_ptr->result_type()->IsI32());
|
EXPECT_TRUE(b_ptr->result_type()->IsI32());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(TypeDeterminerTest, Expr_Cast) {
|
||||||
|
ast::type::F32Type f32;
|
||||||
|
ast::CastExpression cast(&f32,
|
||||||
|
std::make_unique<ast::IdentifierExpression>("name"));
|
||||||
|
|
||||||
|
EXPECT_TRUE(td()->DetermineResultType(&cast));
|
||||||
|
ASSERT_NE(cast.result_type(), nullptr);
|
||||||
|
EXPECT_TRUE(cast.result_type()->IsF32());
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(TypeDeterminerTest, Expr_Constructor_Scalar) {
|
TEST_F(TypeDeterminerTest, Expr_Constructor_Scalar) {
|
||||||
ast::type::F32Type f32;
|
ast::type::F32Type f32;
|
||||||
ast::ScalarConstructorExpression s(
|
ast::ScalarConstructorExpression s(
|
||||||
|
|
Loading…
Reference in New Issue