Post migration to castable cleanup

Change-Id: I5c47b1736bd850548cb1c9c7a6f69242d8626173
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34460
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton
2020-12-01 21:07:27 +00:00
committed by Commit Bot service account
parent 782f6a5e3e
commit 1b6a8ce165
19 changed files with 453 additions and 545 deletions

View File

@@ -2267,11 +2267,11 @@ bool FunctionEmitter::EmitContinuingStart(const Construct* construct) {
// A continue construct has the same depth as its associated loop
// construct. Start a continue construct.
auto* loop_candidate = LastStatement();
if (!loop_candidate->Is<ast::LoopStatement>()) {
auto* loop = loop_candidate->As<ast::LoopStatement>();
if (loop == nullptr) {
return Fail() << "internal error: starting continue construct, "
"expected loop on top of stack";
}
auto* loop = loop_candidate->As<ast::LoopStatement>();
PushNewStatementBlock(
construct, construct->end_id,
[loop](StatementBlock* s) { loop->set_continuing(s->statements_); });
@@ -3268,10 +3268,10 @@ bool FunctionEmitter::RegisterLocallyDefinedValues() {
const auto* type = type_mgr_->GetType(inst.type_id());
if (type) {
if (type->AsPointer()) {
const auto* ast_type = parser_impl_.ConvertType(inst.type_id());
if (ast_type && ast_type->As<ast::type::Pointer>()) {
info->storage_class =
ast_type->As<ast::type::Pointer>()->storage_class();
if (const auto* ast_type = parser_impl_.ConvertType(inst.type_id())) {
if (auto* ptr = ast_type->As<ast::type::Pointer>()) {
info->storage_class = ptr->storage_class();
}
}
switch (inst.opcode()) {
case SpvOpUndef:
@@ -3322,10 +3322,9 @@ ast::StorageClass FunctionEmitter::GetStorageClassForPointerValue(uint32_t id) {
ast::type::Type* FunctionEmitter::RemapStorageClass(ast::type::Type* type,
uint32_t result_id) {
if (type->Is<ast::type::Pointer>()) {
if (const auto* ast_ptr_type = type->As<ast::type::Pointer>()) {
// Remap an old-style storage buffer pointer to a new-style storage
// buffer pointer.
const auto* ast_ptr_type = type->As<ast::type::Pointer>();
const auto sc = GetStorageClassForPointerValue(result_id);
if (ast_ptr_type->storage_class() != sc) {
return parser_impl_.get_module().create<ast::type::Pointer>(

View File

@@ -1349,8 +1349,7 @@ ast::Expression* ParserImpl::MakeNullValue(ast::type::Type* type) {
return create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(type, 0.0f));
}
if (type->Is<ast::type::Vector>()) {
const auto* vec_ty = type->As<ast::type::Vector>();
if (const auto* vec_ty = type->As<ast::type::Vector>()) {
ast::ExpressionList ast_components;
for (size_t i = 0; i < vec_ty->size(); ++i) {
ast_components.emplace_back(MakeNullValue(vec_ty->type()));
@@ -1358,8 +1357,7 @@ ast::Expression* ParserImpl::MakeNullValue(ast::type::Type* type) {
return create<ast::TypeConstructorExpression>(type,
std::move(ast_components));
}
if (type->Is<ast::type::Matrix>()) {
const auto* mat_ty = type->As<ast::type::Matrix>();
if (const auto* mat_ty = type->As<ast::type::Matrix>()) {
// Matrix components are columns
auto* column_ty =
ast_module_.create<ast::type::Vector>(mat_ty->type(), mat_ty->rows());
@@ -1370,8 +1368,7 @@ ast::Expression* ParserImpl::MakeNullValue(ast::type::Type* type) {
return create<ast::TypeConstructorExpression>(type,
std::move(ast_components));
}
if (type->Is<ast::type::Array>()) {
auto* arr_ty = type->As<ast::type::Array>();
if (auto* arr_ty = type->As<ast::type::Array>()) {
ast::ExpressionList ast_components;
for (size_t i = 0; i < arr_ty->size(); ++i) {
ast_components.emplace_back(MakeNullValue(arr_ty->type()));
@@ -1379,8 +1376,7 @@ ast::Expression* ParserImpl::MakeNullValue(ast::type::Type* type) {
return create<ast::TypeConstructorExpression>(original_type,
std::move(ast_components));
}
if (type->Is<ast::type::Struct>()) {
auto* struct_ty = type->As<ast::type::Struct>();
if (auto* struct_ty = type->As<ast::type::Struct>()) {
ast::ExpressionList ast_components;
for (auto* member : struct_ty->impl()->members()) {
ast_components.emplace_back(MakeNullValue(member->type()));

View File

@@ -2941,8 +2941,8 @@ std::vector<T*> ParserImpl::take_decorations(ast::DecorationList& in) {
std::vector<T*> out;
out.reserve(in.size());
for (auto* deco : in) {
if (deco->Is<T>()) {
out.emplace_back(deco->As<T>());
if (auto* t = deco->As<T>()) {
out.emplace_back(t);
} else {
remaining.emplace_back(deco);
}

View File

@@ -37,7 +37,7 @@ TEST_F(ParserImplTest, DepthTextureType_2d) {
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr);
ASSERT_TRUE(t->Is<ast::type::Texture>());
ASSERT_TRUE(t->As<ast::type::Texture>()->Is<ast::type::DepthTexture>());
ASSERT_TRUE(t->Is<ast::type::DepthTexture>());
EXPECT_EQ(t->As<ast::type::Texture>()->dim(),
ast::type::TextureDimension::k2d);
EXPECT_FALSE(p->has_error());
@@ -50,7 +50,7 @@ TEST_F(ParserImplTest, DepthTextureType_2dArray) {
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr);
ASSERT_TRUE(t->Is<ast::type::Texture>());
ASSERT_TRUE(t->As<ast::type::Texture>()->Is<ast::type::DepthTexture>());
ASSERT_TRUE(t->Is<ast::type::DepthTexture>());
EXPECT_EQ(t->As<ast::type::Texture>()->dim(),
ast::type::TextureDimension::k2dArray);
EXPECT_FALSE(p->has_error());
@@ -63,7 +63,7 @@ TEST_F(ParserImplTest, DepthTextureType_Cube) {
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr);
ASSERT_TRUE(t->Is<ast::type::Texture>());
ASSERT_TRUE(t->As<ast::type::Texture>()->Is<ast::type::DepthTexture>());
ASSERT_TRUE(t->Is<ast::type::DepthTexture>());
EXPECT_EQ(t->As<ast::type::Texture>()->dim(),
ast::type::TextureDimension::kCube);
EXPECT_FALSE(p->has_error());
@@ -76,7 +76,7 @@ TEST_F(ParserImplTest, DepthTextureType_CubeArray) {
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr);
ASSERT_TRUE(t->Is<ast::type::Texture>());
ASSERT_TRUE(t->As<ast::type::Texture>()->Is<ast::type::DepthTexture>());
ASSERT_TRUE(t->Is<ast::type::DepthTexture>());
EXPECT_EQ(t->As<ast::type::Texture>()->dim(),
ast::type::TextureDimension::kCubeArray);
EXPECT_FALSE(p->has_error());