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>
diff --git a/src/ast/type/type.cc b/src/ast/type/type.cc
index fdbc0e1..27d8a49 100644
--- a/src/ast/type/type.cc
+++ b/src/ast/type/type.cc
@@ -66,10 +66,6 @@
return UnwrapIfNeeded()->UnwrapPtrIfNeeded()->UnwrapIfNeeded();
}
-bool Type::IsVoid() const {
- return false;
-}
-
uint64_t Type::MinBufferBindingSize(MemoryLayout) const {
return 0;
}
@@ -124,16 +120,6 @@
return is_unsigned_scalar_or_vector() || is_signed_scalar_or_vector();
}
-const VoidType* Type::AsVoid() const {
- assert(IsVoid());
- return static_cast<const VoidType*>(this);
-}
-
-VoidType* Type::AsVoid() {
- assert(IsVoid());
- return static_cast<VoidType*>(this);
-}
-
} // namespace type
} // namespace ast
} // namespace tint
diff --git a/src/ast/type/type.h b/src/ast/type/type.h
index 9c056d7..87a5739 100644
--- a/src/ast/type/type.h
+++ b/src/ast/type/type.h
@@ -23,8 +23,6 @@
namespace ast {
namespace type {
-class VoidType;
-
/// Supported memory layouts for calculating sizes
enum class MemoryLayout { kUniformBuffer, kStorageBuffer };
@@ -35,9 +33,6 @@
Type(Type&&);
~Type() override;
- /// @returns true if the type is a void type
- virtual bool IsVoid() const;
-
/// @returns the name for this type. The |type_name| is unique over all types.
virtual std::string type_name() const = 0;
@@ -92,12 +87,6 @@
/// @returns true if this type is an integer scalar or vector
bool is_integer_scalar_or_vector();
- /// @returns the type as a void type
- const VoidType* AsVoid() const;
-
- /// @returns the type as a void type
- VoidType* AsVoid();
-
protected:
Type();
};
diff --git a/src/ast/type/void_type.cc b/src/ast/type/void_type.cc
index 5cec1f0..ea0ccf6 100644
--- a/src/ast/type/void_type.cc
+++ b/src/ast/type/void_type.cc
@@ -24,10 +24,6 @@
VoidType::~VoidType() = default;
-bool VoidType::IsVoid() const {
- return true;
-}
-
std::string VoidType::type_name() const {
return "__void";
}
diff --git a/src/ast/type/void_type.h b/src/ast/type/void_type.h
index 4aa4842..5099e8b 100644
--- a/src/ast/type/void_type.h
+++ b/src/ast/type/void_type.h
@@ -32,9 +32,6 @@
VoidType(VoidType&&);
~VoidType() override;
- /// @returns true if the type is a void type
- bool IsVoid() const override;
-
/// @returns the name for this type
std::string type_name() const override;
};
diff --git a/src/reader/spirv/function.cc b/src/reader/spirv/function.cc
index d206534..ccff3fd 100644
--- a/src/reader/spirv/function.cc
+++ b/src/reader/spirv/function.cc
@@ -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 @@
<< inst.PrettyPrint();
}
- if (result_type->IsVoid()) {
+ if (result_type->Is<ast::type::VoidType>()) {
return nullptr != AddStatementForInstruction(
create<ast::CallStatement>(call_expr), inst);
}
diff --git a/src/reader/spirv/parser_impl_convert_type_test.cc b/src/reader/spirv/parser_impl_convert_type_test.cc
index 966a43b..f1f2007 100644
--- a/src/reader/spirv/parser_impl_convert_type_test.cc
+++ b/src/reader/spirv/parser_impl_convert_type_test.cc
@@ -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 @@
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 @@
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 @@
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 @@
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());
}
diff --git a/src/reader/wgsl/parser_impl_function_decl_test.cc b/src/reader/wgsl/parser_impl_function_decl_test.cc
index 8f829ac..d25e44d 100644
--- a/src/reader/wgsl/parser_impl_function_decl_test.cc
+++ b/src/reader/wgsl/parser_impl_function_decl_test.cc
@@ -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 @@
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 @@
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 @@
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 @@
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);
diff --git a/src/reader/wgsl/parser_impl_function_header_test.cc b/src/reader/wgsl/parser_impl_function_header_test.cc
index f657a80..77662bf 100644
--- a/src/reader/wgsl/parser_impl_function_header_test.cc
+++ b/src/reader/wgsl/parser_impl_function_header_test.cc
@@ -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 @@
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) {
diff --git a/src/validator/validator_impl.cc b/src/validator/validator_impl.cc
index 49bcb91..8c8d593 100644
--- a/src/validator/validator_impl.cc
+++ b/src/validator/validator_impl.cc
@@ -166,7 +166,7 @@
return false;
}
- if (!func->return_type()->IsVoid()) {
+ if (!func->return_type()->Is<ast::type::VoidType>()) {
add_error(
func->source(), "v-0024",
"Entry point function must return void: '" + func->name() + "'");
@@ -205,7 +205,7 @@
}
variable_stack_.pop_scope();
- if (!current_function_->return_type()->IsVoid()) {
+ if (!current_function_->return_type()->Is<ast::type::VoidType>()) {
if (!func->get_last_statement() ||
!func->get_last_statement()->IsReturn()) {
add_error(func->source(), "v-0002",
diff --git a/src/writer/hlsl/generator_impl.cc b/src/writer/hlsl/generator_impl.cc
index b0e3f90..042708f 100644
--- a/src/writer/hlsl/generator_impl.cc
+++ b/src/writer/hlsl/generator_impl.cc
@@ -51,6 +51,7 @@
#include "src/ast/type/texture_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/uint_literal.h"
#include "src/ast/unary_op_expression.h"
#include "src/ast/variable_decl_statement.h"
@@ -2150,7 +2151,7 @@
}
out << ", " << size << ">";
}
- } else if (type->IsVoid()) {
+ } else if (type->Is<ast::type::VoidType>()) {
out << "void";
} else {
error_ = "unknown type in EmitType";
diff --git a/src/writer/msl/generator_impl.cc b/src/writer/msl/generator_impl.cc
index ee8d27e..085be03 100644
--- a/src/writer/msl/generator_impl.cc
+++ b/src/writer/msl/generator_impl.cc
@@ -1918,7 +1918,7 @@
return false;
}
out_ << vec->size();
- } else if (type->IsVoid()) {
+ } else if (type->Is<ast::type::VoidType>()) {
out_ << "void";
} else {
error_ = "unknown type in EmitType: " + type->type_name();
diff --git a/src/writer/spirv/builder.cc b/src/writer/spirv/builder.cc
index 0b77675..345de30 100644
--- a/src/writer/spirv/builder.cc
+++ b/src/writer/spirv/builder.cc
@@ -2462,7 +2462,7 @@
if (!GenerateVectorType(type->As<ast::type::VectorType>(), result)) {
return 0;
}
- } else if (type->IsVoid()) {
+ } else if (type->Is<ast::type::VoidType>()) {
push_type(spv::Op::OpTypeVoid, {result});
} else if (type->Is<ast::type::TextureType>()) {
if (!GenerateTextureType(type->As<ast::type::TextureType>(), result)) {
diff --git a/src/writer/wgsl/generator_impl.cc b/src/writer/wgsl/generator_impl.cc
index 9411aa5..91212c9 100644
--- a/src/writer/wgsl/generator_impl.cc
+++ b/src/writer/wgsl/generator_impl.cc
@@ -66,6 +66,7 @@
#include "src/ast/type/struct_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_expression.h"
@@ -554,7 +555,7 @@
return false;
}
out_ << ">";
- } else if (type->IsVoid()) {
+ } else if (type->Is<ast::type::VoidType>()) {
out_ << "void";
} else {
error_ = "unknown type in EmitType: " + type->type_name();