Add type determination for as expression.
This CL adds the as expression type determination. Bug: tint:5 Change-Id: I84a06df67844c75112c745f65a2c8102f8677f62 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/18843 Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
parent
973bd6a7b4
commit
a01777c2d9
|
@ -17,6 +17,7 @@
|
|||
#include <memory>
|
||||
|
||||
#include "src/ast/array_accessor_expression.h"
|
||||
#include "src/ast/as_expression.h"
|
||||
#include "src/ast/assignment_statement.h"
|
||||
#include "src/ast/break_statement.h"
|
||||
#include "src/ast/case_statement.h"
|
||||
|
@ -183,6 +184,9 @@ bool TypeDeterminer::DetermineResultType(ast::Expression* expr) {
|
|||
if (expr->IsArrayAccessor()) {
|
||||
return DetermineArrayAccessor(expr->AsArrayAccessor());
|
||||
}
|
||||
if (expr->IsAs()) {
|
||||
return DetermineAs(expr->AsAs());
|
||||
}
|
||||
if (expr->IsConstructor()) {
|
||||
return DetermineConstructor(expr->AsConstructor());
|
||||
}
|
||||
|
@ -215,6 +219,11 @@ bool TypeDeterminer::DetermineArrayAccessor(
|
|||
return true;
|
||||
}
|
||||
|
||||
bool TypeDeterminer::DetermineAs(ast::AsExpression* expr) {
|
||||
expr->set_result_type(expr->type());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TypeDeterminer::DetermineConstructor(ast::ConstructorExpression* expr) {
|
||||
if (expr->IsTypeConstructor()) {
|
||||
expr->set_result_type(expr->AsTypeConstructor()->type());
|
||||
|
|
|
@ -26,6 +26,7 @@ namespace tint {
|
|||
namespace ast {
|
||||
|
||||
class ArrayAccessorExpression;
|
||||
class AsExpression;
|
||||
class ConstructorExpression;
|
||||
class IdentifierExpression;
|
||||
class Function;
|
||||
|
@ -71,6 +72,7 @@ class TypeDeterminer {
|
|||
|
||||
private:
|
||||
bool DetermineArrayAccessor(ast::ArrayAccessorExpression* expr);
|
||||
bool DetermineAs(ast::AsExpression* expr);
|
||||
bool DetermineConstructor(ast::ConstructorExpression* expr);
|
||||
bool DetermineIdentifier(ast::IdentifierExpression* expr);
|
||||
Context& ctx_;
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include "gtest/gtest.h"
|
||||
#include "src/ast/array_accessor_expression.h"
|
||||
#include "src/ast/as_expression.h"
|
||||
#include "src/ast/assignment_statement.h"
|
||||
#include "src/ast/break_statement.h"
|
||||
#include "src/ast/case_statement.h"
|
||||
|
@ -478,6 +479,16 @@ TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Vector) {
|
|||
EXPECT_TRUE(acc.result_type()->IsF32());
|
||||
}
|
||||
|
||||
TEST_F(TypeDeterminerTest, Expr_As) {
|
||||
ast::type::F32Type f32;
|
||||
ast::AsExpression as(&f32,
|
||||
std::make_unique<ast::IdentifierExpression>("name"));
|
||||
|
||||
EXPECT_TRUE(td()->DetermineResultType(&as));
|
||||
ASSERT_NE(as.result_type(), nullptr);
|
||||
EXPECT_TRUE(as.result_type()->IsF32());
|
||||
}
|
||||
|
||||
TEST_F(TypeDeterminerTest, Expr_Constructor_Scalar) {
|
||||
ast::type::F32Type f32;
|
||||
ast::ScalarConstructorExpression s(
|
||||
|
|
Loading…
Reference in New Issue