Replace Type::(Is|As)U32 with Castable

Change-Id: I4999d45950fdffe4345cf0abae1b026244abba1d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34273
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton
2020-11-30 23:30:58 +00:00
parent 38409c79dc
commit d11ced4765
33 changed files with 124 additions and 118 deletions

View File

@@ -979,7 +979,7 @@ bool ParserImpl::EmitScalarSpecConstants() {
ast_expr =
create<ast::ScalarConstructorExpression>(create<ast::SintLiteral>(
ast_type, static_cast<int32_t>(literal_value)));
} else if (ast_type->IsU32()) {
} else if (ast_type->Is<ast::type::U32Type>()) {
ast_expr =
create<ast::ScalarConstructorExpression>(create<ast::UintLiteral>(
ast_type, static_cast<uint32_t>(literal_value)));
@@ -1263,7 +1263,7 @@ TypedExpression ParserImpl::MakeConstantExpression(uint32_t id) {
// So canonicalization should map that way too.
// Currently "null<type>" is missing from the WGSL parser.
// See https://bugs.chromium.org/p/tint/issues/detail?id=34
if (ast_type->IsU32()) {
if (ast_type->Is<ast::type::U32Type>()) {
return {ast_type,
create<ast::ScalarConstructorExpression>(
create<ast::UintLiteral>(ast_type, spirv_const->GetU32()))};
@@ -1339,7 +1339,7 @@ ast::Expression* ParserImpl::MakeNullValue(ast::type::Type* type) {
return create<ast::ScalarConstructorExpression>(
create<ast::BoolLiteral>(type, false));
}
if (type->IsU32()) {
if (type->Is<ast::type::U32Type>()) {
return create<ast::ScalarConstructorExpression>(
create<ast::UintLiteral>(type, 0u));
}
@@ -1446,7 +1446,7 @@ ast::type::Type* ParserImpl::GetSignedIntMatchingShape(ast::type::Type* other) {
Fail() << "no type provided";
}
auto* i32 = ast_module_.create<ast::type::I32Type>();
if (other->Is<ast::type::F32Type>() || other->IsU32() ||
if (other->Is<ast::type::F32Type>() || other->Is<ast::type::U32Type>() ||
other->Is<ast::type::I32Type>()) {
return i32;
}
@@ -1465,7 +1465,7 @@ ast::type::Type* ParserImpl::GetUnsignedIntMatchingShape(
return nullptr;
}
auto* u32 = ast_module_.create<ast::type::U32Type>();
if (other->Is<ast::type::F32Type>() || other->IsU32() ||
if (other->Is<ast::type::F32Type>() || other->Is<ast::type::U32Type>() ||
other->Is<ast::type::I32Type>()) {
return u32;
}

View File

@@ -26,6 +26,7 @@
#include "src/ast/type/pointer_type.h"
#include "src/ast/type/struct_type.h"
#include "src/ast/type/type.h"
#include "src/ast/type/u32_type.h"
#include "src/ast/type/vector_type.h"
#include "src/reader/spirv/parser_impl.h"
#include "src/reader/spirv/parser_impl_test_helper.h"
@@ -117,7 +118,7 @@ TEST_F(SpvParserTest, ConvertType_U32) {
EXPECT_TRUE(p->BuildInternalModule());
auto* type = p->ConvertType(3);
EXPECT_TRUE(type->IsU32());
EXPECT_TRUE(type->Is<ast::type::U32Type>());
EXPECT_TRUE(p->error().empty());
}
@@ -225,17 +226,17 @@ TEST_F(SpvParserTest, ConvertType_VecOverU32) {
auto* v2xu32 = p->ConvertType(20);
EXPECT_TRUE(v2xu32->IsVector());
EXPECT_TRUE(v2xu32->AsVector()->type()->IsU32());
EXPECT_TRUE(v2xu32->AsVector()->type()->Is<ast::type::U32Type>());
EXPECT_EQ(v2xu32->AsVector()->size(), 2u);
auto* v3xu32 = p->ConvertType(30);
EXPECT_TRUE(v3xu32->IsVector());
EXPECT_TRUE(v3xu32->AsVector()->type()->IsU32());
EXPECT_TRUE(v3xu32->AsVector()->type()->Is<ast::type::U32Type>());
EXPECT_EQ(v3xu32->AsVector()->size(), 3u);
auto* v4xu32 = p->ConvertType(40);
EXPECT_TRUE(v4xu32->IsVector());
EXPECT_TRUE(v4xu32->AsVector()->type()->IsU32());
EXPECT_TRUE(v4xu32->AsVector()->type()->Is<ast::type::U32Type>());
EXPECT_EQ(v4xu32->AsVector()->size(), 4u);
EXPECT_TRUE(p->error().empty());
@@ -359,7 +360,7 @@ TEST_F(SpvParserTest, ConvertType_RuntimeArray) {
EXPECT_FALSE(arr_type->has_array_stride());
auto* elem_type = arr_type->type();
ASSERT_NE(elem_type, nullptr);
EXPECT_TRUE(elem_type->IsU32());
EXPECT_TRUE(elem_type->Is<ast::type::U32Type>());
EXPECT_TRUE(p->error().empty());
}
@@ -441,7 +442,7 @@ TEST_F(SpvParserTest, ConvertType_Array) {
EXPECT_FALSE(arr_type->has_array_stride());
auto* elem_type = arr_type->type();
ASSERT_NE(elem_type, nullptr);
EXPECT_TRUE(elem_type->IsU32());
EXPECT_TRUE(elem_type->Is<ast::type::U32Type>());
EXPECT_TRUE(p->error().empty());
}

View File

@@ -18,6 +18,7 @@
#include "src/ast/type/multisampled_texture_type.h"
#include "src/ast/type/sampled_texture_type.h"
#include "src/ast/type/sampler_type.h"
#include "src/ast/type/u32_type.h"
#include "src/reader/wgsl/parser_impl.h"
#include "src/reader/wgsl/parser_impl_test_helper.h"
@@ -113,7 +114,10 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_U32_Old) {
ASSERT_NE(t.value, nullptr);
ASSERT_TRUE(t->Is<ast::type::TextureType>());
ASSERT_TRUE(t->As<ast::type::TextureType>()->IsSampled());
ASSERT_TRUE(t->As<ast::type::TextureType>()->AsSampled()->type()->IsU32());
ASSERT_TRUE(t->As<ast::type::TextureType>()
->AsSampled()
->type()
->Is<ast::type::U32Type>());
EXPECT_EQ(t->As<ast::type::TextureType>()->dim(),
ast::type::TextureDimension::k3d);
}
@@ -202,7 +206,10 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_U32) {
ASSERT_NE(t.value, nullptr);
ASSERT_TRUE(t->Is<ast::type::TextureType>());
ASSERT_TRUE(t->As<ast::type::TextureType>()->IsSampled());
ASSERT_TRUE(t->As<ast::type::TextureType>()->AsSampled()->type()->IsU32());
ASSERT_TRUE(t->As<ast::type::TextureType>()
->AsSampled()
->type()
->Is<ast::type::U32Type>());
EXPECT_EQ(t->As<ast::type::TextureType>()->dim(),
ast::type::TextureDimension::k3d);
}

View File

@@ -129,7 +129,7 @@ TEST_F(ParserImplTest, TypeDecl_U32) {
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr) << p->error();
EXPECT_EQ(t.value, uint_type);
ASSERT_TRUE(t->IsU32());
ASSERT_TRUE(t->Is<ast::type::U32Type>());
}
struct VecData {
@@ -528,7 +528,7 @@ TEST_F(ParserImplTest, TypeDecl_Array_Runtime) {
auto* a = t->As<ast::type::ArrayType>();
ASSERT_TRUE(a->IsRuntimeArray());
ASSERT_TRUE(a->type()->IsU32());
ASSERT_TRUE(a->type()->Is<ast::type::U32Type>());
}
TEST_F(ParserImplTest, TypeDecl_Array_BadType) {