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:
parent
8a083ce9c8
commit
16ec1bb626
|
@ -66,10 +66,6 @@ Type* Type::UnwrapAll() {
|
|||
return UnwrapIfNeeded()->UnwrapPtrIfNeeded()->UnwrapIfNeeded();
|
||||
}
|
||||
|
||||
bool Type::IsVoid() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint64_t Type::MinBufferBindingSize(MemoryLayout) const {
|
||||
return 0;
|
||||
}
|
||||
|
@ -124,16 +120,6 @@ bool Type::is_integer_scalar_or_vector() {
|
|||
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
|
||||
|
|
|
@ -23,8 +23,6 @@ namespace tint {
|
|||
namespace ast {
|
||||
namespace type {
|
||||
|
||||
class VoidType;
|
||||
|
||||
/// Supported memory layouts for calculating sizes
|
||||
enum class MemoryLayout { kUniformBuffer, kStorageBuffer };
|
||||
|
||||
|
@ -35,9 +33,6 @@ class Type : public Castable<Type> {
|
|||
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 @@ class Type : public Castable<Type> {
|
|||
/// @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();
|
||||
};
|
||||
|
|
|
@ -24,10 +24,6 @@ VoidType::VoidType(VoidType&&) = default;
|
|||
|
||||
VoidType::~VoidType() = default;
|
||||
|
||||
bool VoidType::IsVoid() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string VoidType::type_name() const {
|
||||
return "__void";
|
||||
}
|
||||
|
|
|
@ -32,9 +32,6 @@ class VoidType : public Castable<VoidType, Type> {
|
|||
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;
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -166,7 +166,7 @@ bool ValidatorImpl::ValidateEntryPoint(const ast::FunctionList& funcs) {
|
|||
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 @@ bool ValidatorImpl::ValidateFunction(const ast::Function* func) {
|
|||
}
|
||||
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",
|
||||
|
|
|
@ -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 @@ bool GeneratorImpl::EmitType(std::ostream& out,
|
|||
}
|
||||
out << ", " << size << ">";
|
||||
}
|
||||
} else if (type->IsVoid()) {
|
||||
} else if (type->Is<ast::type::VoidType>()) {
|
||||
out << "void";
|
||||
} else {
|
||||
error_ = "unknown type in EmitType";
|
||||
|
|
|
@ -1918,7 +1918,7 @@ bool GeneratorImpl::EmitType(ast::type::Type* type, const std::string& name) {
|
|||
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();
|
||||
|
|
|
@ -2462,7 +2462,7 @@ uint32_t Builder::GenerateTypeIfNeeded(ast::type::Type* type) {
|
|||
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)) {
|
||||
|
|
|
@ -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 @@ bool GeneratorImpl::EmitType(ast::type::Type* type) {
|
|||
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();
|
||||
|
|
Loading…
Reference in New Issue