Replace Type::(Is|As)I32 with Castable
Change-Id: Id130581f72e762bd398a4c1c509cdbe21739e750 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34267 Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
75f39be976
commit
9857f81e94
|
@ -38,7 +38,7 @@ TEST_F(ExpressionTest, set_result_type) {
|
|||
Expr e;
|
||||
e.set_result_type(&i32);
|
||||
ASSERT_NE(e.result_type(), nullptr);
|
||||
EXPECT_TRUE(e.result_type()->IsI32());
|
||||
EXPECT_TRUE(e.result_type()->Is<ast::type::I32Type>());
|
||||
}
|
||||
|
||||
TEST_F(ExpressionTest, set_result_type_alias) {
|
||||
|
@ -49,7 +49,7 @@ TEST_F(ExpressionTest, set_result_type_alias) {
|
|||
Expr e;
|
||||
e.set_result_type(&b);
|
||||
ASSERT_NE(e.result_type(), nullptr);
|
||||
EXPECT_TRUE(e.result_type()->IsI32());
|
||||
EXPECT_TRUE(e.result_type()->Is<ast::type::I32Type>());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -55,7 +55,7 @@ TEST_F(AccessControlTypeTest, Is) {
|
|||
EXPECT_FALSE(ty->Is<ArrayType>());
|
||||
EXPECT_FALSE(ty->Is<BoolType>());
|
||||
EXPECT_FALSE(ty->Is<F32Type>());
|
||||
EXPECT_FALSE(ty->IsI32());
|
||||
EXPECT_FALSE(ty->Is<I32Type>());
|
||||
EXPECT_FALSE(ty->IsMatrix());
|
||||
EXPECT_FALSE(ty->IsPointer());
|
||||
EXPECT_FALSE(ty->IsSampler());
|
||||
|
|
|
@ -56,7 +56,7 @@ TEST_F(AliasTypeTest, Is) {
|
|||
EXPECT_FALSE(ty->Is<ArrayType>());
|
||||
EXPECT_FALSE(ty->Is<BoolType>());
|
||||
EXPECT_FALSE(ty->Is<F32Type>());
|
||||
EXPECT_FALSE(ty->IsI32());
|
||||
EXPECT_FALSE(ty->Is<I32Type>());
|
||||
EXPECT_FALSE(ty->IsMatrix());
|
||||
EXPECT_FALSE(ty->IsPointer());
|
||||
EXPECT_FALSE(ty->IsSampler());
|
||||
|
|
|
@ -60,7 +60,7 @@ TEST_F(ArrayTypeTest, Is) {
|
|||
EXPECT_TRUE(ty->Is<ArrayType>());
|
||||
EXPECT_FALSE(ty->Is<BoolType>());
|
||||
EXPECT_FALSE(ty->Is<F32Type>());
|
||||
EXPECT_FALSE(ty->IsI32());
|
||||
EXPECT_FALSE(ty->Is<I32Type>());
|
||||
EXPECT_FALSE(ty->IsMatrix());
|
||||
EXPECT_FALSE(ty->IsPointer());
|
||||
EXPECT_FALSE(ty->IsSampler());
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "src/ast/type/access_control_type.h"
|
||||
#include "src/ast/type/array_type.h"
|
||||
#include "src/ast/type/f32_type.h"
|
||||
#include "src/ast/type/i32_type.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
@ -34,7 +35,7 @@ TEST_F(BoolTypeTest, Is) {
|
|||
EXPECT_FALSE(ty->Is<ArrayType>());
|
||||
EXPECT_TRUE(ty->Is<BoolType>());
|
||||
EXPECT_FALSE(ty->Is<F32Type>());
|
||||
EXPECT_FALSE(ty->IsI32());
|
||||
EXPECT_FALSE(ty->Is<I32Type>());
|
||||
EXPECT_FALSE(ty->IsMatrix());
|
||||
EXPECT_FALSE(ty->IsPointer());
|
||||
EXPECT_FALSE(ty->IsSampler());
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "src/ast/type/array_type.h"
|
||||
#include "src/ast/type/bool_type.h"
|
||||
#include "src/ast/type/f32_type.h"
|
||||
#include "src/ast/type/i32_type.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
@ -36,7 +37,7 @@ TEST_F(DepthTextureTypeTest, Is) {
|
|||
EXPECT_FALSE(ty->Is<ArrayType>());
|
||||
EXPECT_FALSE(ty->Is<BoolType>());
|
||||
EXPECT_FALSE(ty->Is<F32Type>());
|
||||
EXPECT_FALSE(ty->IsI32());
|
||||
EXPECT_FALSE(ty->Is<I32Type>());
|
||||
EXPECT_FALSE(ty->IsMatrix());
|
||||
EXPECT_FALSE(ty->IsPointer());
|
||||
EXPECT_FALSE(ty->IsSampler());
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "src/ast/type/access_control_type.h"
|
||||
#include "src/ast/type/array_type.h"
|
||||
#include "src/ast/type/bool_type.h"
|
||||
#include "src/ast/type/i32_type.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
@ -34,7 +35,7 @@ TEST_F(F32TypeTest, Is) {
|
|||
EXPECT_FALSE(ty->Is<ArrayType>());
|
||||
EXPECT_FALSE(ty->Is<BoolType>());
|
||||
EXPECT_TRUE(ty->Is<F32Type>());
|
||||
EXPECT_FALSE(ty->IsI32());
|
||||
EXPECT_FALSE(ty->Is<I32Type>());
|
||||
EXPECT_FALSE(ty->IsMatrix());
|
||||
EXPECT_FALSE(ty->IsPointer());
|
||||
EXPECT_FALSE(ty->IsSampler());
|
||||
|
|
|
@ -24,10 +24,6 @@ I32Type::I32Type(I32Type&&) = default;
|
|||
|
||||
I32Type::~I32Type() = default;
|
||||
|
||||
bool I32Type::IsI32() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string I32Type::type_name() const {
|
||||
return "__i32";
|
||||
}
|
||||
|
|
|
@ -32,9 +32,6 @@ class I32Type : public Castable<I32Type, Type> {
|
|||
I32Type(I32Type&&);
|
||||
~I32Type() override;
|
||||
|
||||
/// @returns true if the type is an i32 type
|
||||
bool IsI32() const override;
|
||||
|
||||
/// @returns the name for this type
|
||||
std::string type_name() const override;
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ TEST_F(I32TypeTest, Is) {
|
|||
EXPECT_FALSE(ty->Is<ArrayType>());
|
||||
EXPECT_FALSE(ty->Is<BoolType>());
|
||||
EXPECT_FALSE(ty->Is<F32Type>());
|
||||
EXPECT_TRUE(ty->IsI32());
|
||||
EXPECT_TRUE(ty->Is<I32Type>());
|
||||
EXPECT_FALSE(ty->IsMatrix());
|
||||
EXPECT_FALSE(ty->IsPointer());
|
||||
EXPECT_FALSE(ty->IsSampler());
|
||||
|
|
|
@ -45,7 +45,7 @@ TEST_F(MatrixTypeTest, Is) {
|
|||
EXPECT_FALSE(ty->Is<ArrayType>());
|
||||
EXPECT_FALSE(ty->Is<BoolType>());
|
||||
EXPECT_FALSE(ty->Is<F32Type>());
|
||||
EXPECT_FALSE(ty->IsI32());
|
||||
EXPECT_FALSE(ty->Is<I32Type>());
|
||||
EXPECT_TRUE(ty->IsMatrix());
|
||||
EXPECT_FALSE(ty->IsPointer());
|
||||
EXPECT_FALSE(ty->IsSampler());
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "src/ast/type/array_type.h"
|
||||
#include "src/ast/type/bool_type.h"
|
||||
#include "src/ast/type/f32_type.h"
|
||||
#include "src/ast/type/i32_type.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
@ -36,7 +37,7 @@ TEST_F(MultisampledTextureTypeTest, Is) {
|
|||
EXPECT_FALSE(ty->Is<ArrayType>());
|
||||
EXPECT_FALSE(ty->Is<BoolType>());
|
||||
EXPECT_FALSE(ty->Is<F32Type>());
|
||||
EXPECT_FALSE(ty->IsI32());
|
||||
EXPECT_FALSE(ty->Is<I32Type>());
|
||||
EXPECT_FALSE(ty->IsMatrix());
|
||||
EXPECT_FALSE(ty->IsPointer());
|
||||
EXPECT_FALSE(ty->IsSampler());
|
||||
|
|
|
@ -44,7 +44,7 @@ TEST_F(PointerTypeTest, Is) {
|
|||
EXPECT_FALSE(ty->Is<ArrayType>());
|
||||
EXPECT_FALSE(ty->Is<BoolType>());
|
||||
EXPECT_FALSE(ty->Is<F32Type>());
|
||||
EXPECT_FALSE(ty->IsI32());
|
||||
EXPECT_FALSE(ty->Is<I32Type>());
|
||||
EXPECT_FALSE(ty->IsMatrix());
|
||||
EXPECT_TRUE(ty->IsPointer());
|
||||
EXPECT_FALSE(ty->IsSampler());
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "src/ast/type/array_type.h"
|
||||
#include "src/ast/type/bool_type.h"
|
||||
#include "src/ast/type/f32_type.h"
|
||||
#include "src/ast/type/i32_type.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
@ -36,7 +37,7 @@ TEST_F(SampledTextureTypeTest, Is) {
|
|||
EXPECT_FALSE(ty->Is<ArrayType>());
|
||||
EXPECT_FALSE(ty->Is<BoolType>());
|
||||
EXPECT_FALSE(ty->Is<F32Type>());
|
||||
EXPECT_FALSE(ty->IsI32());
|
||||
EXPECT_FALSE(ty->Is<I32Type>());
|
||||
EXPECT_FALSE(ty->IsMatrix());
|
||||
EXPECT_FALSE(ty->IsPointer());
|
||||
EXPECT_FALSE(ty->IsSampler());
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "src/ast/type/array_type.h"
|
||||
#include "src/ast/type/bool_type.h"
|
||||
#include "src/ast/type/f32_type.h"
|
||||
#include "src/ast/type/i32_type.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
@ -46,7 +47,7 @@ TEST_F(SamplerTypeTest, Is) {
|
|||
EXPECT_FALSE(ty->Is<ArrayType>());
|
||||
EXPECT_FALSE(ty->Is<BoolType>());
|
||||
EXPECT_FALSE(ty->Is<F32Type>());
|
||||
EXPECT_FALSE(ty->IsI32());
|
||||
EXPECT_FALSE(ty->Is<I32Type>());
|
||||
EXPECT_FALSE(ty->IsMatrix());
|
||||
EXPECT_FALSE(ty->IsPointer());
|
||||
EXPECT_TRUE(ty->IsSampler());
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "src/ast/type/array_type.h"
|
||||
#include "src/ast/type/bool_type.h"
|
||||
#include "src/ast/type/f32_type.h"
|
||||
#include "src/ast/type/i32_type.h"
|
||||
#include "src/type_determiner.h"
|
||||
|
||||
namespace tint {
|
||||
|
@ -40,7 +41,7 @@ TEST_F(StorageTextureTypeTest, Is) {
|
|||
EXPECT_FALSE(ty->Is<ArrayType>());
|
||||
EXPECT_FALSE(ty->Is<BoolType>());
|
||||
EXPECT_FALSE(ty->Is<F32Type>());
|
||||
EXPECT_FALSE(ty->IsI32());
|
||||
EXPECT_FALSE(ty->Is<I32Type>());
|
||||
EXPECT_FALSE(ty->IsMatrix());
|
||||
EXPECT_FALSE(ty->IsPointer());
|
||||
EXPECT_FALSE(ty->IsSampler());
|
||||
|
@ -93,7 +94,7 @@ TEST_F(StorageTextureTypeTest, F32Type) {
|
|||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
ASSERT_TRUE(s->IsTexture());
|
||||
ASSERT_TRUE(s->AsTexture()->IsStorage());
|
||||
EXPECT_TRUE(s->AsTexture()->AsStorage()->type()->Is<ast::type::F32Type>());
|
||||
EXPECT_TRUE(s->AsTexture()->AsStorage()->type()->Is<F32Type>());
|
||||
}
|
||||
|
||||
TEST_F(StorageTextureTypeTest, U32Type) {
|
||||
|
@ -121,7 +122,7 @@ TEST_F(StorageTextureTypeTest, I32Type) {
|
|||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
ASSERT_TRUE(s->IsTexture());
|
||||
ASSERT_TRUE(s->AsTexture()->IsStorage());
|
||||
EXPECT_TRUE(s->AsTexture()->AsStorage()->type()->IsI32());
|
||||
EXPECT_TRUE(s->AsTexture()->AsStorage()->type()->Is<I32Type>());
|
||||
}
|
||||
|
||||
TEST_F(StorageTextureTypeTest, MinBufferBindingSize) {
|
||||
|
|
|
@ -52,7 +52,7 @@ TEST_F(StructTypeTest, Is) {
|
|||
EXPECT_FALSE(ty->Is<ArrayType>());
|
||||
EXPECT_FALSE(ty->Is<BoolType>());
|
||||
EXPECT_FALSE(ty->Is<F32Type>());
|
||||
EXPECT_FALSE(ty->IsI32());
|
||||
EXPECT_FALSE(ty->Is<I32Type>());
|
||||
EXPECT_FALSE(ty->IsMatrix());
|
||||
EXPECT_FALSE(ty->IsPointer());
|
||||
EXPECT_FALSE(ty->IsSampler());
|
||||
|
|
|
@ -66,10 +66,6 @@ Type* Type::UnwrapAll() {
|
|||
return UnwrapIfNeeded()->UnwrapPtrIfNeeded()->UnwrapIfNeeded();
|
||||
}
|
||||
|
||||
bool Type::IsI32() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Type::IsMatrix() const {
|
||||
return false;
|
||||
}
|
||||
|
@ -131,7 +127,7 @@ bool Type::is_float_scalar_or_vector() {
|
|||
}
|
||||
|
||||
bool Type::is_integer_scalar() {
|
||||
return IsU32() || IsI32();
|
||||
return IsU32() || Is<I32Type>();
|
||||
}
|
||||
|
||||
bool Type::is_unsigned_integer_vector() {
|
||||
|
@ -139,7 +135,7 @@ bool Type::is_unsigned_integer_vector() {
|
|||
}
|
||||
|
||||
bool Type::is_signed_integer_vector() {
|
||||
return IsVector() && AsVector()->type()->IsI32();
|
||||
return IsVector() && AsVector()->type()->Is<I32Type>();
|
||||
}
|
||||
|
||||
bool Type::is_unsigned_scalar_or_vector() {
|
||||
|
@ -147,18 +143,13 @@ bool Type::is_unsigned_scalar_or_vector() {
|
|||
}
|
||||
|
||||
bool Type::is_signed_scalar_or_vector() {
|
||||
return IsI32() || (IsVector() && AsVector()->type()->IsI32());
|
||||
return Is<I32Type>() || (IsVector() && AsVector()->type()->Is<I32Type>());
|
||||
}
|
||||
|
||||
bool Type::is_integer_scalar_or_vector() {
|
||||
return is_unsigned_scalar_or_vector() || is_signed_scalar_or_vector();
|
||||
}
|
||||
|
||||
const I32Type* Type::AsI32() const {
|
||||
assert(IsI32());
|
||||
return static_cast<const I32Type*>(this);
|
||||
}
|
||||
|
||||
const MatrixType* Type::AsMatrix() const {
|
||||
assert(IsMatrix());
|
||||
return static_cast<const MatrixType*>(this);
|
||||
|
@ -199,11 +190,6 @@ const VoidType* Type::AsVoid() const {
|
|||
return static_cast<const VoidType*>(this);
|
||||
}
|
||||
|
||||
I32Type* Type::AsI32() {
|
||||
assert(IsI32());
|
||||
return static_cast<I32Type*>(this);
|
||||
}
|
||||
|
||||
MatrixType* Type::AsMatrix() {
|
||||
assert(IsMatrix());
|
||||
return static_cast<MatrixType*>(this);
|
||||
|
|
|
@ -23,7 +23,6 @@ namespace tint {
|
|||
namespace ast {
|
||||
namespace type {
|
||||
|
||||
class I32Type;
|
||||
class MatrixType;
|
||||
class PointerType;
|
||||
class SamplerType;
|
||||
|
@ -43,8 +42,6 @@ class Type : public Castable<Type> {
|
|||
Type(Type&&);
|
||||
~Type() override;
|
||||
|
||||
/// @returns true if the type is an i32 type
|
||||
virtual bool IsI32() const;
|
||||
/// @returns true if the type is a matrix type
|
||||
virtual bool IsMatrix() const;
|
||||
/// @returns true if the type is a ptr type
|
||||
|
@ -116,8 +113,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 an i32 type
|
||||
const I32Type* AsI32() const;
|
||||
/// @returns the type as a matrix type
|
||||
const MatrixType* AsMatrix() const;
|
||||
/// @returns the type as a pointer type
|
||||
|
@ -135,8 +130,6 @@ class Type : public Castable<Type> {
|
|||
/// @returns the type as a void type
|
||||
const VoidType* AsVoid() const;
|
||||
|
||||
/// @returns the type as an i32 type
|
||||
I32Type* AsI32();
|
||||
/// @returns the type as a matrix type
|
||||
MatrixType* AsMatrix();
|
||||
/// @returns the type as a pointer type
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "src/ast/type/array_type.h"
|
||||
#include "src/ast/type/bool_type.h"
|
||||
#include "src/ast/type/f32_type.h"
|
||||
#include "src/ast/type/i32_type.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
@ -35,7 +36,7 @@ TEST_F(U32TypeTest, Is) {
|
|||
EXPECT_FALSE(ty->Is<ArrayType>());
|
||||
EXPECT_FALSE(ty->Is<BoolType>());
|
||||
EXPECT_FALSE(ty->Is<F32Type>());
|
||||
EXPECT_FALSE(ty->IsI32());
|
||||
EXPECT_FALSE(ty->Is<I32Type>());
|
||||
EXPECT_FALSE(ty->IsMatrix());
|
||||
EXPECT_FALSE(ty->IsPointer());
|
||||
EXPECT_FALSE(ty->IsSampler());
|
||||
|
|
|
@ -44,7 +44,7 @@ TEST_F(VectorTypeTest, Is) {
|
|||
EXPECT_FALSE(ty->Is<ArrayType>());
|
||||
EXPECT_FALSE(ty->Is<BoolType>());
|
||||
EXPECT_FALSE(ty->Is<F32Type>());
|
||||
EXPECT_FALSE(ty->IsI32());
|
||||
EXPECT_FALSE(ty->Is<I32Type>());
|
||||
EXPECT_FALSE(ty->IsMatrix());
|
||||
EXPECT_FALSE(ty->IsPointer());
|
||||
EXPECT_FALSE(ty->IsSampler());
|
||||
|
|
|
@ -28,14 +28,14 @@ TEST_F(TypeManagerTest, GetUnregistered) {
|
|||
ast::TypeManager tm;
|
||||
auto* t = tm.Get(std::make_unique<ast::type::I32Type>());
|
||||
ASSERT_NE(t, nullptr);
|
||||
EXPECT_TRUE(t->IsI32());
|
||||
EXPECT_TRUE(t->Is<ast::type::I32Type>());
|
||||
}
|
||||
|
||||
TEST_F(TypeManagerTest, GetSameTypeReturnsSamePtr) {
|
||||
ast::TypeManager tm;
|
||||
auto* t = tm.Get(std::make_unique<ast::type::I32Type>());
|
||||
ASSERT_NE(t, nullptr);
|
||||
EXPECT_TRUE(t->IsI32());
|
||||
EXPECT_TRUE(t->Is<ast::type::I32Type>());
|
||||
|
||||
auto* t2 = tm.Get(std::make_unique<ast::type::I32Type>());
|
||||
EXPECT_EQ(t, t2);
|
||||
|
@ -45,7 +45,7 @@ TEST_F(TypeManagerTest, GetDifferentTypeReturnsDifferentPtr) {
|
|||
ast::TypeManager tm;
|
||||
auto* t = tm.Get(std::make_unique<ast::type::I32Type>());
|
||||
ASSERT_NE(t, nullptr);
|
||||
EXPECT_TRUE(t->IsI32());
|
||||
EXPECT_TRUE(t->Is<ast::type::I32Type>());
|
||||
|
||||
auto* t2 = tm.Get(std::make_unique<ast::type::U32Type>());
|
||||
ASSERT_NE(t2, nullptr);
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include "src/ast/type/access_control_type.h"
|
||||
#include "src/ast/type/array_type.h"
|
||||
#include "src/ast/type/f32_type.h"
|
||||
#include "src/ast/type/i32_type.h"
|
||||
#include "src/ast/type/matrix_type.h"
|
||||
#include "src/ast/type/multisampled_texture_type.h"
|
||||
#include "src/ast/type/sampled_texture_type.h"
|
||||
|
@ -396,7 +397,7 @@ std::vector<ResourceBinding> Inspector::GetSampledTextureResourceBindingsImpl(
|
|||
entry.sampled_kind = ResourceBinding::SampledKind::kFloat;
|
||||
} else if (base_type->IsU32()) {
|
||||
entry.sampled_kind = ResourceBinding::SampledKind::kUInt;
|
||||
} else if (base_type->IsI32()) {
|
||||
} else if (base_type->Is<ast::type::I32Type>()) {
|
||||
entry.sampled_kind = ResourceBinding::SampledKind::kSInt;
|
||||
} else {
|
||||
entry.sampled_kind = ResourceBinding::SampledKind::kUnknown;
|
||||
|
|
|
@ -975,7 +975,7 @@ bool ParserImpl::EmitScalarSpecConstants() {
|
|||
case SpvOpSpecConstant: {
|
||||
ast_type = ConvertType(inst.type_id());
|
||||
const uint32_t literal_value = inst.GetSingleWordInOperand(0);
|
||||
if (ast_type->IsI32()) {
|
||||
if (ast_type->Is<ast::type::I32Type>()) {
|
||||
ast_expr =
|
||||
create<ast::ScalarConstructorExpression>(create<ast::SintLiteral>(
|
||||
ast_type, static_cast<int32_t>(literal_value)));
|
||||
|
@ -1267,7 +1267,7 @@ TypedExpression ParserImpl::MakeConstantExpression(uint32_t id) {
|
|||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::UintLiteral>(ast_type, spirv_const->GetU32()))};
|
||||
}
|
||||
if (ast_type->IsI32()) {
|
||||
if (ast_type->Is<ast::type::I32Type>()) {
|
||||
return {ast_type,
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(ast_type, spirv_const->GetS32()))};
|
||||
|
@ -1342,7 +1342,7 @@ ast::Expression* ParserImpl::MakeNullValue(ast::type::Type* type) {
|
|||
return create<ast::ScalarConstructorExpression>(
|
||||
create<ast::UintLiteral>(type, 0u));
|
||||
}
|
||||
if (type->IsI32()) {
|
||||
if (type->Is<ast::type::I32Type>()) {
|
||||
return create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(type, 0));
|
||||
}
|
||||
|
@ -1445,7 +1445,8 @@ ast::type::Type* ParserImpl::GetSignedIntMatchingShape(ast::type::Type* other) {
|
|||
Fail() << "no type provided";
|
||||
}
|
||||
auto* i32 = ast_module_.create<ast::type::I32Type>();
|
||||
if (other->Is<ast::type::F32Type>() || other->IsU32() || other->IsI32()) {
|
||||
if (other->Is<ast::type::F32Type>() || other->IsU32() ||
|
||||
other->Is<ast::type::I32Type>()) {
|
||||
return i32;
|
||||
}
|
||||
auto* vec_ty = other->AsVector();
|
||||
|
@ -1463,7 +1464,8 @@ ast::type::Type* ParserImpl::GetUnsignedIntMatchingShape(
|
|||
return nullptr;
|
||||
}
|
||||
auto* u32 = ast_module_.create<ast::type::U32Type>();
|
||||
if (other->Is<ast::type::F32Type>() || other->IsU32() || other->IsI32()) {
|
||||
if (other->Is<ast::type::F32Type>() || other->IsU32() ||
|
||||
other->Is<ast::type::I32Type>()) {
|
||||
return u32;
|
||||
}
|
||||
auto* vec_ty = other->AsVector();
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "src/ast/type/array_type.h"
|
||||
#include "src/ast/type/bool_type.h"
|
||||
#include "src/ast/type/f32_type.h"
|
||||
#include "src/ast/type/i32_type.h"
|
||||
#include "src/ast/type/matrix_type.h"
|
||||
#include "src/ast/type/pointer_type.h"
|
||||
#include "src/ast/type/struct_type.h"
|
||||
|
@ -107,7 +108,7 @@ TEST_F(SpvParserTest, ConvertType_I32) {
|
|||
EXPECT_TRUE(p->BuildInternalModule());
|
||||
|
||||
auto* type = p->ConvertType(2);
|
||||
EXPECT_TRUE(type->IsI32());
|
||||
EXPECT_TRUE(type->Is<ast::type::I32Type>());
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
}
|
||||
|
||||
|
@ -197,17 +198,17 @@ TEST_F(SpvParserTest, ConvertType_VecOverI32) {
|
|||
|
||||
auto* v2xi32 = p->ConvertType(20);
|
||||
EXPECT_TRUE(v2xi32->IsVector());
|
||||
EXPECT_TRUE(v2xi32->AsVector()->type()->IsI32());
|
||||
EXPECT_TRUE(v2xi32->AsVector()->type()->Is<ast::type::I32Type>());
|
||||
EXPECT_EQ(v2xi32->AsVector()->size(), 2u);
|
||||
|
||||
auto* v3xi32 = p->ConvertType(30);
|
||||
EXPECT_TRUE(v3xi32->IsVector());
|
||||
EXPECT_TRUE(v3xi32->AsVector()->type()->IsI32());
|
||||
EXPECT_TRUE(v3xi32->AsVector()->type()->Is<ast::type::I32Type>());
|
||||
EXPECT_EQ(v3xi32->AsVector()->size(), 3u);
|
||||
|
||||
auto* v4xi32 = p->ConvertType(40);
|
||||
EXPECT_TRUE(v4xi32->IsVector());
|
||||
EXPECT_TRUE(v4xi32->AsVector()->type()->IsI32());
|
||||
EXPECT_TRUE(v4xi32->AsVector()->type()->Is<ast::type::I32Type>());
|
||||
EXPECT_EQ(v4xi32->AsVector()->size(), 4u);
|
||||
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
#include "gtest/gtest.h"
|
||||
#include "src/ast/type/f32_type.h"
|
||||
#include "src/ast/type/i32_type.h"
|
||||
#include "src/ast/type/multisampled_texture_type.h"
|
||||
#include "src/ast/type/sampled_texture_type.h"
|
||||
#include "src/ast/type/sampler_type.h"
|
||||
|
@ -90,7 +91,7 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_I32_Old) {
|
|||
ASSERT_NE(t.value, nullptr);
|
||||
ASSERT_TRUE(t->IsTexture());
|
||||
ASSERT_TRUE(t->AsTexture()->IsSampled());
|
||||
ASSERT_TRUE(t->AsTexture()->AsSampled()->type()->IsI32());
|
||||
ASSERT_TRUE(t->AsTexture()->AsSampled()->type()->Is<ast::type::I32Type>());
|
||||
EXPECT_EQ(t->AsTexture()->dim(), ast::type::TextureDimension::k2d);
|
||||
}
|
||||
|
||||
|
@ -170,7 +171,7 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_I32) {
|
|||
ASSERT_NE(t.value, nullptr);
|
||||
ASSERT_TRUE(t->IsTexture());
|
||||
ASSERT_TRUE(t->AsTexture()->IsSampled());
|
||||
ASSERT_TRUE(t->AsTexture()->AsSampled()->type()->IsI32());
|
||||
ASSERT_TRUE(t->AsTexture()->AsSampled()->type()->Is<ast::type::I32Type>());
|
||||
EXPECT_EQ(t->AsTexture()->dim(), ast::type::TextureDimension::k2d);
|
||||
}
|
||||
|
||||
|
@ -236,7 +237,8 @@ TEST_F(ParserImplTest, TextureSamplerTypes_MultisampledTexture_I32) {
|
|||
ASSERT_NE(t.value, nullptr);
|
||||
ASSERT_TRUE(t->IsTexture());
|
||||
ASSERT_TRUE(t->AsTexture()->IsMultisampled());
|
||||
ASSERT_TRUE(t->AsTexture()->AsMultisampled()->type()->IsI32());
|
||||
ASSERT_TRUE(
|
||||
t->AsTexture()->AsMultisampled()->type()->Is<ast::type::I32Type>());
|
||||
EXPECT_EQ(t->AsTexture()->dim(), ast::type::TextureDimension::k2d);
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ TEST_F(ParserImplTest, TypeDecl_ParsesType) {
|
|||
ASSERT_NE(t.value, nullptr);
|
||||
ASSERT_TRUE(t->Is<ast::type::AliasType>());
|
||||
auto* alias = t->As<ast::type::AliasType>();
|
||||
ASSERT_TRUE(alias->type()->IsI32());
|
||||
ASSERT_TRUE(alias->type()->Is<ast::type::I32Type>());
|
||||
ASSERT_EQ(alias->type(), i32);
|
||||
}
|
||||
|
||||
|
|
|
@ -115,7 +115,7 @@ TEST_F(ParserImplTest, TypeDecl_I32) {
|
|||
EXPECT_FALSE(t.errored);
|
||||
ASSERT_NE(t.value, nullptr) << p->error();
|
||||
EXPECT_EQ(t.value, int_type);
|
||||
ASSERT_TRUE(t->IsI32());
|
||||
ASSERT_TRUE(t->Is<ast::type::I32Type>());
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, TypeDecl_U32) {
|
||||
|
|
|
@ -375,7 +375,7 @@ TEST_F(BoundArrayAccessorsTest, Array_Idx_Negative) {
|
|||
EXPECT_EQ(scalar->literal()->AsSint()->value(), 0);
|
||||
|
||||
ASSERT_NE(ptr->idx_expr()->result_type(), nullptr);
|
||||
ASSERT_TRUE(ptr->idx_expr()->result_type()->IsI32());
|
||||
ASSERT_TRUE(ptr->idx_expr()->result_type()->Is<ast::type::I32Type>());
|
||||
}
|
||||
|
||||
TEST_F(BoundArrayAccessorsTest, Array_Idx_OutOfBounds) {
|
||||
|
@ -553,7 +553,7 @@ TEST_F(BoundArrayAccessorsTest, Vector_Idx_Negative) {
|
|||
EXPECT_EQ(scalar->literal()->AsSint()->value(), 0);
|
||||
|
||||
ASSERT_NE(ptr->idx_expr()->result_type(), nullptr);
|
||||
ASSERT_TRUE(ptr->idx_expr()->result_type()->IsI32());
|
||||
ASSERT_TRUE(ptr->idx_expr()->result_type()->Is<ast::type::I32Type>());
|
||||
}
|
||||
|
||||
TEST_F(BoundArrayAccessorsTest, Vector_Idx_OutOfBounds) {
|
||||
|
@ -848,7 +848,7 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Negative_Column) {
|
|||
EXPECT_EQ(scalar->literal()->AsSint()->value(), 0);
|
||||
|
||||
ASSERT_NE(ary->idx_expr()->result_type(), nullptr);
|
||||
ASSERT_TRUE(ary->idx_expr()->result_type()->IsI32());
|
||||
ASSERT_TRUE(ary->idx_expr()->result_type()->Is<ast::type::I32Type>());
|
||||
|
||||
ASSERT_TRUE(ptr->idx_expr()->IsConstructor());
|
||||
ASSERT_TRUE(ptr->idx_expr()->AsConstructor()->IsScalarConstructor());
|
||||
|
@ -858,7 +858,7 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Negative_Column) {
|
|||
EXPECT_EQ(scalar->literal()->AsSint()->value(), 1);
|
||||
|
||||
ASSERT_NE(ptr->idx_expr()->result_type(), nullptr);
|
||||
ASSERT_TRUE(ptr->idx_expr()->result_type()->IsI32());
|
||||
ASSERT_TRUE(ptr->idx_expr()->result_type()->Is<ast::type::I32Type>());
|
||||
}
|
||||
|
||||
TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Negative_Row) {
|
||||
|
@ -902,7 +902,7 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Negative_Row) {
|
|||
EXPECT_EQ(scalar->literal()->AsSint()->value(), 2);
|
||||
|
||||
ASSERT_NE(ary->idx_expr()->result_type(), nullptr);
|
||||
ASSERT_TRUE(ary->idx_expr()->result_type()->IsI32());
|
||||
ASSERT_TRUE(ary->idx_expr()->result_type()->Is<ast::type::I32Type>());
|
||||
|
||||
ASSERT_TRUE(ptr->idx_expr()->IsConstructor());
|
||||
ASSERT_TRUE(ptr->idx_expr()->AsConstructor()->IsScalarConstructor());
|
||||
|
@ -912,7 +912,7 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Negative_Row) {
|
|||
EXPECT_EQ(scalar->literal()->AsSint()->value(), 0);
|
||||
|
||||
ASSERT_NE(ptr->idx_expr()->result_type(), nullptr);
|
||||
ASSERT_TRUE(ptr->idx_expr()->result_type()->IsI32());
|
||||
ASSERT_TRUE(ptr->idx_expr()->result_type()->Is<ast::type::I32Type>());
|
||||
}
|
||||
|
||||
TEST_F(BoundArrayAccessorsTest, Matrix_Idx_OutOfBounds_Column) {
|
||||
|
|
|
@ -135,7 +135,7 @@ TEST_F(TypeDeterminerTest, Stmt_Assign) {
|
|||
ASSERT_NE(lhs->result_type(), nullptr);
|
||||
ASSERT_NE(rhs->result_type(), nullptr);
|
||||
|
||||
EXPECT_TRUE(lhs->result_type()->IsI32());
|
||||
EXPECT_TRUE(lhs->result_type()->Is<ast::type::I32Type>());
|
||||
EXPECT_TRUE(rhs->result_type()->Is<ast::type::F32Type>());
|
||||
}
|
||||
|
||||
|
@ -158,7 +158,7 @@ TEST_F(TypeDeterminerTest, Stmt_Case) {
|
|||
EXPECT_TRUE(td()->DetermineResultType(&cse));
|
||||
ASSERT_NE(lhs->result_type(), nullptr);
|
||||
ASSERT_NE(rhs->result_type(), nullptr);
|
||||
EXPECT_TRUE(lhs->result_type()->IsI32());
|
||||
EXPECT_TRUE(lhs->result_type()->Is<ast::type::I32Type>());
|
||||
EXPECT_TRUE(rhs->result_type()->Is<ast::type::F32Type>());
|
||||
}
|
||||
|
||||
|
@ -177,7 +177,7 @@ TEST_F(TypeDeterminerTest, Stmt_Block) {
|
|||
EXPECT_TRUE(td()->DetermineResultType(&block));
|
||||
ASSERT_NE(lhs->result_type(), nullptr);
|
||||
ASSERT_NE(rhs->result_type(), nullptr);
|
||||
EXPECT_TRUE(lhs->result_type()->IsI32());
|
||||
EXPECT_TRUE(lhs->result_type()->Is<ast::type::I32Type>());
|
||||
EXPECT_TRUE(rhs->result_type()->Is<ast::type::F32Type>());
|
||||
}
|
||||
|
||||
|
@ -201,8 +201,8 @@ TEST_F(TypeDeterminerTest, Stmt_Else) {
|
|||
ASSERT_NE(stmt.condition()->result_type(), nullptr);
|
||||
ASSERT_NE(lhs->result_type(), nullptr);
|
||||
ASSERT_NE(rhs->result_type(), nullptr);
|
||||
EXPECT_TRUE(stmt.condition()->result_type()->IsI32());
|
||||
EXPECT_TRUE(lhs->result_type()->IsI32());
|
||||
EXPECT_TRUE(stmt.condition()->result_type()->Is<ast::type::I32Type>());
|
||||
EXPECT_TRUE(lhs->result_type()->Is<ast::type::I32Type>());
|
||||
EXPECT_TRUE(rhs->result_type()->Is<ast::type::F32Type>());
|
||||
}
|
||||
|
||||
|
@ -245,10 +245,10 @@ TEST_F(TypeDeterminerTest, Stmt_If) {
|
|||
ASSERT_NE(else_rhs->result_type(), nullptr);
|
||||
ASSERT_NE(lhs->result_type(), nullptr);
|
||||
ASSERT_NE(rhs->result_type(), nullptr);
|
||||
EXPECT_TRUE(stmt.condition()->result_type()->IsI32());
|
||||
EXPECT_TRUE(else_lhs->result_type()->IsI32());
|
||||
EXPECT_TRUE(stmt.condition()->result_type()->Is<ast::type::I32Type>());
|
||||
EXPECT_TRUE(else_lhs->result_type()->Is<ast::type::I32Type>());
|
||||
EXPECT_TRUE(else_rhs->result_type()->Is<ast::type::F32Type>());
|
||||
EXPECT_TRUE(lhs->result_type()->IsI32());
|
||||
EXPECT_TRUE(lhs->result_type()->Is<ast::type::I32Type>());
|
||||
EXPECT_TRUE(rhs->result_type()->Is<ast::type::F32Type>());
|
||||
}
|
||||
|
||||
|
@ -280,9 +280,9 @@ TEST_F(TypeDeterminerTest, Stmt_Loop) {
|
|||
ASSERT_NE(body_rhs->result_type(), nullptr);
|
||||
ASSERT_NE(continuing_lhs->result_type(), nullptr);
|
||||
ASSERT_NE(continuing_rhs->result_type(), nullptr);
|
||||
EXPECT_TRUE(body_lhs->result_type()->IsI32());
|
||||
EXPECT_TRUE(body_lhs->result_type()->Is<ast::type::I32Type>());
|
||||
EXPECT_TRUE(body_rhs->result_type()->Is<ast::type::F32Type>());
|
||||
EXPECT_TRUE(continuing_lhs->result_type()->IsI32());
|
||||
EXPECT_TRUE(continuing_lhs->result_type()->Is<ast::type::I32Type>());
|
||||
EXPECT_TRUE(continuing_rhs->result_type()->Is<ast::type::F32Type>());
|
||||
}
|
||||
|
||||
|
@ -296,7 +296,7 @@ TEST_F(TypeDeterminerTest, Stmt_Return) {
|
|||
|
||||
EXPECT_TRUE(td()->DetermineResultType(&ret));
|
||||
ASSERT_NE(cond->result_type(), nullptr);
|
||||
EXPECT_TRUE(cond->result_type()->IsI32());
|
||||
EXPECT_TRUE(cond->result_type()->Is<ast::type::I32Type>());
|
||||
}
|
||||
|
||||
TEST_F(TypeDeterminerTest, Stmt_Return_WithoutValue) {
|
||||
|
@ -332,8 +332,8 @@ TEST_F(TypeDeterminerTest, Stmt_Switch) {
|
|||
ASSERT_NE(lhs->result_type(), nullptr);
|
||||
ASSERT_NE(rhs->result_type(), nullptr);
|
||||
|
||||
EXPECT_TRUE(stmt.condition()->result_type()->IsI32());
|
||||
EXPECT_TRUE(lhs->result_type()->IsI32());
|
||||
EXPECT_TRUE(stmt.condition()->result_type()->Is<ast::type::I32Type>());
|
||||
EXPECT_TRUE(lhs->result_type()->Is<ast::type::I32Type>());
|
||||
EXPECT_TRUE(rhs->result_type()->Is<ast::type::F32Type>());
|
||||
}
|
||||
|
||||
|
@ -395,7 +395,7 @@ TEST_F(TypeDeterminerTest, Stmt_VariableDecl) {
|
|||
|
||||
EXPECT_TRUE(td()->DetermineResultType(&decl));
|
||||
ASSERT_NE(init->result_type(), nullptr);
|
||||
EXPECT_TRUE(init->result_type()->IsI32());
|
||||
EXPECT_TRUE(init->result_type()->Is<ast::type::I32Type>());
|
||||
}
|
||||
|
||||
TEST_F(TypeDeterminerTest, Stmt_VariableDecl_ModuleScope) {
|
||||
|
@ -409,7 +409,7 @@ TEST_F(TypeDeterminerTest, Stmt_VariableDecl_ModuleScope) {
|
|||
|
||||
EXPECT_TRUE(td()->Determine());
|
||||
ASSERT_NE(init->result_type(), nullptr);
|
||||
EXPECT_TRUE(init->result_type()->IsI32());
|
||||
EXPECT_TRUE(init->result_type()->Is<ast::type::I32Type>());
|
||||
}
|
||||
|
||||
TEST_F(TypeDeterminerTest, Expr_Error_Unknown) {
|
||||
|
@ -1140,7 +1140,7 @@ TEST_P(Expr_Binary_BitwiseTest, Scalar) {
|
|||
|
||||
ASSERT_TRUE(td()->DetermineResultType(&expr)) << td()->error();
|
||||
ASSERT_NE(expr.result_type(), nullptr);
|
||||
EXPECT_TRUE(expr.result_type()->IsI32());
|
||||
EXPECT_TRUE(expr.result_type()->Is<ast::type::I32Type>());
|
||||
}
|
||||
|
||||
TEST_P(Expr_Binary_BitwiseTest, Vector) {
|
||||
|
@ -1161,7 +1161,7 @@ TEST_P(Expr_Binary_BitwiseTest, Vector) {
|
|||
ASSERT_TRUE(td()->DetermineResultType(&expr)) << td()->error();
|
||||
ASSERT_NE(expr.result_type(), nullptr);
|
||||
ASSERT_TRUE(expr.result_type()->IsVector());
|
||||
EXPECT_TRUE(expr.result_type()->AsVector()->type()->IsI32());
|
||||
EXPECT_TRUE(expr.result_type()->AsVector()->type()->Is<ast::type::I32Type>());
|
||||
EXPECT_EQ(expr.result_type()->AsVector()->size(), 3u);
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(TypeDeterminerTest,
|
||||
|
@ -1290,7 +1290,7 @@ TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Scalar_Scalar) {
|
|||
|
||||
ASSERT_TRUE(td()->DetermineResultType(&expr)) << td()->error();
|
||||
ASSERT_NE(expr.result_type(), nullptr);
|
||||
EXPECT_TRUE(expr.result_type()->IsI32());
|
||||
EXPECT_TRUE(expr.result_type()->Is<ast::type::I32Type>());
|
||||
}
|
||||
|
||||
TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Vector_Scalar) {
|
||||
|
@ -1748,7 +1748,7 @@ class Intrinsic_TextureOperation
|
|||
ast::type::TextureDimension dim,
|
||||
ast::type::Type* type) {
|
||||
if (dim == ast::type::TextureDimension::k1d) {
|
||||
if (type->IsI32()) {
|
||||
if (type->Is<ast::type::I32Type>()) {
|
||||
return std::make_unique<ast::type::I32Type>();
|
||||
} else if (type->IsU32()) {
|
||||
return std::make_unique<ast::type::U32Type>();
|
||||
|
@ -1814,7 +1814,8 @@ TEST_P(Intrinsic_StorageTextureOperation, TextureLoadRo) {
|
|||
EXPECT_TRUE(
|
||||
expr.result_type()->AsVector()->type()->Is<ast::type::F32Type>());
|
||||
} else if (type == TextureType::kI32) {
|
||||
EXPECT_TRUE(expr.result_type()->AsVector()->type()->IsI32());
|
||||
EXPECT_TRUE(
|
||||
expr.result_type()->AsVector()->type()->Is<ast::type::I32Type>());
|
||||
} else {
|
||||
EXPECT_TRUE(expr.result_type()->AsVector()->type()->IsU32());
|
||||
}
|
||||
|
@ -1885,7 +1886,8 @@ TEST_P(Intrinsic_SampledTextureOperation, TextureLoadSampled) {
|
|||
EXPECT_TRUE(
|
||||
expr.result_type()->AsVector()->type()->Is<ast::type::F32Type>());
|
||||
} else if (type == TextureType::kI32) {
|
||||
EXPECT_TRUE(expr.result_type()->AsVector()->type()->IsI32());
|
||||
EXPECT_TRUE(
|
||||
expr.result_type()->AsVector()->type()->Is<ast::type::I32Type>());
|
||||
} else {
|
||||
EXPECT_TRUE(expr.result_type()->AsVector()->type()->IsU32());
|
||||
}
|
||||
|
@ -2426,7 +2428,7 @@ TEST_P(ImportData_SingleParam_FloatOrInt_Test, Sint_Scalar) {
|
|||
|
||||
EXPECT_TRUE(td()->DetermineResultType(&call)) << td()->error();
|
||||
ASSERT_NE(ident->result_type(), nullptr);
|
||||
EXPECT_TRUE(ident->result_type()->IsI32());
|
||||
EXPECT_TRUE(ident->result_type()->Is<ast::type::I32Type>());
|
||||
}
|
||||
|
||||
TEST_P(ImportData_SingleParam_FloatOrInt_Test, Sint_Vector) {
|
||||
|
@ -3488,7 +3490,7 @@ TEST_P(ImportData_ThreeParam_FloatOrInt_Test, Sint_Scalar) {
|
|||
|
||||
EXPECT_TRUE(td()->DetermineResultType(&call)) << td()->error();
|
||||
ASSERT_NE(ident->result_type(), nullptr);
|
||||
EXPECT_TRUE(ident->result_type()->IsI32());
|
||||
EXPECT_TRUE(ident->result_type()->Is<ast::type::I32Type>());
|
||||
}
|
||||
|
||||
TEST_P(ImportData_ThreeParam_FloatOrInt_Test, Sint_Vector) {
|
||||
|
@ -3894,7 +3896,7 @@ TEST_P(ImportData_FloatOrInt_TwoParamTest, Scalar_Signed) {
|
|||
|
||||
EXPECT_TRUE(td()->DetermineResultType(&call)) << td()->error();
|
||||
ASSERT_NE(ident->result_type(), nullptr);
|
||||
EXPECT_TRUE(ident->result_type()->IsI32());
|
||||
EXPECT_TRUE(ident->result_type()->Is<ast::type::I32Type>());
|
||||
}
|
||||
|
||||
TEST_P(ImportData_FloatOrInt_TwoParamTest, Scalar_Unsigned) {
|
||||
|
|
|
@ -316,7 +316,7 @@ bool ValidatorImpl::ValidateSwitch(const ast::SwitchStatement* s) {
|
|||
}
|
||||
|
||||
auto* cond_type = s->condition()->result_type()->UnwrapAll();
|
||||
if (!(cond_type->IsI32() || cond_type->IsU32())) {
|
||||
if (!(cond_type->Is<ast::type::I32Type>() || cond_type->IsU32())) {
|
||||
add_error(s->condition()->source(), "v-0025",
|
||||
"switch statement selector expression must be of a "
|
||||
"scalar integer type");
|
||||
|
|
|
@ -265,8 +265,8 @@ bool GeneratorImpl::EmitArrayAccessor(std::ostream& pre,
|
|||
bool GeneratorImpl::EmitBitcast(std::ostream& pre,
|
||||
std::ostream& out,
|
||||
ast::BitcastExpression* expr) {
|
||||
if (!expr->type()->Is<ast::type::F32Type>() && !expr->type()->IsI32() &&
|
||||
!expr->type()->IsU32()) {
|
||||
if (!expr->type()->Is<ast::type::F32Type>() &&
|
||||
!expr->type()->Is<ast::type::I32Type>() && !expr->type()->IsU32()) {
|
||||
error_ = "Unable to do bitcast to type " + expr->type()->type_name();
|
||||
return false;
|
||||
}
|
||||
|
@ -1547,7 +1547,7 @@ bool GeneratorImpl::EmitZeroValue(std::ostream& out, ast::type::Type* type) {
|
|||
out << "false";
|
||||
} else if (type->Is<ast::type::F32Type>()) {
|
||||
out << "0.0f";
|
||||
} else if (type->IsI32()) {
|
||||
} else if (type->Is<ast::type::I32Type>()) {
|
||||
out << "0";
|
||||
} else if (type->IsU32()) {
|
||||
out << "0u";
|
||||
|
@ -2062,7 +2062,7 @@ bool GeneratorImpl::EmitType(std::ostream& out,
|
|||
out << "bool";
|
||||
} else if (type->Is<ast::type::F32Type>()) {
|
||||
out << "float";
|
||||
} else if (type->IsI32()) {
|
||||
} else if (type->Is<ast::type::I32Type>()) {
|
||||
out << "int";
|
||||
} else if (type->IsMatrix()) {
|
||||
auto* mat = type->AsMatrix();
|
||||
|
@ -2125,7 +2125,8 @@ bool GeneratorImpl::EmitType(std::ostream& out,
|
|||
auto size = vec->size();
|
||||
if (vec->type()->Is<ast::type::F32Type>() && size >= 1 && size <= 4) {
|
||||
out << "float" << size;
|
||||
} else if (vec->type()->IsI32() && size >= 1 && size <= 4) {
|
||||
} else if (vec->type()->Is<ast::type::I32Type>() && size >= 1 &&
|
||||
size <= 4) {
|
||||
out << "int" << size;
|
||||
} else if (vec->type()->IsU32() && size >= 1 && size <= 4) {
|
||||
out << "uint" << size;
|
||||
|
|
|
@ -200,7 +200,8 @@ uint32_t GeneratorImpl::calculate_alignment_size(ast::type::Type* type) {
|
|||
if (type->IsPointer()) {
|
||||
return 0;
|
||||
}
|
||||
if (type->Is<ast::type::F32Type>() || type->IsI32() || type->IsU32()) {
|
||||
if (type->Is<ast::type::F32Type>() || type->Is<ast::type::I32Type>() ||
|
||||
type->IsU32()) {
|
||||
return 4;
|
||||
}
|
||||
if (type->IsMatrix()) {
|
||||
|
@ -796,7 +797,7 @@ std::string GeneratorImpl::generate_builtin_name(
|
|||
if (ident->result_type()->Is<ast::type::F32Type>()) {
|
||||
out += "fabs";
|
||||
} else if (ident->result_type()->IsU32() ||
|
||||
ident->result_type()->IsI32()) {
|
||||
ident->result_type()->Is<ast::type::I32Type>()) {
|
||||
out += "abs";
|
||||
}
|
||||
break;
|
||||
|
@ -804,7 +805,7 @@ std::string GeneratorImpl::generate_builtin_name(
|
|||
if (ident->result_type()->Is<ast::type::F32Type>()) {
|
||||
out += "fmax";
|
||||
} else if (ident->result_type()->IsU32() ||
|
||||
ident->result_type()->IsI32()) {
|
||||
ident->result_type()->Is<ast::type::I32Type>()) {
|
||||
out += "max";
|
||||
}
|
||||
break;
|
||||
|
@ -812,7 +813,7 @@ std::string GeneratorImpl::generate_builtin_name(
|
|||
if (ident->result_type()->Is<ast::type::F32Type>()) {
|
||||
out += "fmin";
|
||||
} else if (ident->result_type()->IsU32() ||
|
||||
ident->result_type()->IsI32()) {
|
||||
ident->result_type()->Is<ast::type::I32Type>()) {
|
||||
out += "min";
|
||||
}
|
||||
break;
|
||||
|
@ -932,7 +933,7 @@ bool GeneratorImpl::EmitZeroValue(ast::type::Type* type) {
|
|||
out_ << "false";
|
||||
} else if (type->Is<ast::type::F32Type>()) {
|
||||
out_ << "0.0f";
|
||||
} else if (type->IsI32()) {
|
||||
} else if (type->Is<ast::type::I32Type>()) {
|
||||
out_ << "0";
|
||||
} else if (type->IsU32()) {
|
||||
out_ << "0u";
|
||||
|
@ -1816,7 +1817,7 @@ bool GeneratorImpl::EmitType(ast::type::Type* type, const std::string& name) {
|
|||
out_ << "bool";
|
||||
} else if (type->Is<ast::type::F32Type>()) {
|
||||
out_ << "float";
|
||||
} else if (type->IsI32()) {
|
||||
} else if (type->Is<ast::type::I32Type>()) {
|
||||
out_ << "int";
|
||||
} else if (type->IsMatrix()) {
|
||||
auto* mat = type->AsMatrix();
|
||||
|
|
|
@ -748,7 +748,7 @@ bool Builder::GenerateGlobalVariable(ast::Variable* var) {
|
|||
} else if (type->IsU32()) {
|
||||
ast::UintLiteral l(type, 0);
|
||||
init_id = GenerateLiteralIfNeeded(var, &l);
|
||||
} else if (type->IsI32()) {
|
||||
} else if (type->Is<ast::type::I32Type>()) {
|
||||
ast::SintLiteral l(type, 0);
|
||||
init_id = GenerateLiteralIfNeeded(var, &l);
|
||||
} else if (type->Is<ast::type::BoolType>()) {
|
||||
|
@ -1393,14 +1393,16 @@ uint32_t Builder::GenerateCastOrCopyOrPassthrough(ast::type::Type* to_type,
|
|||
auto* from_type = from_expr->result_type()->UnwrapPtrIfNeeded();
|
||||
|
||||
spv::Op op = spv::Op::OpNop;
|
||||
if ((from_type->IsI32() && to_type->Is<ast::type::F32Type>()) ||
|
||||
if ((from_type->Is<ast::type::I32Type>() &&
|
||||
to_type->Is<ast::type::F32Type>()) ||
|
||||
(from_type->is_signed_integer_vector() && to_type->is_float_vector())) {
|
||||
op = spv::Op::OpConvertSToF;
|
||||
} else if ((from_type->IsU32() && to_type->Is<ast::type::F32Type>()) ||
|
||||
(from_type->is_unsigned_integer_vector() &&
|
||||
to_type->is_float_vector())) {
|
||||
op = spv::Op::OpConvertUToF;
|
||||
} else if ((from_type->Is<ast::type::F32Type>() && to_type->IsI32()) ||
|
||||
} else if ((from_type->Is<ast::type::F32Type>() &&
|
||||
to_type->Is<ast::type::I32Type>()) ||
|
||||
(from_type->is_float_vector() &&
|
||||
to_type->is_signed_integer_vector())) {
|
||||
op = spv::Op::OpConvertFToS;
|
||||
|
@ -1411,13 +1413,14 @@ uint32_t Builder::GenerateCastOrCopyOrPassthrough(ast::type::Type* to_type,
|
|||
} else if ((from_type->Is<ast::type::BoolType>() &&
|
||||
to_type->Is<ast::type::BoolType>()) ||
|
||||
(from_type->IsU32() && to_type->IsU32()) ||
|
||||
(from_type->IsI32() && to_type->IsI32()) ||
|
||||
(from_type->Is<ast::type::I32Type>() &&
|
||||
to_type->Is<ast::type::I32Type>()) ||
|
||||
(from_type->Is<ast::type::F32Type>() &&
|
||||
to_type->Is<ast::type::F32Type>()) ||
|
||||
(from_type->IsVector() && (from_type == to_type))) {
|
||||
return val_id;
|
||||
} else if ((from_type->IsI32() && to_type->IsU32()) ||
|
||||
(from_type->IsU32() && to_type->IsI32()) ||
|
||||
} else if ((from_type->Is<ast::type::I32Type>() && to_type->IsU32()) ||
|
||||
(from_type->IsU32() && to_type->Is<ast::type::I32Type>()) ||
|
||||
(from_type->is_signed_integer_vector() &&
|
||||
to_type->is_unsigned_integer_vector()) ||
|
||||
(from_type->is_unsigned_integer_vector() &&
|
||||
|
@ -2421,7 +2424,7 @@ uint32_t Builder::GenerateTypeIfNeeded(ast::type::Type* type) {
|
|||
push_type(spv::Op::OpTypeBool, {result});
|
||||
} else if (type->Is<ast::type::F32Type>()) {
|
||||
push_type(spv::Op::OpTypeFloat, {result, Operand::Int(32)});
|
||||
} else if (type->IsI32()) {
|
||||
} else if (type->Is<ast::type::I32Type>()) {
|
||||
push_type(spv::Op::OpTypeInt, {result, Operand::Int(32), Operand::Int(1)});
|
||||
} else if (type->IsMatrix()) {
|
||||
if (!GenerateMatrixType(type->AsMatrix(), result)) {
|
||||
|
|
|
@ -54,8 +54,9 @@
|
|||
#include "src/ast/type/access_control_type.h"
|
||||
#include "src/ast/type/array_type.h"
|
||||
#include "src/ast/type/bool_type.h"
|
||||
#include "src/ast/type/f32_type.h"
|
||||
#include "src/ast/type/depth_texture_type.h"
|
||||
#include "src/ast/type/f32_type.h"
|
||||
#include "src/ast/type/i32_type.h"
|
||||
#include "src/ast/type/matrix_type.h"
|
||||
#include "src/ast/type/multisampled_texture_type.h"
|
||||
#include "src/ast/type/pointer_type.h"
|
||||
|
@ -436,7 +437,7 @@ bool GeneratorImpl::EmitType(ast::type::Type* type) {
|
|||
out_ << "bool";
|
||||
} else if (type->Is<ast::type::F32Type>()) {
|
||||
out_ << "f32";
|
||||
} else if (type->IsI32()) {
|
||||
} else if (type->Is<ast::type::I32Type>()) {
|
||||
out_ << "i32";
|
||||
} else if (type->IsMatrix()) {
|
||||
auto* mat = type->AsMatrix();
|
||||
|
|
Loading…
Reference in New Issue