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

Change-Id: I8d9b916f5977121380325d373c4e2f805b691fae
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34264
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton
2020-11-30 23:30:58 +00:00
parent 67864267c2
commit af37c4ae83
34 changed files with 118 additions and 125 deletions

View File

@@ -1371,8 +1371,8 @@ ast::Expression* ParserImpl::MakeNullValue(ast::type::Type* type) {
return create<ast::TypeConstructorExpression>(type,
std::move(ast_components));
}
if (type->IsArray()) {
auto* arr_ty = type->AsArray();
if (type->Is<ast::type::ArrayType>()) {
auto* arr_ty = type->As<ast::type::ArrayType>();
ast::ExpressionList ast_components;
for (size_t i = 0; i < arr_ty->size(); ++i) {
ast_components.emplace_back(MakeNullValue(arr_ty->type()));

View File

@@ -35,6 +35,7 @@
#include "src/ast/module.h"
#include "src/ast/struct_member_decoration.h"
#include "src/ast/type/alias_type.h"
#include "src/ast/type/array_type.h"
#include "src/ast/type/type.h"
#include "src/reader/reader.h"
#include "src/reader/spirv/entry_point_info.h"

View File

@@ -338,8 +338,8 @@ TEST_F(SpvParserTest, ConvertType_RuntimeArray) {
auto* type = p->ConvertType(10);
ASSERT_NE(type, nullptr);
EXPECT_TRUE(type->IsArray());
auto* arr_type = type->AsArray();
EXPECT_TRUE(type->Is<ast::type::ArrayType>());
auto* arr_type = type->As<ast::type::ArrayType>();
EXPECT_TRUE(arr_type->IsRuntimeArray());
ASSERT_NE(arr_type, nullptr);
EXPECT_EQ(arr_type->size(), 0u);
@@ -374,7 +374,7 @@ TEST_F(SpvParserTest, ConvertType_RuntimeArray_ArrayStride_Valid) {
EXPECT_TRUE(p->BuildInternalModule());
auto* type = p->ConvertType(10);
ASSERT_NE(type, nullptr);
auto* arr_type = type->AsArray();
auto* arr_type = type->As<ast::type::ArrayType>();
EXPECT_TRUE(arr_type->IsRuntimeArray());
ASSERT_NE(arr_type, nullptr);
EXPECT_EQ(arr_type->array_stride(), 64u);
@@ -420,8 +420,8 @@ TEST_F(SpvParserTest, ConvertType_Array) {
auto* type = p->ConvertType(10);
ASSERT_NE(type, nullptr);
EXPECT_TRUE(type->IsArray());
auto* arr_type = type->AsArray();
EXPECT_TRUE(type->Is<ast::type::ArrayType>());
auto* arr_type = type->As<ast::type::ArrayType>();
EXPECT_FALSE(arr_type->IsRuntimeArray());
ASSERT_NE(arr_type, nullptr);
EXPECT_EQ(arr_type->size(), 42u);
@@ -508,8 +508,8 @@ TEST_F(SpvParserTest, ConvertType_ArrayStride_Valid) {
auto* type = p->ConvertType(10);
ASSERT_NE(type, nullptr);
EXPECT_TRUE(type->IsArray());
auto* arr_type = type->AsArray();
EXPECT_TRUE(type->Is<ast::type::ArrayType>());
auto* arr_type = type->As<ast::type::ArrayType>();
ASSERT_NE(arr_type, nullptr);
ASSERT_EQ(arr_type->array_stride(), 8u);
EXPECT_TRUE(arr_type->has_array_stride());

View File

@@ -191,8 +191,8 @@ TEST_F(ParserImplTest, GlobalDecl_Struct_WithStride) {
EXPECT_FALSE(str->IsBlockDecorated());
const auto* ty = str->impl()->members()[0]->type();
ASSERT_TRUE(ty->IsArray());
const auto* arr = ty->AsArray();
ASSERT_TRUE(ty->Is<ast::type::ArrayType>());
const auto* arr = ty->As<ast::type::ArrayType>();
EXPECT_TRUE(arr->has_array_stride());
EXPECT_EQ(arr->array_stride(), 4u);
}

View File

@@ -351,9 +351,9 @@ TEST_F(ParserImplTest, TypeDecl_Array) {
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr) << p->error();
ASSERT_FALSE(p->has_error());
ASSERT_TRUE(t->IsArray());
ASSERT_TRUE(t->Is<ast::type::ArrayType>());
auto* a = t->AsArray();
auto* a = t->As<ast::type::ArrayType>();
ASSERT_FALSE(a->IsRuntimeArray());
ASSERT_EQ(a->size(), 5u);
ASSERT_TRUE(a->type()->IsF32());
@@ -367,9 +367,9 @@ TEST_F(ParserImplTest, TypeDecl_Array_Stride) {
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr) << p->error();
ASSERT_FALSE(p->has_error());
ASSERT_TRUE(t->IsArray());
ASSERT_TRUE(t->Is<ast::type::ArrayType>());
auto* a = t->AsArray();
auto* a = t->As<ast::type::ArrayType>();
ASSERT_FALSE(a->IsRuntimeArray());
ASSERT_EQ(a->size(), 5u);
ASSERT_TRUE(a->type()->IsF32());
@@ -384,9 +384,9 @@ TEST_F(ParserImplTest, TypeDecl_Array_Runtime_Stride) {
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr) << p->error();
ASSERT_FALSE(p->has_error());
ASSERT_TRUE(t->IsArray());
ASSERT_TRUE(t->Is<ast::type::ArrayType>());
auto* a = t->AsArray();
auto* a = t->As<ast::type::ArrayType>();
ASSERT_TRUE(a->IsRuntimeArray());
ASSERT_TRUE(a->type()->IsF32());
ASSERT_TRUE(a->has_array_stride());
@@ -400,9 +400,9 @@ TEST_F(ParserImplTest, TypeDecl_Array_MultipleDecorations_OneBlock) {
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr) << p->error();
ASSERT_FALSE(p->has_error());
ASSERT_TRUE(t->IsArray());
ASSERT_TRUE(t->Is<ast::type::ArrayType>());
auto* a = t->AsArray();
auto* a = t->As<ast::type::ArrayType>();
ASSERT_TRUE(a->IsRuntimeArray());
ASSERT_TRUE(a->type()->IsF32());
@@ -421,9 +421,9 @@ TEST_F(ParserImplTest, TypeDecl_Array_MultipleDecorations_MultipleBlocks) {
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr) << p->error();
ASSERT_FALSE(p->has_error());
ASSERT_TRUE(t->IsArray());
ASSERT_TRUE(t->Is<ast::type::ArrayType>());
auto* a = t->AsArray();
auto* a = t->As<ast::type::ArrayType>();
ASSERT_TRUE(a->IsRuntimeArray());
ASSERT_TRUE(a->type()->IsF32());
@@ -524,9 +524,9 @@ TEST_F(ParserImplTest, TypeDecl_Array_Runtime) {
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr) << p->error();
ASSERT_FALSE(p->has_error());
ASSERT_TRUE(t->IsArray());
ASSERT_TRUE(t->Is<ast::type::ArrayType>());
auto* a = t->AsArray();
auto* a = t->As<ast::type::ArrayType>();
ASSERT_TRUE(a->IsRuntimeArray());
ASSERT_TRUE(a->type()->IsU32());
}