mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-21 10:49:14 +00:00
Replace Type::(Is|As)Vector with Castable
Change-Id: Ic838aa783a279d0939a972773206fee2e33c4bff Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34274 Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
@@ -3206,7 +3206,7 @@ TypedExpression FunctionEmitter::MakeVectorShuffle(
|
||||
// Generate an ast::TypeConstructor expression.
|
||||
// Assume the literal indices are valid, and there is a valid number of them.
|
||||
ast::type::VectorType* result_type =
|
||||
parser_impl_.ConvertType(inst.type_id())->AsVector();
|
||||
parser_impl_.ConvertType(inst.type_id())->As<ast::type::VectorType>();
|
||||
ast::ExpressionList values;
|
||||
for (uint32_t i = 2; i < inst.NumInOperands(); ++i) {
|
||||
const auto index = inst.GetSingleWordInOperand(i);
|
||||
@@ -3598,7 +3598,7 @@ TypedExpression FunctionEmitter::MakeSimpleSelect(
|
||||
// - you can't select over pointers or pointer vectors, unless you also have
|
||||
// a VariablePointers* capability, which is not allowed in by WebGPU.
|
||||
auto* op_ty = operand1.type;
|
||||
if (op_ty->IsVector() || op_ty->is_float_scalar() ||
|
||||
if (op_ty->Is<ast::type::VectorType>() || op_ty->is_float_scalar() ||
|
||||
op_ty->is_integer_scalar() || op_ty->Is<ast::type::BoolType>()) {
|
||||
ast::ExpressionList params;
|
||||
params.push_back(operand1.expr);
|
||||
@@ -3829,8 +3829,8 @@ ast::ExpressionList FunctionEmitter::MakeCoordinateOperandsForImageAccess(
|
||||
uint32_t num_coords_supplied = 0;
|
||||
if (raw_coords.type->Is<ast::type::F32Type>()) {
|
||||
num_coords_supplied = 1;
|
||||
} else if (raw_coords.type->IsVector()) {
|
||||
num_coords_supplied = raw_coords.type->AsVector()->size();
|
||||
} else if (raw_coords.type->Is<ast::type::VectorType>()) {
|
||||
num_coords_supplied = raw_coords.type->As<ast::type::VectorType>()->size();
|
||||
}
|
||||
if (num_coords_supplied == 0) {
|
||||
Fail() << "bad or unsupported coordinate type for image access: "
|
||||
|
||||
@@ -1351,8 +1351,8 @@ ast::Expression* ParserImpl::MakeNullValue(ast::type::Type* type) {
|
||||
return create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(type, 0.0f));
|
||||
}
|
||||
if (type->IsVector()) {
|
||||
const auto* vec_ty = type->AsVector();
|
||||
if (type->Is<ast::type::VectorType>()) {
|
||||
const auto* vec_ty = type->As<ast::type::VectorType>();
|
||||
ast::ExpressionList ast_components;
|
||||
for (size_t i = 0; i < vec_ty->size(); ++i) {
|
||||
ast_components.emplace_back(MakeNullValue(vec_ty->type()));
|
||||
@@ -1450,7 +1450,7 @@ ast::type::Type* ParserImpl::GetSignedIntMatchingShape(ast::type::Type* other) {
|
||||
other->Is<ast::type::I32Type>()) {
|
||||
return i32;
|
||||
}
|
||||
auto* vec_ty = other->AsVector();
|
||||
auto* vec_ty = other->As<ast::type::VectorType>();
|
||||
if (vec_ty) {
|
||||
return ast_module_.create<ast::type::VectorType>(i32, vec_ty->size());
|
||||
}
|
||||
@@ -1469,7 +1469,7 @@ ast::type::Type* ParserImpl::GetUnsignedIntMatchingShape(
|
||||
other->Is<ast::type::I32Type>()) {
|
||||
return u32;
|
||||
}
|
||||
auto* vec_ty = other->AsVector();
|
||||
auto* vec_ty = other->As<ast::type::VectorType>();
|
||||
if (vec_ty) {
|
||||
return ast_module_.create<ast::type::VectorType>(u32, vec_ty->size());
|
||||
}
|
||||
|
||||
@@ -171,19 +171,22 @@ TEST_F(SpvParserTest, ConvertType_VecOverF32) {
|
||||
EXPECT_TRUE(p->BuildInternalModule());
|
||||
|
||||
auto* v2xf32 = p->ConvertType(20);
|
||||
EXPECT_TRUE(v2xf32->IsVector());
|
||||
EXPECT_TRUE(v2xf32->AsVector()->type()->Is<ast::type::F32Type>());
|
||||
EXPECT_EQ(v2xf32->AsVector()->size(), 2u);
|
||||
EXPECT_TRUE(v2xf32->Is<ast::type::VectorType>());
|
||||
EXPECT_TRUE(
|
||||
v2xf32->As<ast::type::VectorType>()->type()->Is<ast::type::F32Type>());
|
||||
EXPECT_EQ(v2xf32->As<ast::type::VectorType>()->size(), 2u);
|
||||
|
||||
auto* v3xf32 = p->ConvertType(30);
|
||||
EXPECT_TRUE(v3xf32->IsVector());
|
||||
EXPECT_TRUE(v3xf32->AsVector()->type()->Is<ast::type::F32Type>());
|
||||
EXPECT_EQ(v3xf32->AsVector()->size(), 3u);
|
||||
EXPECT_TRUE(v3xf32->Is<ast::type::VectorType>());
|
||||
EXPECT_TRUE(
|
||||
v3xf32->As<ast::type::VectorType>()->type()->Is<ast::type::F32Type>());
|
||||
EXPECT_EQ(v3xf32->As<ast::type::VectorType>()->size(), 3u);
|
||||
|
||||
auto* v4xf32 = p->ConvertType(40);
|
||||
EXPECT_TRUE(v4xf32->IsVector());
|
||||
EXPECT_TRUE(v4xf32->AsVector()->type()->Is<ast::type::F32Type>());
|
||||
EXPECT_EQ(v4xf32->AsVector()->size(), 4u);
|
||||
EXPECT_TRUE(v4xf32->Is<ast::type::VectorType>());
|
||||
EXPECT_TRUE(
|
||||
v4xf32->As<ast::type::VectorType>()->type()->Is<ast::type::F32Type>());
|
||||
EXPECT_EQ(v4xf32->As<ast::type::VectorType>()->size(), 4u);
|
||||
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
}
|
||||
@@ -198,19 +201,22 @@ TEST_F(SpvParserTest, ConvertType_VecOverI32) {
|
||||
EXPECT_TRUE(p->BuildInternalModule());
|
||||
|
||||
auto* v2xi32 = p->ConvertType(20);
|
||||
EXPECT_TRUE(v2xi32->IsVector());
|
||||
EXPECT_TRUE(v2xi32->AsVector()->type()->Is<ast::type::I32Type>());
|
||||
EXPECT_EQ(v2xi32->AsVector()->size(), 2u);
|
||||
EXPECT_TRUE(v2xi32->Is<ast::type::VectorType>());
|
||||
EXPECT_TRUE(
|
||||
v2xi32->As<ast::type::VectorType>()->type()->Is<ast::type::I32Type>());
|
||||
EXPECT_EQ(v2xi32->As<ast::type::VectorType>()->size(), 2u);
|
||||
|
||||
auto* v3xi32 = p->ConvertType(30);
|
||||
EXPECT_TRUE(v3xi32->IsVector());
|
||||
EXPECT_TRUE(v3xi32->AsVector()->type()->Is<ast::type::I32Type>());
|
||||
EXPECT_EQ(v3xi32->AsVector()->size(), 3u);
|
||||
EXPECT_TRUE(v3xi32->Is<ast::type::VectorType>());
|
||||
EXPECT_TRUE(
|
||||
v3xi32->As<ast::type::VectorType>()->type()->Is<ast::type::I32Type>());
|
||||
EXPECT_EQ(v3xi32->As<ast::type::VectorType>()->size(), 3u);
|
||||
|
||||
auto* v4xi32 = p->ConvertType(40);
|
||||
EXPECT_TRUE(v4xi32->IsVector());
|
||||
EXPECT_TRUE(v4xi32->AsVector()->type()->Is<ast::type::I32Type>());
|
||||
EXPECT_EQ(v4xi32->AsVector()->size(), 4u);
|
||||
EXPECT_TRUE(v4xi32->Is<ast::type::VectorType>());
|
||||
EXPECT_TRUE(
|
||||
v4xi32->As<ast::type::VectorType>()->type()->Is<ast::type::I32Type>());
|
||||
EXPECT_EQ(v4xi32->As<ast::type::VectorType>()->size(), 4u);
|
||||
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
}
|
||||
@@ -225,19 +231,22 @@ TEST_F(SpvParserTest, ConvertType_VecOverU32) {
|
||||
EXPECT_TRUE(p->BuildInternalModule());
|
||||
|
||||
auto* v2xu32 = p->ConvertType(20);
|
||||
EXPECT_TRUE(v2xu32->IsVector());
|
||||
EXPECT_TRUE(v2xu32->AsVector()->type()->Is<ast::type::U32Type>());
|
||||
EXPECT_EQ(v2xu32->AsVector()->size(), 2u);
|
||||
EXPECT_TRUE(v2xu32->Is<ast::type::VectorType>());
|
||||
EXPECT_TRUE(
|
||||
v2xu32->As<ast::type::VectorType>()->type()->Is<ast::type::U32Type>());
|
||||
EXPECT_EQ(v2xu32->As<ast::type::VectorType>()->size(), 2u);
|
||||
|
||||
auto* v3xu32 = p->ConvertType(30);
|
||||
EXPECT_TRUE(v3xu32->IsVector());
|
||||
EXPECT_TRUE(v3xu32->AsVector()->type()->Is<ast::type::U32Type>());
|
||||
EXPECT_EQ(v3xu32->AsVector()->size(), 3u);
|
||||
EXPECT_TRUE(v3xu32->Is<ast::type::VectorType>());
|
||||
EXPECT_TRUE(
|
||||
v3xu32->As<ast::type::VectorType>()->type()->Is<ast::type::U32Type>());
|
||||
EXPECT_EQ(v3xu32->As<ast::type::VectorType>()->size(), 3u);
|
||||
|
||||
auto* v4xu32 = p->ConvertType(40);
|
||||
EXPECT_TRUE(v4xu32->IsVector());
|
||||
EXPECT_TRUE(v4xu32->AsVector()->type()->Is<ast::type::U32Type>());
|
||||
EXPECT_EQ(v4xu32->AsVector()->size(), 4u);
|
||||
EXPECT_TRUE(v4xu32->Is<ast::type::VectorType>());
|
||||
EXPECT_TRUE(
|
||||
v4xu32->As<ast::type::VectorType>()->type()->Is<ast::type::U32Type>());
|
||||
EXPECT_EQ(v4xu32->As<ast::type::VectorType>()->size(), 4u);
|
||||
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
}
|
||||
|
||||
@@ -35,8 +35,8 @@ TEST_F(ParserImplTest, ConstExpr_TypeDecl) {
|
||||
ASSERT_TRUE(e->AsConstructor()->IsTypeConstructor());
|
||||
|
||||
auto* t = e->AsConstructor()->AsTypeConstructor();
|
||||
ASSERT_TRUE(t->type()->IsVector());
|
||||
EXPECT_EQ(t->type()->AsVector()->size(), 2u);
|
||||
ASSERT_TRUE(t->type()->Is<ast::type::VectorType>());
|
||||
EXPECT_EQ(t->type()->As<ast::type::VectorType>()->size(), 2u);
|
||||
|
||||
ASSERT_EQ(t->values().size(), 2u);
|
||||
auto& v = t->values();
|
||||
|
||||
@@ -151,8 +151,8 @@ TEST_P(VecTest, Parse) {
|
||||
EXPECT_FALSE(t.errored);
|
||||
ASSERT_NE(t.value, nullptr) << p->error();
|
||||
ASSERT_FALSE(p->has_error());
|
||||
EXPECT_TRUE(t->IsVector());
|
||||
EXPECT_EQ(t->AsVector()->size(), params.count);
|
||||
EXPECT_TRUE(t->Is<ast::type::VectorType>());
|
||||
EXPECT_EQ(t->As<ast::type::VectorType>()->size(), params.count);
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(ParserImplTest,
|
||||
VecTest,
|
||||
@@ -256,10 +256,10 @@ TEST_F(ParserImplTest, TypeDecl_Ptr_ToVec) {
|
||||
ASSERT_TRUE(t->Is<ast::type::PointerType>());
|
||||
|
||||
auto* ptr = t->As<ast::type::PointerType>();
|
||||
ASSERT_TRUE(ptr->type()->IsVector());
|
||||
ASSERT_TRUE(ptr->type()->Is<ast::type::VectorType>());
|
||||
ASSERT_EQ(ptr->storage_class(), ast::StorageClass::kFunction);
|
||||
|
||||
auto* vec = ptr->type()->AsVector();
|
||||
auto* vec = ptr->type()->As<ast::type::VectorType>();
|
||||
ASSERT_EQ(vec->size(), 2u);
|
||||
ASSERT_TRUE(vec->type()->Is<ast::type::F32Type>());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user