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

Change-Id: If8a27c69c91a968a40a982c02b9fcaf9481e60b7
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34275
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton
2020-11-30 23:30:58 +00:00
parent 8a083ce9c8
commit 16ec1bb626
13 changed files with 26 additions and 52 deletions

View File

@@ -59,6 +59,7 @@
#include "src/ast/type/type.h"
#include "src/ast/type/u32_type.h"
#include "src/ast/type/vector_type.h"
#include "src/ast/type/void_type.h"
#include "src/ast/type_constructor_expression.h"
#include "src/ast/uint_literal.h"
#include "src/ast/unary_op.h"
@@ -3556,7 +3557,7 @@ bool FunctionEmitter::EmitFunctionCall(const spvtools::opt::Instruction& inst) {
<< inst.PrettyPrint();
}
if (result_type->IsVoid()) {
if (result_type->Is<ast::type::VoidType>()) {
return nullptr != AddStatementForInstruction(
create<ast::CallStatement>(call_expr), inst);
}

View File

@@ -28,6 +28,7 @@
#include "src/ast/type/type.h"
#include "src/ast/type/u32_type.h"
#include "src/ast/type/vector_type.h"
#include "src/ast/type/void_type.h"
#include "src/reader/spirv/parser_impl.h"
#include "src/reader/spirv/parser_impl_test_helper.h"
#include "src/reader/spirv/spirv_tools_helpers_test.h"
@@ -91,7 +92,7 @@ TEST_F(SpvParserTest, ConvertType_Void) {
EXPECT_TRUE(p->BuildInternalModule());
auto* type = p->ConvertType(1);
EXPECT_TRUE(type->IsVoid());
EXPECT_TRUE(type->Is<ast::type::VoidType>());
EXPECT_TRUE(p->error().empty());
}
@@ -845,7 +846,7 @@ TEST_F(SpvParserTest, ConvertType_Sampler_PretendVoid) {
EXPECT_TRUE(p->BuildInternalModule());
auto* type = p->ConvertType(1);
EXPECT_TRUE(type->IsVoid());
EXPECT_TRUE(type->Is<ast::type::VoidType>());
EXPECT_TRUE(p->error().empty());
}
@@ -858,7 +859,7 @@ TEST_F(SpvParserTest, ConvertType_Image_PretendVoid) {
EXPECT_TRUE(p->BuildInternalModule());
auto* type = p->ConvertType(1);
EXPECT_TRUE(type->IsVoid());
EXPECT_TRUE(type->Is<ast::type::VoidType>());
EXPECT_TRUE(p->error().empty());
}
@@ -871,7 +872,7 @@ TEST_F(SpvParserTest, ConvertType_SampledImage_PretendVoid) {
EXPECT_TRUE(p->BuildInternalModule());
auto* type = p->ConvertType(1);
EXPECT_TRUE(type->IsVoid());
EXPECT_TRUE(type->Is<ast::type::VoidType>());
EXPECT_TRUE(p->error().empty());
}

View File

@@ -15,6 +15,7 @@
#include "gtest/gtest.h"
#include "src/ast/function.h"
#include "src/ast/type/type.h"
#include "src/ast/type/void_type.h"
#include "src/ast/workgroup_decoration.h"
#include "src/reader/wgsl/parser_impl.h"
#include "src/reader/wgsl/parser_impl_test_helper.h"
@@ -38,14 +39,14 @@ TEST_F(ParserImplTest, FunctionDecl) {
EXPECT_EQ(f->name(), "main");
ASSERT_NE(f->return_type(), nullptr);
EXPECT_TRUE(f->return_type()->IsVoid());
EXPECT_TRUE(f->return_type()->Is<ast::type::VoidType>());
ASSERT_EQ(f->params().size(), 2u);
EXPECT_EQ(f->params()[0]->name(), "a");
EXPECT_EQ(f->params()[1]->name(), "b");
ASSERT_NE(f->return_type(), nullptr);
EXPECT_TRUE(f->return_type()->IsVoid());
EXPECT_TRUE(f->return_type()->Is<ast::type::VoidType>());
auto* body = f->body();
ASSERT_EQ(body->size(), 1u);
@@ -66,10 +67,10 @@ TEST_F(ParserImplTest, FunctionDecl_DecorationList) {
EXPECT_EQ(f->name(), "main");
ASSERT_NE(f->return_type(), nullptr);
EXPECT_TRUE(f->return_type()->IsVoid());
EXPECT_TRUE(f->return_type()->Is<ast::type::VoidType>());
ASSERT_EQ(f->params().size(), 0u);
ASSERT_NE(f->return_type(), nullptr);
EXPECT_TRUE(f->return_type()->IsVoid());
EXPECT_TRUE(f->return_type()->Is<ast::type::VoidType>());
auto& decorations = f->decorations();
ASSERT_EQ(decorations.size(), 1u);
@@ -104,10 +105,10 @@ fn main() -> void { return; })");
EXPECT_EQ(f->name(), "main");
ASSERT_NE(f->return_type(), nullptr);
EXPECT_TRUE(f->return_type()->IsVoid());
EXPECT_TRUE(f->return_type()->Is<ast::type::VoidType>());
ASSERT_EQ(f->params().size(), 0u);
ASSERT_NE(f->return_type(), nullptr);
EXPECT_TRUE(f->return_type()->IsVoid());
EXPECT_TRUE(f->return_type()->Is<ast::type::VoidType>());
auto& decorations = f->decorations();
ASSERT_EQ(decorations.size(), 2u);
@@ -149,10 +150,10 @@ fn main() -> void { return; })");
EXPECT_EQ(f->name(), "main");
ASSERT_NE(f->return_type(), nullptr);
EXPECT_TRUE(f->return_type()->IsVoid());
EXPECT_TRUE(f->return_type()->Is<ast::type::VoidType>());
ASSERT_EQ(f->params().size(), 0u);
ASSERT_NE(f->return_type(), nullptr);
EXPECT_TRUE(f->return_type()->IsVoid());
EXPECT_TRUE(f->return_type()->Is<ast::type::VoidType>());
auto& decos = f->decorations();
ASSERT_EQ(decos.size(), 2u);

View File

@@ -15,6 +15,7 @@
#include "gtest/gtest.h"
#include "src/ast/function.h"
#include "src/ast/type/type.h"
#include "src/ast/type/void_type.h"
#include "src/reader/wgsl/parser_impl.h"
#include "src/reader/wgsl/parser_impl_test_helper.h"
@@ -35,7 +36,7 @@ TEST_F(ParserImplTest, FunctionHeader) {
ASSERT_EQ(f->params().size(), 2u);
EXPECT_EQ(f->params()[0]->name(), "a");
EXPECT_EQ(f->params()[1]->name(), "b");
EXPECT_TRUE(f->return_type()->IsVoid());
EXPECT_TRUE(f->return_type()->Is<ast::type::VoidType>());
}
TEST_F(ParserImplTest, FunctionHeader_MissingIdent) {