ast/type: Remove Type suffix from all types

They already exist in a `ast::type` namespace, so `ast::type::BlahType` is just stuttering.
This is more important now that Is<> and As<> use the full type name.

Change-Id: I7c661fe58cdc33ba7e9a95c82c996a799786661f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34321
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton 2020-11-30 23:30:58 +00:00
parent 03ae9a397f
commit f1b0e1ee57
202 changed files with 3909 additions and 3998 deletions

View File

@ -19,15 +19,15 @@ namespace ast {
std::ostream& operator<<(std::ostream& out, AccessControl access) { std::ostream& operator<<(std::ostream& out, AccessControl access) {
switch (access) { switch (access) {
case AccessControl::kReadOnly: { case ast::AccessControl::kReadOnly: {
out << "read_only"; out << "read_only";
break; break;
} }
case AccessControl::kReadWrite: { case ast::AccessControl::kReadWrite: {
out << "read_write"; out << "read_write";
break; break;
} }
case AccessControl::kWriteOnly: { case ast::AccessControl::kWriteOnly: {
out << "write_only"; out << "write_only";
break; break;
} }

View File

@ -41,7 +41,7 @@ class AccessDecoration : public Castable<AccessDecoration, TypeDecoration> {
void to_str(std::ostream& out, size_t indent) const override; void to_str(std::ostream& out, size_t indent) const override;
private: private:
AccessControl value_ = AccessControl::kReadWrite; AccessControl value_ = ast::AccessControl::kReadWrite;
}; };
} // namespace ast } // namespace ast

View File

@ -25,17 +25,17 @@ namespace {
using AccessDecorationTest = TestHelper; using AccessDecorationTest = TestHelper;
TEST_F(AccessDecorationTest, Creation) { TEST_F(AccessDecorationTest, Creation) {
AccessDecoration d{AccessControl::kWriteOnly, Source{}}; AccessDecoration d{ast::AccessControl::kWriteOnly, Source{}};
EXPECT_EQ(AccessControl::kWriteOnly, d.value()); EXPECT_EQ(ast::AccessControl::kWriteOnly, d.value());
} }
TEST_F(AccessDecorationTest, Is) { TEST_F(AccessDecorationTest, Is) {
AccessDecoration d{AccessControl::kReadWrite, Source{}}; AccessDecoration d{ast::AccessControl::kReadWrite, Source{}};
EXPECT_FALSE(d.IsAccess()); EXPECT_FALSE(d.IsAccess());
} }
TEST_F(AccessDecorationTest, ToStr) { TEST_F(AccessDecorationTest, ToStr) {
AccessDecoration d{AccessControl::kReadOnly, Source{}}; AccessDecoration d{ast::AccessControl::kReadOnly, Source{}};
std::ostringstream out; std::ostringstream out;
d.to_str(out, 0); d.to_str(out, 0);
EXPECT_EQ(out.str(), R"(AccessDecoration{read} EXPECT_EQ(out.str(), R"(AccessDecoration{read}

View File

@ -25,7 +25,7 @@ namespace {
using BitcastExpressionTest = TestHelper; using BitcastExpressionTest = TestHelper;
TEST_F(BitcastExpressionTest, Create) { TEST_F(BitcastExpressionTest, Create) {
type::F32Type f32; type::F32 f32;
auto* expr = create<IdentifierExpression>("expr"); auto* expr = create<IdentifierExpression>("expr");
BitcastExpression exp(&f32, expr); BitcastExpression exp(&f32, expr);
@ -34,7 +34,7 @@ TEST_F(BitcastExpressionTest, Create) {
} }
TEST_F(BitcastExpressionTest, CreateWithSource) { TEST_F(BitcastExpressionTest, CreateWithSource) {
type::F32Type f32; type::F32 f32;
auto* expr = create<IdentifierExpression>("expr"); auto* expr = create<IdentifierExpression>("expr");
BitcastExpression exp(Source{Source::Location{20, 2}}, &f32, expr); BitcastExpression exp(Source{Source::Location{20, 2}}, &f32, expr);
@ -49,7 +49,7 @@ TEST_F(BitcastExpressionTest, IsBitcast) {
} }
TEST_F(BitcastExpressionTest, IsValid) { TEST_F(BitcastExpressionTest, IsValid) {
type::F32Type f32; type::F32 f32;
auto* expr = create<IdentifierExpression>("expr"); auto* expr = create<IdentifierExpression>("expr");
BitcastExpression exp(&f32, expr); BitcastExpression exp(&f32, expr);
@ -65,7 +65,7 @@ TEST_F(BitcastExpressionTest, IsValid_MissingType) {
} }
TEST_F(BitcastExpressionTest, IsValid_MissingExpr) { TEST_F(BitcastExpressionTest, IsValid_MissingExpr) {
type::F32Type f32; type::F32 f32;
BitcastExpression exp; BitcastExpression exp;
exp.set_type(&f32); exp.set_type(&f32);
@ -73,14 +73,14 @@ TEST_F(BitcastExpressionTest, IsValid_MissingExpr) {
} }
TEST_F(BitcastExpressionTest, IsValid_InvalidExpr) { TEST_F(BitcastExpressionTest, IsValid_InvalidExpr) {
type::F32Type f32; type::F32 f32;
auto* expr = create<IdentifierExpression>(""); auto* expr = create<IdentifierExpression>("");
BitcastExpression e(&f32, expr); BitcastExpression e(&f32, expr);
EXPECT_FALSE(e.IsValid()); EXPECT_FALSE(e.IsValid());
} }
TEST_F(BitcastExpressionTest, ToStr) { TEST_F(BitcastExpressionTest, ToStr) {
type::F32Type f32; type::F32 f32;
auto* expr = create<IdentifierExpression>("expr"); auto* expr = create<IdentifierExpression>("expr");
BitcastExpression exp(&f32, expr); BitcastExpression exp(&f32, expr);

View File

@ -28,7 +28,7 @@ namespace {
using BoolLiteralTest = TestHelper; using BoolLiteralTest = TestHelper;
TEST_F(BoolLiteralTest, True) { TEST_F(BoolLiteralTest, True) {
type::BoolType bool_type; type::Bool bool_type;
BoolLiteral b{&bool_type, true}; BoolLiteral b{&bool_type, true};
ASSERT_TRUE(b.Is<BoolLiteral>()); ASSERT_TRUE(b.Is<BoolLiteral>());
ASSERT_TRUE(b.IsTrue()); ASSERT_TRUE(b.IsTrue());
@ -36,7 +36,7 @@ TEST_F(BoolLiteralTest, True) {
} }
TEST_F(BoolLiteralTest, False) { TEST_F(BoolLiteralTest, False) {
type::BoolType bool_type; type::Bool bool_type;
BoolLiteral b{&bool_type, false}; BoolLiteral b{&bool_type, false};
ASSERT_TRUE(b.Is<BoolLiteral>()); ASSERT_TRUE(b.Is<BoolLiteral>());
ASSERT_FALSE(b.IsTrue()); ASSERT_FALSE(b.IsTrue());
@ -44,7 +44,7 @@ TEST_F(BoolLiteralTest, False) {
} }
TEST_F(BoolLiteralTest, Is) { TEST_F(BoolLiteralTest, Is) {
type::BoolType bool_type; type::Bool bool_type;
BoolLiteral b{&bool_type, false}; BoolLiteral b{&bool_type, false};
Literal* l = &b; Literal* l = &b;
EXPECT_TRUE(l->Is<BoolLiteral>()); EXPECT_TRUE(l->Is<BoolLiteral>());
@ -56,7 +56,7 @@ TEST_F(BoolLiteralTest, Is) {
} }
TEST_F(BoolLiteralTest, ToStr) { TEST_F(BoolLiteralTest, ToStr) {
type::BoolType bool_type; type::Bool bool_type;
BoolLiteral t{&bool_type, true}; BoolLiteral t{&bool_type, true};
BoolLiteral f{&bool_type, false}; BoolLiteral f{&bool_type, false};

View File

@ -18,11 +18,11 @@ namespace tint {
namespace ast { namespace ast {
TypesBuilder::TypesBuilder(Module* mod) TypesBuilder::TypesBuilder(Module* mod)
: bool_(mod->create<type::BoolType>()), : bool_(mod->create<type::Bool>()),
f32(mod->create<type::F32Type>()), f32(mod->create<type::F32>()),
i32(mod->create<type::I32Type>()), i32(mod->create<type::I32>()),
u32(mod->create<type::U32Type>()), u32(mod->create<type::U32>()),
void_(mod->create<type::VoidType>()), void_(mod->create<type::Void>()),
mod_(mod) {} mod_(mod) {}
Builder::Builder(Context* c, Module* m) : ctx(c), mod(m), ty(m) {} Builder::Builder(Context* c, Module* m) : ctx(c), mod(m), ty(m) {}

View File

@ -52,15 +52,15 @@ class TypesBuilder {
explicit TypesBuilder(Module* mod); explicit TypesBuilder(Module* mod);
/// A boolean type /// A boolean type
type::BoolType* const bool_; type::Bool* const bool_;
/// A f32 type /// A f32 type
type::F32Type* const f32; type::F32* const f32;
/// A i32 type /// A i32 type
type::I32Type* const i32; type::I32* const i32;
/// A u32 type /// A u32 type
type::U32Type* const u32; type::U32* const u32;
/// A void type /// A void type
type::VoidType* const void_; type::Void* const void_;
/// @return the tint AST type for the C type `T`. /// @return the tint AST type for the C type `T`.
template <typename T> template <typename T>
@ -70,86 +70,86 @@ class TypesBuilder {
/// @return the tint AST type for a 2-element vector of the C type `T`. /// @return the tint AST type for a 2-element vector of the C type `T`.
template <typename T> template <typename T>
type::VectorType* vec2() const { type::Vector* vec2() const {
return mod_->create<type::VectorType>(Of<T>(), 2); return mod_->create<type::Vector>(Of<T>(), 2);
} }
/// @return the tint AST type for a 3-element vector of the C type `T`. /// @return the tint AST type for a 3-element vector of the C type `T`.
template <typename T> template <typename T>
type::VectorType* vec3() const { type::Vector* vec3() const {
return mod_->create<type::VectorType>(Of<T>(), 3); return mod_->create<type::Vector>(Of<T>(), 3);
} }
/// @return the tint AST type for a 4-element vector of the C type `T`. /// @return the tint AST type for a 4-element vector of the C type `T`.
template <typename T> template <typename T>
type::Type* vec4() const { type::Type* vec4() const {
return mod_->create<type::VectorType>(Of<T>(), 4); return mod_->create<type::Vector>(Of<T>(), 4);
} }
/// @return the tint AST type for a 2x3 matrix of the C type `T`. /// @return the tint AST type for a 2x3 matrix of the C type `T`.
template <typename T> template <typename T>
type::MatrixType* mat2x2() const { type::Matrix* mat2x2() const {
return mod_->create<type::MatrixType>(Of<T>(), 2, 2); return mod_->create<type::Matrix>(Of<T>(), 2, 2);
} }
/// @return the tint AST type for a 2x3 matrix of the C type `T`. /// @return the tint AST type for a 2x3 matrix of the C type `T`.
template <typename T> template <typename T>
type::MatrixType* mat2x3() const { type::Matrix* mat2x3() const {
return mod_->create<type::MatrixType>(Of<T>(), 3, 2); return mod_->create<type::Matrix>(Of<T>(), 3, 2);
} }
/// @return the tint AST type for a 2x4 matrix of the C type `T`. /// @return the tint AST type for a 2x4 matrix of the C type `T`.
template <typename T> template <typename T>
type::MatrixType* mat2x4() const { type::Matrix* mat2x4() const {
return mod_->create<type::MatrixType>(Of<T>(), 4, 2); return mod_->create<type::Matrix>(Of<T>(), 4, 2);
} }
/// @return the tint AST type for a 3x2 matrix of the C type `T`. /// @return the tint AST type for a 3x2 matrix of the C type `T`.
template <typename T> template <typename T>
type::MatrixType* mat3x2() const { type::Matrix* mat3x2() const {
return mod_->create<type::MatrixType>(Of<T>(), 2, 3); return mod_->create<type::Matrix>(Of<T>(), 2, 3);
} }
/// @return the tint AST type for a 3x3 matrix of the C type `T`. /// @return the tint AST type for a 3x3 matrix of the C type `T`.
template <typename T> template <typename T>
type::MatrixType* mat3x3() const { type::Matrix* mat3x3() const {
return mod_->create<type::MatrixType>(Of<T>(), 3, 3); return mod_->create<type::Matrix>(Of<T>(), 3, 3);
} }
/// @return the tint AST type for a 3x4 matrix of the C type `T`. /// @return the tint AST type for a 3x4 matrix of the C type `T`.
template <typename T> template <typename T>
type::MatrixType* mat3x4() const { type::Matrix* mat3x4() const {
return mod_->create<type::MatrixType>(Of<T>(), 4, 3); return mod_->create<type::Matrix>(Of<T>(), 4, 3);
} }
/// @return the tint AST type for a 4x2 matrix of the C type `T`. /// @return the tint AST type for a 4x2 matrix of the C type `T`.
template <typename T> template <typename T>
type::MatrixType* mat4x2() const { type::Matrix* mat4x2() const {
return mod_->create<type::MatrixType>(Of<T>(), 2, 4); return mod_->create<type::Matrix>(Of<T>(), 2, 4);
} }
/// @return the tint AST type for a 4x3 matrix of the C type `T`. /// @return the tint AST type for a 4x3 matrix of the C type `T`.
template <typename T> template <typename T>
type::MatrixType* mat4x3() const { type::Matrix* mat4x3() const {
return mod_->create<type::MatrixType>(Of<T>(), 3, 4); return mod_->create<type::Matrix>(Of<T>(), 3, 4);
} }
/// @return the tint AST type for a 4x4 matrix of the C type `T`. /// @return the tint AST type for a 4x4 matrix of the C type `T`.
template <typename T> template <typename T>
type::MatrixType* mat4x4() const { type::Matrix* mat4x4() const {
return mod_->create<type::MatrixType>(Of<T>(), 4, 4); return mod_->create<type::Matrix>(Of<T>(), 4, 4);
} }
/// @param subtype the array element type /// @param subtype the array element type
/// @param n the array size. 0 represents unbounded /// @param n the array size. 0 represents unbounded
/// @return the tint AST type for a array of size `n` of type `T` /// @return the tint AST type for a array of size `n` of type `T`
type::ArrayType* array(type::Type* subtype, uint32_t n) const { type::Array* array(type::Type* subtype, uint32_t n) const {
return mod_->create<type::ArrayType>(subtype, n); return mod_->create<type::Array>(subtype, n);
} }
/// @return the tint AST type for an array of size `N` of type `T` /// @return the tint AST type for an array of size `N` of type `T`
template <typename T, int N = 0> template <typename T, int N = 0>
type::ArrayType* array() const { type::Array* array() const {
return array(Of<T>(), N); return array(Of<T>(), N);
} }

View File

@ -29,7 +29,7 @@ namespace {
using CaseStatementTest = TestHelper; using CaseStatementTest = TestHelper;
TEST_F(CaseStatementTest, Creation_i32) { TEST_F(CaseStatementTest, Creation_i32) {
type::I32Type i32; type::I32 i32;
CaseSelectorList b; CaseSelectorList b;
auto* selector = create<SintLiteral>(&i32, 2); auto* selector = create<SintLiteral>(&i32, 2);
@ -47,7 +47,7 @@ TEST_F(CaseStatementTest, Creation_i32) {
} }
TEST_F(CaseStatementTest, Creation_u32) { TEST_F(CaseStatementTest, Creation_u32) {
type::U32Type u32; type::U32 u32;
CaseSelectorList b; CaseSelectorList b;
auto* selector = create<SintLiteral>(&u32, 2); auto* selector = create<SintLiteral>(&u32, 2);
@ -65,7 +65,7 @@ TEST_F(CaseStatementTest, Creation_u32) {
} }
TEST_F(CaseStatementTest, Creation_WithSource) { TEST_F(CaseStatementTest, Creation_WithSource) {
type::I32Type i32; type::I32 i32;
CaseSelectorList b; CaseSelectorList b;
b.push_back(create<SintLiteral>(&i32, 2)); b.push_back(create<SintLiteral>(&i32, 2));
@ -88,7 +88,7 @@ TEST_F(CaseStatementTest, IsDefault_WithoutSelectors) {
} }
TEST_F(CaseStatementTest, IsDefault_WithSelectors) { TEST_F(CaseStatementTest, IsDefault_WithSelectors) {
type::I32Type i32; type::I32 i32;
CaseSelectorList b; CaseSelectorList b;
b.push_back(create<SintLiteral>(&i32, 2)); b.push_back(create<SintLiteral>(&i32, 2));
@ -108,7 +108,7 @@ TEST_F(CaseStatementTest, IsValid) {
} }
TEST_F(CaseStatementTest, IsValid_NullBodyStatement) { TEST_F(CaseStatementTest, IsValid_NullBodyStatement) {
type::I32Type i32; type::I32 i32;
CaseSelectorList b; CaseSelectorList b;
b.push_back(create<SintLiteral>(&i32, 2)); b.push_back(create<SintLiteral>(&i32, 2));
@ -121,7 +121,7 @@ TEST_F(CaseStatementTest, IsValid_NullBodyStatement) {
} }
TEST_F(CaseStatementTest, IsValid_InvalidBodyStatement) { TEST_F(CaseStatementTest, IsValid_InvalidBodyStatement) {
type::I32Type i32; type::I32 i32;
CaseSelectorList b; CaseSelectorList b;
b.push_back(create<SintLiteral>(&i32, 2)); b.push_back(create<SintLiteral>(&i32, 2));
@ -133,7 +133,7 @@ TEST_F(CaseStatementTest, IsValid_InvalidBodyStatement) {
} }
TEST_F(CaseStatementTest, ToStr_WithSelectors_i32) { TEST_F(CaseStatementTest, ToStr_WithSelectors_i32) {
type::I32Type i32; type::I32 i32;
CaseSelectorList b; CaseSelectorList b;
b.push_back(create<SintLiteral>(&i32, -2)); b.push_back(create<SintLiteral>(&i32, -2));
@ -150,7 +150,7 @@ TEST_F(CaseStatementTest, ToStr_WithSelectors_i32) {
} }
TEST_F(CaseStatementTest, ToStr_WithSelectors_u32) { TEST_F(CaseStatementTest, ToStr_WithSelectors_u32) {
type::U32Type u32; type::U32 u32;
CaseSelectorList b; CaseSelectorList b;
b.push_back(create<UintLiteral>(&u32, 2)); b.push_back(create<UintLiteral>(&u32, 2));
@ -167,7 +167,7 @@ TEST_F(CaseStatementTest, ToStr_WithSelectors_u32) {
} }
TEST_F(CaseStatementTest, ToStr_WithMultipleSelectors) { TEST_F(CaseStatementTest, ToStr_WithMultipleSelectors) {
type::I32Type i32; type::I32 i32;
CaseSelectorList b; CaseSelectorList b;
b.push_back(create<SintLiteral>(&i32, 1)); b.push_back(create<SintLiteral>(&i32, 1));

View File

@ -33,7 +33,7 @@ namespace {
using DecoratedVariableTest = TestHelper; using DecoratedVariableTest = TestHelper;
TEST_F(DecoratedVariableTest, Creation) { TEST_F(DecoratedVariableTest, Creation) {
type::I32Type t; type::I32 t;
auto* var = create<Variable>("my_var", StorageClass::kFunction, &t); auto* var = create<Variable>("my_var", StorageClass::kFunction, &t);
DecoratedVariable dv(var); DecoratedVariable dv(var);
@ -48,7 +48,7 @@ TEST_F(DecoratedVariableTest, Creation) {
TEST_F(DecoratedVariableTest, CreationWithSource) { TEST_F(DecoratedVariableTest, CreationWithSource) {
Source s{Source::Range{Source::Location{27, 4}, Source::Location{27, 5}}}; Source s{Source::Range{Source::Location{27, 4}, Source::Location{27, 5}}};
type::F32Type t; type::F32 t;
auto* var = create<Variable>(s, "i", StorageClass::kPrivate, &t); auto* var = create<Variable>(s, "i", StorageClass::kPrivate, &t);
DecoratedVariable dv(var); DecoratedVariable dv(var);
@ -62,7 +62,7 @@ TEST_F(DecoratedVariableTest, CreationWithSource) {
} }
TEST_F(DecoratedVariableTest, NoDecorations) { TEST_F(DecoratedVariableTest, NoDecorations) {
type::I32Type t; type::I32 t;
auto* var = create<Variable>("my_var", StorageClass::kFunction, &t); auto* var = create<Variable>("my_var", StorageClass::kFunction, &t);
DecoratedVariable dv(var); DecoratedVariable dv(var);
EXPECT_FALSE(dv.HasLocationDecoration()); EXPECT_FALSE(dv.HasLocationDecoration());
@ -71,7 +71,7 @@ TEST_F(DecoratedVariableTest, NoDecorations) {
} }
TEST_F(DecoratedVariableTest, WithDecorations) { TEST_F(DecoratedVariableTest, WithDecorations) {
type::F32Type t; type::F32 t;
auto* var = create<Variable>("my_var", StorageClass::kFunction, &t); auto* var = create<Variable>("my_var", StorageClass::kFunction, &t);
DecoratedVariable dv(var); DecoratedVariable dv(var);
@ -88,7 +88,7 @@ TEST_F(DecoratedVariableTest, WithDecorations) {
} }
TEST_F(DecoratedVariableTest, ConstantId) { TEST_F(DecoratedVariableTest, ConstantId) {
type::F32Type t; type::F32 t;
auto* var = create<Variable>("my_var", StorageClass::kFunction, &t); auto* var = create<Variable>("my_var", StorageClass::kFunction, &t);
DecoratedVariable dv(var); DecoratedVariable dv(var);
@ -100,7 +100,7 @@ TEST_F(DecoratedVariableTest, ConstantId) {
} }
TEST_F(DecoratedVariableTest, IsValid) { TEST_F(DecoratedVariableTest, IsValid) {
type::I32Type t; type::I32 t;
auto* var = create<Variable>("my_var", StorageClass::kNone, &t); auto* var = create<Variable>("my_var", StorageClass::kNone, &t);
DecoratedVariable dv(var); DecoratedVariable dv(var);
EXPECT_TRUE(dv.IsValid()); EXPECT_TRUE(dv.IsValid());
@ -112,7 +112,7 @@ TEST_F(DecoratedVariableTest, IsDecorated) {
} }
TEST_F(DecoratedVariableTest, to_str) { TEST_F(DecoratedVariableTest, to_str) {
type::F32Type t; type::F32 t;
auto* var = create<Variable>("my_var", StorageClass::kFunction, &t); auto* var = create<Variable>("my_var", StorageClass::kFunction, &t);
DecoratedVariable dv(var); DecoratedVariable dv(var);
dv.set_constructor(create<IdentifierExpression>("expr")); dv.set_constructor(create<IdentifierExpression>("expr"));

View File

@ -28,7 +28,7 @@ namespace {
using ElseStatementTest = TestHelper; using ElseStatementTest = TestHelper;
TEST_F(ElseStatementTest, Creation) { TEST_F(ElseStatementTest, Creation) {
type::BoolType bool_type; type::Bool bool_type;
auto* cond = create<ScalarConstructorExpression>( auto* cond = create<ScalarConstructorExpression>(
create<BoolLiteral>(&bool_type, true)); create<BoolLiteral>(&bool_type, true));
auto* body = create<BlockStatement>(); auto* body = create<BlockStatement>();
@ -55,7 +55,7 @@ TEST_F(ElseStatementTest, IsElse) {
} }
TEST_F(ElseStatementTest, HasCondition) { TEST_F(ElseStatementTest, HasCondition) {
type::BoolType bool_type; type::Bool bool_type;
auto* cond = create<ScalarConstructorExpression>( auto* cond = create<ScalarConstructorExpression>(
create<BoolLiteral>(&bool_type, true)); create<BoolLiteral>(&bool_type, true));
ElseStatement e(cond, create<BlockStatement>()); ElseStatement e(cond, create<BlockStatement>());
@ -104,7 +104,7 @@ TEST_F(ElseStatementTest, IsValid_InvalidBodyStatement) {
} }
TEST_F(ElseStatementTest, ToStr) { TEST_F(ElseStatementTest, ToStr) {
type::BoolType bool_type; type::Bool bool_type;
auto* cond = create<ScalarConstructorExpression>( auto* cond = create<ScalarConstructorExpression>(
create<BoolLiteral>(&bool_type, true)); create<BoolLiteral>(&bool_type, true));
auto* body = create<BlockStatement>(); auto* body = create<BlockStatement>();

View File

@ -33,23 +33,23 @@ class Expr : public Expression {
using ExpressionTest = TestHelper; using ExpressionTest = TestHelper;
TEST_F(ExpressionTest, set_result_type) { TEST_F(ExpressionTest, set_result_type) {
type::I32Type i32; type::I32 i32;
Expr e; Expr e;
e.set_result_type(&i32); e.set_result_type(&i32);
ASSERT_NE(e.result_type(), nullptr); ASSERT_NE(e.result_type(), nullptr);
EXPECT_TRUE(e.result_type()->Is<type::I32Type>()); EXPECT_TRUE(e.result_type()->Is<type::I32>());
} }
TEST_F(ExpressionTest, set_result_type_alias) { TEST_F(ExpressionTest, set_result_type_alias) {
type::I32Type i32; type::I32 i32;
type::AliasType a("a", &i32); type::Alias a("a", &i32);
type::AliasType b("b", &a); type::Alias b("b", &a);
Expr e; Expr e;
e.set_result_type(&b); e.set_result_type(&b);
ASSERT_NE(e.result_type(), nullptr); ASSERT_NE(e.result_type(), nullptr);
EXPECT_TRUE(e.result_type()->Is<type::I32Type>()); EXPECT_TRUE(e.result_type()->Is<type::I32>());
} }
} // namespace } // namespace

View File

@ -28,14 +28,14 @@ namespace {
using FloatLiteralTest = TestHelper; using FloatLiteralTest = TestHelper;
TEST_F(FloatLiteralTest, Value) { TEST_F(FloatLiteralTest, Value) {
type::F32Type f32; type::F32 f32;
FloatLiteral f{&f32, 47.2f}; FloatLiteral f{&f32, 47.2f};
ASSERT_TRUE(f.Is<FloatLiteral>()); ASSERT_TRUE(f.Is<FloatLiteral>());
EXPECT_EQ(f.value(), 47.2f); EXPECT_EQ(f.value(), 47.2f);
} }
TEST_F(FloatLiteralTest, Is) { TEST_F(FloatLiteralTest, Is) {
type::F32Type f32; type::F32 f32;
FloatLiteral f{&f32, 42.f}; FloatLiteral f{&f32, 42.f};
Literal* l = &f; Literal* l = &f;
EXPECT_FALSE(l->Is<BoolLiteral>()); EXPECT_FALSE(l->Is<BoolLiteral>());
@ -47,14 +47,14 @@ TEST_F(FloatLiteralTest, Is) {
} }
TEST_F(FloatLiteralTest, ToStr) { TEST_F(FloatLiteralTest, ToStr) {
type::F32Type f32; type::F32 f32;
FloatLiteral f{&f32, 42.1f}; FloatLiteral f{&f32, 42.1f};
EXPECT_EQ(f.to_str(), "42.099998"); EXPECT_EQ(f.to_str(), "42.099998");
} }
TEST_F(FloatLiteralTest, ToName) { TEST_F(FloatLiteralTest, ToName) {
type::F32Type f32; type::F32 f32;
FloatLiteral f{&f32, 42.1f}; FloatLiteral f{&f32, 42.1f};
EXPECT_EQ(f.name(), "__float42.0999985"); EXPECT_EQ(f.name(), "__float42.0999985");
} }

View File

@ -282,9 +282,8 @@ Function::ReferencedSamplerVariablesImpl(type::SamplerKind kind) const {
for (auto* var : referenced_module_variables()) { for (auto* var : referenced_module_variables()) {
auto* unwrapped_type = var->type()->UnwrapIfNeeded(); auto* unwrapped_type = var->type()->UnwrapIfNeeded();
if (!var->Is<DecoratedVariable>() || if (!var->Is<DecoratedVariable>() || !unwrapped_type->Is<type::Sampler>() ||
!unwrapped_type->Is<type::SamplerType>() || unwrapped_type->As<type::Sampler>()->kind() != kind) {
unwrapped_type->As<type::SamplerType>()->kind() != kind) {
continue; continue;
} }
@ -312,14 +311,12 @@ Function::ReferencedSampledTextureVariablesImpl(bool multisampled) const {
for (auto* var : referenced_module_variables()) { for (auto* var : referenced_module_variables()) {
auto* unwrapped_type = var->type()->UnwrapIfNeeded(); auto* unwrapped_type = var->type()->UnwrapIfNeeded();
if (!var->Is<DecoratedVariable>() || if (!var->Is<DecoratedVariable>() || !unwrapped_type->Is<type::Texture>()) {
!unwrapped_type->Is<type::TextureType>()) {
continue; continue;
} }
if ((multisampled && if ((multisampled && !unwrapped_type->Is<type::MultisampledTexture>()) ||
!unwrapped_type->Is<type::MultisampledTextureType>()) || (!multisampled && !unwrapped_type->Is<type::SampledTexture>())) {
(!multisampled && !unwrapped_type->Is<type::SampledTextureType>())) {
continue; continue;
} }

View File

@ -33,8 +33,8 @@ namespace {
using FunctionTest = TestHelper; using FunctionTest = TestHelper;
TEST_F(FunctionTest, Creation) { TEST_F(FunctionTest, Creation) {
type::VoidType void_type; type::Void void_type;
type::I32Type i32; type::I32 i32;
VariableList params; VariableList params;
params.push_back(create<Variable>("var", StorageClass::kNone, &i32)); params.push_back(create<Variable>("var", StorageClass::kNone, &i32));
@ -48,8 +48,8 @@ TEST_F(FunctionTest, Creation) {
} }
TEST_F(FunctionTest, Creation_WithSource) { TEST_F(FunctionTest, Creation_WithSource) {
type::VoidType void_type; type::Void void_type;
type::I32Type i32; type::I32 i32;
VariableList params; VariableList params;
params.push_back(create<Variable>("var", StorageClass::kNone, &i32)); params.push_back(create<Variable>("var", StorageClass::kNone, &i32));
@ -62,8 +62,8 @@ TEST_F(FunctionTest, Creation_WithSource) {
} }
TEST_F(FunctionTest, AddDuplicateReferencedVariables) { TEST_F(FunctionTest, AddDuplicateReferencedVariables) {
type::VoidType void_type; type::Void void_type;
type::I32Type i32; type::I32 i32;
Variable v("var", StorageClass::kInput, &i32); Variable v("var", StorageClass::kInput, &i32);
Function f("func", VariableList{}, &void_type, create<BlockStatement>()); Function f("func", VariableList{}, &void_type, create<BlockStatement>());
@ -82,8 +82,8 @@ TEST_F(FunctionTest, AddDuplicateReferencedVariables) {
} }
TEST_F(FunctionTest, GetReferenceLocations) { TEST_F(FunctionTest, GetReferenceLocations) {
type::VoidType void_type; type::Void void_type;
type::I32Type i32; type::I32 i32;
DecoratedVariable loc1(create<Variable>("loc1", StorageClass::kInput, &i32)); DecoratedVariable loc1(create<Variable>("loc1", StorageClass::kInput, &i32));
loc1.set_decorations({create<LocationDecoration>(0, Source{})}); loc1.set_decorations({create<LocationDecoration>(0, Source{})});
@ -118,8 +118,8 @@ TEST_F(FunctionTest, GetReferenceLocations) {
} }
TEST_F(FunctionTest, GetReferenceBuiltins) { TEST_F(FunctionTest, GetReferenceBuiltins) {
type::VoidType void_type; type::Void void_type;
type::I32Type i32; type::I32 i32;
DecoratedVariable loc1(create<Variable>("loc1", StorageClass::kInput, &i32)); DecoratedVariable loc1(create<Variable>("loc1", StorageClass::kInput, &i32));
loc1.set_decorations({create<LocationDecoration>(0, Source{})}); loc1.set_decorations({create<LocationDecoration>(0, Source{})});
@ -154,7 +154,7 @@ TEST_F(FunctionTest, GetReferenceBuiltins) {
} }
TEST_F(FunctionTest, AddDuplicateEntryPoints) { TEST_F(FunctionTest, AddDuplicateEntryPoints) {
type::VoidType void_type; type::Void void_type;
Function f("func", VariableList{}, &void_type, create<BlockStatement>()); Function f("func", VariableList{}, &void_type, create<BlockStatement>());
f.add_ancestor_entry_point("main"); f.add_ancestor_entry_point("main");
@ -167,8 +167,8 @@ TEST_F(FunctionTest, AddDuplicateEntryPoints) {
} }
TEST_F(FunctionTest, IsValid) { TEST_F(FunctionTest, IsValid) {
type::VoidType void_type; type::Void void_type;
type::I32Type i32; type::I32 i32;
VariableList params; VariableList params;
params.push_back(create<Variable>("var", StorageClass::kNone, &i32)); params.push_back(create<Variable>("var", StorageClass::kNone, &i32));
@ -182,8 +182,8 @@ TEST_F(FunctionTest, IsValid) {
} }
TEST_F(FunctionTest, IsValid_EmptyName) { TEST_F(FunctionTest, IsValid_EmptyName) {
type::VoidType void_type; type::Void void_type;
type::I32Type i32; type::I32 i32;
VariableList params; VariableList params;
params.push_back(create<Variable>("var", StorageClass::kNone, &i32)); params.push_back(create<Variable>("var", StorageClass::kNone, &i32));
@ -193,7 +193,7 @@ TEST_F(FunctionTest, IsValid_EmptyName) {
} }
TEST_F(FunctionTest, IsValid_MissingReturnType) { TEST_F(FunctionTest, IsValid_MissingReturnType) {
type::I32Type i32; type::I32 i32;
VariableList params; VariableList params;
params.push_back(create<Variable>("var", StorageClass::kNone, &i32)); params.push_back(create<Variable>("var", StorageClass::kNone, &i32));
@ -203,8 +203,8 @@ TEST_F(FunctionTest, IsValid_MissingReturnType) {
} }
TEST_F(FunctionTest, IsValid_NullParam) { TEST_F(FunctionTest, IsValid_NullParam) {
type::VoidType void_type; type::Void void_type;
type::I32Type i32; type::I32 i32;
VariableList params; VariableList params;
params.push_back(create<Variable>("var", StorageClass::kNone, &i32)); params.push_back(create<Variable>("var", StorageClass::kNone, &i32));
@ -215,7 +215,7 @@ TEST_F(FunctionTest, IsValid_NullParam) {
} }
TEST_F(FunctionTest, IsValid_InvalidParam) { TEST_F(FunctionTest, IsValid_InvalidParam) {
type::VoidType void_type; type::Void void_type;
VariableList params; VariableList params;
params.push_back(create<Variable>("var", StorageClass::kNone, nullptr)); params.push_back(create<Variable>("var", StorageClass::kNone, nullptr));
@ -225,8 +225,8 @@ TEST_F(FunctionTest, IsValid_InvalidParam) {
} }
TEST_F(FunctionTest, IsValid_NullBodyStatement) { TEST_F(FunctionTest, IsValid_NullBodyStatement) {
type::VoidType void_type; type::Void void_type;
type::I32Type i32; type::I32 i32;
VariableList params; VariableList params;
params.push_back(create<Variable>("var", StorageClass::kNone, &i32)); params.push_back(create<Variable>("var", StorageClass::kNone, &i32));
@ -241,8 +241,8 @@ TEST_F(FunctionTest, IsValid_NullBodyStatement) {
} }
TEST_F(FunctionTest, IsValid_InvalidBodyStatement) { TEST_F(FunctionTest, IsValid_InvalidBodyStatement) {
type::VoidType void_type; type::Void void_type;
type::I32Type i32; type::I32 i32;
VariableList params; VariableList params;
params.push_back(create<Variable>("var", StorageClass::kNone, &i32)); params.push_back(create<Variable>("var", StorageClass::kNone, &i32));
@ -257,8 +257,8 @@ TEST_F(FunctionTest, IsValid_InvalidBodyStatement) {
} }
TEST_F(FunctionTest, ToStr) { TEST_F(FunctionTest, ToStr) {
type::VoidType void_type; type::Void void_type;
type::I32Type i32; type::I32 i32;
auto* block = create<BlockStatement>(); auto* block = create<BlockStatement>();
block->append(create<DiscardStatement>()); block->append(create<DiscardStatement>());
@ -277,8 +277,8 @@ TEST_F(FunctionTest, ToStr) {
} }
TEST_F(FunctionTest, ToStr_WithDecoration) { TEST_F(FunctionTest, ToStr_WithDecoration) {
type::VoidType void_type; type::Void void_type;
type::I32Type i32; type::I32 i32;
auto* block = create<BlockStatement>(); auto* block = create<BlockStatement>();
block->append(create<DiscardStatement>()); block->append(create<DiscardStatement>());
@ -299,8 +299,8 @@ TEST_F(FunctionTest, ToStr_WithDecoration) {
} }
TEST_F(FunctionTest, ToStr_WithParams) { TEST_F(FunctionTest, ToStr_WithParams) {
type::VoidType void_type; type::Void void_type;
type::I32Type i32; type::I32 i32;
VariableList params; VariableList params;
params.push_back(create<Variable>("var", StorageClass::kNone, &i32)); params.push_back(create<Variable>("var", StorageClass::kNone, &i32));
@ -328,16 +328,16 @@ TEST_F(FunctionTest, ToStr_WithParams) {
} }
TEST_F(FunctionTest, TypeName) { TEST_F(FunctionTest, TypeName) {
type::VoidType void_type; type::Void void_type;
Function f("func", {}, &void_type, create<BlockStatement>()); Function f("func", {}, &void_type, create<BlockStatement>());
EXPECT_EQ(f.type_name(), "__func__void"); EXPECT_EQ(f.type_name(), "__func__void");
} }
TEST_F(FunctionTest, TypeName_WithParams) { TEST_F(FunctionTest, TypeName_WithParams) {
type::VoidType void_type; type::Void void_type;
type::I32Type i32; type::I32 i32;
type::F32Type f32; type::F32 f32;
VariableList params; VariableList params;
params.push_back(create<Variable>("var1", StorageClass::kNone, &i32)); params.push_back(create<Variable>("var1", StorageClass::kNone, &i32));
@ -348,7 +348,7 @@ TEST_F(FunctionTest, TypeName_WithParams) {
} }
TEST_F(FunctionTest, GetLastStatement) { TEST_F(FunctionTest, GetLastStatement) {
type::VoidType void_type; type::Void void_type;
VariableList params; VariableList params;
auto* body = create<BlockStatement>(); auto* body = create<BlockStatement>();
@ -361,7 +361,7 @@ TEST_F(FunctionTest, GetLastStatement) {
} }
TEST_F(FunctionTest, GetLastStatement_nullptr) { TEST_F(FunctionTest, GetLastStatement_nullptr) {
type::VoidType void_type; type::Void void_type;
VariableList params; VariableList params;
auto* body = create<BlockStatement>(); auto* body = create<BlockStatement>();
@ -372,7 +372,7 @@ TEST_F(FunctionTest, GetLastStatement_nullptr) {
} }
TEST_F(FunctionTest, WorkgroupSize_NoneSet) { TEST_F(FunctionTest, WorkgroupSize_NoneSet) {
type::VoidType void_type; type::Void void_type;
Function f("f", {}, &void_type, create<BlockStatement>()); Function f("f", {}, &void_type, create<BlockStatement>());
uint32_t x = 0; uint32_t x = 0;
uint32_t y = 0; uint32_t y = 0;
@ -384,7 +384,7 @@ TEST_F(FunctionTest, WorkgroupSize_NoneSet) {
} }
TEST_F(FunctionTest, WorkgroupSize) { TEST_F(FunctionTest, WorkgroupSize) {
type::VoidType void_type; type::Void void_type;
Function f("f", {}, &void_type, create<BlockStatement>()); Function f("f", {}, &void_type, create<BlockStatement>());
f.add_decoration(create<WorkgroupDecoration>(2u, 4u, 6u, Source{})); f.add_decoration(create<WorkgroupDecoration>(2u, 4u, 6u, Source{}));

View File

@ -30,13 +30,13 @@ namespace {
using IntLiteralTest = TestHelper; using IntLiteralTest = TestHelper;
TEST_F(IntLiteralTest, Sint_IsInt) { TEST_F(IntLiteralTest, Sint_IsInt) {
type::I32Type i32; type::I32 i32;
SintLiteral i{&i32, 47}; SintLiteral i{&i32, 47};
ASSERT_TRUE(i.Is<IntLiteral>()); ASSERT_TRUE(i.Is<IntLiteral>());
} }
TEST_F(IntLiteralTest, Uint_IsInt) { TEST_F(IntLiteralTest, Uint_IsInt) {
type::I32Type i32; type::I32 i32;
UintLiteral i{&i32, 42}; UintLiteral i{&i32, 42};
EXPECT_TRUE(i.Is<IntLiteral>()); EXPECT_TRUE(i.Is<IntLiteral>());
} }

View File

@ -56,17 +56,17 @@ bool Module::IsValid() const {
if (ty == nullptr) { if (ty == nullptr) {
return false; return false;
} }
if (ty->Is<type::AliasType>()) { if (ty->Is<type::Alias>()) {
auto* alias = ty->As<type::AliasType>(); auto* alias = ty->As<type::Alias>();
if (alias->type() == nullptr) { if (alias->type() == nullptr) {
return false; return false;
} }
if (alias->type()->Is<type::StructType>() && if (alias->type()->Is<type::Struct>() &&
alias->type()->As<type::StructType>()->name().empty()) { alias->type()->As<type::Struct>()->name().empty()) {
return false; return false;
} }
} else if (ty->Is<type::StructType>()) { } else if (ty->Is<type::Struct>()) {
auto* str = ty->As<type::StructType>(); auto* str = ty->As<type::Struct>();
if (str->name().empty()) { if (str->name().empty()) {
return false; return false;
} }
@ -91,14 +91,14 @@ std::string Module::to_str() const {
for (size_t i = 0; i < indent; ++i) { for (size_t i = 0; i < indent; ++i) {
out << " "; out << " ";
} }
if (ty->Is<type::AliasType>()) { if (ty->Is<type::Alias>()) {
auto* alias = ty->As<type::AliasType>(); auto* alias = ty->As<type::Alias>();
out << alias->name() << " -> " << alias->type()->type_name() << std::endl; out << alias->name() << " -> " << alias->type()->type_name() << std::endl;
if (alias->type()->Is<type::StructType>()) { if (alias->type()->Is<type::Struct>()) {
alias->type()->As<type::StructType>()->impl()->to_str(out, indent); alias->type()->As<type::Struct>()->impl()->to_str(out, indent);
} }
} else if (ty->Is<type::StructType>()) { } else if (ty->Is<type::Struct>()) {
auto* str = ty->As<type::StructType>(); auto* str = ty->As<type::Struct>();
out << str->name() << " "; out << str->name() << " ";
str->impl()->to_str(out, indent); str->impl()->to_str(out, indent);
} }

View File

@ -45,7 +45,7 @@ TEST_F(ModuleTest, ToStrEmitsPreambleAndPostamble) {
} }
TEST_F(ModuleTest, LookupFunction) { TEST_F(ModuleTest, LookupFunction) {
type::F32Type f32; type::F32 f32;
Module m; Module m;
auto* func = auto* func =
@ -65,7 +65,7 @@ TEST_F(ModuleTest, IsValid_Empty) {
} }
TEST_F(ModuleTest, IsValid_GlobalVariable) { TEST_F(ModuleTest, IsValid_GlobalVariable) {
type::F32Type f32; type::F32 f32;
auto* var = create<Variable>("var", StorageClass::kInput, &f32); auto* var = create<Variable>("var", StorageClass::kInput, &f32);
Module m; Module m;
@ -88,8 +88,8 @@ TEST_F(ModuleTest, IsValid_Invalid_GlobalVariable) {
} }
TEST_F(ModuleTest, IsValid_Alias) { TEST_F(ModuleTest, IsValid_Alias) {
type::F32Type f32; type::F32 f32;
type::AliasType alias("alias", &f32); type::Alias alias("alias", &f32);
Module m; Module m;
m.AddConstructedType(&alias); m.AddConstructedType(&alias);
@ -103,9 +103,9 @@ TEST_F(ModuleTest, IsValid_Null_Alias) {
} }
TEST_F(ModuleTest, IsValid_Struct) { TEST_F(ModuleTest, IsValid_Struct) {
type::F32Type f32; type::F32 f32;
type::StructType st("name", {}); type::Struct st("name", {});
type::AliasType alias("name", &st); type::Alias alias("name", &st);
Module m; Module m;
m.AddConstructedType(&alias); m.AddConstructedType(&alias);
@ -113,9 +113,9 @@ TEST_F(ModuleTest, IsValid_Struct) {
} }
TEST_F(ModuleTest, IsValid_Struct_EmptyName) { TEST_F(ModuleTest, IsValid_Struct_EmptyName) {
type::F32Type f32; type::F32 f32;
type::StructType st("", {}); type::Struct st("", {});
type::AliasType alias("name", &st); type::Alias alias("name", &st);
Module m; Module m;
m.AddConstructedType(&alias); m.AddConstructedType(&alias);
@ -123,7 +123,7 @@ TEST_F(ModuleTest, IsValid_Struct_EmptyName) {
} }
TEST_F(ModuleTest, IsValid_Function) { TEST_F(ModuleTest, IsValid_Function) {
type::F32Type f32; type::F32 f32;
auto* func = auto* func =
create<Function>("main", VariableList(), &f32, create<BlockStatement>()); create<Function>("main", VariableList(), &f32, create<BlockStatement>());

View File

@ -28,7 +28,7 @@ namespace {
using NullLiteralTest = TestHelper; using NullLiteralTest = TestHelper;
TEST_F(NullLiteralTest, Is) { TEST_F(NullLiteralTest, Is) {
type::I32Type i32; type::I32 i32;
NullLiteral i{&i32}; NullLiteral i{&i32};
Literal* l = &i; Literal* l = &i;
EXPECT_FALSE(l->Is<BoolLiteral>()); EXPECT_FALSE(l->Is<BoolLiteral>());
@ -40,14 +40,14 @@ TEST_F(NullLiteralTest, Is) {
} }
TEST_F(NullLiteralTest, ToStr) { TEST_F(NullLiteralTest, ToStr) {
type::I32Type i32; type::I32 i32;
NullLiteral i{&i32}; NullLiteral i{&i32};
EXPECT_EQ(i.to_str(), "null __i32"); EXPECT_EQ(i.to_str(), "null __i32");
} }
TEST_F(NullLiteralTest, Name_I32) { TEST_F(NullLiteralTest, Name_I32) {
type::I32Type i32; type::I32 i32;
NullLiteral i{&i32}; NullLiteral i{&i32};
EXPECT_EQ("__null__i32", i.name()); EXPECT_EQ("__null__i32", i.name());
} }

View File

@ -25,14 +25,14 @@ namespace {
using ScalarConstructorExpressionTest = TestHelper; using ScalarConstructorExpressionTest = TestHelper;
TEST_F(ScalarConstructorExpressionTest, Creation) { TEST_F(ScalarConstructorExpressionTest, Creation) {
type::BoolType bool_type; type::Bool bool_type;
auto* b = create<BoolLiteral>(&bool_type, true); auto* b = create<BoolLiteral>(&bool_type, true);
ScalarConstructorExpression c(b); ScalarConstructorExpression c(b);
EXPECT_EQ(c.literal(), b); EXPECT_EQ(c.literal(), b);
} }
TEST_F(ScalarConstructorExpressionTest, Creation_WithSource) { TEST_F(ScalarConstructorExpressionTest, Creation_WithSource) {
type::BoolType bool_type; type::Bool bool_type;
auto* b = create<BoolLiteral>(&bool_type, true); auto* b = create<BoolLiteral>(&bool_type, true);
ScalarConstructorExpression c(Source{Source::Location{20, 2}}, b); ScalarConstructorExpression c(Source{Source::Location{20, 2}}, b);
auto src = c.source(); auto src = c.source();
@ -41,7 +41,7 @@ TEST_F(ScalarConstructorExpressionTest, Creation_WithSource) {
} }
TEST_F(ScalarConstructorExpressionTest, IsValid) { TEST_F(ScalarConstructorExpressionTest, IsValid) {
type::BoolType bool_type; type::Bool bool_type;
auto* b = create<BoolLiteral>(&bool_type, true); auto* b = create<BoolLiteral>(&bool_type, true);
ScalarConstructorExpression c(b); ScalarConstructorExpression c(b);
EXPECT_TRUE(c.IsValid()); EXPECT_TRUE(c.IsValid());
@ -53,7 +53,7 @@ TEST_F(ScalarConstructorExpressionTest, IsValid_MissingLiteral) {
} }
TEST_F(ScalarConstructorExpressionTest, ToStr) { TEST_F(ScalarConstructorExpressionTest, ToStr) {
type::BoolType bool_type; type::Bool bool_type;
auto* b = create<BoolLiteral>(&bool_type, true); auto* b = create<BoolLiteral>(&bool_type, true);
ScalarConstructorExpression c(b); ScalarConstructorExpression c(b);
std::ostringstream out; std::ostringstream out;

View File

@ -29,14 +29,14 @@ namespace {
using SintLiteralTest = TestHelper; using SintLiteralTest = TestHelper;
TEST_F(SintLiteralTest, Value) { TEST_F(SintLiteralTest, Value) {
type::I32Type i32; type::I32 i32;
SintLiteral i{&i32, 47}; SintLiteral i{&i32, 47};
ASSERT_TRUE(i.Is<SintLiteral>()); ASSERT_TRUE(i.Is<SintLiteral>());
EXPECT_EQ(i.value(), 47); EXPECT_EQ(i.value(), 47);
} }
TEST_F(SintLiteralTest, Is) { TEST_F(SintLiteralTest, Is) {
type::I32Type i32; type::I32 i32;
SintLiteral i{&i32, 42}; SintLiteral i{&i32, 42};
Literal* l = &i; Literal* l = &i;
EXPECT_FALSE(l->Is<BoolLiteral>()); EXPECT_FALSE(l->Is<BoolLiteral>());
@ -47,20 +47,20 @@ TEST_F(SintLiteralTest, Is) {
} }
TEST_F(SintLiteralTest, ToStr) { TEST_F(SintLiteralTest, ToStr) {
type::I32Type i32; type::I32 i32;
SintLiteral i{&i32, -42}; SintLiteral i{&i32, -42};
EXPECT_EQ(i.to_str(), "-42"); EXPECT_EQ(i.to_str(), "-42");
} }
TEST_F(SintLiteralTest, Name_I32) { TEST_F(SintLiteralTest, Name_I32) {
type::I32Type i32; type::I32 i32;
SintLiteral i{&i32, 2}; SintLiteral i{&i32, 2};
EXPECT_EQ("__sint__i32_2", i.name()); EXPECT_EQ("__sint__i32_2", i.name());
} }
TEST_F(SintLiteralTest, Name_U32) { TEST_F(SintLiteralTest, Name_U32) {
type::U32Type u32; type::U32 u32;
SintLiteral i{&u32, 2}; SintLiteral i{&u32, 2};
EXPECT_EQ("__sint__u32_2", i.name()); EXPECT_EQ("__sint__u32_2", i.name());
} }

View File

@ -28,7 +28,7 @@ namespace {
using StructMemberTest = TestHelper; using StructMemberTest = TestHelper;
TEST_F(StructMemberTest, Creation) { TEST_F(StructMemberTest, Creation) {
type::I32Type i32; type::I32 i32;
StructMemberDecorationList decorations; StructMemberDecorationList decorations;
decorations.emplace_back(create<StructMemberOffsetDecoration>(4, Source{})); decorations.emplace_back(create<StructMemberOffsetDecoration>(4, Source{}));
@ -44,7 +44,7 @@ TEST_F(StructMemberTest, Creation) {
} }
TEST_F(StructMemberTest, CreationWithSource) { TEST_F(StructMemberTest, CreationWithSource) {
type::I32Type i32; type::I32 i32;
Source s{Source::Range{Source::Location{27, 4}, Source::Location{27, 8}}}; Source s{Source::Range{Source::Location{27, 4}, Source::Location{27, 8}}};
StructMember st{s, "a", &i32, {}}; StructMember st{s, "a", &i32, {}};
@ -58,13 +58,13 @@ TEST_F(StructMemberTest, CreationWithSource) {
} }
TEST_F(StructMemberTest, IsValid) { TEST_F(StructMemberTest, IsValid) {
type::I32Type i32; type::I32 i32;
StructMember st{"a", &i32, {}}; StructMember st{"a", &i32, {}};
EXPECT_TRUE(st.IsValid()); EXPECT_TRUE(st.IsValid());
} }
TEST_F(StructMemberTest, IsValid_EmptyName) { TEST_F(StructMemberTest, IsValid_EmptyName) {
type::I32Type i32; type::I32 i32;
StructMember st{"", &i32, {}}; StructMember st{"", &i32, {}};
EXPECT_FALSE(st.IsValid()); EXPECT_FALSE(st.IsValid());
} }
@ -75,7 +75,7 @@ TEST_F(StructMemberTest, IsValid_NullType) {
} }
TEST_F(StructMemberTest, IsValid_Null_Decoration) { TEST_F(StructMemberTest, IsValid_Null_Decoration) {
type::I32Type i32; type::I32 i32;
StructMemberDecorationList decorations; StructMemberDecorationList decorations;
decorations.emplace_back(create<StructMemberOffsetDecoration>(4, Source{})); decorations.emplace_back(create<StructMemberOffsetDecoration>(4, Source{}));
decorations.push_back(nullptr); decorations.push_back(nullptr);
@ -85,7 +85,7 @@ TEST_F(StructMemberTest, IsValid_Null_Decoration) {
} }
TEST_F(StructMemberTest, ToStr) { TEST_F(StructMemberTest, ToStr) {
type::I32Type i32; type::I32 i32;
StructMemberDecorationList decorations; StructMemberDecorationList decorations;
decorations.emplace_back(create<StructMemberOffsetDecoration>(4, Source{})); decorations.emplace_back(create<StructMemberOffsetDecoration>(4, Source{}));
@ -96,7 +96,7 @@ TEST_F(StructMemberTest, ToStr) {
} }
TEST_F(StructMemberTest, ToStrNoDecorations) { TEST_F(StructMemberTest, ToStrNoDecorations) {
type::I32Type i32; type::I32 i32;
StructMember st{"a", &i32, {}}; StructMember st{"a", &i32, {}};
std::ostringstream out; std::ostringstream out;
st.to_str(out, 2); st.to_str(out, 2);

View File

@ -30,7 +30,7 @@ namespace {
using StructTest = TestHelper; using StructTest = TestHelper;
TEST_F(StructTest, Creation) { TEST_F(StructTest, Creation) {
type::I32Type i32; type::I32 i32;
StructMemberList members; StructMemberList members;
members.push_back( members.push_back(
create<StructMember>("a", &i32, StructMemberDecorationList())); create<StructMember>("a", &i32, StructMemberDecorationList()));
@ -45,7 +45,7 @@ TEST_F(StructTest, Creation) {
} }
TEST_F(StructTest, Creation_WithDecorations) { TEST_F(StructTest, Creation_WithDecorations) {
type::I32Type i32; type::I32 i32;
StructMemberList members; StructMemberList members;
members.push_back( members.push_back(
@ -65,7 +65,7 @@ TEST_F(StructTest, Creation_WithDecorations) {
} }
TEST_F(StructTest, CreationWithSourceAndDecorations) { TEST_F(StructTest, CreationWithSourceAndDecorations) {
type::I32Type i32; type::I32 i32;
StructMemberList members; StructMemberList members;
members.emplace_back( members.emplace_back(
@ -92,7 +92,7 @@ TEST_F(StructTest, IsValid) {
} }
TEST_F(StructTest, IsValid_Null_StructMember) { TEST_F(StructTest, IsValid_Null_StructMember) {
type::I32Type i32; type::I32 i32;
StructMemberList members; StructMemberList members;
members.push_back( members.push_back(
@ -104,7 +104,7 @@ TEST_F(StructTest, IsValid_Null_StructMember) {
} }
TEST_F(StructTest, IsValid_Invalid_StructMember) { TEST_F(StructTest, IsValid_Invalid_StructMember) {
type::I32Type i32; type::I32 i32;
StructMemberList members; StructMemberList members;
members.push_back( members.push_back(
@ -115,7 +115,7 @@ TEST_F(StructTest, IsValid_Invalid_StructMember) {
} }
TEST_F(StructTest, ToStr) { TEST_F(StructTest, ToStr) {
type::I32Type i32; type::I32 i32;
StructMemberList members; StructMemberList members;
members.emplace_back( members.emplace_back(

View File

@ -29,7 +29,7 @@ namespace {
using SwitchStatementTest = TestHelper; using SwitchStatementTest = TestHelper;
TEST_F(SwitchStatementTest, Creation) { TEST_F(SwitchStatementTest, Creation) {
type::I32Type i32; type::I32 i32;
CaseSelectorList lit; CaseSelectorList lit;
lit.push_back(create<SintLiteral>(&i32, 1)); lit.push_back(create<SintLiteral>(&i32, 1));
@ -61,7 +61,7 @@ TEST_F(SwitchStatementTest, IsSwitch) {
} }
TEST_F(SwitchStatementTest, IsValid) { TEST_F(SwitchStatementTest, IsValid) {
type::I32Type i32; type::I32 i32;
CaseSelectorList lit; CaseSelectorList lit;
lit.push_back(create<SintLiteral>(&i32, 2)); lit.push_back(create<SintLiteral>(&i32, 2));
@ -75,7 +75,7 @@ TEST_F(SwitchStatementTest, IsValid) {
} }
TEST_F(SwitchStatementTest, IsValid_Null_Condition) { TEST_F(SwitchStatementTest, IsValid_Null_Condition) {
type::I32Type i32; type::I32 i32;
CaseSelectorList lit; CaseSelectorList lit;
lit.push_back(create<SintLiteral>(&i32, 2)); lit.push_back(create<SintLiteral>(&i32, 2));
@ -89,7 +89,7 @@ TEST_F(SwitchStatementTest, IsValid_Null_Condition) {
} }
TEST_F(SwitchStatementTest, IsValid_Invalid_Condition) { TEST_F(SwitchStatementTest, IsValid_Invalid_Condition) {
type::I32Type i32; type::I32 i32;
CaseSelectorList lit; CaseSelectorList lit;
lit.push_back(create<SintLiteral>(&i32, 2)); lit.push_back(create<SintLiteral>(&i32, 2));
@ -103,7 +103,7 @@ TEST_F(SwitchStatementTest, IsValid_Invalid_Condition) {
} }
TEST_F(SwitchStatementTest, IsValid_Null_BodyStatement) { TEST_F(SwitchStatementTest, IsValid_Null_BodyStatement) {
type::I32Type i32; type::I32 i32;
CaseSelectorList lit; CaseSelectorList lit;
lit.push_back(create<SintLiteral>(&i32, 2)); lit.push_back(create<SintLiteral>(&i32, 2));
@ -145,7 +145,7 @@ TEST_F(SwitchStatementTest, ToStr_Empty) {
} }
TEST_F(SwitchStatementTest, ToStr) { TEST_F(SwitchStatementTest, ToStr) {
type::I32Type i32; type::I32 i32;
CaseSelectorList lit; CaseSelectorList lit;
lit.push_back(create<SintLiteral>(&i32, 2)); lit.push_back(create<SintLiteral>(&i32, 2));

View File

@ -20,38 +20,37 @@ namespace tint {
namespace ast { namespace ast {
namespace type { namespace type {
AccessControlType::AccessControlType(AccessControl access, Type* subtype) AccessControl::AccessControl(ast::AccessControl access, Type* subtype)
: access_(access), subtype_(subtype) { : access_(access), subtype_(subtype) {
assert(subtype_); assert(subtype_);
assert(!subtype_->Is<AccessControlType>()); assert(!subtype_->Is<AccessControl>());
} }
AccessControlType::AccessControlType(AccessControlType&&) = default; AccessControl::AccessControl(AccessControl&&) = default;
AccessControlType::~AccessControlType() = default; AccessControl::~AccessControl() = default;
std::string AccessControlType::type_name() const { std::string AccessControl::type_name() const {
std::string name = "__access_control_"; std::string name = "__access_control_";
switch (access_) { switch (access_) {
case AccessControl::kReadOnly: case ast::AccessControl::kReadOnly:
name += "read_only"; name += "read_only";
break; break;
case AccessControl::kWriteOnly: case ast::AccessControl::kWriteOnly:
name += "write_only"; name += "write_only";
break; break;
case AccessControl::kReadWrite: case ast::AccessControl::kReadWrite:
name += "read_write"; name += "read_write";
break; break;
} }
return name + subtype_->type_name(); return name + subtype_->type_name();
} }
uint64_t AccessControlType::MinBufferBindingSize( uint64_t AccessControl::MinBufferBindingSize(MemoryLayout mem_layout) const {
MemoryLayout mem_layout) const {
return subtype_->MinBufferBindingSize(mem_layout); return subtype_->MinBufferBindingSize(mem_layout);
} }
uint64_t AccessControlType::BaseAlignment(MemoryLayout mem_layout) const { uint64_t AccessControl::BaseAlignment(MemoryLayout mem_layout) const {
return subtype_->BaseAlignment(mem_layout); return subtype_->BaseAlignment(mem_layout);
} }

View File

@ -25,25 +25,25 @@ namespace ast {
namespace type { namespace type {
/// An access control type. Holds an access setting and pointer to another type. /// An access control type. Holds an access setting and pointer to another type.
class AccessControlType : public Castable<AccessControlType, Type> { class AccessControl : public Castable<AccessControl, Type> {
public: public:
/// Constructor /// Constructor
/// @param access the access control setting /// @param access the access control setting
/// @param subtype the access controlled type /// @param subtype the access controlled type
AccessControlType(AccessControl access, Type* subtype); AccessControl(ast::AccessControl access, Type* subtype);
/// Move constructor /// Move constructor
AccessControlType(AccessControlType&&); AccessControl(AccessControl&&);
~AccessControlType() override; ~AccessControl() override;
/// @returns true if the access control is read only /// @returns true if the access control is read only
bool IsReadOnly() const { return access_ == AccessControl::kReadOnly; } bool IsReadOnly() const { return access_ == ast::AccessControl::kReadOnly; }
/// @returns true if the access control is write only /// @returns true if the access control is write only
bool IsWriteOnly() const { return access_ == AccessControl::kWriteOnly; } bool IsWriteOnly() const { return access_ == ast::AccessControl::kWriteOnly; }
/// @returns true if the access control is read/write /// @returns true if the access control is read/write
bool IsReadWrite() const { return access_ == AccessControl::kReadWrite; } bool IsReadWrite() const { return access_ == ast::AccessControl::kReadWrite; }
/// @returns the access control value /// @returns the access control value
AccessControl access_control() const { return access_; } ast::AccessControl access_control() const { return access_; }
/// @returns the subtype type /// @returns the subtype type
Type* type() const { return subtype_; } Type* type() const { return subtype_; }
@ -61,7 +61,7 @@ class AccessControlType : public Castable<AccessControlType, Type> {
uint64_t BaseAlignment(MemoryLayout mem_layout) const override; uint64_t BaseAlignment(MemoryLayout mem_layout) const override;
private: private:
AccessControl access_ = AccessControl::kReadOnly; ast::AccessControl access_ = ast::AccessControl::kReadOnly;
Type* subtype_ = nullptr; Type* subtype_ = nullptr;
}; };

View File

@ -39,38 +39,38 @@ namespace ast {
namespace type { namespace type {
namespace { namespace {
using AccessControlTypeTest = TestHelper; using AccessControlTest = TestHelper;
TEST_F(AccessControlTypeTest, Create) { TEST_F(AccessControlTest, Create) {
U32Type u32; U32 u32;
AccessControlType a{AccessControl::kReadWrite, &u32}; AccessControl a{ast::AccessControl::kReadWrite, &u32};
EXPECT_TRUE(a.IsReadWrite()); EXPECT_TRUE(a.IsReadWrite());
EXPECT_EQ(a.type(), &u32); EXPECT_EQ(a.type(), &u32);
} }
TEST_F(AccessControlTypeTest, Is) { TEST_F(AccessControlTest, Is) {
I32Type i32; I32 i32;
AccessControlType at{AccessControl::kReadOnly, &i32}; AccessControl at{ast::AccessControl::kReadOnly, &i32};
Type* ty = &at; Type* ty = &at;
EXPECT_TRUE(ty->Is<AccessControlType>()); EXPECT_TRUE(ty->Is<AccessControl>());
EXPECT_FALSE(ty->Is<AliasType>()); EXPECT_FALSE(ty->Is<Alias>());
EXPECT_FALSE(ty->Is<ArrayType>()); EXPECT_FALSE(ty->Is<Array>());
EXPECT_FALSE(ty->Is<BoolType>()); EXPECT_FALSE(ty->Is<Bool>());
EXPECT_FALSE(ty->Is<F32Type>()); EXPECT_FALSE(ty->Is<F32>());
EXPECT_FALSE(ty->Is<I32Type>()); EXPECT_FALSE(ty->Is<I32>());
EXPECT_FALSE(ty->Is<MatrixType>()); EXPECT_FALSE(ty->Is<Matrix>());
EXPECT_FALSE(ty->Is<PointerType>()); EXPECT_FALSE(ty->Is<Pointer>());
EXPECT_FALSE(ty->Is<SamplerType>()); EXPECT_FALSE(ty->Is<Sampler>());
EXPECT_FALSE(ty->Is<StructType>()); EXPECT_FALSE(ty->Is<Struct>());
EXPECT_FALSE(ty->Is<TextureType>()); EXPECT_FALSE(ty->Is<Texture>());
EXPECT_FALSE(ty->Is<U32Type>()); EXPECT_FALSE(ty->Is<U32>());
EXPECT_FALSE(ty->Is<VectorType>()); EXPECT_FALSE(ty->Is<Vector>());
} }
TEST_F(AccessControlTypeTest, AccessRead) { TEST_F(AccessControlTest, AccessRead) {
I32Type i32; I32 i32;
AccessControlType at{AccessControl::kReadOnly, &i32}; AccessControl at{ast::AccessControl::kReadOnly, &i32};
EXPECT_TRUE(at.IsReadOnly()); EXPECT_TRUE(at.IsReadOnly());
EXPECT_FALSE(at.IsWriteOnly()); EXPECT_FALSE(at.IsWriteOnly());
EXPECT_FALSE(at.IsReadWrite()); EXPECT_FALSE(at.IsReadWrite());
@ -78,9 +78,9 @@ TEST_F(AccessControlTypeTest, AccessRead) {
EXPECT_EQ(at.type_name(), "__access_control_read_only__i32"); EXPECT_EQ(at.type_name(), "__access_control_read_only__i32");
} }
TEST_F(AccessControlTypeTest, AccessWrite) { TEST_F(AccessControlTest, AccessWrite) {
I32Type i32; I32 i32;
AccessControlType at{AccessControl::kWriteOnly, &i32}; AccessControl at{ast::AccessControl::kWriteOnly, &i32};
EXPECT_FALSE(at.IsReadOnly()); EXPECT_FALSE(at.IsReadOnly());
EXPECT_TRUE(at.IsWriteOnly()); EXPECT_TRUE(at.IsWriteOnly());
EXPECT_FALSE(at.IsReadWrite()); EXPECT_FALSE(at.IsReadWrite());
@ -88,9 +88,9 @@ TEST_F(AccessControlTypeTest, AccessWrite) {
EXPECT_EQ(at.type_name(), "__access_control_write_only__i32"); EXPECT_EQ(at.type_name(), "__access_control_write_only__i32");
} }
TEST_F(AccessControlTypeTest, AccessReadWrite) { TEST_F(AccessControlTest, AccessReadWrite) {
I32Type i32; I32 i32;
AccessControlType at{AccessControl::kReadWrite, &i32}; AccessControl at{ast::AccessControl::kReadWrite, &i32};
EXPECT_FALSE(at.IsReadOnly()); EXPECT_FALSE(at.IsReadOnly());
EXPECT_FALSE(at.IsWriteOnly()); EXPECT_FALSE(at.IsWriteOnly());
EXPECT_TRUE(at.IsReadWrite()); EXPECT_TRUE(at.IsReadWrite());
@ -98,34 +98,34 @@ TEST_F(AccessControlTypeTest, AccessReadWrite) {
EXPECT_EQ(at.type_name(), "__access_control_read_write__i32"); EXPECT_EQ(at.type_name(), "__access_control_read_write__i32");
} }
TEST_F(AccessControlTypeTest, MinBufferBindingSizeU32) { TEST_F(AccessControlTest, MinBufferBindingSizeU32) {
U32Type u32; U32 u32;
AccessControlType at{AccessControl::kReadOnly, &u32}; AccessControl at{ast::AccessControl::kReadOnly, &u32};
EXPECT_EQ(4u, at.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); EXPECT_EQ(4u, at.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
} }
TEST_F(AccessControlTypeTest, MinBufferBindingSizeArray) { TEST_F(AccessControlTest, MinBufferBindingSizeArray) {
U32Type u32; U32 u32;
ArrayType array(&u32, 4); Array array(&u32, 4);
ArrayDecorationList decos; ArrayDecorationList decos;
decos.push_back(create<StrideDecoration>(4, Source{})); decos.push_back(create<StrideDecoration>(4, Source{}));
array.set_decorations(decos); array.set_decorations(decos);
AccessControlType at{AccessControl::kReadOnly, &array}; AccessControl at{ast::AccessControl::kReadOnly, &array};
EXPECT_EQ(16u, at.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, at.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
} }
TEST_F(AccessControlTypeTest, MinBufferBindingSizeRuntimeArray) { TEST_F(AccessControlTest, MinBufferBindingSizeRuntimeArray) {
U32Type u32; U32 u32;
ArrayType array(&u32); Array array(&u32);
ArrayDecorationList decos; ArrayDecorationList decos;
decos.push_back(create<StrideDecoration>(4, Source{})); decos.push_back(create<StrideDecoration>(4, Source{}));
array.set_decorations(decos); array.set_decorations(decos);
AccessControlType at{AccessControl::kReadOnly, &array}; AccessControl at{ast::AccessControl::kReadOnly, &array};
EXPECT_EQ(4u, at.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); EXPECT_EQ(4u, at.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
} }
TEST_F(AccessControlTypeTest, MinBufferBindingSizeStruct) { TEST_F(AccessControlTest, MinBufferBindingSizeStruct) {
U32Type u32; U32 u32;
StructMemberList members; StructMemberList members;
StructMemberDecorationList deco; StructMemberDecorationList deco;
@ -138,41 +138,41 @@ TEST_F(AccessControlTypeTest, MinBufferBindingSizeStruct) {
StructDecorationList decos; StructDecorationList decos;
auto* str = create<Struct>(decos, members); auto* str = create<ast::Struct>(decos, members);
StructType struct_type("struct_type", str); Struct struct_type("struct_type", str);
AccessControlType at{AccessControl::kReadOnly, &struct_type}; AccessControl at{ast::AccessControl::kReadOnly, &struct_type};
EXPECT_EQ(16u, at.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, at.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
EXPECT_EQ(8u, at.MinBufferBindingSize(MemoryLayout::kStorageBuffer)); EXPECT_EQ(8u, at.MinBufferBindingSize(MemoryLayout::kStorageBuffer));
} }
TEST_F(AccessControlTypeTest, BaseAlignmentU32) { TEST_F(AccessControlTest, BaseAlignmentU32) {
U32Type u32; U32 u32;
AccessControlType at{AccessControl::kReadOnly, &u32}; AccessControl at{ast::AccessControl::kReadOnly, &u32};
EXPECT_EQ(4u, at.BaseAlignment(MemoryLayout::kUniformBuffer)); EXPECT_EQ(4u, at.BaseAlignment(MemoryLayout::kUniformBuffer));
} }
TEST_F(AccessControlTypeTest, BaseAlignmentArray) { TEST_F(AccessControlTest, BaseAlignmentArray) {
U32Type u32; U32 u32;
ArrayType array(&u32, 4); Array array(&u32, 4);
ArrayDecorationList decos; ArrayDecorationList decos;
decos.push_back(create<StrideDecoration>(4, Source{})); decos.push_back(create<StrideDecoration>(4, Source{}));
array.set_decorations(decos); array.set_decorations(decos);
AccessControlType at{AccessControl::kReadOnly, &array}; AccessControl at{ast::AccessControl::kReadOnly, &array};
EXPECT_EQ(16u, at.BaseAlignment(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, at.BaseAlignment(MemoryLayout::kUniformBuffer));
} }
TEST_F(AccessControlTypeTest, BaseAlignmentRuntimeArray) { TEST_F(AccessControlTest, BaseAlignmentRuntimeArray) {
U32Type u32; U32 u32;
ArrayType array(&u32); Array array(&u32);
ArrayDecorationList decos; ArrayDecorationList decos;
decos.push_back(create<StrideDecoration>(4, Source{})); decos.push_back(create<StrideDecoration>(4, Source{}));
array.set_decorations(decos); array.set_decorations(decos);
AccessControlType at{AccessControl::kReadOnly, &array}; AccessControl at{ast::AccessControl::kReadOnly, &array};
EXPECT_EQ(16u, at.BaseAlignment(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, at.BaseAlignment(MemoryLayout::kUniformBuffer));
} }
TEST_F(AccessControlTypeTest, BaseAlignmentStruct) { TEST_F(AccessControlTest, BaseAlignmentStruct) {
U32Type u32; U32 u32;
StructMemberList members; StructMemberList members;
{ {
@ -187,9 +187,9 @@ TEST_F(AccessControlTypeTest, BaseAlignmentStruct) {
} }
StructDecorationList decos; StructDecorationList decos;
auto* str = create<Struct>(decos, members); auto* str = create<ast::Struct>(decos, members);
StructType struct_type("struct_type", str); Struct struct_type("struct_type", str);
AccessControlType at{AccessControl::kReadOnly, &struct_type}; AccessControl at{ast::AccessControl::kReadOnly, &struct_type};
EXPECT_EQ(16u, at.BaseAlignment(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, at.BaseAlignment(MemoryLayout::kUniformBuffer));
EXPECT_EQ(4u, at.BaseAlignment(MemoryLayout::kStorageBuffer)); EXPECT_EQ(4u, at.BaseAlignment(MemoryLayout::kStorageBuffer));
} }

View File

@ -20,24 +20,24 @@ namespace tint {
namespace ast { namespace ast {
namespace type { namespace type {
AliasType::AliasType(const std::string& name, Type* subtype) Alias::Alias(const std::string& name, Type* subtype)
: name_(name), subtype_(subtype) { : name_(name), subtype_(subtype) {
assert(subtype_); assert(subtype_);
} }
AliasType::AliasType(AliasType&&) = default; Alias::Alias(Alias&&) = default;
AliasType::~AliasType() = default; Alias::~Alias() = default;
std::string AliasType::type_name() const { std::string Alias::type_name() const {
return "__alias_" + name_ + subtype_->type_name(); return "__alias_" + name_ + subtype_->type_name();
} }
uint64_t AliasType::MinBufferBindingSize(MemoryLayout mem_layout) const { uint64_t Alias::MinBufferBindingSize(MemoryLayout mem_layout) const {
return subtype_->MinBufferBindingSize(mem_layout); return subtype_->MinBufferBindingSize(mem_layout);
} }
uint64_t AliasType::BaseAlignment(MemoryLayout mem_layout) const { uint64_t Alias::BaseAlignment(MemoryLayout mem_layout) const {
return subtype_->BaseAlignment(mem_layout); return subtype_->BaseAlignment(mem_layout);
} }

View File

@ -24,15 +24,15 @@ namespace ast {
namespace type { namespace type {
/// A type alias type. Holds a name and pointer to another type. /// A type alias type. Holds a name and pointer to another type.
class AliasType : public Castable<AliasType, Type> { class Alias : public Castable<Alias, Type> {
public: public:
/// Constructor /// Constructor
/// @param name the alias name /// @param name the alias name
/// @param subtype the alias'd type /// @param subtype the alias'd type
AliasType(const std::string& name, Type* subtype); Alias(const std::string& name, Type* subtype);
/// Move constructor /// Move constructor
AliasType(AliasType&&); Alias(Alias&&);
~AliasType() override; ~Alias() override;
/// @returns the alias name /// @returns the alias name
const std::string& name() const { return name_; } const std::string& name() const { return name_; }

View File

@ -40,155 +40,155 @@ namespace ast {
namespace type { namespace type {
namespace { namespace {
using AliasTypeTest = TestHelper; using AliasTest = TestHelper;
TEST_F(AliasTypeTest, Create) { TEST_F(AliasTest, Create) {
U32Type u32; U32 u32;
AliasType a{"a_type", &u32}; Alias a{"a_type", &u32};
EXPECT_EQ(a.name(), "a_type"); EXPECT_EQ(a.name(), "a_type");
EXPECT_EQ(a.type(), &u32); EXPECT_EQ(a.type(), &u32);
} }
TEST_F(AliasTypeTest, Is) { TEST_F(AliasTest, Is) {
I32Type i32; I32 i32;
AliasType at{"a", &i32}; Alias at{"a", &i32};
Type* ty = &at; Type* ty = &at;
EXPECT_FALSE(ty->Is<AccessControlType>()); EXPECT_FALSE(ty->Is<AccessControl>());
EXPECT_TRUE(ty->Is<AliasType>()); EXPECT_TRUE(ty->Is<Alias>());
EXPECT_FALSE(ty->Is<ArrayType>()); EXPECT_FALSE(ty->Is<Array>());
EXPECT_FALSE(ty->Is<BoolType>()); EXPECT_FALSE(ty->Is<Bool>());
EXPECT_FALSE(ty->Is<F32Type>()); EXPECT_FALSE(ty->Is<F32>());
EXPECT_FALSE(ty->Is<I32Type>()); EXPECT_FALSE(ty->Is<I32>());
EXPECT_FALSE(ty->Is<MatrixType>()); EXPECT_FALSE(ty->Is<Matrix>());
EXPECT_FALSE(ty->Is<PointerType>()); EXPECT_FALSE(ty->Is<Pointer>());
EXPECT_FALSE(ty->Is<SamplerType>()); EXPECT_FALSE(ty->Is<Sampler>());
EXPECT_FALSE(ty->Is<StructType>()); EXPECT_FALSE(ty->Is<Struct>());
EXPECT_FALSE(ty->Is<TextureType>()); EXPECT_FALSE(ty->Is<Texture>());
EXPECT_FALSE(ty->Is<U32Type>()); EXPECT_FALSE(ty->Is<U32>());
EXPECT_FALSE(ty->Is<VectorType>()); EXPECT_FALSE(ty->Is<Vector>());
} }
TEST_F(AliasTypeTest, TypeName) { TEST_F(AliasTest, TypeName) {
I32Type i32; I32 i32;
AliasType at{"Particle", &i32}; Alias at{"Particle", &i32};
EXPECT_EQ(at.type_name(), "__alias_Particle__i32"); EXPECT_EQ(at.type_name(), "__alias_Particle__i32");
} }
TEST_F(AliasTypeTest, UnwrapIfNeeded_Alias) { TEST_F(AliasTest, UnwrapIfNeeded_Alias) {
U32Type u32; U32 u32;
AliasType a{"a_type", &u32}; Alias a{"a_type", &u32};
EXPECT_EQ(a.name(), "a_type"); EXPECT_EQ(a.name(), "a_type");
EXPECT_EQ(a.type(), &u32); EXPECT_EQ(a.type(), &u32);
EXPECT_EQ(a.UnwrapIfNeeded(), &u32); EXPECT_EQ(a.UnwrapIfNeeded(), &u32);
EXPECT_EQ(u32.UnwrapIfNeeded(), &u32); EXPECT_EQ(u32.UnwrapIfNeeded(), &u32);
} }
TEST_F(AliasTypeTest, UnwrapIfNeeded_AccessControl) { TEST_F(AliasTest, UnwrapIfNeeded_AccessControl) {
U32Type u32; U32 u32;
AccessControlType a{AccessControl::kReadOnly, &u32}; AccessControl a{ast::AccessControl::kReadOnly, &u32};
EXPECT_EQ(a.type(), &u32); EXPECT_EQ(a.type(), &u32);
EXPECT_EQ(a.UnwrapIfNeeded(), &u32); EXPECT_EQ(a.UnwrapIfNeeded(), &u32);
} }
TEST_F(AliasTypeTest, UnwrapIfNeeded_MultiLevel) { TEST_F(AliasTest, UnwrapIfNeeded_MultiLevel) {
U32Type u32; U32 u32;
AliasType a{"a_type", &u32}; Alias a{"a_type", &u32};
AliasType aa{"aa_type", &a}; Alias aa{"aa_type", &a};
EXPECT_EQ(aa.name(), "aa_type"); EXPECT_EQ(aa.name(), "aa_type");
EXPECT_EQ(aa.type(), &a); EXPECT_EQ(aa.type(), &a);
EXPECT_EQ(aa.UnwrapIfNeeded(), &u32); EXPECT_EQ(aa.UnwrapIfNeeded(), &u32);
} }
TEST_F(AliasTypeTest, UnwrapIfNeeded_MultiLevel_AliasAccessControl) { TEST_F(AliasTest, UnwrapIfNeeded_MultiLevel_AliasAccessControl) {
U32Type u32; U32 u32;
AliasType a{"a_type", &u32}; Alias a{"a_type", &u32};
AccessControlType aa{AccessControl::kReadWrite, &a}; AccessControl aa{ast::AccessControl::kReadWrite, &a};
EXPECT_EQ(aa.type(), &a); EXPECT_EQ(aa.type(), &a);
EXPECT_EQ(aa.UnwrapIfNeeded(), &u32); EXPECT_EQ(aa.UnwrapIfNeeded(), &u32);
} }
TEST_F(AliasTypeTest, UnwrapAll_TwiceAliasPointerTwiceAlias) { TEST_F(AliasTest, UnwrapAll_TwiceAliasPointerTwiceAlias) {
U32Type u32; U32 u32;
AliasType a{"a_type", &u32}; Alias a{"a_type", &u32};
AliasType aa{"aa_type", &a}; Alias aa{"aa_type", &a};
PointerType paa{&aa, StorageClass::kUniform}; Pointer paa{&aa, StorageClass::kUniform};
AliasType apaa{"paa_type", &paa}; Alias apaa{"paa_type", &paa};
AliasType aapaa{"aapaa_type", &apaa}; Alias aapaa{"aapaa_type", &apaa};
EXPECT_EQ(aapaa.name(), "aapaa_type"); EXPECT_EQ(aapaa.name(), "aapaa_type");
EXPECT_EQ(aapaa.type(), &apaa); EXPECT_EQ(aapaa.type(), &apaa);
EXPECT_EQ(aapaa.UnwrapAll(), &u32); EXPECT_EQ(aapaa.UnwrapAll(), &u32);
EXPECT_EQ(u32.UnwrapAll(), &u32); EXPECT_EQ(u32.UnwrapAll(), &u32);
} }
TEST_F(AliasTypeTest, UnwrapAll_SecondConsecutivePointerBlocksUnrapping) { TEST_F(AliasTest, UnwrapAll_SecondConsecutivePointerBlocksUnrapping) {
U32Type u32; U32 u32;
AliasType a{"a_type", &u32}; Alias a{"a_type", &u32};
AliasType aa{"aa_type", &a}; Alias aa{"aa_type", &a};
PointerType paa{&aa, StorageClass::kUniform}; Pointer paa{&aa, StorageClass::kUniform};
PointerType ppaa{&paa, StorageClass::kUniform}; Pointer ppaa{&paa, StorageClass::kUniform};
AliasType appaa{"appaa_type", &ppaa}; Alias appaa{"appaa_type", &ppaa};
EXPECT_EQ(appaa.UnwrapAll(), &paa); EXPECT_EQ(appaa.UnwrapAll(), &paa);
} }
TEST_F(AliasTypeTest, UnwrapAll_SecondNonConsecutivePointerBlocksUnrapping) { TEST_F(AliasTest, UnwrapAll_SecondNonConsecutivePointerBlocksUnrapping) {
U32Type u32; U32 u32;
AliasType a{"a_type", &u32}; Alias a{"a_type", &u32};
AliasType aa{"aa_type", &a}; Alias aa{"aa_type", &a};
PointerType paa{&aa, StorageClass::kUniform}; Pointer paa{&aa, StorageClass::kUniform};
AliasType apaa{"apaa_type", &paa}; Alias apaa{"apaa_type", &paa};
AliasType aapaa{"aapaa_type", &apaa}; Alias aapaa{"aapaa_type", &apaa};
PointerType paapaa{&aapaa, StorageClass::kUniform}; Pointer paapaa{&aapaa, StorageClass::kUniform};
AliasType apaapaa{"apaapaa_type", &paapaa}; Alias apaapaa{"apaapaa_type", &paapaa};
EXPECT_EQ(apaapaa.UnwrapAll(), &paa); EXPECT_EQ(apaapaa.UnwrapAll(), &paa);
} }
TEST_F(AliasTypeTest, UnwrapAll_AccessControlPointer) { TEST_F(AliasTest, UnwrapAll_AccessControlPointer) {
U32Type u32; U32 u32;
AccessControlType a{AccessControl::kReadOnly, &u32}; AccessControl a{ast::AccessControl::kReadOnly, &u32};
PointerType pa{&a, StorageClass::kUniform}; Pointer pa{&a, StorageClass::kUniform};
EXPECT_EQ(pa.type(), &a); EXPECT_EQ(pa.type(), &a);
EXPECT_EQ(pa.UnwrapAll(), &u32); EXPECT_EQ(pa.UnwrapAll(), &u32);
EXPECT_EQ(u32.UnwrapAll(), &u32); EXPECT_EQ(u32.UnwrapAll(), &u32);
} }
TEST_F(AliasTypeTest, UnwrapAll_PointerAccessControl) { TEST_F(AliasTest, UnwrapAll_PointerAccessControl) {
U32Type u32; U32 u32;
PointerType p{&u32, StorageClass::kUniform}; Pointer p{&u32, StorageClass::kUniform};
AccessControlType a{AccessControl::kReadOnly, &p}; AccessControl a{ast::AccessControl::kReadOnly, &p};
EXPECT_EQ(a.type(), &p); EXPECT_EQ(a.type(), &p);
EXPECT_EQ(a.UnwrapAll(), &u32); EXPECT_EQ(a.UnwrapAll(), &u32);
EXPECT_EQ(u32.UnwrapAll(), &u32); EXPECT_EQ(u32.UnwrapAll(), &u32);
} }
TEST_F(AliasTypeTest, MinBufferBindingSizeU32) { TEST_F(AliasTest, MinBufferBindingSizeU32) {
U32Type u32; U32 u32;
AliasType alias{"alias", &u32}; Alias alias{"alias", &u32};
EXPECT_EQ(4u, alias.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); EXPECT_EQ(4u, alias.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
} }
TEST_F(AliasTypeTest, MinBufferBindingSizeArray) { TEST_F(AliasTest, MinBufferBindingSizeArray) {
U32Type u32; U32 u32;
ArrayType array(&u32, 4); Array array(&u32, 4);
ArrayDecorationList decos; ArrayDecorationList decos;
decos.push_back(create<StrideDecoration>(4, Source{})); decos.push_back(create<StrideDecoration>(4, Source{}));
array.set_decorations(decos); array.set_decorations(decos);
AliasType alias{"alias", &array}; Alias alias{"alias", &array};
EXPECT_EQ(16u, alias.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, alias.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
} }
TEST_F(AliasTypeTest, MinBufferBindingSizeRuntimeArray) { TEST_F(AliasTest, MinBufferBindingSizeRuntimeArray) {
U32Type u32; U32 u32;
ArrayType array(&u32); Array array(&u32);
ArrayDecorationList decos; ArrayDecorationList decos;
decos.push_back(create<StrideDecoration>(4, Source{})); decos.push_back(create<StrideDecoration>(4, Source{}));
array.set_decorations(decos); array.set_decorations(decos);
AliasType alias{"alias", &array}; Alias alias{"alias", &array};
EXPECT_EQ(4u, alias.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); EXPECT_EQ(4u, alias.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
} }
TEST_F(AliasTypeTest, MinBufferBindingSizeStruct) { TEST_F(AliasTest, MinBufferBindingSizeStruct) {
U32Type u32; U32 u32;
StructMemberList members; StructMemberList members;
{ {
@ -203,41 +203,41 @@ TEST_F(AliasTypeTest, MinBufferBindingSizeStruct) {
} }
StructDecorationList decos; StructDecorationList decos;
auto* str = create<Struct>(decos, members); auto* str = create<ast::Struct>(decos, members);
StructType struct_type("struct_type", str); Struct struct_type("struct_type", str);
AliasType alias{"alias", &struct_type}; Alias alias{"alias", &struct_type};
EXPECT_EQ(16u, alias.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, alias.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
EXPECT_EQ(8u, alias.MinBufferBindingSize(MemoryLayout::kStorageBuffer)); EXPECT_EQ(8u, alias.MinBufferBindingSize(MemoryLayout::kStorageBuffer));
} }
TEST_F(AliasTypeTest, BaseAlignmentU32) { TEST_F(AliasTest, BaseAlignmentU32) {
U32Type u32; U32 u32;
AliasType alias{"alias", &u32}; Alias alias{"alias", &u32};
EXPECT_EQ(4u, alias.BaseAlignment(MemoryLayout::kUniformBuffer)); EXPECT_EQ(4u, alias.BaseAlignment(MemoryLayout::kUniformBuffer));
} }
TEST_F(AliasTypeTest, BaseAlignmentArray) { TEST_F(AliasTest, BaseAlignmentArray) {
U32Type u32; U32 u32;
ArrayType array(&u32, 4); Array array(&u32, 4);
ArrayDecorationList decos; ArrayDecorationList decos;
decos.push_back(create<StrideDecoration>(4, Source{})); decos.push_back(create<StrideDecoration>(4, Source{}));
array.set_decorations(decos); array.set_decorations(decos);
AliasType alias{"alias", &array}; Alias alias{"alias", &array};
EXPECT_EQ(16u, alias.BaseAlignment(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, alias.BaseAlignment(MemoryLayout::kUniformBuffer));
} }
TEST_F(AliasTypeTest, BaseAlignmentRuntimeArray) { TEST_F(AliasTest, BaseAlignmentRuntimeArray) {
U32Type u32; U32 u32;
ArrayType array(&u32); Array array(&u32);
ArrayDecorationList decos; ArrayDecorationList decos;
decos.push_back(create<StrideDecoration>(4, Source{})); decos.push_back(create<StrideDecoration>(4, Source{}));
array.set_decorations(decos); array.set_decorations(decos);
AliasType alias{"alias", &array}; Alias alias{"alias", &array};
EXPECT_EQ(16u, alias.BaseAlignment(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, alias.BaseAlignment(MemoryLayout::kUniformBuffer));
} }
TEST_F(AliasTypeTest, BaseAlignmentStruct) { TEST_F(AliasTest, BaseAlignmentStruct) {
U32Type u32; U32 u32;
StructMemberList members; StructMemberList members;
{ {
@ -252,9 +252,9 @@ TEST_F(AliasTypeTest, BaseAlignmentStruct) {
} }
StructDecorationList decos; StructDecorationList decos;
auto* str = create<Struct>(decos, members); auto* str = create<ast::Struct>(decos, members);
StructType struct_type("struct_type", str); Struct struct_type("struct_type", str);
AliasType alias{"alias", &struct_type}; Alias alias{"alias", &struct_type};
EXPECT_EQ(16u, alias.BaseAlignment(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, alias.BaseAlignment(MemoryLayout::kUniformBuffer));
EXPECT_EQ(4u, alias.BaseAlignment(MemoryLayout::kStorageBuffer)); EXPECT_EQ(4u, alias.BaseAlignment(MemoryLayout::kStorageBuffer));
} }

View File

@ -23,16 +23,15 @@ namespace tint {
namespace ast { namespace ast {
namespace type { namespace type {
ArrayType::ArrayType(Type* subtype) : subtype_(subtype) {} Array::Array(Type* subtype) : subtype_(subtype) {}
ArrayType::ArrayType(Type* subtype, uint32_t size) Array::Array(Type* subtype, uint32_t size) : subtype_(subtype), size_(size) {}
: subtype_(subtype), size_(size) {}
ArrayType::ArrayType(ArrayType&&) = default; Array::Array(Array&&) = default;
ArrayType::~ArrayType() = default; Array::~Array() = default;
uint64_t ArrayType::MinBufferBindingSize(MemoryLayout mem_layout) const { uint64_t Array::MinBufferBindingSize(MemoryLayout mem_layout) const {
if (!has_array_stride()) { if (!has_array_stride()) {
// Arrays in buffers are required to have a stride. // Arrays in buffers are required to have a stride.
return 0; return 0;
@ -52,7 +51,7 @@ uint64_t ArrayType::MinBufferBindingSize(MemoryLayout mem_layout) const {
} }
} }
uint64_t ArrayType::BaseAlignment(MemoryLayout mem_layout) const { uint64_t Array::BaseAlignment(MemoryLayout mem_layout) const {
if (mem_layout == MemoryLayout::kUniformBuffer) { if (mem_layout == MemoryLayout::kUniformBuffer) {
float aligment = 16; // for a vec4 float aligment = 16; // for a vec4
float unaligned = static_cast<float>(subtype_->BaseAlignment(mem_layout)); float unaligned = static_cast<float>(subtype_->BaseAlignment(mem_layout));
@ -63,7 +62,7 @@ uint64_t ArrayType::BaseAlignment(MemoryLayout mem_layout) const {
return 0; return 0;
} }
uint32_t ArrayType::array_stride() const { uint32_t Array::array_stride() const {
for (auto* deco : decos_) { for (auto* deco : decos_) {
if (auto* stride = deco->As<StrideDecoration>()) { if (auto* stride = deco->As<StrideDecoration>()) {
return stride->stride(); return stride->stride();
@ -72,7 +71,7 @@ uint32_t ArrayType::array_stride() const {
return 0; return 0;
} }
bool ArrayType::has_array_stride() const { bool Array::has_array_stride() const {
for (auto* deco : decos_) { for (auto* deco : decos_) {
if (deco->Is<StrideDecoration>()) { if (deco->Is<StrideDecoration>()) {
return true; return true;
@ -81,7 +80,7 @@ bool ArrayType::has_array_stride() const {
return false; return false;
} }
std::string ArrayType::type_name() const { std::string Array::type_name() const {
assert(subtype_); assert(subtype_);
std::string type_name = "__array" + subtype_->type_name(); std::string type_name = "__array" + subtype_->type_name();

View File

@ -28,18 +28,18 @@ namespace ast {
namespace type { namespace type {
/// An array type. If size is zero then it is a runtime array. /// An array type. If size is zero then it is a runtime array.
class ArrayType : public Castable<ArrayType, Type> { class Array : public Castable<Array, Type> {
public: public:
/// Constructor for runtime array /// Constructor for runtime array
/// @param subtype the type of the array elements /// @param subtype the type of the array elements
explicit ArrayType(Type* subtype); explicit Array(Type* subtype);
/// Constructor /// Constructor
/// @param subtype the type of the array elements /// @param subtype the type of the array elements
/// @param size the number of elements in the array /// @param size the number of elements in the array
ArrayType(Type* subtype, uint32_t size); Array(Type* subtype, uint32_t size);
/// Move constructor /// Move constructor
ArrayType(ArrayType&&); Array(Array&&);
~ArrayType() override; ~Array() override;
/// @returns true if this is a runtime array. /// @returns true if this is a runtime array.
/// i.e. the size is determined at runtime /// i.e. the size is determined at runtime

View File

@ -35,111 +35,111 @@ namespace ast {
namespace type { namespace type {
namespace { namespace {
using ArrayTypeTest = TestHelper; using ArrayTest = TestHelper;
TEST_F(ArrayTypeTest, CreateSizedArray) { TEST_F(ArrayTest, CreateSizedArray) {
U32Type u32; U32 u32;
ArrayType arr{&u32, 3}; Array arr{&u32, 3};
EXPECT_EQ(arr.type(), &u32); EXPECT_EQ(arr.type(), &u32);
EXPECT_EQ(arr.size(), 3u); EXPECT_EQ(arr.size(), 3u);
EXPECT_TRUE(arr.Is<ArrayType>()); EXPECT_TRUE(arr.Is<Array>());
EXPECT_FALSE(arr.IsRuntimeArray()); EXPECT_FALSE(arr.IsRuntimeArray());
} }
TEST_F(ArrayTypeTest, CreateRuntimeArray) { TEST_F(ArrayTest, CreateRuntimeArray) {
U32Type u32; U32 u32;
ArrayType arr{&u32}; Array arr{&u32};
EXPECT_EQ(arr.type(), &u32); EXPECT_EQ(arr.type(), &u32);
EXPECT_EQ(arr.size(), 0u); EXPECT_EQ(arr.size(), 0u);
EXPECT_TRUE(arr.Is<ArrayType>()); EXPECT_TRUE(arr.Is<Array>());
EXPECT_TRUE(arr.IsRuntimeArray()); EXPECT_TRUE(arr.IsRuntimeArray());
} }
TEST_F(ArrayTypeTest, Is) { TEST_F(ArrayTest, Is) {
I32Type i32; I32 i32;
ArrayType arr{&i32, 3}; Array arr{&i32, 3};
Type* ty = &arr; Type* ty = &arr;
EXPECT_FALSE(ty->Is<AccessControlType>()); EXPECT_FALSE(ty->Is<AccessControl>());
EXPECT_FALSE(ty->Is<AliasType>()); EXPECT_FALSE(ty->Is<Alias>());
EXPECT_TRUE(ty->Is<ArrayType>()); EXPECT_TRUE(ty->Is<Array>());
EXPECT_FALSE(ty->Is<BoolType>()); EXPECT_FALSE(ty->Is<Bool>());
EXPECT_FALSE(ty->Is<F32Type>()); EXPECT_FALSE(ty->Is<F32>());
EXPECT_FALSE(ty->Is<I32Type>()); EXPECT_FALSE(ty->Is<I32>());
EXPECT_FALSE(ty->Is<MatrixType>()); EXPECT_FALSE(ty->Is<Matrix>());
EXPECT_FALSE(ty->Is<PointerType>()); EXPECT_FALSE(ty->Is<Pointer>());
EXPECT_FALSE(ty->Is<SamplerType>()); EXPECT_FALSE(ty->Is<Sampler>());
EXPECT_FALSE(ty->Is<StructType>()); EXPECT_FALSE(ty->Is<Struct>());
EXPECT_FALSE(ty->Is<TextureType>()); EXPECT_FALSE(ty->Is<Texture>());
EXPECT_FALSE(ty->Is<U32Type>()); EXPECT_FALSE(ty->Is<U32>());
EXPECT_FALSE(ty->Is<VectorType>()); EXPECT_FALSE(ty->Is<Vector>());
} }
TEST_F(ArrayTypeTest, TypeName) { TEST_F(ArrayTest, TypeName) {
I32Type i32; I32 i32;
ArrayType arr{&i32}; Array arr{&i32};
EXPECT_EQ(arr.type_name(), "__array__i32"); EXPECT_EQ(arr.type_name(), "__array__i32");
} }
TEST_F(ArrayTypeTest, TypeName_RuntimeArray) { TEST_F(ArrayTest, TypeName_RuntimeArray) {
I32Type i32; I32 i32;
ArrayType arr{&i32, 3}; Array arr{&i32, 3};
EXPECT_EQ(arr.type_name(), "__array__i32_3"); EXPECT_EQ(arr.type_name(), "__array__i32_3");
} }
TEST_F(ArrayTypeTest, TypeName_WithStride) { TEST_F(ArrayTest, TypeName_WithStride) {
I32Type i32; I32 i32;
ArrayDecorationList decos; ArrayDecorationList decos;
decos.push_back(create<StrideDecoration>(16, Source{})); decos.push_back(create<StrideDecoration>(16, Source{}));
ArrayType arr{&i32, 3}; Array arr{&i32, 3};
arr.set_decorations(decos); arr.set_decorations(decos);
EXPECT_EQ(arr.type_name(), "__array__i32_3_stride_16"); EXPECT_EQ(arr.type_name(), "__array__i32_3_stride_16");
} }
TEST_F(ArrayTypeTest, MinBufferBindingSizeNoStride) { TEST_F(ArrayTest, MinBufferBindingSizeNoStride) {
U32Type u32; U32 u32;
ArrayType arr(&u32, 4); Array arr(&u32, 4);
EXPECT_EQ(0u, arr.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); EXPECT_EQ(0u, arr.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
} }
TEST_F(ArrayTypeTest, MinBufferBindingSizeArray) { TEST_F(ArrayTest, MinBufferBindingSizeArray) {
U32Type u32; U32 u32;
ArrayDecorationList decos; ArrayDecorationList decos;
decos.push_back(create<StrideDecoration>(4, Source{})); decos.push_back(create<StrideDecoration>(4, Source{}));
ArrayType arr(&u32, 4); Array arr(&u32, 4);
arr.set_decorations(decos); arr.set_decorations(decos);
EXPECT_EQ(16u, arr.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, arr.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
} }
TEST_F(ArrayTypeTest, MinBufferBindingSizeRuntimeArray) { TEST_F(ArrayTest, MinBufferBindingSizeRuntimeArray) {
U32Type u32; U32 u32;
ArrayDecorationList decos; ArrayDecorationList decos;
decos.push_back(create<StrideDecoration>(4, Source{})); decos.push_back(create<StrideDecoration>(4, Source{}));
ArrayType arr(&u32); Array arr(&u32);
arr.set_decorations(decos); arr.set_decorations(decos);
EXPECT_EQ(4u, arr.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); EXPECT_EQ(4u, arr.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
} }
TEST_F(ArrayTypeTest, BaseAlignmentArray) { TEST_F(ArrayTest, BaseAlignmentArray) {
U32Type u32; U32 u32;
ArrayDecorationList decos; ArrayDecorationList decos;
decos.push_back(create<StrideDecoration>(4, Source{})); decos.push_back(create<StrideDecoration>(4, Source{}));
ArrayType arr(&u32, 4); Array arr(&u32, 4);
arr.set_decorations(decos); arr.set_decorations(decos);
EXPECT_EQ(16u, arr.BaseAlignment(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, arr.BaseAlignment(MemoryLayout::kUniformBuffer));
EXPECT_EQ(4u, arr.BaseAlignment(MemoryLayout::kStorageBuffer)); EXPECT_EQ(4u, arr.BaseAlignment(MemoryLayout::kStorageBuffer));
} }
TEST_F(ArrayTypeTest, BaseAlignmentRuntimeArray) { TEST_F(ArrayTest, BaseAlignmentRuntimeArray) {
U32Type u32; U32 u32;
ArrayDecorationList decos; ArrayDecorationList decos;
decos.push_back(create<StrideDecoration>(4, Source{})); decos.push_back(create<StrideDecoration>(4, Source{}));
ArrayType arr(&u32); Array arr(&u32);
arr.set_decorations(decos); arr.set_decorations(decos);
EXPECT_EQ(16u, arr.BaseAlignment(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, arr.BaseAlignment(MemoryLayout::kUniformBuffer));
EXPECT_EQ(4u, arr.BaseAlignment(MemoryLayout::kStorageBuffer)); EXPECT_EQ(4u, arr.BaseAlignment(MemoryLayout::kStorageBuffer));

View File

@ -18,13 +18,13 @@ namespace tint {
namespace ast { namespace ast {
namespace type { namespace type {
BoolType::BoolType() = default; Bool::Bool() = default;
BoolType::BoolType(BoolType&&) = default; Bool::Bool(Bool&&) = default;
BoolType::~BoolType() = default; Bool::~Bool() = default;
std::string BoolType::type_name() const { std::string Bool::type_name() const {
return "__bool"; return "__bool";
} }

View File

@ -24,13 +24,13 @@ namespace ast {
namespace type { namespace type {
/// A boolean type /// A boolean type
class BoolType : public Castable<BoolType, Type> { class Bool : public Castable<Bool, Type> {
public: public:
/// Constructor /// Constructor
BoolType(); Bool();
/// Move constructor /// Move constructor
BoolType(BoolType&&); Bool(Bool&&);
~BoolType() override; ~Bool() override;
/// @returns the name for this type /// @returns the name for this type
std::string type_name() const override; std::string type_name() const override;

View File

@ -31,33 +31,33 @@ namespace ast {
namespace type { namespace type {
namespace { namespace {
using BoolTypeTest = TestHelper; using BoolTest = TestHelper;
TEST_F(BoolTypeTest, Is) { TEST_F(BoolTest, Is) {
BoolType b; Bool b;
Type* ty = &b; Type* ty = &b;
EXPECT_FALSE(ty->Is<AccessControlType>()); EXPECT_FALSE(ty->Is<AccessControl>());
EXPECT_FALSE(ty->Is<AliasType>()); EXPECT_FALSE(ty->Is<Alias>());
EXPECT_FALSE(ty->Is<ArrayType>()); EXPECT_FALSE(ty->Is<Array>());
EXPECT_TRUE(ty->Is<BoolType>()); EXPECT_TRUE(ty->Is<Bool>());
EXPECT_FALSE(ty->Is<F32Type>()); EXPECT_FALSE(ty->Is<F32>());
EXPECT_FALSE(ty->Is<I32Type>()); EXPECT_FALSE(ty->Is<I32>());
EXPECT_FALSE(ty->Is<MatrixType>()); EXPECT_FALSE(ty->Is<Matrix>());
EXPECT_FALSE(ty->Is<PointerType>()); EXPECT_FALSE(ty->Is<Pointer>());
EXPECT_FALSE(ty->Is<SamplerType>()); EXPECT_FALSE(ty->Is<Sampler>());
EXPECT_FALSE(ty->Is<StructType>()); EXPECT_FALSE(ty->Is<Struct>());
EXPECT_FALSE(ty->Is<TextureType>()); EXPECT_FALSE(ty->Is<Texture>());
EXPECT_FALSE(ty->Is<U32Type>()); EXPECT_FALSE(ty->Is<U32>());
EXPECT_FALSE(ty->Is<VectorType>()); EXPECT_FALSE(ty->Is<Vector>());
} }
TEST_F(BoolTypeTest, TypeName) { TEST_F(BoolTest, TypeName) {
BoolType b; Bool b;
EXPECT_EQ(b.type_name(), "__bool"); EXPECT_EQ(b.type_name(), "__bool");
} }
TEST_F(BoolTypeTest, MinBufferBindingSize) { TEST_F(BoolTest, MinBufferBindingSize) {
BoolType b; Bool b;
EXPECT_EQ(0u, b.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); EXPECT_EQ(0u, b.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
} }

View File

@ -33,15 +33,15 @@ bool IsValidDepthDimension(TextureDimension dim) {
} // namespace } // namespace
DepthTextureType::DepthTextureType(TextureDimension dim) : Base(dim) { DepthTexture::DepthTexture(TextureDimension dim) : Base(dim) {
assert(IsValidDepthDimension(dim)); assert(IsValidDepthDimension(dim));
} }
DepthTextureType::DepthTextureType(DepthTextureType&&) = default; DepthTexture::DepthTexture(DepthTexture&&) = default;
DepthTextureType::~DepthTextureType() = default; DepthTexture::~DepthTexture() = default;
std::string DepthTextureType::type_name() const { std::string DepthTexture::type_name() const {
std::ostringstream out; std::ostringstream out;
out << "__depth_texture_" << dim(); out << "__depth_texture_" << dim();
return out.str(); return out.str();

View File

@ -24,14 +24,14 @@ namespace ast {
namespace type { namespace type {
/// A depth texture type. /// A depth texture type.
class DepthTextureType : public Castable<DepthTextureType, TextureType> { class DepthTexture : public Castable<DepthTexture, Texture> {
public: public:
/// Constructor /// Constructor
/// @param dim the dimensionality of the texture /// @param dim the dimensionality of the texture
explicit DepthTextureType(TextureDimension dim); explicit DepthTexture(TextureDimension dim);
/// Move constructor /// Move constructor
DepthTextureType(DepthTextureType&&); DepthTexture(DepthTexture&&);
~DepthTextureType() override; ~DepthTexture() override;
/// @returns the name for this type /// @returns the name for this type
std::string type_name() const override; std::string type_name() const override;

View File

@ -34,46 +34,46 @@ namespace ast {
namespace type { namespace type {
namespace { namespace {
using DepthTextureTypeTest = TestHelper; using DepthTextureTest = TestHelper;
TEST_F(DepthTextureTypeTest, Is) { TEST_F(DepthTextureTest, Is) {
DepthTextureType d(TextureDimension::kCube); DepthTexture d(TextureDimension::kCube);
Type* ty = &d; Type* ty = &d;
EXPECT_FALSE(ty->Is<AccessControlType>()); EXPECT_FALSE(ty->Is<AccessControl>());
EXPECT_FALSE(ty->Is<AliasType>()); EXPECT_FALSE(ty->Is<Alias>());
EXPECT_FALSE(ty->Is<ArrayType>()); EXPECT_FALSE(ty->Is<Array>());
EXPECT_FALSE(ty->Is<BoolType>()); EXPECT_FALSE(ty->Is<Bool>());
EXPECT_FALSE(ty->Is<F32Type>()); EXPECT_FALSE(ty->Is<F32>());
EXPECT_FALSE(ty->Is<I32Type>()); EXPECT_FALSE(ty->Is<I32>());
EXPECT_FALSE(ty->Is<MatrixType>()); EXPECT_FALSE(ty->Is<Matrix>());
EXPECT_FALSE(ty->Is<PointerType>()); EXPECT_FALSE(ty->Is<Pointer>());
EXPECT_FALSE(ty->Is<SamplerType>()); EXPECT_FALSE(ty->Is<Sampler>());
EXPECT_FALSE(ty->Is<StructType>()); EXPECT_FALSE(ty->Is<Struct>());
EXPECT_TRUE(ty->Is<TextureType>()); EXPECT_TRUE(ty->Is<Texture>());
EXPECT_FALSE(ty->Is<U32Type>()); EXPECT_FALSE(ty->Is<U32>());
EXPECT_FALSE(ty->Is<VectorType>()); EXPECT_FALSE(ty->Is<Vector>());
} }
TEST_F(DepthTextureTypeTest, IsTextureType) { TEST_F(DepthTextureTest, IsTexture) {
DepthTextureType d(TextureDimension::kCube); DepthTexture d(TextureDimension::kCube);
TextureType* ty = &d; Texture* ty = &d;
EXPECT_TRUE(ty->Is<DepthTextureType>()); EXPECT_TRUE(ty->Is<DepthTexture>());
EXPECT_FALSE(ty->Is<SampledTextureType>()); EXPECT_FALSE(ty->Is<SampledTexture>());
EXPECT_FALSE(ty->Is<StorageTextureType>()); EXPECT_FALSE(ty->Is<StorageTexture>());
} }
TEST_F(DepthTextureTypeTest, Dim) { TEST_F(DepthTextureTest, Dim) {
DepthTextureType d(TextureDimension::kCube); DepthTexture d(TextureDimension::kCube);
EXPECT_EQ(d.dim(), TextureDimension::kCube); EXPECT_EQ(d.dim(), TextureDimension::kCube);
} }
TEST_F(DepthTextureTypeTest, TypeName) { TEST_F(DepthTextureTest, TypeName) {
DepthTextureType d(TextureDimension::kCube); DepthTexture d(TextureDimension::kCube);
EXPECT_EQ(d.type_name(), "__depth_texture_cube"); EXPECT_EQ(d.type_name(), "__depth_texture_cube");
} }
TEST_F(DepthTextureTypeTest, MinBufferBindingSize) { TEST_F(DepthTextureTest, MinBufferBindingSize) {
DepthTextureType d(TextureDimension::kCube); DepthTexture d(TextureDimension::kCube);
EXPECT_EQ(0u, d.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); EXPECT_EQ(0u, d.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
} }

View File

@ -18,21 +18,21 @@ namespace tint {
namespace ast { namespace ast {
namespace type { namespace type {
F32Type::F32Type() = default; F32::F32() = default;
F32Type::F32Type(F32Type&&) = default; F32::F32(F32&&) = default;
F32Type::~F32Type() = default; F32::~F32() = default;
std::string F32Type::type_name() const { std::string F32::type_name() const {
return "__f32"; return "__f32";
} }
uint64_t F32Type::MinBufferBindingSize(MemoryLayout) const { uint64_t F32::MinBufferBindingSize(MemoryLayout) const {
return 4; return 4;
} }
uint64_t F32Type::BaseAlignment(MemoryLayout) const { uint64_t F32::BaseAlignment(MemoryLayout) const {
return 4; return 4;
} }

View File

@ -24,13 +24,13 @@ namespace ast {
namespace type { namespace type {
/// A float 32 type /// A float 32 type
class F32Type : public Castable<F32Type, Type> { class F32 : public Castable<F32, Type> {
public: public:
/// Constructor /// Constructor
F32Type(); F32();
/// Move constructor /// Move constructor
F32Type(F32Type&&); F32(F32&&);
~F32Type() override; ~F32() override;
/// @returns the name for this type /// @returns the name for this type
std::string type_name() const override; std::string type_name() const override;

View File

@ -31,38 +31,38 @@ namespace ast {
namespace type { namespace type {
namespace { namespace {
using F32TypeTest = TestHelper; using F32Test = TestHelper;
TEST_F(F32TypeTest, Is) { TEST_F(F32Test, Is) {
F32Type f; F32 f;
Type* ty = &f; Type* ty = &f;
EXPECT_FALSE(ty->Is<AccessControlType>()); EXPECT_FALSE(ty->Is<AccessControl>());
EXPECT_FALSE(ty->Is<AliasType>()); EXPECT_FALSE(ty->Is<Alias>());
EXPECT_FALSE(ty->Is<ArrayType>()); EXPECT_FALSE(ty->Is<Array>());
EXPECT_FALSE(ty->Is<BoolType>()); EXPECT_FALSE(ty->Is<Bool>());
EXPECT_TRUE(ty->Is<F32Type>()); EXPECT_TRUE(ty->Is<F32>());
EXPECT_FALSE(ty->Is<I32Type>()); EXPECT_FALSE(ty->Is<I32>());
EXPECT_FALSE(ty->Is<MatrixType>()); EXPECT_FALSE(ty->Is<Matrix>());
EXPECT_FALSE(ty->Is<PointerType>()); EXPECT_FALSE(ty->Is<Pointer>());
EXPECT_FALSE(ty->Is<SamplerType>()); EXPECT_FALSE(ty->Is<Sampler>());
EXPECT_FALSE(ty->Is<StructType>()); EXPECT_FALSE(ty->Is<Struct>());
EXPECT_FALSE(ty->Is<TextureType>()); EXPECT_FALSE(ty->Is<Texture>());
EXPECT_FALSE(ty->Is<U32Type>()); EXPECT_FALSE(ty->Is<U32>());
EXPECT_FALSE(ty->Is<VectorType>()); EXPECT_FALSE(ty->Is<Vector>());
} }
TEST_F(F32TypeTest, TypeName) { TEST_F(F32Test, TypeName) {
F32Type f; F32 f;
EXPECT_EQ(f.type_name(), "__f32"); EXPECT_EQ(f.type_name(), "__f32");
} }
TEST_F(F32TypeTest, MinBufferBindingSize) { TEST_F(F32Test, MinBufferBindingSize) {
F32Type f; F32 f;
EXPECT_EQ(4u, f.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); EXPECT_EQ(4u, f.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
} }
TEST_F(F32TypeTest, BaseAlignment) { TEST_F(F32Test, BaseAlignment) {
F32Type f; F32 f;
EXPECT_EQ(4u, f.BaseAlignment(MemoryLayout::kUniformBuffer)); EXPECT_EQ(4u, f.BaseAlignment(MemoryLayout::kUniformBuffer));
} }

View File

@ -18,21 +18,21 @@ namespace tint {
namespace ast { namespace ast {
namespace type { namespace type {
I32Type::I32Type() = default; I32::I32() = default;
I32Type::I32Type(I32Type&&) = default; I32::I32(I32&&) = default;
I32Type::~I32Type() = default; I32::~I32() = default;
std::string I32Type::type_name() const { std::string I32::type_name() const {
return "__i32"; return "__i32";
} }
uint64_t I32Type::MinBufferBindingSize(MemoryLayout) const { uint64_t I32::MinBufferBindingSize(MemoryLayout) const {
return 4; return 4;
} }
uint64_t I32Type::BaseAlignment(MemoryLayout) const { uint64_t I32::BaseAlignment(MemoryLayout) const {
return 4; return 4;
} }

View File

@ -24,13 +24,13 @@ namespace ast {
namespace type { namespace type {
/// A signed int 32 type. /// A signed int 32 type.
class I32Type : public Castable<I32Type, Type> { class I32 : public Castable<I32, Type> {
public: public:
/// Constructor /// Constructor
I32Type(); I32();
/// Move constructor /// Move constructor
I32Type(I32Type&&); I32(I32&&);
~I32Type() override; ~I32() override;
/// @returns the name for this type /// @returns the name for this type
std::string type_name() const override; std::string type_name() const override;

View File

@ -31,38 +31,38 @@ namespace ast {
namespace type { namespace type {
namespace { namespace {
using I32TypeTest = TestHelper; using I32Test = TestHelper;
TEST_F(I32TypeTest, Is) { TEST_F(I32Test, Is) {
I32Type i; I32 i;
Type* ty = &i; Type* ty = &i;
EXPECT_FALSE(ty->Is<AccessControlType>()); EXPECT_FALSE(ty->Is<AccessControl>());
EXPECT_FALSE(ty->Is<AliasType>()); EXPECT_FALSE(ty->Is<Alias>());
EXPECT_FALSE(ty->Is<ArrayType>()); EXPECT_FALSE(ty->Is<Array>());
EXPECT_FALSE(ty->Is<BoolType>()); EXPECT_FALSE(ty->Is<Bool>());
EXPECT_FALSE(ty->Is<F32Type>()); EXPECT_FALSE(ty->Is<F32>());
EXPECT_TRUE(ty->Is<I32Type>()); EXPECT_TRUE(ty->Is<I32>());
EXPECT_FALSE(ty->Is<MatrixType>()); EXPECT_FALSE(ty->Is<Matrix>());
EXPECT_FALSE(ty->Is<PointerType>()); EXPECT_FALSE(ty->Is<Pointer>());
EXPECT_FALSE(ty->Is<SamplerType>()); EXPECT_FALSE(ty->Is<Sampler>());
EXPECT_FALSE(ty->Is<StructType>()); EXPECT_FALSE(ty->Is<Struct>());
EXPECT_FALSE(ty->Is<TextureType>()); EXPECT_FALSE(ty->Is<Texture>());
EXPECT_FALSE(ty->Is<U32Type>()); EXPECT_FALSE(ty->Is<U32>());
EXPECT_FALSE(ty->Is<VectorType>()); EXPECT_FALSE(ty->Is<Vector>());
} }
TEST_F(I32TypeTest, TypeName) { TEST_F(I32Test, TypeName) {
I32Type i; I32 i;
EXPECT_EQ(i.type_name(), "__i32"); EXPECT_EQ(i.type_name(), "__i32");
} }
TEST_F(I32TypeTest, MinBufferBindingSize) { TEST_F(I32Test, MinBufferBindingSize) {
I32Type i; I32 i;
EXPECT_EQ(4u, i.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); EXPECT_EQ(4u, i.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
} }
TEST_F(I32TypeTest, BaseAlignment) { TEST_F(I32Test, BaseAlignment) {
I32Type i; I32 i;
EXPECT_EQ(4u, i.BaseAlignment(MemoryLayout::kUniformBuffer)); EXPECT_EQ(4u, i.BaseAlignment(MemoryLayout::kUniformBuffer));
} }

View File

@ -23,7 +23,7 @@ namespace tint {
namespace ast { namespace ast {
namespace type { namespace type {
MatrixType::MatrixType(Type* subtype, uint32_t rows, uint32_t columns) Matrix::Matrix(Type* subtype, uint32_t rows, uint32_t columns)
: subtype_(subtype), rows_(rows), columns_(columns) { : subtype_(subtype), rows_(rows), columns_(columns) {
assert(rows > 1); assert(rows > 1);
assert(rows < 5); assert(rows < 5);
@ -31,24 +31,24 @@ MatrixType::MatrixType(Type* subtype, uint32_t rows, uint32_t columns)
assert(columns < 5); assert(columns < 5);
} }
MatrixType::MatrixType(MatrixType&&) = default; Matrix::Matrix(Matrix&&) = default;
MatrixType::~MatrixType() = default; Matrix::~Matrix() = default;
std::string MatrixType::type_name() const { std::string Matrix::type_name() const {
return "__mat_" + std::to_string(rows_) + "_" + std::to_string(columns_) + return "__mat_" + std::to_string(rows_) + "_" + std::to_string(columns_) +
subtype_->type_name(); subtype_->type_name();
} }
uint64_t MatrixType::MinBufferBindingSize(MemoryLayout mem_layout) const { uint64_t Matrix::MinBufferBindingSize(MemoryLayout mem_layout) const {
VectorType vec(subtype_, rows_); Vector vec(subtype_, rows_);
return (columns_ - 1) * vec.BaseAlignment(mem_layout) + return (columns_ - 1) * vec.BaseAlignment(mem_layout) +
vec.MinBufferBindingSize(mem_layout); vec.MinBufferBindingSize(mem_layout);
} }
uint64_t MatrixType::BaseAlignment(MemoryLayout mem_layout) const { uint64_t Matrix::BaseAlignment(MemoryLayout mem_layout) const {
VectorType vec(subtype_, rows_); Vector vec(subtype_, rows_);
ArrayType arr(&vec, columns_); Array arr(&vec, columns_);
return arr.BaseAlignment(mem_layout); return arr.BaseAlignment(mem_layout);
} }

View File

@ -24,16 +24,16 @@ namespace ast {
namespace type { namespace type {
/// A matrix type /// A matrix type
class MatrixType : public Castable<MatrixType, Type> { class Matrix : public Castable<Matrix, Type> {
public: public:
/// Constructor /// Constructor
/// @param subtype type matrix type /// @param subtype type matrix type
/// @param rows the number of rows in the matrix /// @param rows the number of rows in the matrix
/// @param columns the number of columns in the matrix /// @param columns the number of columns in the matrix
MatrixType(Type* subtype, uint32_t rows, uint32_t columns); Matrix(Type* subtype, uint32_t rows, uint32_t columns);
/// Move constructor /// Move constructor
MatrixType(MatrixType&&); Matrix(Matrix&&);
~MatrixType() override; ~Matrix() override;
/// @returns the type of the matrix /// @returns the type of the matrix
Type* type() const { return subtype_; } Type* type() const { return subtype_; }

View File

@ -31,93 +31,93 @@ namespace ast {
namespace type { namespace type {
namespace { namespace {
using MatrixTypeTest = TestHelper; using MatrixTest = TestHelper;
TEST_F(MatrixTypeTest, Creation) { TEST_F(MatrixTest, Creation) {
I32Type i32; I32 i32;
MatrixType m{&i32, 2, 4}; Matrix m{&i32, 2, 4};
EXPECT_EQ(m.type(), &i32); EXPECT_EQ(m.type(), &i32);
EXPECT_EQ(m.rows(), 2u); EXPECT_EQ(m.rows(), 2u);
EXPECT_EQ(m.columns(), 4u); EXPECT_EQ(m.columns(), 4u);
} }
TEST_F(MatrixTypeTest, Is) { TEST_F(MatrixTest, Is) {
I32Type i32; I32 i32;
MatrixType m{&i32, 2, 3}; Matrix m{&i32, 2, 3};
Type* ty = &m; Type* ty = &m;
EXPECT_FALSE(ty->Is<AccessControlType>()); EXPECT_FALSE(ty->Is<AccessControl>());
EXPECT_FALSE(ty->Is<AliasType>()); EXPECT_FALSE(ty->Is<Alias>());
EXPECT_FALSE(ty->Is<ArrayType>()); EXPECT_FALSE(ty->Is<Array>());
EXPECT_FALSE(ty->Is<BoolType>()); EXPECT_FALSE(ty->Is<Bool>());
EXPECT_FALSE(ty->Is<F32Type>()); EXPECT_FALSE(ty->Is<F32>());
EXPECT_FALSE(ty->Is<I32Type>()); EXPECT_FALSE(ty->Is<I32>());
EXPECT_TRUE(ty->Is<MatrixType>()); EXPECT_TRUE(ty->Is<Matrix>());
EXPECT_FALSE(ty->Is<PointerType>()); EXPECT_FALSE(ty->Is<Pointer>());
EXPECT_FALSE(ty->Is<SamplerType>()); EXPECT_FALSE(ty->Is<Sampler>());
EXPECT_FALSE(ty->Is<StructType>()); EXPECT_FALSE(ty->Is<Struct>());
EXPECT_FALSE(ty->Is<TextureType>()); EXPECT_FALSE(ty->Is<Texture>());
EXPECT_FALSE(ty->Is<U32Type>()); EXPECT_FALSE(ty->Is<U32>());
EXPECT_FALSE(ty->Is<VectorType>()); EXPECT_FALSE(ty->Is<Vector>());
} }
TEST_F(MatrixTypeTest, TypeName) { TEST_F(MatrixTest, TypeName) {
I32Type i32; I32 i32;
MatrixType m{&i32, 2, 3}; Matrix m{&i32, 2, 3};
EXPECT_EQ(m.type_name(), "__mat_2_3__i32"); EXPECT_EQ(m.type_name(), "__mat_2_3__i32");
} }
TEST_F(MatrixTypeTest, MinBufferBindingSize4x2) { TEST_F(MatrixTest, MinBufferBindingSize4x2) {
I32Type i32; I32 i32;
MatrixType m{&i32, 4, 2}; Matrix m{&i32, 4, 2};
EXPECT_EQ(32u, m.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); EXPECT_EQ(32u, m.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
EXPECT_EQ(32u, m.MinBufferBindingSize(MemoryLayout::kStorageBuffer)); EXPECT_EQ(32u, m.MinBufferBindingSize(MemoryLayout::kStorageBuffer));
} }
TEST_F(MatrixTypeTest, MinBufferBindingSize3x2) { TEST_F(MatrixTest, MinBufferBindingSize3x2) {
I32Type i32; I32 i32;
MatrixType m{&i32, 3, 2}; Matrix m{&i32, 3, 2};
EXPECT_EQ(28u, m.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); EXPECT_EQ(28u, m.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
EXPECT_EQ(28u, m.MinBufferBindingSize(MemoryLayout::kStorageBuffer)); EXPECT_EQ(28u, m.MinBufferBindingSize(MemoryLayout::kStorageBuffer));
} }
TEST_F(MatrixTypeTest, MinBufferBindingSize2x3) { TEST_F(MatrixTest, MinBufferBindingSize2x3) {
I32Type i32; I32 i32;
MatrixType m{&i32, 2, 3}; Matrix m{&i32, 2, 3};
EXPECT_EQ(24u, m.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); EXPECT_EQ(24u, m.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
EXPECT_EQ(24u, m.MinBufferBindingSize(MemoryLayout::kStorageBuffer)); EXPECT_EQ(24u, m.MinBufferBindingSize(MemoryLayout::kStorageBuffer));
} }
TEST_F(MatrixTypeTest, MinBufferBindingSize2x2) { TEST_F(MatrixTest, MinBufferBindingSize2x2) {
I32Type i32; I32 i32;
MatrixType m{&i32, 2, 2}; Matrix m{&i32, 2, 2};
EXPECT_EQ(16u, m.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, m.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
EXPECT_EQ(16u, m.MinBufferBindingSize(MemoryLayout::kStorageBuffer)); EXPECT_EQ(16u, m.MinBufferBindingSize(MemoryLayout::kStorageBuffer));
} }
TEST_F(MatrixTypeTest, BaseAlignment4x2) { TEST_F(MatrixTest, BaseAlignment4x2) {
I32Type i32; I32 i32;
MatrixType m{&i32, 4, 2}; Matrix m{&i32, 4, 2};
EXPECT_EQ(16u, m.BaseAlignment(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, m.BaseAlignment(MemoryLayout::kUniformBuffer));
EXPECT_EQ(16u, m.BaseAlignment(MemoryLayout::kStorageBuffer)); EXPECT_EQ(16u, m.BaseAlignment(MemoryLayout::kStorageBuffer));
} }
TEST_F(MatrixTypeTest, BaseAlignment3x2) { TEST_F(MatrixTest, BaseAlignment3x2) {
I32Type i32; I32 i32;
MatrixType m{&i32, 3, 2}; Matrix m{&i32, 3, 2};
EXPECT_EQ(16u, m.BaseAlignment(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, m.BaseAlignment(MemoryLayout::kUniformBuffer));
EXPECT_EQ(16u, m.BaseAlignment(MemoryLayout::kStorageBuffer)); EXPECT_EQ(16u, m.BaseAlignment(MemoryLayout::kStorageBuffer));
} }
TEST_F(MatrixTypeTest, BaseAlignment2x3) { TEST_F(MatrixTest, BaseAlignment2x3) {
I32Type i32; I32 i32;
MatrixType m{&i32, 2, 3}; Matrix m{&i32, 2, 3};
EXPECT_EQ(16u, m.BaseAlignment(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, m.BaseAlignment(MemoryLayout::kUniformBuffer));
EXPECT_EQ(8u, m.BaseAlignment(MemoryLayout::kStorageBuffer)); EXPECT_EQ(8u, m.BaseAlignment(MemoryLayout::kStorageBuffer));
} }
TEST_F(MatrixTypeTest, BaseAlignment2x2) { TEST_F(MatrixTest, BaseAlignment2x2) {
I32Type i32; I32 i32;
MatrixType m{&i32, 2, 2}; Matrix m{&i32, 2, 2};
EXPECT_EQ(16u, m.BaseAlignment(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, m.BaseAlignment(MemoryLayout::kUniformBuffer));
EXPECT_EQ(8u, m.BaseAlignment(MemoryLayout::kStorageBuffer)); EXPECT_EQ(8u, m.BaseAlignment(MemoryLayout::kStorageBuffer));
} }

View File

@ -21,19 +21,16 @@ namespace tint {
namespace ast { namespace ast {
namespace type { namespace type {
MultisampledTextureType::MultisampledTextureType(TextureDimension dim, MultisampledTexture::MultisampledTexture(TextureDimension dim, Type* type)
Type* type)
: Base(dim), type_(type) { : Base(dim), type_(type) {
assert(type_); assert(type_);
} }
MultisampledTextureType::MultisampledTextureType(MultisampledTextureType&&) = MultisampledTexture::MultisampledTexture(MultisampledTexture&&) = default;
default;
MultisampledTextureType::~MultisampledTextureType() = default; MultisampledTexture::~MultisampledTexture() = default;
std::string MultisampledTexture::type_name() const {
std::string MultisampledTextureType::type_name() const {
std::ostringstream out; std::ostringstream out;
out << "__multisampled_texture_" << dim() << type_->type_name(); out << "__multisampled_texture_" << dim() << type_->type_name();
return out.str(); return out.str();

View File

@ -24,16 +24,15 @@ namespace ast {
namespace type { namespace type {
/// A multisampled texture type. /// A multisampled texture type.
class MultisampledTextureType class MultisampledTexture : public Castable<MultisampledTexture, Texture> {
: public Castable<MultisampledTextureType, TextureType> {
public: public:
/// Constructor /// Constructor
/// @param dim the dimensionality of the texture /// @param dim the dimensionality of the texture
/// @param type the data type of the multisampled texture /// @param type the data type of the multisampled texture
MultisampledTextureType(TextureDimension dim, Type* type); MultisampledTexture(TextureDimension dim, Type* type);
/// Move constructor /// Move constructor
MultisampledTextureType(MultisampledTextureType&&); MultisampledTexture(MultisampledTexture&&);
~MultisampledTextureType() override; ~MultisampledTexture() override;
/// @returns the subtype of the sampled texture /// @returns the subtype of the sampled texture
Type* type() const { return type_; } Type* type() const { return type_; }

View File

@ -34,58 +34,58 @@ namespace ast {
namespace type { namespace type {
namespace { namespace {
using MultisampledTextureTypeTest = TestHelper; using MultisampledTextureTest = TestHelper;
TEST_F(MultisampledTextureTypeTest, Is) { TEST_F(MultisampledTextureTest, Is) {
F32Type f32; F32 f32;
MultisampledTextureType s(TextureDimension::kCube, &f32); MultisampledTexture s(TextureDimension::kCube, &f32);
Type* ty = &s; Type* ty = &s;
EXPECT_FALSE(ty->Is<AccessControlType>()); EXPECT_FALSE(ty->Is<AccessControl>());
EXPECT_FALSE(ty->Is<AliasType>()); EXPECT_FALSE(ty->Is<Alias>());
EXPECT_FALSE(ty->Is<ArrayType>()); EXPECT_FALSE(ty->Is<Array>());
EXPECT_FALSE(ty->Is<BoolType>()); EXPECT_FALSE(ty->Is<Bool>());
EXPECT_FALSE(ty->Is<F32Type>()); EXPECT_FALSE(ty->Is<F32>());
EXPECT_FALSE(ty->Is<I32Type>()); EXPECT_FALSE(ty->Is<I32>());
EXPECT_FALSE(ty->Is<MatrixType>()); EXPECT_FALSE(ty->Is<Matrix>());
EXPECT_FALSE(ty->Is<PointerType>()); EXPECT_FALSE(ty->Is<Pointer>());
EXPECT_FALSE(ty->Is<SamplerType>()); EXPECT_FALSE(ty->Is<Sampler>());
EXPECT_FALSE(ty->Is<StructType>()); EXPECT_FALSE(ty->Is<Struct>());
EXPECT_TRUE(ty->Is<TextureType>()); EXPECT_TRUE(ty->Is<Texture>());
EXPECT_FALSE(ty->Is<U32Type>()); EXPECT_FALSE(ty->Is<U32>());
EXPECT_FALSE(ty->Is<VectorType>()); EXPECT_FALSE(ty->Is<Vector>());
} }
TEST_F(MultisampledTextureTypeTest, IsTextureType) { TEST_F(MultisampledTextureTest, IsTexture) {
F32Type f32; F32 f32;
MultisampledTextureType s(TextureDimension::kCube, &f32); MultisampledTexture s(TextureDimension::kCube, &f32);
TextureType* ty = &s; Texture* ty = &s;
EXPECT_FALSE(ty->Is<DepthTextureType>()); EXPECT_FALSE(ty->Is<DepthTexture>());
EXPECT_TRUE(ty->Is<MultisampledTextureType>()); EXPECT_TRUE(ty->Is<MultisampledTexture>());
EXPECT_FALSE(ty->Is<SampledTextureType>()); EXPECT_FALSE(ty->Is<SampledTexture>());
EXPECT_FALSE(ty->Is<StorageTextureType>()); EXPECT_FALSE(ty->Is<StorageTexture>());
} }
TEST_F(MultisampledTextureTypeTest, Dim) { TEST_F(MultisampledTextureTest, Dim) {
F32Type f32; F32 f32;
MultisampledTextureType s(TextureDimension::k3d, &f32); MultisampledTexture s(TextureDimension::k3d, &f32);
EXPECT_EQ(s.dim(), TextureDimension::k3d); EXPECT_EQ(s.dim(), TextureDimension::k3d);
} }
TEST_F(MultisampledTextureTypeTest, Type) { TEST_F(MultisampledTextureTest, Type) {
F32Type f32; F32 f32;
MultisampledTextureType s(TextureDimension::k3d, &f32); MultisampledTexture s(TextureDimension::k3d, &f32);
EXPECT_EQ(s.type(), &f32); EXPECT_EQ(s.type(), &f32);
} }
TEST_F(MultisampledTextureTypeTest, TypeName) { TEST_F(MultisampledTextureTest, TypeName) {
F32Type f32; F32 f32;
MultisampledTextureType s(TextureDimension::k3d, &f32); MultisampledTexture s(TextureDimension::k3d, &f32);
EXPECT_EQ(s.type_name(), "__multisampled_texture_3d__f32"); EXPECT_EQ(s.type_name(), "__multisampled_texture_3d__f32");
} }
TEST_F(MultisampledTextureTypeTest, MinBufferBindingSize) { TEST_F(MultisampledTextureTest, MinBufferBindingSize) {
F32Type f32; F32 f32;
MultisampledTextureType s(TextureDimension::k3d, &f32); MultisampledTexture s(TextureDimension::k3d, &f32);
EXPECT_EQ(0u, s.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); EXPECT_EQ(0u, s.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
} }

View File

@ -18,18 +18,18 @@ namespace tint {
namespace ast { namespace ast {
namespace type { namespace type {
PointerType::PointerType(Type* subtype, StorageClass storage_class) Pointer::Pointer(Type* subtype, StorageClass storage_class)
: subtype_(subtype), storage_class_(storage_class) {} : subtype_(subtype), storage_class_(storage_class) {}
std::string PointerType::type_name() const { std::string Pointer::type_name() const {
std::ostringstream out; std::ostringstream out;
out << "__ptr_" << storage_class_ << subtype_->type_name(); out << "__ptr_" << storage_class_ << subtype_->type_name();
return out.str(); return out.str();
} }
PointerType::PointerType(PointerType&&) = default; Pointer::Pointer(Pointer&&) = default;
PointerType::~PointerType() = default; Pointer::~Pointer() = default;
} // namespace type } // namespace type
} // namespace ast } // namespace ast

View File

@ -26,15 +26,15 @@ namespace ast {
namespace type { namespace type {
/// A pointer type. /// A pointer type.
class PointerType : public Castable<PointerType, Type> { class Pointer : public Castable<Pointer, Type> {
public: public:
/// Construtor /// Construtor
/// @param subtype the pointee type /// @param subtype the pointee type
/// @param storage_class the storage class of the pointer /// @param storage_class the storage class of the pointer
explicit PointerType(Type* subtype, StorageClass storage_class); explicit Pointer(Type* subtype, StorageClass storage_class);
/// Move constructor /// Move constructor
PointerType(PointerType&&); Pointer(Pointer&&);
~PointerType() override; ~Pointer() override;
/// @returns the pointee type /// @returns the pointee type
Type* type() const { return subtype_; } Type* type() const { return subtype_; }

View File

@ -31,37 +31,37 @@ namespace ast {
namespace type { namespace type {
namespace { namespace {
using PointerTypeTest = TestHelper; using PointerTest = TestHelper;
TEST_F(PointerTypeTest, Creation) { TEST_F(PointerTest, Creation) {
I32Type i32; I32 i32;
PointerType p{&i32, StorageClass::kStorageBuffer}; Pointer p{&i32, StorageClass::kStorageBuffer};
EXPECT_EQ(p.type(), &i32); EXPECT_EQ(p.type(), &i32);
EXPECT_EQ(p.storage_class(), StorageClass::kStorageBuffer); EXPECT_EQ(p.storage_class(), StorageClass::kStorageBuffer);
} }
TEST_F(PointerTypeTest, Is) { TEST_F(PointerTest, Is) {
I32Type i32; I32 i32;
PointerType p{&i32, StorageClass::kFunction}; Pointer p{&i32, StorageClass::kFunction};
Type* ty = &p; Type* ty = &p;
EXPECT_FALSE(ty->Is<AccessControlType>()); EXPECT_FALSE(ty->Is<AccessControl>());
EXPECT_FALSE(ty->Is<AliasType>()); EXPECT_FALSE(ty->Is<Alias>());
EXPECT_FALSE(ty->Is<ArrayType>()); EXPECT_FALSE(ty->Is<Array>());
EXPECT_FALSE(ty->Is<BoolType>()); EXPECT_FALSE(ty->Is<Bool>());
EXPECT_FALSE(ty->Is<F32Type>()); EXPECT_FALSE(ty->Is<F32>());
EXPECT_FALSE(ty->Is<I32Type>()); EXPECT_FALSE(ty->Is<I32>());
EXPECT_FALSE(ty->Is<MatrixType>()); EXPECT_FALSE(ty->Is<Matrix>());
EXPECT_TRUE(ty->Is<PointerType>()); EXPECT_TRUE(ty->Is<Pointer>());
EXPECT_FALSE(ty->Is<SamplerType>()); EXPECT_FALSE(ty->Is<Sampler>());
EXPECT_FALSE(ty->Is<StructType>()); EXPECT_FALSE(ty->Is<Struct>());
EXPECT_FALSE(ty->Is<TextureType>()); EXPECT_FALSE(ty->Is<Texture>());
EXPECT_FALSE(ty->Is<U32Type>()); EXPECT_FALSE(ty->Is<U32>());
EXPECT_FALSE(ty->Is<VectorType>()); EXPECT_FALSE(ty->Is<Vector>());
} }
TEST_F(PointerTypeTest, TypeName) { TEST_F(PointerTest, TypeName) {
I32Type i32; I32 i32;
PointerType p{&i32, StorageClass::kWorkgroup}; Pointer p{&i32, StorageClass::kWorkgroup};
EXPECT_EQ(p.type_name(), "__ptr_workgroup__i32"); EXPECT_EQ(p.type_name(), "__ptr_workgroup__i32");
} }

View File

@ -21,16 +21,16 @@ namespace tint {
namespace ast { namespace ast {
namespace type { namespace type {
SampledTextureType::SampledTextureType(TextureDimension dim, Type* type) SampledTexture::SampledTexture(TextureDimension dim, Type* type)
: Base(dim), type_(type) { : Base(dim), type_(type) {
assert(type_); assert(type_);
} }
SampledTextureType::SampledTextureType(SampledTextureType&&) = default; SampledTexture::SampledTexture(SampledTexture&&) = default;
SampledTextureType::~SampledTextureType() = default; SampledTexture::~SampledTexture() = default;
std::string SampledTextureType::type_name() const { std::string SampledTexture::type_name() const {
std::ostringstream out; std::ostringstream out;
out << "__sampled_texture_" << dim() << type_->type_name(); out << "__sampled_texture_" << dim() << type_->type_name();
return out.str(); return out.str();

View File

@ -24,15 +24,15 @@ namespace ast {
namespace type { namespace type {
/// A sampled texture type. /// A sampled texture type.
class SampledTextureType : public Castable<SampledTextureType, TextureType> { class SampledTexture : public Castable<SampledTexture, Texture> {
public: public:
/// Constructor /// Constructor
/// @param dim the dimensionality of the texture /// @param dim the dimensionality of the texture
/// @param type the data type of the sampled texture /// @param type the data type of the sampled texture
SampledTextureType(TextureDimension dim, Type* type); SampledTexture(TextureDimension dim, Type* type);
/// Move constructor /// Move constructor
SampledTextureType(SampledTextureType&&); SampledTexture(SampledTexture&&);
~SampledTextureType() override; ~SampledTexture() override;
/// @returns the subtype of the sampled texture /// @returns the subtype of the sampled texture
Type* type() const { return type_; } Type* type() const { return type_; }

View File

@ -33,57 +33,57 @@ namespace ast {
namespace type { namespace type {
namespace { namespace {
using SampledTextureTypeTest = TestHelper; using SampledTextureTest = TestHelper;
TEST_F(SampledTextureTypeTest, Is) { TEST_F(SampledTextureTest, Is) {
F32Type f32; F32 f32;
SampledTextureType s(TextureDimension::kCube, &f32); SampledTexture s(TextureDimension::kCube, &f32);
Type* ty = &s; Type* ty = &s;
EXPECT_FALSE(ty->Is<AccessControlType>()); EXPECT_FALSE(ty->Is<AccessControl>());
EXPECT_FALSE(ty->Is<AliasType>()); EXPECT_FALSE(ty->Is<Alias>());
EXPECT_FALSE(ty->Is<ArrayType>()); EXPECT_FALSE(ty->Is<Array>());
EXPECT_FALSE(ty->Is<BoolType>()); EXPECT_FALSE(ty->Is<Bool>());
EXPECT_FALSE(ty->Is<F32Type>()); EXPECT_FALSE(ty->Is<F32>());
EXPECT_FALSE(ty->Is<I32Type>()); EXPECT_FALSE(ty->Is<I32>());
EXPECT_FALSE(ty->Is<MatrixType>()); EXPECT_FALSE(ty->Is<Matrix>());
EXPECT_FALSE(ty->Is<PointerType>()); EXPECT_FALSE(ty->Is<Pointer>());
EXPECT_FALSE(ty->Is<SamplerType>()); EXPECT_FALSE(ty->Is<Sampler>());
EXPECT_FALSE(ty->Is<StructType>()); EXPECT_FALSE(ty->Is<Struct>());
EXPECT_TRUE(ty->Is<TextureType>()); EXPECT_TRUE(ty->Is<Texture>());
EXPECT_FALSE(ty->Is<U32Type>()); EXPECT_FALSE(ty->Is<U32>());
EXPECT_FALSE(ty->Is<VectorType>()); EXPECT_FALSE(ty->Is<Vector>());
} }
TEST_F(SampledTextureTypeTest, IsTextureType) { TEST_F(SampledTextureTest, IsTexture) {
F32Type f32; F32 f32;
SampledTextureType s(TextureDimension::kCube, &f32); SampledTexture s(TextureDimension::kCube, &f32);
TextureType* ty = &s; Texture* ty = &s;
EXPECT_FALSE(ty->Is<DepthTextureType>()); EXPECT_FALSE(ty->Is<DepthTexture>());
EXPECT_TRUE(ty->Is<SampledTextureType>()); EXPECT_TRUE(ty->Is<SampledTexture>());
EXPECT_FALSE(ty->Is<StorageTextureType>()); EXPECT_FALSE(ty->Is<StorageTexture>());
} }
TEST_F(SampledTextureTypeTest, Dim) { TEST_F(SampledTextureTest, Dim) {
F32Type f32; F32 f32;
SampledTextureType s(TextureDimension::k3d, &f32); SampledTexture s(TextureDimension::k3d, &f32);
EXPECT_EQ(s.dim(), TextureDimension::k3d); EXPECT_EQ(s.dim(), TextureDimension::k3d);
} }
TEST_F(SampledTextureTypeTest, Type) { TEST_F(SampledTextureTest, Type) {
F32Type f32; F32 f32;
SampledTextureType s(TextureDimension::k3d, &f32); SampledTexture s(TextureDimension::k3d, &f32);
EXPECT_EQ(s.type(), &f32); EXPECT_EQ(s.type(), &f32);
} }
TEST_F(SampledTextureTypeTest, TypeName) { TEST_F(SampledTextureTest, TypeName) {
F32Type f32; F32 f32;
SampledTextureType s(TextureDimension::k3d, &f32); SampledTexture s(TextureDimension::k3d, &f32);
EXPECT_EQ(s.type_name(), "__sampled_texture_3d__f32"); EXPECT_EQ(s.type_name(), "__sampled_texture_3d__f32");
} }
TEST_F(SampledTextureTypeTest, MinBufferBindingSize) { TEST_F(SampledTextureTest, MinBufferBindingSize) {
F32Type f32; F32 f32;
SampledTextureType s(TextureDimension::kCube, &f32); SampledTexture s(TextureDimension::kCube, &f32);
EXPECT_EQ(0u, s.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); EXPECT_EQ(0u, s.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
} }

View File

@ -30,13 +30,13 @@ std::ostream& operator<<(std::ostream& out, SamplerKind kind) {
return out; return out;
} }
SamplerType::SamplerType(SamplerKind kind) : kind_(kind) {} Sampler::Sampler(SamplerKind kind) : kind_(kind) {}
SamplerType::SamplerType(SamplerType&&) = default; Sampler::Sampler(Sampler&&) = default;
SamplerType::~SamplerType() = default; Sampler::~Sampler() = default;
std::string SamplerType::type_name() const { std::string Sampler::type_name() const {
return std::string("__sampler_") + return std::string("__sampler_") +
(kind_ == SamplerKind::kSampler ? "sampler" : "comparison"); (kind_ == SamplerKind::kSampler ? "sampler" : "comparison");
} }

View File

@ -34,14 +34,14 @@ enum class SamplerKind {
std::ostream& operator<<(std::ostream& out, SamplerKind kind); std::ostream& operator<<(std::ostream& out, SamplerKind kind);
/// A sampler type. /// A sampler type.
class SamplerType : public Castable<SamplerType, Type> { class Sampler : public Castable<Sampler, Type> {
public: public:
/// Constructor /// Constructor
/// @param kind the kind of sampler /// @param kind the kind of sampler
explicit SamplerType(SamplerKind kind); explicit Sampler(SamplerKind kind);
/// Move constructor /// Move constructor
SamplerType(SamplerType&&); Sampler(Sampler&&);
~SamplerType() override; ~Sampler() override;
/// @returns the sampler type /// @returns the sampler type
SamplerKind kind() const { return kind_; } SamplerKind kind() const { return kind_; }

View File

@ -32,49 +32,49 @@ namespace ast {
namespace type { namespace type {
namespace { namespace {
using SamplerTypeTest = TestHelper; using SamplerTest = TestHelper;
TEST_F(SamplerTypeTest, Creation) { TEST_F(SamplerTest, Creation) {
SamplerType s{SamplerKind::kSampler}; Sampler s{SamplerKind::kSampler};
EXPECT_EQ(s.kind(), SamplerKind::kSampler); EXPECT_EQ(s.kind(), SamplerKind::kSampler);
} }
TEST_F(SamplerTypeTest, Creation_ComparisonSampler) { TEST_F(SamplerTest, Creation_ComparisonSampler) {
SamplerType s{SamplerKind::kComparisonSampler}; Sampler s{SamplerKind::kComparisonSampler};
EXPECT_EQ(s.kind(), SamplerKind::kComparisonSampler); EXPECT_EQ(s.kind(), SamplerKind::kComparisonSampler);
EXPECT_TRUE(s.IsComparison()); EXPECT_TRUE(s.IsComparison());
} }
TEST_F(SamplerTypeTest, Is) { TEST_F(SamplerTest, Is) {
SamplerType s{SamplerKind::kSampler}; Sampler s{SamplerKind::kSampler};
Type* ty = &s; Type* ty = &s;
EXPECT_FALSE(ty->Is<AccessControlType>()); EXPECT_FALSE(ty->Is<AccessControl>());
EXPECT_FALSE(ty->Is<AliasType>()); EXPECT_FALSE(ty->Is<Alias>());
EXPECT_FALSE(ty->Is<ArrayType>()); EXPECT_FALSE(ty->Is<Array>());
EXPECT_FALSE(ty->Is<BoolType>()); EXPECT_FALSE(ty->Is<Bool>());
EXPECT_FALSE(ty->Is<F32Type>()); EXPECT_FALSE(ty->Is<F32>());
EXPECT_FALSE(ty->Is<I32Type>()); EXPECT_FALSE(ty->Is<I32>());
EXPECT_FALSE(ty->Is<MatrixType>()); EXPECT_FALSE(ty->Is<Matrix>());
EXPECT_FALSE(ty->Is<PointerType>()); EXPECT_FALSE(ty->Is<Pointer>());
EXPECT_TRUE(ty->Is<SamplerType>()); EXPECT_TRUE(ty->Is<Sampler>());
EXPECT_FALSE(ty->Is<StructType>()); EXPECT_FALSE(ty->Is<Struct>());
EXPECT_FALSE(ty->Is<TextureType>()); EXPECT_FALSE(ty->Is<Texture>());
EXPECT_FALSE(ty->Is<U32Type>()); EXPECT_FALSE(ty->Is<U32>());
EXPECT_FALSE(ty->Is<VectorType>()); EXPECT_FALSE(ty->Is<Vector>());
} }
TEST_F(SamplerTypeTest, TypeName_Sampler) { TEST_F(SamplerTest, TypeName_Sampler) {
SamplerType s{SamplerKind::kSampler}; Sampler s{SamplerKind::kSampler};
EXPECT_EQ(s.type_name(), "__sampler_sampler"); EXPECT_EQ(s.type_name(), "__sampler_sampler");
} }
TEST_F(SamplerTypeTest, TypeName_Comparison) { TEST_F(SamplerTest, TypeName_Comparison) {
SamplerType s{SamplerKind::kComparisonSampler}; Sampler s{SamplerKind::kComparisonSampler};
EXPECT_EQ(s.type_name(), "__sampler_comparison"); EXPECT_EQ(s.type_name(), "__sampler_comparison");
} }
TEST_F(SamplerTypeTest, MinBufferBindingSize) { TEST_F(SamplerTest, MinBufferBindingSize) {
SamplerType s{SamplerKind::kSampler}; Sampler s{SamplerKind::kSampler};
EXPECT_EQ(0u, s.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); EXPECT_EQ(0u, s.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
} }

View File

@ -150,26 +150,26 @@ std::ostream& operator<<(std::ostream& out, ImageFormat format) {
return out; return out;
} }
StorageTextureType::StorageTextureType(TextureDimension dim, StorageTexture::StorageTexture(TextureDimension dim,
AccessControl access, ast::AccessControl access,
ImageFormat format) ImageFormat format)
: Base(dim), access_(access), image_format_(format) { : Base(dim), access_(access), image_format_(format) {
assert(IsValidStorageDimension(dim)); assert(IsValidStorageDimension(dim));
} }
void StorageTextureType::set_type(Type* const type) { void StorageTexture::set_type(Type* const type) {
type_ = type; type_ = type;
} }
Type* StorageTextureType::type() const { Type* StorageTexture::type() const {
return type_; return type_;
} }
StorageTextureType::StorageTextureType(StorageTextureType&&) = default; StorageTexture::StorageTexture(StorageTexture&&) = default;
StorageTextureType::~StorageTextureType() = default; StorageTexture::~StorageTexture() = default;
std::string StorageTextureType::type_name() const { std::string StorageTexture::type_name() const {
std::ostringstream out; std::ostringstream out;
out << "__storage_texture_" << access_ << "_" << dim() << "_" out << "__storage_texture_" << access_ << "_" << dim() << "_"
<< image_format_; << image_format_;

View File

@ -66,19 +66,19 @@ enum class ImageFormat {
std::ostream& operator<<(std::ostream& out, ImageFormat dim); std::ostream& operator<<(std::ostream& out, ImageFormat dim);
/// A storage texture type. /// A storage texture type.
class StorageTextureType : public Castable<StorageTextureType, TextureType> { class StorageTexture : public Castable<StorageTexture, Texture> {
public: public:
/// Constructor /// Constructor
/// @param dim the dimensionality of the texture /// @param dim the dimensionality of the texture
/// @param access the access type for the texture /// @param access the access type for the texture
/// @param format the image format of the texture /// @param format the image format of the texture
StorageTextureType(TextureDimension dim, StorageTexture(TextureDimension dim,
AccessControl access, ast::AccessControl access,
ImageFormat format); ImageFormat format);
/// Move constructor /// Move constructor
StorageTextureType(StorageTextureType&&); StorageTexture(StorageTexture&&);
~StorageTextureType() override; ~StorageTexture() override;
/// @param type the subtype of the storage texture /// @param type the subtype of the storage texture
void set_type(Type* const type); void set_type(Type* const type);
@ -87,7 +87,7 @@ class StorageTextureType : public Castable<StorageTextureType, TextureType> {
Type* type() const; Type* type() const;
/// @returns the storage access /// @returns the storage access
AccessControl access() const { return access_; } ast::AccessControl access() const { return access_; }
/// @returns the image format /// @returns the image format
ImageFormat image_format() const { return image_format_; } ImageFormat image_format() const { return image_format_; }
@ -97,7 +97,7 @@ class StorageTextureType : public Castable<StorageTextureType, TextureType> {
private: private:
Type* type_ = nullptr; Type* type_ = nullptr;
AccessControl access_ = AccessControl::kReadOnly; ast::AccessControl access_ = ast::AccessControl::kReadOnly;
ImageFormat image_format_ = ImageFormat::kRgba32Float; ImageFormat image_format_ = ImageFormat::kRgba32Float;
}; };

View File

@ -37,106 +37,104 @@ namespace ast {
namespace type { namespace type {
namespace { namespace {
using StorageTextureTypeTest = TestHelper; using StorageTextureTest = TestHelper;
TEST_F(StorageTextureTypeTest, Is) { TEST_F(StorageTextureTest, Is) {
StorageTextureType s(TextureDimension::k2dArray, AccessControl::kReadOnly, StorageTexture s(TextureDimension::k2dArray, ast::AccessControl::kReadOnly,
ImageFormat::kRgba32Float); ImageFormat::kRgba32Float);
Type* ty = &s; Type* ty = &s;
EXPECT_FALSE(ty->Is<AccessControlType>()); EXPECT_FALSE(ty->Is<AccessControl>());
EXPECT_FALSE(ty->Is<AliasType>()); EXPECT_FALSE(ty->Is<Alias>());
EXPECT_FALSE(ty->Is<ArrayType>()); EXPECT_FALSE(ty->Is<Array>());
EXPECT_FALSE(ty->Is<BoolType>()); EXPECT_FALSE(ty->Is<Bool>());
EXPECT_FALSE(ty->Is<F32Type>()); EXPECT_FALSE(ty->Is<F32>());
EXPECT_FALSE(ty->Is<I32Type>()); EXPECT_FALSE(ty->Is<I32>());
EXPECT_FALSE(ty->Is<MatrixType>()); EXPECT_FALSE(ty->Is<Matrix>());
EXPECT_FALSE(ty->Is<PointerType>()); EXPECT_FALSE(ty->Is<Pointer>());
EXPECT_FALSE(ty->Is<SamplerType>()); EXPECT_FALSE(ty->Is<Sampler>());
EXPECT_FALSE(ty->Is<StructType>()); EXPECT_FALSE(ty->Is<Struct>());
EXPECT_TRUE(ty->Is<TextureType>()); EXPECT_TRUE(ty->Is<Texture>());
EXPECT_FALSE(ty->Is<U32Type>()); EXPECT_FALSE(ty->Is<U32>());
EXPECT_FALSE(ty->Is<VectorType>()); EXPECT_FALSE(ty->Is<Vector>());
} }
TEST_F(StorageTextureTypeTest, IsTextureType) { TEST_F(StorageTextureTest, IsTexture) {
StorageTextureType s(TextureDimension::k2dArray, AccessControl::kReadOnly, StorageTexture s(TextureDimension::k2dArray, ast::AccessControl::kReadOnly,
ImageFormat::kRgba32Float); ImageFormat::kRgba32Float);
TextureType* ty = &s; Texture* ty = &s;
EXPECT_FALSE(ty->Is<DepthTextureType>()); EXPECT_FALSE(ty->Is<DepthTexture>());
EXPECT_FALSE(ty->Is<SampledTextureType>()); EXPECT_FALSE(ty->Is<SampledTexture>());
EXPECT_TRUE(ty->Is<StorageTextureType>()); EXPECT_TRUE(ty->Is<StorageTexture>());
} }
TEST_F(StorageTextureTypeTest, Dim) { TEST_F(StorageTextureTest, Dim) {
StorageTextureType s(TextureDimension::k2dArray, AccessControl::kReadOnly, StorageTexture s(TextureDimension::k2dArray, ast::AccessControl::kReadOnly,
ImageFormat::kRgba32Float); ImageFormat::kRgba32Float);
EXPECT_EQ(s.dim(), TextureDimension::k2dArray); EXPECT_EQ(s.dim(), TextureDimension::k2dArray);
} }
TEST_F(StorageTextureTypeTest, Access) { TEST_F(StorageTextureTest, Access) {
StorageTextureType s(TextureDimension::k2dArray, AccessControl::kReadOnly, StorageTexture s(TextureDimension::k2dArray, ast::AccessControl::kReadOnly,
ImageFormat::kRgba32Float); ImageFormat::kRgba32Float);
EXPECT_EQ(s.access(), AccessControl::kReadOnly); EXPECT_EQ(s.access(), ast::AccessControl::kReadOnly);
} }
TEST_F(StorageTextureTypeTest, Format) { TEST_F(StorageTextureTest, Format) {
StorageTextureType s(TextureDimension::k2dArray, AccessControl::kReadOnly, StorageTexture s(TextureDimension::k2dArray, ast::AccessControl::kReadOnly,
ImageFormat::kRgba32Float); ImageFormat::kRgba32Float);
EXPECT_EQ(s.image_format(), ImageFormat::kRgba32Float); EXPECT_EQ(s.image_format(), ImageFormat::kRgba32Float);
} }
TEST_F(StorageTextureTypeTest, TypeName) { TEST_F(StorageTextureTest, TypeName) {
StorageTextureType s(TextureDimension::k2dArray, AccessControl::kReadOnly, StorageTexture s(TextureDimension::k2dArray, ast::AccessControl::kReadOnly,
ImageFormat::kRgba32Float); ImageFormat::kRgba32Float);
EXPECT_EQ(s.type_name(), "__storage_texture_read_only_2d_array_rgba32float"); EXPECT_EQ(s.type_name(), "__storage_texture_read_only_2d_array_rgba32float");
} }
TEST_F(StorageTextureTypeTest, F32Type) { TEST_F(StorageTextureTest, F32) {
Context ctx; Context ctx;
Module mod; Module mod;
Type* s = mod.create<StorageTextureType>(TextureDimension::k2dArray, Type* s = mod.create<StorageTexture>(TextureDimension::k2dArray,
AccessControl::kReadOnly, ast::AccessControl::kReadOnly,
ImageFormat::kRgba32Float); ImageFormat::kRgba32Float);
TypeDeterminer td(&ctx, &mod); TypeDeterminer td(&ctx, &mod);
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(s->Is<TextureType>()); ASSERT_TRUE(s->Is<Texture>());
ASSERT_TRUE(s->Is<StorageTextureType>()); ASSERT_TRUE(s->Is<StorageTexture>());
EXPECT_TRUE( EXPECT_TRUE(s->As<Texture>()->As<StorageTexture>()->type()->Is<F32>());
s->As<TextureType>()->As<StorageTextureType>()->type()->Is<F32Type>());
} }
TEST_F(StorageTextureTypeTest, U32Type) { TEST_F(StorageTextureTest, U32) {
Context ctx; Context ctx;
Module mod; Module mod;
Type* s = mod.create<StorageTextureType>(TextureDimension::k2dArray, Type* s = mod.create<StorageTexture>(TextureDimension::k2dArray,
AccessControl::kReadOnly, ast::AccessControl::kReadOnly,
ImageFormat::kRg32Uint); ImageFormat::kRg32Uint);
TypeDeterminer td(&ctx, &mod); TypeDeterminer td(&ctx, &mod);
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(s->Is<TextureType>()); ASSERT_TRUE(s->Is<Texture>());
ASSERT_TRUE(s->Is<StorageTextureType>()); ASSERT_TRUE(s->Is<StorageTexture>());
EXPECT_TRUE(s->As<StorageTextureType>()->type()->Is<U32Type>()); EXPECT_TRUE(s->As<StorageTexture>()->type()->Is<U32>());
} }
TEST_F(StorageTextureTypeTest, I32Type) { TEST_F(StorageTextureTest, I32) {
Context ctx; Context ctx;
Module mod; Module mod;
Type* s = mod.create<StorageTextureType>(TextureDimension::k2dArray, Type* s = mod.create<StorageTexture>(TextureDimension::k2dArray,
AccessControl::kReadOnly, ast::AccessControl::kReadOnly,
ImageFormat::kRgba32Sint); ImageFormat::kRgba32Sint);
TypeDeterminer td(&ctx, &mod); TypeDeterminer td(&ctx, &mod);
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(s->Is<TextureType>()); ASSERT_TRUE(s->Is<Texture>());
ASSERT_TRUE(s->Is<StorageTextureType>()); ASSERT_TRUE(s->Is<StorageTexture>());
EXPECT_TRUE( EXPECT_TRUE(s->As<Texture>()->As<StorageTexture>()->type()->Is<I32>());
s->As<TextureType>()->As<StorageTextureType>()->type()->Is<I32Type>());
} }
TEST_F(StorageTextureTypeTest, MinBufferBindingSize) { TEST_F(StorageTextureTest, MinBufferBindingSize) {
StorageTextureType s(TextureDimension::k2dArray, AccessControl::kReadOnly, StorageTexture s(TextureDimension::k2dArray, ast::AccessControl::kReadOnly,
ImageFormat::kRgba32Sint); ImageFormat::kRgba32Sint);
EXPECT_EQ(0u, s.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); EXPECT_EQ(0u, s.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
} }

View File

@ -26,18 +26,18 @@ namespace tint {
namespace ast { namespace ast {
namespace type { namespace type {
StructType::StructType(const std::string& name, Struct* impl) Struct::Struct(const std::string& name, ast::Struct* impl)
: name_(name), struct_(impl) {} : name_(name), struct_(impl) {}
StructType::StructType(StructType&&) = default; Struct::Struct(Struct&&) = default;
StructType::~StructType() = default; Struct::~Struct() = default;
std::string StructType::type_name() const { std::string Struct::type_name() const {
return "__struct_" + name_; return "__struct_" + name_;
} }
uint64_t StructType::MinBufferBindingSize(MemoryLayout mem_layout) const { uint64_t Struct::MinBufferBindingSize(MemoryLayout mem_layout) const {
if (!struct_->members().size()) { if (!struct_->members().size()) {
return 0; return 0;
} }
@ -61,7 +61,7 @@ uint64_t StructType::MinBufferBindingSize(MemoryLayout mem_layout) const {
return static_cast<uint64_t>(alignment * std::ceil(unaligned / alignment)); return static_cast<uint64_t>(alignment * std::ceil(unaligned / alignment));
} }
uint64_t StructType::BaseAlignment(MemoryLayout mem_layout) const { uint64_t Struct::BaseAlignment(MemoryLayout mem_layout) const {
uint64_t max = 0; uint64_t max = 0;
for (auto* member : struct_->members()) { for (auto* member : struct_->members()) {
if (member->type()->BaseAlignment(mem_layout) > max) { if (member->type()->BaseAlignment(mem_layout) > max) {

View File

@ -26,15 +26,15 @@ namespace ast {
namespace type { namespace type {
/// A structure type /// A structure type
class StructType : public Castable<StructType, Type> { class Struct : public Castable<Struct, Type> {
public: public:
/// Constructor /// Constructor
/// @param name the name of the struct /// @param name the name of the struct
/// @param impl the struct data /// @param impl the struct data
StructType(const std::string& name, Struct* impl); Struct(const std::string& name, ast::Struct* impl);
/// Move constructor /// Move constructor
StructType(StructType&&); Struct(Struct&&);
~StructType() override; ~Struct() override;
/// @returns the struct name /// @returns the struct name
const std::string& name() const { return name_; } const std::string& name() const { return name_; }
@ -43,7 +43,7 @@ class StructType : public Castable<StructType, Type> {
bool IsBlockDecorated() const { return struct_->IsBlockDecorated(); } bool IsBlockDecorated() const { return struct_->IsBlockDecorated(); }
/// @returns the struct name /// @returns the struct name
Struct* impl() const { return struct_; } ast::Struct* impl() const { return struct_; }
/// @returns the name for the type /// @returns the name for the type
std::string type_name() const override; std::string type_name() const override;
@ -60,7 +60,7 @@ class StructType : public Castable<StructType, Type> {
private: private:
std::string name_; std::string name_;
Struct* struct_ = nullptr; ast::Struct* struct_ = nullptr;
uint64_t LargestMemberBaseAlignment(MemoryLayout mem_layout) const; uint64_t LargestMemberBaseAlignment(MemoryLayout mem_layout) const;
}; };

View File

@ -37,42 +37,42 @@ namespace ast {
namespace type { namespace type {
namespace { namespace {
using StructTypeTest = TestHelper; using StructTest = TestHelper;
TEST_F(StructTypeTest, Creation) { TEST_F(StructTest, Creation) {
auto* impl = create<Struct>(); auto* impl = create<ast::Struct>();
auto* ptr = impl; auto* ptr = impl;
StructType s{"S", impl}; Struct s{"S", impl};
EXPECT_EQ(s.impl(), ptr); EXPECT_EQ(s.impl(), ptr);
} }
TEST_F(StructTypeTest, Is) { TEST_F(StructTest, Is) {
auto* impl = create<Struct>(); auto* impl = create<ast::Struct>();
StructType s{"S", impl}; Struct s{"S", impl};
Type* ty = &s; Type* ty = &s;
EXPECT_FALSE(ty->Is<AccessControlType>()); EXPECT_FALSE(ty->Is<AccessControl>());
EXPECT_FALSE(ty->Is<AliasType>()); EXPECT_FALSE(ty->Is<Alias>());
EXPECT_FALSE(ty->Is<ArrayType>()); EXPECT_FALSE(ty->Is<Array>());
EXPECT_FALSE(ty->Is<BoolType>()); EXPECT_FALSE(ty->Is<Bool>());
EXPECT_FALSE(ty->Is<F32Type>()); EXPECT_FALSE(ty->Is<F32>());
EXPECT_FALSE(ty->Is<I32Type>()); EXPECT_FALSE(ty->Is<I32>());
EXPECT_FALSE(ty->Is<MatrixType>()); EXPECT_FALSE(ty->Is<Matrix>());
EXPECT_FALSE(ty->Is<PointerType>()); EXPECT_FALSE(ty->Is<Pointer>());
EXPECT_FALSE(ty->Is<SamplerType>()); EXPECT_FALSE(ty->Is<Sampler>());
EXPECT_TRUE(ty->Is<StructType>()); EXPECT_TRUE(ty->Is<Struct>());
EXPECT_FALSE(ty->Is<TextureType>()); EXPECT_FALSE(ty->Is<Texture>());
EXPECT_FALSE(ty->Is<U32Type>()); EXPECT_FALSE(ty->Is<U32>());
EXPECT_FALSE(ty->Is<VectorType>()); EXPECT_FALSE(ty->Is<Vector>());
} }
TEST_F(StructTypeTest, TypeName) { TEST_F(StructTest, TypeName) {
auto* impl = create<Struct>(); auto* impl = create<ast::Struct>();
StructType s{"my_struct", impl}; Struct s{"my_struct", impl};
EXPECT_EQ(s.type_name(), "__struct_my_struct"); EXPECT_EQ(s.type_name(), "__struct_my_struct");
} }
TEST_F(StructTypeTest, MinBufferBindingSize) { TEST_F(StructTest, MinBufferBindingSize) {
U32Type u32; U32 u32;
StructMemberList members; StructMemberList members;
{ {
@ -87,16 +87,16 @@ TEST_F(StructTypeTest, MinBufferBindingSize) {
} }
StructDecorationList decos; StructDecorationList decos;
auto* str = create<Struct>(decos, members); auto* str = create<ast::Struct>(decos, members);
StructType struct_type("struct_type", str); Struct struct_type("struct_type", str);
EXPECT_EQ(16u, EXPECT_EQ(16u,
struct_type.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); struct_type.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
EXPECT_EQ(8u, struct_type.MinBufferBindingSize(MemoryLayout::kStorageBuffer)); EXPECT_EQ(8u, struct_type.MinBufferBindingSize(MemoryLayout::kStorageBuffer));
} }
TEST_F(StructTypeTest, MinBufferBindingSizeArray) { TEST_F(StructTest, MinBufferBindingSizeArray) {
U32Type u32; U32 u32;
ArrayType arr(&u32, 4); Array arr(&u32, 4);
{ {
ArrayDecorationList decos; ArrayDecorationList decos;
decos.push_back(create<StrideDecoration>(4, Source{})); decos.push_back(create<StrideDecoration>(4, Source{}));
@ -121,17 +121,17 @@ TEST_F(StructTypeTest, MinBufferBindingSizeArray) {
} }
StructDecorationList decos; StructDecorationList decos;
auto* str = create<Struct>(decos, members); auto* str = create<ast::Struct>(decos, members);
StructType struct_type("struct_type", str); Struct struct_type("struct_type", str);
EXPECT_EQ(32u, EXPECT_EQ(32u,
struct_type.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); struct_type.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
EXPECT_EQ(24u, EXPECT_EQ(24u,
struct_type.MinBufferBindingSize(MemoryLayout::kStorageBuffer)); struct_type.MinBufferBindingSize(MemoryLayout::kStorageBuffer));
} }
TEST_F(StructTypeTest, MinBufferBindingSizeRuntimeArray) { TEST_F(StructTest, MinBufferBindingSizeRuntimeArray) {
U32Type u32; U32 u32;
ArrayType arr(&u32); Array arr(&u32);
{ {
ArrayDecorationList decos; ArrayDecorationList decos;
decos.push_back(create<StrideDecoration>(4, Source{})); decos.push_back(create<StrideDecoration>(4, Source{}));
@ -156,15 +156,15 @@ TEST_F(StructTypeTest, MinBufferBindingSizeRuntimeArray) {
} }
StructDecorationList decos; StructDecorationList decos;
auto* str = create<Struct>(decos, members); auto* str = create<ast::Struct>(decos, members);
StructType struct_type("struct_type", str); Struct struct_type("struct_type", str);
EXPECT_EQ(12u, EXPECT_EQ(12u,
struct_type.MinBufferBindingSize(MemoryLayout::kStorageBuffer)); struct_type.MinBufferBindingSize(MemoryLayout::kStorageBuffer));
} }
TEST_F(StructTypeTest, MinBufferBindingSizeVec2) { TEST_F(StructTest, MinBufferBindingSizeVec2) {
U32Type u32; U32 u32;
VectorType vec2(&u32, 2); Vector vec2(&u32, 2);
StructMemberList members; StructMemberList members;
{ {
@ -174,16 +174,16 @@ TEST_F(StructTypeTest, MinBufferBindingSizeVec2) {
} }
StructDecorationList decos; StructDecorationList decos;
auto* str = create<Struct>(decos, members); auto* str = create<ast::Struct>(decos, members);
StructType struct_type("struct_type", str); Struct struct_type("struct_type", str);
EXPECT_EQ(16u, EXPECT_EQ(16u,
struct_type.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); struct_type.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
EXPECT_EQ(8u, struct_type.MinBufferBindingSize(MemoryLayout::kStorageBuffer)); EXPECT_EQ(8u, struct_type.MinBufferBindingSize(MemoryLayout::kStorageBuffer));
} }
TEST_F(StructTypeTest, MinBufferBindingSizeVec3) { TEST_F(StructTest, MinBufferBindingSizeVec3) {
U32Type u32; U32 u32;
VectorType vec3(&u32, 3); Vector vec3(&u32, 3);
StructMemberList members; StructMemberList members;
{ {
@ -193,17 +193,17 @@ TEST_F(StructTypeTest, MinBufferBindingSizeVec3) {
} }
StructDecorationList decos; StructDecorationList decos;
auto* str = create<Struct>(decos, members); auto* str = create<ast::Struct>(decos, members);
StructType struct_type("struct_type", str); Struct struct_type("struct_type", str);
EXPECT_EQ(16u, EXPECT_EQ(16u,
struct_type.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); struct_type.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
EXPECT_EQ(16u, EXPECT_EQ(16u,
struct_type.MinBufferBindingSize(MemoryLayout::kStorageBuffer)); struct_type.MinBufferBindingSize(MemoryLayout::kStorageBuffer));
} }
TEST_F(StructTypeTest, MinBufferBindingSizeVec4) { TEST_F(StructTest, MinBufferBindingSizeVec4) {
U32Type u32; U32 u32;
VectorType vec4(&u32, 4); Vector vec4(&u32, 4);
StructMemberList members; StructMemberList members;
{ {
@ -213,16 +213,16 @@ TEST_F(StructTypeTest, MinBufferBindingSizeVec4) {
} }
StructDecorationList decos; StructDecorationList decos;
auto* str = create<Struct>(decos, members); auto* str = create<ast::Struct>(decos, members);
StructType struct_type("struct_type", str); Struct struct_type("struct_type", str);
EXPECT_EQ(16u, EXPECT_EQ(16u,
struct_type.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); struct_type.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
EXPECT_EQ(16u, EXPECT_EQ(16u,
struct_type.MinBufferBindingSize(MemoryLayout::kStorageBuffer)); struct_type.MinBufferBindingSize(MemoryLayout::kStorageBuffer));
} }
TEST_F(StructTypeTest, BaseAlignment) { TEST_F(StructTest, BaseAlignment) {
U32Type u32; U32 u32;
StructMemberList members; StructMemberList members;
{ {
@ -237,15 +237,15 @@ TEST_F(StructTypeTest, BaseAlignment) {
} }
StructDecorationList decos; StructDecorationList decos;
auto* str = create<Struct>(decos, members); auto* str = create<ast::Struct>(decos, members);
StructType struct_type("struct_type", str); Struct struct_type("struct_type", str);
EXPECT_EQ(16u, struct_type.BaseAlignment(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, struct_type.BaseAlignment(MemoryLayout::kUniformBuffer));
EXPECT_EQ(4u, struct_type.BaseAlignment(MemoryLayout::kStorageBuffer)); EXPECT_EQ(4u, struct_type.BaseAlignment(MemoryLayout::kStorageBuffer));
} }
TEST_F(StructTypeTest, BaseAlignmentArray) { TEST_F(StructTest, BaseAlignmentArray) {
U32Type u32; U32 u32;
ArrayType arr(&u32, 4); Array arr(&u32, 4);
{ {
ArrayDecorationList decos; ArrayDecorationList decos;
decos.push_back(create<StrideDecoration>(4, Source{})); decos.push_back(create<StrideDecoration>(4, Source{}));
@ -270,15 +270,15 @@ TEST_F(StructTypeTest, BaseAlignmentArray) {
} }
StructDecorationList decos; StructDecorationList decos;
auto* str = create<Struct>(decos, members); auto* str = create<ast::Struct>(decos, members);
StructType struct_type("struct_type", str); Struct struct_type("struct_type", str);
EXPECT_EQ(16u, struct_type.BaseAlignment(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, struct_type.BaseAlignment(MemoryLayout::kUniformBuffer));
EXPECT_EQ(4u, struct_type.BaseAlignment(MemoryLayout::kStorageBuffer)); EXPECT_EQ(4u, struct_type.BaseAlignment(MemoryLayout::kStorageBuffer));
} }
TEST_F(StructTypeTest, BaseAlignmentRuntimeArray) { TEST_F(StructTest, BaseAlignmentRuntimeArray) {
U32Type u32; U32 u32;
ArrayType arr(&u32); Array arr(&u32);
{ {
ArrayDecorationList decos; ArrayDecorationList decos;
decos.push_back(create<StrideDecoration>(4, Source{})); decos.push_back(create<StrideDecoration>(4, Source{}));
@ -303,14 +303,14 @@ TEST_F(StructTypeTest, BaseAlignmentRuntimeArray) {
} }
StructDecorationList decos; StructDecorationList decos;
auto* str = create<Struct>(decos, members); auto* str = create<ast::Struct>(decos, members);
StructType struct_type("struct_type", str); Struct struct_type("struct_type", str);
EXPECT_EQ(4u, struct_type.BaseAlignment(MemoryLayout::kStorageBuffer)); EXPECT_EQ(4u, struct_type.BaseAlignment(MemoryLayout::kStorageBuffer));
} }
TEST_F(StructTypeTest, BaseAlignmentVec2) { TEST_F(StructTest, BaseAlignmentVec2) {
U32Type u32; U32 u32;
VectorType vec2(&u32, 2); Vector vec2(&u32, 2);
StructMemberList members; StructMemberList members;
{ {
@ -320,15 +320,15 @@ TEST_F(StructTypeTest, BaseAlignmentVec2) {
} }
StructDecorationList decos; StructDecorationList decos;
auto* str = create<Struct>(decos, members); auto* str = create<ast::Struct>(decos, members);
StructType struct_type("struct_type", str); Struct struct_type("struct_type", str);
EXPECT_EQ(16u, struct_type.BaseAlignment(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, struct_type.BaseAlignment(MemoryLayout::kUniformBuffer));
EXPECT_EQ(8u, struct_type.BaseAlignment(MemoryLayout::kStorageBuffer)); EXPECT_EQ(8u, struct_type.BaseAlignment(MemoryLayout::kStorageBuffer));
} }
TEST_F(StructTypeTest, BaseAlignmentVec3) { TEST_F(StructTest, BaseAlignmentVec3) {
U32Type u32; U32 u32;
VectorType vec3(&u32, 3); Vector vec3(&u32, 3);
StructMemberList members; StructMemberList members;
{ {
@ -338,15 +338,15 @@ TEST_F(StructTypeTest, BaseAlignmentVec3) {
} }
StructDecorationList decos; StructDecorationList decos;
auto* str = create<Struct>(decos, members); auto* str = create<ast::Struct>(decos, members);
StructType struct_type("struct_type", str); Struct struct_type("struct_type", str);
EXPECT_EQ(16u, struct_type.BaseAlignment(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, struct_type.BaseAlignment(MemoryLayout::kUniformBuffer));
EXPECT_EQ(16u, struct_type.BaseAlignment(MemoryLayout::kStorageBuffer)); EXPECT_EQ(16u, struct_type.BaseAlignment(MemoryLayout::kStorageBuffer));
} }
TEST_F(StructTypeTest, BaseAlignmentVec4) { TEST_F(StructTest, BaseAlignmentVec4) {
U32Type u32; U32 u32;
VectorType vec4(&u32, 4); Vector vec4(&u32, 4);
StructMemberList members; StructMemberList members;
{ {
@ -356,8 +356,8 @@ TEST_F(StructTypeTest, BaseAlignmentVec4) {
} }
StructDecorationList decos; StructDecorationList decos;
auto* str = create<Struct>(decos, members); auto* str = create<ast::Struct>(decos, members);
StructType struct_type("struct_type", str); Struct struct_type("struct_type", str);
EXPECT_EQ(16u, struct_type.BaseAlignment(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, struct_type.BaseAlignment(MemoryLayout::kUniformBuffer));
EXPECT_EQ(16u, struct_type.BaseAlignment(MemoryLayout::kStorageBuffer)); EXPECT_EQ(16u, struct_type.BaseAlignment(MemoryLayout::kStorageBuffer));
} }

View File

@ -53,11 +53,11 @@ std::ostream& operator<<(std::ostream& out, TextureDimension dim) {
return out; return out;
} }
TextureType::TextureType(TextureDimension dim) : dim_(dim) {} Texture::Texture(TextureDimension dim) : dim_(dim) {}
TextureType::TextureType(TextureType&&) = default; Texture::Texture(Texture&&) = default;
TextureType::~TextureType() = default; Texture::~Texture() = default;
} // namespace type } // namespace type
} // namespace ast } // namespace ast

View File

@ -46,14 +46,14 @@ enum class TextureDimension {
std::ostream& operator<<(std::ostream& out, TextureDimension dim); std::ostream& operator<<(std::ostream& out, TextureDimension dim);
/// A texture type. /// A texture type.
class TextureType : public Castable<TextureType, Type> { class Texture : public Castable<Texture, Type> {
public: public:
/// Constructor /// Constructor
/// @param dim the dimensionality of the texture /// @param dim the dimensionality of the texture
explicit TextureType(TextureDimension dim); explicit Texture(TextureDimension dim);
/// Move constructor /// Move constructor
TextureType(TextureType&&); Texture(Texture&&);
~TextureType() override; ~Texture() override;
/// @returns the texture dimension /// @returns the texture dimension
TextureDimension dim() const { return dim_; } TextureDimension dim() const { return dim_; }

View File

@ -42,8 +42,8 @@ Type::Type(Type&&) = default;
Type::~Type() = default; Type::~Type() = default;
Type* Type::UnwrapPtrIfNeeded() { Type* Type::UnwrapPtrIfNeeded() {
if (Is<PointerType>()) { if (Is<Pointer>()) {
return As<PointerType>()->type(); return As<Pointer>()->type();
} }
return this; return this;
} }
@ -51,10 +51,10 @@ Type* Type::UnwrapPtrIfNeeded() {
Type* Type::UnwrapIfNeeded() { Type* Type::UnwrapIfNeeded() {
auto* where = this; auto* where = this;
while (true) { while (true) {
if (where->Is<AliasType>()) { if (where->Is<Alias>()) {
where = where->As<AliasType>()->type(); where = where->As<Alias>()->type();
} else if (where->Is<AccessControlType>()) { } else if (where->Is<AccessControl>()) {
where = where->As<AccessControlType>()->type(); where = where->As<AccessControl>()->type();
} else { } else {
break; break;
} }
@ -75,19 +75,19 @@ uint64_t Type::BaseAlignment(MemoryLayout) const {
} }
bool Type::is_scalar() { bool Type::is_scalar() {
return is_float_scalar() || is_integer_scalar() || Is<BoolType>(); return is_float_scalar() || is_integer_scalar() || Is<Bool>();
} }
bool Type::is_float_scalar() { bool Type::is_float_scalar() {
return Is<F32Type>(); return Is<F32>();
} }
bool Type::is_float_matrix() { bool Type::is_float_matrix() {
return Is<MatrixType>() && As<MatrixType>()->type()->is_float_scalar(); return Is<Matrix>() && As<Matrix>()->type()->is_float_scalar();
} }
bool Type::is_float_vector() { bool Type::is_float_vector() {
return Is<VectorType>() && As<VectorType>()->type()->is_float_scalar(); return Is<Vector>() && As<Vector>()->type()->is_float_scalar();
} }
bool Type::is_float_scalar_or_vector() { bool Type::is_float_scalar_or_vector() {
@ -95,25 +95,23 @@ bool Type::is_float_scalar_or_vector() {
} }
bool Type::is_integer_scalar() { bool Type::is_integer_scalar() {
return Is<U32Type>() || Is<I32Type>(); return Is<U32>() || Is<I32>();
} }
bool Type::is_unsigned_integer_vector() { bool Type::is_unsigned_integer_vector() {
return Is<VectorType>() && As<VectorType>()->type()->Is<U32Type>(); return Is<Vector>() && As<Vector>()->type()->Is<U32>();
} }
bool Type::is_signed_integer_vector() { bool Type::is_signed_integer_vector() {
return Is<VectorType>() && As<VectorType>()->type()->Is<I32Type>(); return Is<Vector>() && As<Vector>()->type()->Is<I32>();
} }
bool Type::is_unsigned_scalar_or_vector() { bool Type::is_unsigned_scalar_or_vector() {
return Is<U32Type>() || return Is<U32>() || (Is<Vector>() && As<Vector>()->type()->Is<U32>());
(Is<VectorType>() && As<VectorType>()->type()->Is<U32Type>());
} }
bool Type::is_signed_scalar_or_vector() { bool Type::is_signed_scalar_or_vector() {
return Is<I32Type>() || return Is<I32>() || (Is<Vector>() && As<Vector>()->type()->Is<I32>());
(Is<VectorType>() && As<VectorType>()->type()->Is<I32Type>());
} }
bool Type::is_integer_scalar_or_vector() { bool Type::is_integer_scalar_or_vector() {

View File

@ -18,21 +18,21 @@ namespace tint {
namespace ast { namespace ast {
namespace type { namespace type {
U32Type::U32Type() = default; U32::U32() = default;
U32Type::~U32Type() = default; U32::~U32() = default;
U32Type::U32Type(U32Type&&) = default; U32::U32(U32&&) = default;
std::string U32Type::type_name() const { std::string U32::type_name() const {
return "__u32"; return "__u32";
} }
uint64_t U32Type::MinBufferBindingSize(MemoryLayout) const { uint64_t U32::MinBufferBindingSize(MemoryLayout) const {
return 4; return 4;
} }
uint64_t U32Type::BaseAlignment(MemoryLayout) const { uint64_t U32::BaseAlignment(MemoryLayout) const {
return 4; return 4;
} }

View File

@ -24,13 +24,13 @@ namespace ast {
namespace type { namespace type {
/// A unsigned int 32 type. /// A unsigned int 32 type.
class U32Type : public Castable<U32Type, Type> { class U32 : public Castable<U32, Type> {
public: public:
/// Constructor /// Constructor
U32Type(); U32();
/// Move constructor /// Move constructor
U32Type(U32Type&&); U32(U32&&);
~U32Type() override; ~U32() override;
/// @returns the name for th type /// @returns the name for th type
std::string type_name() const override; std::string type_name() const override;

View File

@ -32,38 +32,38 @@ namespace ast {
namespace type { namespace type {
namespace { namespace {
using U32TypeTest = TestHelper; using U32Test = TestHelper;
TEST_F(U32TypeTest, Is) { TEST_F(U32Test, Is) {
U32Type u; U32 u;
Type* ty = &u; Type* ty = &u;
EXPECT_FALSE(ty->Is<AccessControlType>()); EXPECT_FALSE(ty->Is<AccessControl>());
EXPECT_FALSE(ty->Is<AliasType>()); EXPECT_FALSE(ty->Is<Alias>());
EXPECT_FALSE(ty->Is<ArrayType>()); EXPECT_FALSE(ty->Is<Array>());
EXPECT_FALSE(ty->Is<BoolType>()); EXPECT_FALSE(ty->Is<Bool>());
EXPECT_FALSE(ty->Is<F32Type>()); EXPECT_FALSE(ty->Is<F32>());
EXPECT_FALSE(ty->Is<I32Type>()); EXPECT_FALSE(ty->Is<I32>());
EXPECT_FALSE(ty->Is<MatrixType>()); EXPECT_FALSE(ty->Is<Matrix>());
EXPECT_FALSE(ty->Is<PointerType>()); EXPECT_FALSE(ty->Is<Pointer>());
EXPECT_FALSE(ty->Is<SamplerType>()); EXPECT_FALSE(ty->Is<Sampler>());
EXPECT_FALSE(ty->Is<StructType>()); EXPECT_FALSE(ty->Is<Struct>());
EXPECT_FALSE(ty->Is<TextureType>()); EXPECT_FALSE(ty->Is<Texture>());
EXPECT_TRUE(ty->Is<U32Type>()); EXPECT_TRUE(ty->Is<U32>());
EXPECT_FALSE(ty->Is<VectorType>()); EXPECT_FALSE(ty->Is<Vector>());
} }
TEST_F(U32TypeTest, TypeName) { TEST_F(U32Test, TypeName) {
U32Type u; U32 u;
EXPECT_EQ(u.type_name(), "__u32"); EXPECT_EQ(u.type_name(), "__u32");
} }
TEST_F(U32TypeTest, MinBufferBindingSize) { TEST_F(U32Test, MinBufferBindingSize) {
U32Type u; U32 u;
EXPECT_EQ(4u, u.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); EXPECT_EQ(4u, u.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
} }
TEST_F(U32TypeTest, BaseAlignment) { TEST_F(U32Test, BaseAlignment) {
U32Type u; U32 u;
EXPECT_EQ(4u, u.BaseAlignment(MemoryLayout::kUniformBuffer)); EXPECT_EQ(4u, u.BaseAlignment(MemoryLayout::kUniformBuffer));
} }

View File

@ -21,25 +21,24 @@ namespace tint {
namespace ast { namespace ast {
namespace type { namespace type {
VectorType::VectorType(Type* subtype, uint32_t size) Vector::Vector(Type* subtype, uint32_t size) : subtype_(subtype), size_(size) {
: subtype_(subtype), size_(size) {
assert(size_ > 1); assert(size_ > 1);
assert(size_ < 5); assert(size_ < 5);
} }
VectorType::VectorType(VectorType&&) = default; Vector::Vector(Vector&&) = default;
VectorType::~VectorType() = default; Vector::~Vector() = default;
std::string VectorType::type_name() const { std::string Vector::type_name() const {
return "__vec_" + std::to_string(size_) + subtype_->type_name(); return "__vec_" + std::to_string(size_) + subtype_->type_name();
} }
uint64_t VectorType::MinBufferBindingSize(MemoryLayout mem_layout) const { uint64_t Vector::MinBufferBindingSize(MemoryLayout mem_layout) const {
return size_ * subtype_->MinBufferBindingSize(mem_layout); return size_ * subtype_->MinBufferBindingSize(mem_layout);
} }
uint64_t VectorType::BaseAlignment(MemoryLayout mem_layout) const { uint64_t Vector::BaseAlignment(MemoryLayout mem_layout) const {
if (size_ == 2) { if (size_ == 2) {
return 2 * subtype_->BaseAlignment(mem_layout); return 2 * subtype_->BaseAlignment(mem_layout);
} else if (size_ == 3 || size_ == 4) { } else if (size_ == 3 || size_ == 4) {

View File

@ -24,15 +24,15 @@ namespace ast {
namespace type { namespace type {
/// A vector type. /// A vector type.
class VectorType : public Castable<VectorType, Type> { class Vector : public Castable<Vector, Type> {
public: public:
/// Constructor /// Constructor
/// @param subtype the vector element type /// @param subtype the vector element type
/// @param size the number of elements in the vector /// @param size the number of elements in the vector
VectorType(Type* subtype, uint32_t size); Vector(Type* subtype, uint32_t size);
/// Move constructor /// Move constructor
VectorType(VectorType&&); Vector(Vector&&);
~VectorType() override; ~Vector() override;
/// @returns the type of the vector elements /// @returns the type of the vector elements
Type* type() const { return subtype_; } Type* type() const { return subtype_; }

View File

@ -31,73 +31,73 @@ namespace ast {
namespace type { namespace type {
namespace { namespace {
using VectorTypeTest = TestHelper; using VectorTest = TestHelper;
TEST_F(VectorTypeTest, Creation) { TEST_F(VectorTest, Creation) {
I32Type i32; I32 i32;
VectorType v{&i32, 2}; Vector v{&i32, 2};
EXPECT_EQ(v.type(), &i32); EXPECT_EQ(v.type(), &i32);
EXPECT_EQ(v.size(), 2u); EXPECT_EQ(v.size(), 2u);
} }
TEST_F(VectorTypeTest, Is) { TEST_F(VectorTest, Is) {
I32Type i32; I32 i32;
VectorType v{&i32, 4}; Vector v{&i32, 4};
Type* ty = &v; Type* ty = &v;
EXPECT_FALSE(ty->Is<AccessControlType>()); EXPECT_FALSE(ty->Is<AccessControl>());
EXPECT_FALSE(ty->Is<AliasType>()); EXPECT_FALSE(ty->Is<Alias>());
EXPECT_FALSE(ty->Is<ArrayType>()); EXPECT_FALSE(ty->Is<Array>());
EXPECT_FALSE(ty->Is<BoolType>()); EXPECT_FALSE(ty->Is<Bool>());
EXPECT_FALSE(ty->Is<F32Type>()); EXPECT_FALSE(ty->Is<F32>());
EXPECT_FALSE(ty->Is<I32Type>()); EXPECT_FALSE(ty->Is<I32>());
EXPECT_FALSE(ty->Is<MatrixType>()); EXPECT_FALSE(ty->Is<Matrix>());
EXPECT_FALSE(ty->Is<PointerType>()); EXPECT_FALSE(ty->Is<Pointer>());
EXPECT_FALSE(ty->Is<SamplerType>()); EXPECT_FALSE(ty->Is<Sampler>());
EXPECT_FALSE(ty->Is<StructType>()); EXPECT_FALSE(ty->Is<Struct>());
EXPECT_FALSE(ty->Is<TextureType>()); EXPECT_FALSE(ty->Is<Texture>());
EXPECT_FALSE(ty->Is<U32Type>()); EXPECT_FALSE(ty->Is<U32>());
EXPECT_TRUE(ty->Is<VectorType>()); EXPECT_TRUE(ty->Is<Vector>());
} }
TEST_F(VectorTypeTest, TypeName) { TEST_F(VectorTest, TypeName) {
I32Type i32; I32 i32;
VectorType v{&i32, 3}; Vector v{&i32, 3};
EXPECT_EQ(v.type_name(), "__vec_3__i32"); EXPECT_EQ(v.type_name(), "__vec_3__i32");
} }
TEST_F(VectorTypeTest, MinBufferBindingSizeVec2) { TEST_F(VectorTest, MinBufferBindingSizeVec2) {
I32Type i32; I32 i32;
VectorType v{&i32, 2}; Vector v{&i32, 2};
EXPECT_EQ(8u, v.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); EXPECT_EQ(8u, v.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
} }
TEST_F(VectorTypeTest, MinBufferBindingSizeVec3) { TEST_F(VectorTest, MinBufferBindingSizeVec3) {
I32Type i32; I32 i32;
VectorType v{&i32, 3}; Vector v{&i32, 3};
EXPECT_EQ(12u, v.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); EXPECT_EQ(12u, v.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
} }
TEST_F(VectorTypeTest, MinBufferBindingSizeVec4) { TEST_F(VectorTest, MinBufferBindingSizeVec4) {
I32Type i32; I32 i32;
VectorType v{&i32, 4}; Vector v{&i32, 4};
EXPECT_EQ(16u, v.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, v.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
} }
TEST_F(VectorTypeTest, BaseAlignmentVec2) { TEST_F(VectorTest, BaseAlignmentVec2) {
I32Type i32; I32 i32;
VectorType v{&i32, 2}; Vector v{&i32, 2};
EXPECT_EQ(8u, v.BaseAlignment(MemoryLayout::kUniformBuffer)); EXPECT_EQ(8u, v.BaseAlignment(MemoryLayout::kUniformBuffer));
} }
TEST_F(VectorTypeTest, BaseAlignmentVec3) { TEST_F(VectorTest, BaseAlignmentVec3) {
I32Type i32; I32 i32;
VectorType v{&i32, 3}; Vector v{&i32, 3};
EXPECT_EQ(16u, v.BaseAlignment(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, v.BaseAlignment(MemoryLayout::kUniformBuffer));
} }
TEST_F(VectorTypeTest, BaseAlignmentVec4) { TEST_F(VectorTest, BaseAlignmentVec4) {
I32Type i32; I32 i32;
VectorType v{&i32, 4}; Vector v{&i32, 4};
EXPECT_EQ(16u, v.BaseAlignment(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, v.BaseAlignment(MemoryLayout::kUniformBuffer));
} }

View File

@ -18,13 +18,13 @@ namespace tint {
namespace ast { namespace ast {
namespace type { namespace type {
VoidType::VoidType() = default; Void::Void() = default;
VoidType::VoidType(VoidType&&) = default; Void::Void(Void&&) = default;
VoidType::~VoidType() = default; Void::~Void() = default;
std::string VoidType::type_name() const { std::string Void::type_name() const {
return "__void"; return "__void";
} }

View File

@ -24,13 +24,13 @@ namespace ast {
namespace type { namespace type {
/// A void type /// A void type
class VoidType : public Castable<VoidType, Type> { class Void : public Castable<Void, Type> {
public: public:
/// Constructor /// Constructor
VoidType(); Void();
/// Move constructor /// Move constructor
VoidType(VoidType&&); Void(Void&&);
~VoidType() override; ~Void() override;
/// @returns the name for this type /// @returns the name for this type
std::string type_name() const override; std::string type_name() const override;

View File

@ -30,7 +30,7 @@ namespace {
using TypeConstructorExpressionTest = TestHelper; using TypeConstructorExpressionTest = TestHelper;
TEST_F(TypeConstructorExpressionTest, Creation) { TEST_F(TypeConstructorExpressionTest, Creation) {
type::F32Type f32; type::F32 f32;
ExpressionList expr; ExpressionList expr;
expr.push_back(create<IdentifierExpression>("expr")); expr.push_back(create<IdentifierExpression>("expr"));
@ -41,7 +41,7 @@ TEST_F(TypeConstructorExpressionTest, Creation) {
} }
TEST_F(TypeConstructorExpressionTest, Creation_WithSource) { TEST_F(TypeConstructorExpressionTest, Creation_WithSource) {
type::F32Type f32; type::F32 f32;
ExpressionList expr; ExpressionList expr;
expr.push_back(create<IdentifierExpression>("expr")); expr.push_back(create<IdentifierExpression>("expr"));
@ -57,7 +57,7 @@ TEST_F(TypeConstructorExpressionTest, IsTypeConstructor) {
} }
TEST_F(TypeConstructorExpressionTest, IsValid) { TEST_F(TypeConstructorExpressionTest, IsValid) {
type::F32Type f32; type::F32 f32;
ExpressionList expr; ExpressionList expr;
expr.push_back(create<IdentifierExpression>("expr")); expr.push_back(create<IdentifierExpression>("expr"));
@ -66,7 +66,7 @@ TEST_F(TypeConstructorExpressionTest, IsValid) {
} }
TEST_F(TypeConstructorExpressionTest, IsValid_EmptyValue) { TEST_F(TypeConstructorExpressionTest, IsValid_EmptyValue) {
type::F32Type f32; type::F32 f32;
ExpressionList expr; ExpressionList expr;
TypeConstructorExpression t(&f32, expr); TypeConstructorExpression t(&f32, expr);
@ -83,7 +83,7 @@ TEST_F(TypeConstructorExpressionTest, IsValid_NullType) {
} }
TEST_F(TypeConstructorExpressionTest, IsValid_NullValue) { TEST_F(TypeConstructorExpressionTest, IsValid_NullValue) {
type::F32Type f32; type::F32 f32;
ExpressionList expr; ExpressionList expr;
expr.push_back(create<IdentifierExpression>("expr")); expr.push_back(create<IdentifierExpression>("expr"));
expr.push_back(nullptr); expr.push_back(nullptr);
@ -93,7 +93,7 @@ TEST_F(TypeConstructorExpressionTest, IsValid_NullValue) {
} }
TEST_F(TypeConstructorExpressionTest, IsValid_InvalidValue) { TEST_F(TypeConstructorExpressionTest, IsValid_InvalidValue) {
type::F32Type f32; type::F32 f32;
ExpressionList expr; ExpressionList expr;
expr.push_back(create<IdentifierExpression>("")); expr.push_back(create<IdentifierExpression>(""));
@ -102,8 +102,8 @@ TEST_F(TypeConstructorExpressionTest, IsValid_InvalidValue) {
} }
TEST_F(TypeConstructorExpressionTest, ToStr) { TEST_F(TypeConstructorExpressionTest, ToStr) {
type::F32Type f32; type::F32 f32;
type::VectorType vec(&f32, 3); type::Vector vec(&f32, 3);
ExpressionList expr; ExpressionList expr;
expr.push_back(create<IdentifierExpression>("expr_1")); expr.push_back(create<IdentifierExpression>("expr_1"));
expr.push_back(create<IdentifierExpression>("expr_2")); expr.push_back(create<IdentifierExpression>("expr_2"));

View File

@ -27,43 +27,43 @@ using TypeManagerTest = testing::Test;
TEST_F(TypeManagerTest, GetUnregistered) { TEST_F(TypeManagerTest, GetUnregistered) {
TypeManager tm; TypeManager tm;
auto* t = tm.Get(std::make_unique<type::I32Type>()); auto* t = tm.Get(std::make_unique<type::I32>());
ASSERT_NE(t, nullptr); ASSERT_NE(t, nullptr);
EXPECT_TRUE(t->Is<type::I32Type>()); EXPECT_TRUE(t->Is<type::I32>());
} }
TEST_F(TypeManagerTest, GetSameTypeReturnsSamePtr) { TEST_F(TypeManagerTest, GetSameTypeReturnsSamePtr) {
TypeManager tm; TypeManager tm;
auto* t = tm.Get(std::make_unique<type::I32Type>()); auto* t = tm.Get(std::make_unique<type::I32>());
ASSERT_NE(t, nullptr); ASSERT_NE(t, nullptr);
EXPECT_TRUE(t->Is<type::I32Type>()); EXPECT_TRUE(t->Is<type::I32>());
auto* t2 = tm.Get(std::make_unique<type::I32Type>()); auto* t2 = tm.Get(std::make_unique<type::I32>());
EXPECT_EQ(t, t2); EXPECT_EQ(t, t2);
} }
TEST_F(TypeManagerTest, GetDifferentTypeReturnsDifferentPtr) { TEST_F(TypeManagerTest, GetDifferentTypeReturnsDifferentPtr) {
TypeManager tm; TypeManager tm;
auto* t = tm.Get(std::make_unique<type::I32Type>()); auto* t = tm.Get(std::make_unique<type::I32>());
ASSERT_NE(t, nullptr); ASSERT_NE(t, nullptr);
EXPECT_TRUE(t->Is<type::I32Type>()); EXPECT_TRUE(t->Is<type::I32>());
auto* t2 = tm.Get(std::make_unique<type::U32Type>()); auto* t2 = tm.Get(std::make_unique<type::U32>());
ASSERT_NE(t2, nullptr); ASSERT_NE(t2, nullptr);
EXPECT_NE(t, t2); EXPECT_NE(t, t2);
EXPECT_TRUE(t2->Is<type::U32Type>()); EXPECT_TRUE(t2->Is<type::U32>());
} }
TEST_F(TypeManagerTest, ResetClearsPreviousData) { TEST_F(TypeManagerTest, ResetClearsPreviousData) {
TypeManager tm; TypeManager tm;
auto* t = tm.Get(std::make_unique<type::I32Type>()); auto* t = tm.Get(std::make_unique<type::I32>());
ASSERT_NE(t, nullptr); ASSERT_NE(t, nullptr);
EXPECT_FALSE(tm.types().empty()); EXPECT_FALSE(tm.types().empty());
tm.Reset(); tm.Reset();
EXPECT_TRUE(tm.types().empty()); EXPECT_TRUE(tm.types().empty());
auto* t2 = tm.Get(std::make_unique<type::I32Type>()); auto* t2 = tm.Get(std::make_unique<type::I32>());
ASSERT_NE(t2, nullptr); ASSERT_NE(t2, nullptr);
} }

View File

@ -28,14 +28,14 @@ namespace {
using UintLiteralTest = TestHelper; using UintLiteralTest = TestHelper;
TEST_F(UintLiteralTest, Value) { TEST_F(UintLiteralTest, Value) {
type::U32Type u32; type::U32 u32;
UintLiteral u{&u32, 47}; UintLiteral u{&u32, 47};
ASSERT_TRUE(u.Is<UintLiteral>()); ASSERT_TRUE(u.Is<UintLiteral>());
EXPECT_EQ(u.value(), 47u); EXPECT_EQ(u.value(), 47u);
} }
TEST_F(UintLiteralTest, Is) { TEST_F(UintLiteralTest, Is) {
type::U32Type u32; type::U32 u32;
UintLiteral u{&u32, 42}; UintLiteral u{&u32, 42};
Literal* l = &u; Literal* l = &u;
EXPECT_FALSE(l->Is<BoolLiteral>()); EXPECT_FALSE(l->Is<BoolLiteral>());
@ -46,7 +46,7 @@ TEST_F(UintLiteralTest, Is) {
} }
TEST_F(UintLiteralTest, ToStr) { TEST_F(UintLiteralTest, ToStr) {
type::U32Type u32; type::U32 u32;
UintLiteral i{&u32, 42}; UintLiteral i{&u32, 42};
EXPECT_EQ(i.to_str(), "42"); EXPECT_EQ(i.to_str(), "42");

View File

@ -25,7 +25,7 @@ namespace {
using VariableDeclStatementTest = TestHelper; using VariableDeclStatementTest = TestHelper;
TEST_F(VariableDeclStatementTest, Creation) { TEST_F(VariableDeclStatementTest, Creation) {
type::F32Type f32; type::F32 f32;
auto* var = create<Variable>("a", StorageClass::kNone, &f32); auto* var = create<Variable>("a", StorageClass::kNone, &f32);
VariableDeclStatement stmt(var); VariableDeclStatement stmt(var);
@ -33,7 +33,7 @@ TEST_F(VariableDeclStatementTest, Creation) {
} }
TEST_F(VariableDeclStatementTest, Creation_WithSource) { TEST_F(VariableDeclStatementTest, Creation_WithSource) {
type::F32Type f32; type::F32 f32;
auto* var = create<Variable>("a", StorageClass::kNone, &f32); auto* var = create<Variable>("a", StorageClass::kNone, &f32);
VariableDeclStatement stmt(Source{Source::Location{20, 2}}, var); VariableDeclStatement stmt(Source{Source::Location{20, 2}}, var);
@ -48,14 +48,14 @@ TEST_F(VariableDeclStatementTest, IsVariableDecl) {
} }
TEST_F(VariableDeclStatementTest, IsValid) { TEST_F(VariableDeclStatementTest, IsValid) {
type::F32Type f32; type::F32 f32;
auto* var = create<Variable>("a", StorageClass::kNone, &f32); auto* var = create<Variable>("a", StorageClass::kNone, &f32);
VariableDeclStatement stmt(var); VariableDeclStatement stmt(var);
EXPECT_TRUE(stmt.IsValid()); EXPECT_TRUE(stmt.IsValid());
} }
TEST_F(VariableDeclStatementTest, IsValid_InvalidVariable) { TEST_F(VariableDeclStatementTest, IsValid_InvalidVariable) {
type::F32Type f32; type::F32 f32;
auto* var = create<Variable>("", StorageClass::kNone, &f32); auto* var = create<Variable>("", StorageClass::kNone, &f32);
VariableDeclStatement stmt(var); VariableDeclStatement stmt(var);
EXPECT_FALSE(stmt.IsValid()); EXPECT_FALSE(stmt.IsValid());
@ -67,7 +67,7 @@ TEST_F(VariableDeclStatementTest, IsValid_NullVariable) {
} }
TEST_F(VariableDeclStatementTest, ToStr) { TEST_F(VariableDeclStatementTest, ToStr) {
type::F32Type f32; type::F32 f32;
auto* var = create<Variable>("a", StorageClass::kNone, &f32); auto* var = create<Variable>("a", StorageClass::kNone, &f32);
VariableDeclStatement stmt(Source{Source::Location{20, 2}}, var); VariableDeclStatement stmt(Source{Source::Location{20, 2}}, var);

View File

@ -26,7 +26,7 @@ namespace {
using VariableTest = TestHelper; using VariableTest = TestHelper;
TEST_F(VariableTest, Creation) { TEST_F(VariableTest, Creation) {
type::I32Type t; type::I32 t;
Variable v("my_var", StorageClass::kFunction, &t); Variable v("my_var", StorageClass::kFunction, &t);
EXPECT_EQ(v.name(), "my_var"); EXPECT_EQ(v.name(), "my_var");
@ -40,7 +40,7 @@ TEST_F(VariableTest, Creation) {
TEST_F(VariableTest, CreationWithSource) { TEST_F(VariableTest, CreationWithSource) {
Source s{Source::Range{Source::Location{27, 4}, Source::Location{27, 5}}}; Source s{Source::Range{Source::Location{27, 4}, Source::Location{27, 5}}};
type::F32Type t; type::F32 t;
Variable v(s, "i", StorageClass::kPrivate, &t); Variable v(s, "i", StorageClass::kPrivate, &t);
EXPECT_EQ(v.name(), "i"); EXPECT_EQ(v.name(), "i");
@ -59,7 +59,7 @@ TEST_F(VariableTest, CreationEmpty) {
v.set_storage_class(StorageClass::kWorkgroup); v.set_storage_class(StorageClass::kWorkgroup);
v.set_name("a_var"); v.set_name("a_var");
type::I32Type t; type::I32 t;
v.set_type(&t); v.set_type(&t);
EXPECT_EQ(v.name(), "a_var"); EXPECT_EQ(v.name(), "a_var");
@ -72,20 +72,20 @@ TEST_F(VariableTest, CreationEmpty) {
} }
TEST_F(VariableTest, IsValid) { TEST_F(VariableTest, IsValid) {
type::I32Type t; type::I32 t;
Variable v{"my_var", StorageClass::kNone, &t}; Variable v{"my_var", StorageClass::kNone, &t};
EXPECT_TRUE(v.IsValid()); EXPECT_TRUE(v.IsValid());
} }
TEST_F(VariableTest, IsValid_WithConstructor) { TEST_F(VariableTest, IsValid_WithConstructor) {
type::I32Type t; type::I32 t;
Variable v{"my_var", StorageClass::kNone, &t}; Variable v{"my_var", StorageClass::kNone, &t};
v.set_constructor(create<IdentifierExpression>("ident")); v.set_constructor(create<IdentifierExpression>("ident"));
EXPECT_TRUE(v.IsValid()); EXPECT_TRUE(v.IsValid());
} }
TEST_F(VariableTest, IsValid_MissinName) { TEST_F(VariableTest, IsValid_MissinName) {
type::I32Type t; type::I32 t;
Variable v{"", StorageClass::kNone, &t}; Variable v{"", StorageClass::kNone, &t};
EXPECT_FALSE(v.IsValid()); EXPECT_FALSE(v.IsValid());
} }
@ -101,14 +101,14 @@ TEST_F(VariableTest, IsValid_MissingBoth) {
} }
TEST_F(VariableTest, IsValid_InvalidConstructor) { TEST_F(VariableTest, IsValid_InvalidConstructor) {
type::I32Type t; type::I32 t;
Variable v{"my_var", StorageClass::kNone, &t}; Variable v{"my_var", StorageClass::kNone, &t};
v.set_constructor(create<IdentifierExpression>("")); v.set_constructor(create<IdentifierExpression>(""));
EXPECT_FALSE(v.IsValid()); EXPECT_FALSE(v.IsValid());
} }
TEST_F(VariableTest, to_str) { TEST_F(VariableTest, to_str) {
type::F32Type t; type::F32 t;
Variable v{"my_var", StorageClass::kFunction, &t}; Variable v{"my_var", StorageClass::kFunction, &t};
std::ostringstream out; std::ostringstream out;
v.to_str(out, 2); v.to_str(out, 2);

View File

@ -185,16 +185,16 @@ std::vector<ResourceBinding> Inspector::GetUniformBufferResourceBindings(
ast::Variable* var = nullptr; ast::Variable* var = nullptr;
ast::Function::BindingInfo binding_info; ast::Function::BindingInfo binding_info;
std::tie(var, binding_info) = ruv; std::tie(var, binding_info) = ruv;
if (!var->type()->Is<ast::type::AccessControlType>()) { if (!var->type()->Is<ast::type::AccessControl>()) {
continue; continue;
} }
auto* unwrapped_type = var->type()->UnwrapIfNeeded(); auto* unwrapped_type = var->type()->UnwrapIfNeeded();
if (!unwrapped_type->Is<ast::type::StructType>()) { if (!unwrapped_type->Is<ast::type::Struct>()) {
continue; continue;
} }
if (!unwrapped_type->As<ast::type::StructType>()->IsBlockDecorated()) { if (!unwrapped_type->As<ast::type::Struct>()->IsBlockDecorated()) {
continue; continue;
} }
@ -307,16 +307,16 @@ std::vector<ResourceBinding> Inspector::GetStorageBufferResourceBindingsImpl(
ast::Variable* var = nullptr; ast::Variable* var = nullptr;
ast::Function::BindingInfo binding_info; ast::Function::BindingInfo binding_info;
std::tie(var, binding_info) = rsv; std::tie(var, binding_info) = rsv;
if (!var->type()->Is<ast::type::AccessControlType>()) { if (!var->type()->Is<ast::type::AccessControl>()) {
continue; continue;
} }
auto* ac_type = var->type()->As<ast::type::AccessControlType>(); auto* ac_type = var->type()->As<ast::type::AccessControl>();
if (read_only != ac_type->IsReadOnly()) { if (read_only != ac_type->IsReadOnly()) {
continue; continue;
} }
if (!var->type()->UnwrapIfNeeded()->Is<ast::type::StructType>()) { if (!var->type()->UnwrapIfNeeded()->Is<ast::type::Struct>()) {
continue; continue;
} }
@ -353,7 +353,7 @@ std::vector<ResourceBinding> Inspector::GetSampledTextureResourceBindingsImpl(
entry.binding = binding_info.binding->value(); entry.binding = binding_info.binding->value();
auto* texture_type = auto* texture_type =
var->type()->UnwrapIfNeeded()->As<ast::type::TextureType>(); var->type()->UnwrapIfNeeded()->As<ast::type::Texture>();
switch (texture_type->dim()) { switch (texture_type->dim()) {
case ast::type::TextureDimension::k1d: case ast::type::TextureDimension::k1d:
entry.dim = ResourceBinding::TextureDimension::k1d; entry.dim = ResourceBinding::TextureDimension::k1d;
@ -383,28 +383,28 @@ std::vector<ResourceBinding> Inspector::GetSampledTextureResourceBindingsImpl(
ast::type::Type* base_type = nullptr; ast::type::Type* base_type = nullptr;
if (multisampled_only) { if (multisampled_only) {
base_type = texture_type->As<ast::type::MultisampledTextureType>() base_type = texture_type->As<ast::type::MultisampledTexture>()
->type() ->type()
->UnwrapIfNeeded(); ->UnwrapIfNeeded();
} else { } else {
base_type = texture_type->As<ast::type::SampledTextureType>() base_type = texture_type->As<ast::type::SampledTexture>()
->type() ->type()
->UnwrapIfNeeded(); ->UnwrapIfNeeded();
} }
if (base_type->Is<ast::type::ArrayType>()) { if (base_type->Is<ast::type::Array>()) {
base_type = base_type->As<ast::type::ArrayType>()->type(); base_type = base_type->As<ast::type::Array>()->type();
} else if (base_type->Is<ast::type::MatrixType>()) { } else if (base_type->Is<ast::type::Matrix>()) {
base_type = base_type->As<ast::type::MatrixType>()->type(); base_type = base_type->As<ast::type::Matrix>()->type();
} else if (base_type->Is<ast::type::VectorType>()) { } else if (base_type->Is<ast::type::Vector>()) {
base_type = base_type->As<ast::type::VectorType>()->type(); base_type = base_type->As<ast::type::Vector>()->type();
} }
if (base_type->Is<ast::type::F32Type>()) { if (base_type->Is<ast::type::F32>()) {
entry.sampled_kind = ResourceBinding::SampledKind::kFloat; entry.sampled_kind = ResourceBinding::SampledKind::kFloat;
} else if (base_type->Is<ast::type::U32Type>()) { } else if (base_type->Is<ast::type::U32>()) {
entry.sampled_kind = ResourceBinding::SampledKind::kUInt; entry.sampled_kind = ResourceBinding::SampledKind::kUInt;
} else if (base_type->Is<ast::type::I32Type>()) { } else if (base_type->Is<ast::type::I32>()) {
entry.sampled_kind = ResourceBinding::SampledKind::kSInt; entry.sampled_kind = ResourceBinding::SampledKind::kSInt;
} else { } else {
entry.sampled_kind = ResourceBinding::SampledKind::kUnknown; entry.sampled_kind = ResourceBinding::SampledKind::kUnknown;

View File

@ -244,7 +244,7 @@ class InspectorHelper {
/// type and offset of a member of the struct /// type and offset of a member of the struct
/// @param is_block whether or not to decorate as a Block /// @param is_block whether or not to decorate as a Block
/// @returns a struct type /// @returns a struct type
std::unique_ptr<ast::type::StructType> MakeStructType( std::unique_ptr<ast::type::Struct> MakeStructType(
const std::string& name, const std::string& name,
std::vector<std::tuple<ast::type::Type*, uint32_t>> members_info, std::vector<std::tuple<ast::type::Type*, uint32_t>> members_info,
bool is_block) { bool is_block) {
@ -269,7 +269,7 @@ class InspectorHelper {
auto* str = create<ast::Struct>(decos, members); auto* str = create<ast::Struct>(decos, members);
return std::make_unique<ast::type::StructType>(name, str); return std::make_unique<ast::type::Struct>(name, str);
} }
/// Generates types appropriate for using in an uniform buffer /// Generates types appropriate for using in an uniform buffer
@ -279,13 +279,13 @@ class InspectorHelper {
/// @returns a tuple {struct type, access control type}, where the struct has /// @returns a tuple {struct type, access control type}, where the struct has
/// the layout for an uniform buffer, and the control type wraps the /// the layout for an uniform buffer, and the control type wraps the
/// struct. /// struct.
std::tuple<std::unique_ptr<ast::type::StructType>, std::tuple<std::unique_ptr<ast::type::Struct>,
std::unique_ptr<ast::type::AccessControlType>> std::unique_ptr<ast::type::AccessControl>>
MakeUniformBufferTypes( MakeUniformBufferTypes(
const std::string& name, const std::string& name,
std::vector<std::tuple<ast::type::Type*, uint32_t>> members_info) { std::vector<std::tuple<ast::type::Type*, uint32_t>> members_info) {
auto struct_type = MakeStructType(name, members_info, true); auto struct_type = MakeStructType(name, members_info, true);
auto access_type = std::make_unique<ast::type::AccessControlType>( auto access_type = std::make_unique<ast::type::AccessControl>(
ast::AccessControl::kReadOnly, struct_type.get()); ast::AccessControl::kReadOnly, struct_type.get());
return {std::move(struct_type), std::move(access_type)}; return {std::move(struct_type), std::move(access_type)};
} }
@ -297,13 +297,13 @@ class InspectorHelper {
/// @returns a tuple {struct type, access control type}, where the struct has /// @returns a tuple {struct type, access control type}, where the struct has
/// the layout for a storage buffer, and the control type wraps the /// the layout for a storage buffer, and the control type wraps the
/// struct. /// struct.
std::tuple<std::unique_ptr<ast::type::StructType>, std::tuple<std::unique_ptr<ast::type::Struct>,
std::unique_ptr<ast::type::AccessControlType>> std::unique_ptr<ast::type::AccessControl>>
MakeStorageBufferTypes( MakeStorageBufferTypes(
const std::string& name, const std::string& name,
std::vector<std::tuple<ast::type::Type*, uint32_t>> members_info) { std::vector<std::tuple<ast::type::Type*, uint32_t>> members_info) {
auto struct_type = MakeStructType(name, members_info, false); auto struct_type = MakeStructType(name, members_info, false);
auto access_type = std::make_unique<ast::type::AccessControlType>( auto access_type = std::make_unique<ast::type::AccessControl>(
ast::AccessControl::kReadWrite, struct_type.get()); ast::AccessControl::kReadWrite, struct_type.get());
return {std::move(struct_type), std::move(access_type)}; return {std::move(struct_type), std::move(access_type)};
} }
@ -315,13 +315,13 @@ class InspectorHelper {
/// @returns a tuple {struct type, access control type}, where the struct has /// @returns a tuple {struct type, access control type}, where the struct has
/// the layout for a read-only storage buffer, and the control type /// the layout for a read-only storage buffer, and the control type
/// wraps the struct. /// wraps the struct.
std::tuple<std::unique_ptr<ast::type::StructType>, std::tuple<std::unique_ptr<ast::type::Struct>,
std::unique_ptr<ast::type::AccessControlType>> std::unique_ptr<ast::type::AccessControl>>
MakeReadOnlyStorageBufferTypes( MakeReadOnlyStorageBufferTypes(
const std::string& name, const std::string& name,
std::vector<std::tuple<ast::type::Type*, uint32_t>> members_info) { std::vector<std::tuple<ast::type::Type*, uint32_t>> members_info) {
auto struct_type = MakeStructType(name, members_info, false); auto struct_type = MakeStructType(name, members_info, false);
auto access_type = std::make_unique<ast::type::AccessControlType>( auto access_type = std::make_unique<ast::type::AccessControl>(
ast::AccessControl::kReadOnly, struct_type.get()); ast::AccessControl::kReadOnly, struct_type.get());
return {std::move(struct_type), std::move(access_type)}; return {std::move(struct_type), std::move(access_type)};
} }
@ -429,32 +429,32 @@ class InspectorHelper {
ast::StorageClass::kUniformConstant, set, binding); ast::StorageClass::kUniformConstant, set, binding);
} }
/// Generates a SampledTextureType appropriate for the params /// Generates a SampledTexture appropriate for the params
/// @param dim the dimensions of the texture /// @param dim the dimensions of the texture
/// @param type the data type of the sampled texture /// @param type the data type of the sampled texture
/// @returns the generated SampleTextureType /// @returns the generated SampleTextureType
std::unique_ptr<ast::type::SampledTextureType> MakeSampledTextureType( std::unique_ptr<ast::type::SampledTexture> MakeSampledTextureType(
ast::type::TextureDimension dim, ast::type::TextureDimension dim,
ast::type::Type* type) { ast::type::Type* type) {
return std::make_unique<ast::type::SampledTextureType>(dim, type); return std::make_unique<ast::type::SampledTexture>(dim, type);
} }
/// Generates a DepthTextureType appropriate for the params /// Generates a DepthTexture appropriate for the params
/// @param dim the dimensions of the texture /// @param dim the dimensions of the texture
/// @returns the generated DepthTextureType /// @returns the generated DepthTexture
std::unique_ptr<ast::type::DepthTextureType> MakeDepthTextureType( std::unique_ptr<ast::type::DepthTexture> MakeDepthTextureType(
ast::type::TextureDimension dim) { ast::type::TextureDimension dim) {
return std::make_unique<ast::type::DepthTextureType>(dim); return std::make_unique<ast::type::DepthTexture>(dim);
} }
/// Generates a MultisampledTextureType appropriate for the params /// Generates a MultisampledTexture appropriate for the params
/// @param dim the dimensions of the texture /// @param dim the dimensions of the texture
/// @param type the data type of the sampled texture /// @param type the data type of the sampled texture
/// @returns the generated SampleTextureType /// @returns the generated SampleTextureType
std::unique_ptr<ast::type::MultisampledTextureType> std::unique_ptr<ast::type::MultisampledTexture> MakeMultisampledTextureType(
MakeMultisampledTextureType(ast::type::TextureDimension dim, ast::type::TextureDimension dim,
ast::type::Type* type) { ast::type::Type* type) {
return std::make_unique<ast::type::MultisampledTextureType>(dim, type); return std::make_unique<ast::type::MultisampledTexture>(dim, type);
} }
/// Adds a sampled texture variable to the module /// Adds a sampled texture variable to the module
@ -645,31 +645,31 @@ class InspectorHelper {
TypeDeterminer* td() { return td_.get(); } TypeDeterminer* td() { return td_.get(); }
Inspector* inspector() { return inspector_.get(); } Inspector* inspector() { return inspector_.get(); }
ast::type::BoolType* bool_type() { return &bool_type_; } ast::type::Bool* bool_type() { return &bool_type_; }
ast::type::F32Type* f32_type() { return &f32_type_; } ast::type::F32* f32_type() { return &f32_type_; }
ast::type::I32Type* i32_type() { return &i32_type_; } ast::type::I32* i32_type() { return &i32_type_; }
ast::type::U32Type* u32_type() { return &u32_type_; } ast::type::U32* u32_type() { return &u32_type_; }
ast::type::ArrayType* u32_array_type(uint32_t count) { ast::type::Array* u32_array_type(uint32_t count) {
if (array_type_memo_.find(count) == array_type_memo_.end()) { if (array_type_memo_.find(count) == array_type_memo_.end()) {
array_type_memo_[count] = array_type_memo_[count] =
std::make_unique<ast::type::ArrayType>(u32_type(), count); std::make_unique<ast::type::Array>(u32_type(), count);
ast::ArrayDecorationList decos; ast::ArrayDecorationList decos;
decos.push_back(create<ast::StrideDecoration>(4, Source{})); decos.push_back(create<ast::StrideDecoration>(4, Source{}));
array_type_memo_[count]->set_decorations(decos); array_type_memo_[count]->set_decorations(decos);
} }
return array_type_memo_[count].get(); return array_type_memo_[count].get();
} }
ast::type::VectorType* vec_type(ast::type::Type* type, uint32_t count) { ast::type::Vector* vec_type(ast::type::Type* type, uint32_t count) {
if (vector_type_memo_.find(std::tie(type, count)) == if (vector_type_memo_.find(std::tie(type, count)) ==
vector_type_memo_.end()) { vector_type_memo_.end()) {
vector_type_memo_[std::tie(type, count)] = vector_type_memo_[std::tie(type, count)] =
std::make_unique<ast::type::VectorType>(u32_type(), count); std::make_unique<ast::type::Vector>(u32_type(), count);
} }
return vector_type_memo_[std::tie(type, count)].get(); return vector_type_memo_[std::tie(type, count)].get();
} }
ast::type::VoidType* void_type() { return &void_type_; } ast::type::Void* void_type() { return &void_type_; }
ast::type::SamplerType* sampler_type() { return &sampler_type_; } ast::type::Sampler* sampler_type() { return &sampler_type_; }
ast::type::SamplerType* comparison_sampler_type() { ast::type::Sampler* comparison_sampler_type() {
return &comparison_sampler_type_; return &comparison_sampler_type_;
} }
@ -688,16 +688,16 @@ class InspectorHelper {
std::unique_ptr<TypeDeterminer> td_; std::unique_ptr<TypeDeterminer> td_;
std::unique_ptr<Inspector> inspector_; std::unique_ptr<Inspector> inspector_;
ast::type::BoolType bool_type_; ast::type::Bool bool_type_;
ast::type::F32Type f32_type_; ast::type::F32 f32_type_;
ast::type::I32Type i32_type_; ast::type::I32 i32_type_;
ast::type::U32Type u32_type_; ast::type::U32 u32_type_;
ast::type::VoidType void_type_; ast::type::Void void_type_;
ast::type::SamplerType sampler_type_; ast::type::Sampler sampler_type_;
ast::type::SamplerType comparison_sampler_type_; ast::type::Sampler comparison_sampler_type_;
std::map<uint32_t, std::unique_ptr<ast::type::ArrayType>> array_type_memo_; std::map<uint32_t, std::unique_ptr<ast::type::Array>> array_type_memo_;
std::map<std::tuple<ast::type::Type*, uint32_t>, std::map<std::tuple<ast::type::Type*, uint32_t>,
std::unique_ptr<ast::type::VectorType>> std::unique_ptr<ast::type::Vector>>
vector_type_memo_; vector_type_memo_;
}; };
@ -1234,8 +1234,8 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, MissingEntryPoint) {
} }
TEST_F(InspectorGetUniformBufferResourceBindingsTest, NonEntryPointFunc) { TEST_F(InspectorGetUniformBufferResourceBindingsTest, NonEntryPointFunc) {
std::unique_ptr<ast::type::StructType> foo_struct_type; std::unique_ptr<ast::type::Struct> foo_struct_type;
std::unique_ptr<ast::type::AccessControlType> foo_control_type; std::unique_ptr<ast::type::AccessControl> foo_control_type;
std::tie(foo_struct_type, foo_control_type) = std::tie(foo_struct_type, foo_control_type) =
MakeUniformBufferTypes("foo_type", {{i32_type(), 0}}); MakeUniformBufferTypes("foo_type", {{i32_type(), 0}});
AddUniformBuffer("foo_ub", foo_control_type.get(), 0, 0); AddUniformBuffer("foo_ub", foo_control_type.get(), 0, 0);
@ -1267,7 +1267,7 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, MissingBlockDeco) {
ast::StructDecorationList decos; ast::StructDecorationList decos;
auto* str = create<ast::Struct>(decos, members); auto* str = create<ast::Struct>(decos, members);
auto foo_type = std::make_unique<ast::type::StructType>("foo_type", str); auto foo_type = std::make_unique<ast::type::Struct>("foo_type", str);
AddUniformBuffer("foo_ub", foo_type.get(), 0, 0); AddUniformBuffer("foo_ub", foo_type.get(), 0, 0);
@ -1288,8 +1288,8 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, MissingBlockDeco) {
} }
TEST_F(InspectorGetUniformBufferResourceBindingsTest, Simple) { TEST_F(InspectorGetUniformBufferResourceBindingsTest, Simple) {
std::unique_ptr<ast::type::StructType> foo_struct_type; std::unique_ptr<ast::type::Struct> foo_struct_type;
std::unique_ptr<ast::type::AccessControlType> foo_control_type; std::unique_ptr<ast::type::AccessControl> foo_control_type;
std::tie(foo_struct_type, foo_control_type) = std::tie(foo_struct_type, foo_control_type) =
MakeUniformBufferTypes("foo_type", {{i32_type(), 0}}); MakeUniformBufferTypes("foo_type", {{i32_type(), 0}});
AddUniformBuffer("foo_ub", foo_control_type.get(), 0, 0); AddUniformBuffer("foo_ub", foo_control_type.get(), 0, 0);
@ -1315,8 +1315,8 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, Simple) {
} }
TEST_F(InspectorGetUniformBufferResourceBindingsTest, MultipleMembers) { TEST_F(InspectorGetUniformBufferResourceBindingsTest, MultipleMembers) {
std::unique_ptr<ast::type::StructType> foo_struct_type; std::unique_ptr<ast::type::Struct> foo_struct_type;
std::unique_ptr<ast::type::AccessControlType> foo_control_type; std::unique_ptr<ast::type::AccessControl> foo_control_type;
std::tie(foo_struct_type, foo_control_type) = MakeUniformBufferTypes( std::tie(foo_struct_type, foo_control_type) = MakeUniformBufferTypes(
"foo_type", {{i32_type(), 0}, {u32_type(), 4}, {f32_type(), 8}}); "foo_type", {{i32_type(), 0}, {u32_type(), 4}, {f32_type(), 8}});
AddUniformBuffer("foo_ub", foo_control_type.get(), 0, 0); AddUniformBuffer("foo_ub", foo_control_type.get(), 0, 0);
@ -1342,8 +1342,8 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, MultipleMembers) {
} }
TEST_F(InspectorGetUniformBufferResourceBindingsTest, MultipleUniformBuffers) { TEST_F(InspectorGetUniformBufferResourceBindingsTest, MultipleUniformBuffers) {
std::unique_ptr<ast::type::StructType> ub_struct_type; std::unique_ptr<ast::type::Struct> ub_struct_type;
std::unique_ptr<ast::type::AccessControlType> ub_control_type; std::unique_ptr<ast::type::AccessControl> ub_control_type;
std::tie(ub_struct_type, ub_control_type) = MakeUniformBufferTypes( std::tie(ub_struct_type, ub_control_type) = MakeUniformBufferTypes(
"ub_type", {{i32_type(), 0}, {u32_type(), 4}, {f32_type(), 8}}); "ub_type", {{i32_type(), 0}, {u32_type(), 4}, {f32_type(), 8}});
AddUniformBuffer("ub_foo", ub_control_type.get(), 0, 0); AddUniformBuffer("ub_foo", ub_control_type.get(), 0, 0);
@ -1401,8 +1401,8 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, MultipleUniformBuffers) {
} }
TEST_F(InspectorGetUniformBufferResourceBindingsTest, ContainingArray) { TEST_F(InspectorGetUniformBufferResourceBindingsTest, ContainingArray) {
std::unique_ptr<ast::type::StructType> foo_struct_type; std::unique_ptr<ast::type::Struct> foo_struct_type;
std::unique_ptr<ast::type::AccessControlType> foo_control_type; std::unique_ptr<ast::type::AccessControl> foo_control_type;
std::tie(foo_struct_type, foo_control_type) = MakeUniformBufferTypes( std::tie(foo_struct_type, foo_control_type) = MakeUniformBufferTypes(
"foo_type", {{i32_type(), 0}, {u32_array_type(4), 4}}); "foo_type", {{i32_type(), 0}, {u32_array_type(4), 4}});
AddUniformBuffer("foo_ub", foo_control_type.get(), 0, 0); AddUniformBuffer("foo_ub", foo_control_type.get(), 0, 0);
@ -1428,8 +1428,8 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, ContainingArray) {
} }
TEST_F(InspectorGetStorageBufferResourceBindingsTest, Simple) { TEST_F(InspectorGetStorageBufferResourceBindingsTest, Simple) {
std::unique_ptr<ast::type::StructType> foo_struct_type; std::unique_ptr<ast::type::Struct> foo_struct_type;
std::unique_ptr<ast::type::AccessControlType> foo_control_type; std::unique_ptr<ast::type::AccessControl> foo_control_type;
std::tie(foo_struct_type, foo_control_type) = std::tie(foo_struct_type, foo_control_type) =
MakeStorageBufferTypes("foo_type", {{i32_type(), 0}}); MakeStorageBufferTypes("foo_type", {{i32_type(), 0}});
AddStorageBuffer("foo_sb", foo_control_type.get(), 0, 0); AddStorageBuffer("foo_sb", foo_control_type.get(), 0, 0);
@ -1455,8 +1455,8 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, Simple) {
} }
TEST_F(InspectorGetStorageBufferResourceBindingsTest, MultipleMembers) { TEST_F(InspectorGetStorageBufferResourceBindingsTest, MultipleMembers) {
std::unique_ptr<ast::type::StructType> foo_struct_type; std::unique_ptr<ast::type::Struct> foo_struct_type;
std::unique_ptr<ast::type::AccessControlType> foo_control_type; std::unique_ptr<ast::type::AccessControl> foo_control_type;
std::tie(foo_struct_type, foo_control_type) = MakeStorageBufferTypes( std::tie(foo_struct_type, foo_control_type) = MakeStorageBufferTypes(
"foo_type", {{i32_type(), 0}, {u32_type(), 4}, {f32_type(), 8}}); "foo_type", {{i32_type(), 0}, {u32_type(), 4}, {f32_type(), 8}});
AddStorageBuffer("foo_sb", foo_control_type.get(), 0, 0); AddStorageBuffer("foo_sb", foo_control_type.get(), 0, 0);
@ -1482,8 +1482,8 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, MultipleMembers) {
} }
TEST_F(InspectorGetStorageBufferResourceBindingsTest, MultipleStorageBuffers) { TEST_F(InspectorGetStorageBufferResourceBindingsTest, MultipleStorageBuffers) {
std::unique_ptr<ast::type::StructType> sb_struct_type; std::unique_ptr<ast::type::Struct> sb_struct_type;
std::unique_ptr<ast::type::AccessControlType> sb_control_type; std::unique_ptr<ast::type::AccessControl> sb_control_type;
std::tie(sb_struct_type, sb_control_type) = MakeStorageBufferTypes( std::tie(sb_struct_type, sb_control_type) = MakeStorageBufferTypes(
"sb_type", {{i32_type(), 0}, {u32_type(), 4}, {f32_type(), 8}}); "sb_type", {{i32_type(), 0}, {u32_type(), 4}, {f32_type(), 8}});
AddStorageBuffer("sb_foo", sb_control_type.get(), 0, 0); AddStorageBuffer("sb_foo", sb_control_type.get(), 0, 0);
@ -1541,8 +1541,8 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, MultipleStorageBuffers) {
} }
TEST_F(InspectorGetStorageBufferResourceBindingsTest, ContainingArray) { TEST_F(InspectorGetStorageBufferResourceBindingsTest, ContainingArray) {
std::unique_ptr<ast::type::StructType> foo_struct_type; std::unique_ptr<ast::type::Struct> foo_struct_type;
std::unique_ptr<ast::type::AccessControlType> foo_control_type; std::unique_ptr<ast::type::AccessControl> foo_control_type;
std::tie(foo_struct_type, foo_control_type) = MakeStorageBufferTypes( std::tie(foo_struct_type, foo_control_type) = MakeStorageBufferTypes(
"foo_type", {{i32_type(), 0}, {u32_array_type(4), 4}}); "foo_type", {{i32_type(), 0}, {u32_array_type(4), 4}});
AddStorageBuffer("foo_sb", foo_control_type.get(), 0, 0); AddStorageBuffer("foo_sb", foo_control_type.get(), 0, 0);
@ -1568,8 +1568,8 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, ContainingArray) {
} }
TEST_F(InspectorGetStorageBufferResourceBindingsTest, ContainingRuntimeArray) { TEST_F(InspectorGetStorageBufferResourceBindingsTest, ContainingRuntimeArray) {
std::unique_ptr<ast::type::StructType> foo_struct_type; std::unique_ptr<ast::type::Struct> foo_struct_type;
std::unique_ptr<ast::type::AccessControlType> foo_control_type; std::unique_ptr<ast::type::AccessControl> foo_control_type;
std::tie(foo_struct_type, foo_control_type) = MakeStorageBufferTypes( std::tie(foo_struct_type, foo_control_type) = MakeStorageBufferTypes(
"foo_type", {{i32_type(), 0}, {u32_array_type(0), 4}}); "foo_type", {{i32_type(), 0}, {u32_array_type(0), 4}});
AddStorageBuffer("foo_sb", foo_control_type.get(), 0, 0); AddStorageBuffer("foo_sb", foo_control_type.get(), 0, 0);
@ -1595,8 +1595,8 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, ContainingRuntimeArray) {
} }
TEST_F(InspectorGetStorageBufferResourceBindingsTest, SkipReadOnly) { TEST_F(InspectorGetStorageBufferResourceBindingsTest, SkipReadOnly) {
std::unique_ptr<ast::type::StructType> foo_struct_type; std::unique_ptr<ast::type::Struct> foo_struct_type;
std::unique_ptr<ast::type::AccessControlType> foo_control_type; std::unique_ptr<ast::type::AccessControl> foo_control_type;
std::tie(foo_struct_type, foo_control_type) = std::tie(foo_struct_type, foo_control_type) =
MakeReadOnlyStorageBufferTypes("foo_type", {{i32_type(), 0}}); MakeReadOnlyStorageBufferTypes("foo_type", {{i32_type(), 0}});
AddStorageBuffer("foo_sb", foo_control_type.get(), 0, 0); AddStorageBuffer("foo_sb", foo_control_type.get(), 0, 0);
@ -1618,8 +1618,8 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, SkipReadOnly) {
} }
TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, Simple) { TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, Simple) {
std::unique_ptr<ast::type::StructType> foo_struct_type; std::unique_ptr<ast::type::Struct> foo_struct_type;
std::unique_ptr<ast::type::AccessControlType> foo_control_type; std::unique_ptr<ast::type::AccessControl> foo_control_type;
std::tie(foo_struct_type, foo_control_type) = std::tie(foo_struct_type, foo_control_type) =
MakeReadOnlyStorageBufferTypes("foo_type", {{i32_type(), 0}}); MakeReadOnlyStorageBufferTypes("foo_type", {{i32_type(), 0}});
AddStorageBuffer("foo_sb", foo_control_type.get(), 0, 0); AddStorageBuffer("foo_sb", foo_control_type.get(), 0, 0);
@ -1647,8 +1647,8 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, Simple) {
TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest,
MultipleStorageBuffers) { MultipleStorageBuffers) {
std::unique_ptr<ast::type::StructType> sb_struct_type; std::unique_ptr<ast::type::Struct> sb_struct_type;
std::unique_ptr<ast::type::AccessControlType> sb_control_type; std::unique_ptr<ast::type::AccessControl> sb_control_type;
std::tie(sb_struct_type, sb_control_type) = MakeReadOnlyStorageBufferTypes( std::tie(sb_struct_type, sb_control_type) = MakeReadOnlyStorageBufferTypes(
"sb_type", {{i32_type(), 0}, {u32_type(), 4}, {f32_type(), 8}}); "sb_type", {{i32_type(), 0}, {u32_type(), 4}, {f32_type(), 8}});
AddStorageBuffer("sb_foo", sb_control_type.get(), 0, 0); AddStorageBuffer("sb_foo", sb_control_type.get(), 0, 0);
@ -1707,8 +1707,8 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest,
} }
TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, ContainingArray) { TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, ContainingArray) {
std::unique_ptr<ast::type::StructType> foo_struct_type; std::unique_ptr<ast::type::Struct> foo_struct_type;
std::unique_ptr<ast::type::AccessControlType> foo_control_type; std::unique_ptr<ast::type::AccessControl> foo_control_type;
std::tie(foo_struct_type, foo_control_type) = MakeReadOnlyStorageBufferTypes( std::tie(foo_struct_type, foo_control_type) = MakeReadOnlyStorageBufferTypes(
"foo_type", {{i32_type(), 0}, {u32_array_type(4), 4}}); "foo_type", {{i32_type(), 0}, {u32_array_type(4), 4}});
AddStorageBuffer("foo_sb", foo_control_type.get(), 0, 0); AddStorageBuffer("foo_sb", foo_control_type.get(), 0, 0);
@ -1736,8 +1736,8 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, ContainingArray) {
TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest,
ContainingRuntimeArray) { ContainingRuntimeArray) {
std::unique_ptr<ast::type::StructType> foo_struct_type; std::unique_ptr<ast::type::Struct> foo_struct_type;
std::unique_ptr<ast::type::AccessControlType> foo_control_type; std::unique_ptr<ast::type::AccessControl> foo_control_type;
std::tie(foo_struct_type, foo_control_type) = MakeReadOnlyStorageBufferTypes( std::tie(foo_struct_type, foo_control_type) = MakeReadOnlyStorageBufferTypes(
"foo_type", {{i32_type(), 0}, {u32_array_type(0), 4}}); "foo_type", {{i32_type(), 0}, {u32_array_type(0), 4}});
AddStorageBuffer("foo_sb", foo_control_type.get(), 0, 0); AddStorageBuffer("foo_sb", foo_control_type.get(), 0, 0);
@ -1764,8 +1764,8 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest,
} }
TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, SkipNonReadOnly) { TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, SkipNonReadOnly) {
std::unique_ptr<ast::type::StructType> foo_struct_type; std::unique_ptr<ast::type::Struct> foo_struct_type;
std::unique_ptr<ast::type::AccessControlType> foo_control_type; std::unique_ptr<ast::type::AccessControl> foo_control_type;
std::tie(foo_struct_type, foo_control_type) = std::tie(foo_struct_type, foo_control_type) =
MakeStorageBufferTypes("foo_type", {{i32_type(), 0}}); MakeStorageBufferTypes("foo_type", {{i32_type(), 0}});
AddStorageBuffer("foo_sb", foo_control_type.get(), 0, 0); AddStorageBuffer("foo_sb", foo_control_type.get(), 0, 0);

View File

@ -2013,7 +2013,7 @@ bool FunctionEmitter::EmitIfStart(const BlockInfo& block_info) {
if (!guard_name.empty()) { if (!guard_name.empty()) {
// Declare the guard variable just before the "if", initialized to true. // Declare the guard variable just before the "if", initialized to true.
auto* guard_var = create<ast::Variable>( auto* guard_var = create<ast::Variable>(
guard_name, ast::StorageClass::kFunction, parser_impl_.BoolType()); guard_name, ast::StorageClass::kFunction, parser_impl_.Bool());
guard_var->set_constructor(MakeTrue()); guard_var->set_constructor(MakeTrue());
auto* guard_decl = create<ast::VariableDeclStatement>(guard_var); auto* guard_decl = create<ast::VariableDeclStatement>(guard_var);
AddStatement(guard_decl); AddStatement(guard_decl);
@ -2700,8 +2700,8 @@ bool FunctionEmitter::EmitStatement(const spvtools::opt::Instruction& inst) {
// So represent a load by a new const definition. // So represent a load by a new const definition.
auto expr = MakeExpression(inst.GetSingleWordInOperand(0)); auto expr = MakeExpression(inst.GetSingleWordInOperand(0));
// The load result type is the pointee type of its operand. // The load result type is the pointee type of its operand.
assert(expr.type->Is<ast::type::PointerType>()); assert(expr.type->Is<ast::type::Pointer>());
expr.type = expr.type->As<ast::type::PointerType>()->type(); expr.type = expr.type->As<ast::type::Pointer>()->type();
return EmitConstDefOrWriteToHoistedVar(inst, expr); return EmitConstDefOrWriteToHoistedVar(inst, expr);
} }
case SpvOpCopyObject: { case SpvOpCopyObject: {
@ -3061,7 +3061,7 @@ TypedExpression FunctionEmitter::MakeAccessChain(
type_mgr_->FindPointerToType(pointee_type_id, storage_class); type_mgr_->FindPointerToType(pointee_type_id, storage_class);
auto* ast_pointer_type = parser_impl_.ConvertType(pointer_type_id); auto* ast_pointer_type = parser_impl_.ConvertType(pointer_type_id);
assert(ast_pointer_type); assert(ast_pointer_type);
assert(ast_pointer_type->Is<ast::type::PointerType>()); assert(ast_pointer_type->Is<ast::type::Pointer>());
current_expr = TypedExpression{ast_pointer_type, next_expr}; current_expr = TypedExpression{ast_pointer_type, next_expr};
} }
return current_expr; return current_expr;
@ -3080,7 +3080,7 @@ TypedExpression FunctionEmitter::MakeCompositeExtract(
TypedExpression current_expr(MakeOperand(inst, 0)); TypedExpression current_expr(MakeOperand(inst, 0));
auto make_index = [this](uint32_t literal) { auto make_index = [this](uint32_t literal) {
ast::type::U32Type u32; ast::type::U32 u32;
return create<ast::ScalarConstructorExpression>( return create<ast::ScalarConstructorExpression>(
create<ast::UintLiteral>(&u32, literal)); create<ast::UintLiteral>(&u32, literal));
}; };
@ -3183,13 +3183,13 @@ TypedExpression FunctionEmitter::MakeCompositeExtract(
ast::Expression* FunctionEmitter::MakeTrue() const { ast::Expression* FunctionEmitter::MakeTrue() const {
return create<ast::ScalarConstructorExpression>( return create<ast::ScalarConstructorExpression>(
create<ast::BoolLiteral>(parser_impl_.BoolType(), true)); create<ast::BoolLiteral>(parser_impl_.Bool(), true));
} }
ast::Expression* FunctionEmitter::MakeFalse() const { ast::Expression* FunctionEmitter::MakeFalse() const {
ast::type::BoolType bool_type; ast::type::Bool bool_type;
return create<ast::ScalarConstructorExpression>( return create<ast::ScalarConstructorExpression>(
create<ast::BoolLiteral>(parser_impl_.BoolType(), false)); create<ast::BoolLiteral>(parser_impl_.Bool(), false));
} }
TypedExpression FunctionEmitter::MakeVectorShuffle( TypedExpression FunctionEmitter::MakeVectorShuffle(
@ -3207,8 +3207,8 @@ TypedExpression FunctionEmitter::MakeVectorShuffle(
// Generate an ast::TypeConstructor expression. // Generate an ast::TypeConstructor expression.
// Assume the literal indices are valid, and there is a valid number of them. // Assume the literal indices are valid, and there is a valid number of them.
ast::type::VectorType* result_type = ast::type::Vector* result_type =
parser_impl_.ConvertType(inst.type_id())->As<ast::type::VectorType>(); parser_impl_.ConvertType(inst.type_id())->As<ast::type::Vector>();
ast::ExpressionList values; ast::ExpressionList values;
for (uint32_t i = 2; i < inst.NumInOperands(); ++i) { for (uint32_t i = 2; i < inst.NumInOperands(); ++i) {
const auto index = inst.GetSingleWordInOperand(i); const auto index = inst.GetSingleWordInOperand(i);
@ -3257,9 +3257,9 @@ bool FunctionEmitter::RegisterLocallyDefinedValues() {
if (type) { if (type) {
if (type->AsPointer()) { if (type->AsPointer()) {
const auto* ast_type = parser_impl_.ConvertType(inst.type_id()); const auto* ast_type = parser_impl_.ConvertType(inst.type_id());
if (ast_type && ast_type->As<ast::type::PointerType>()) { if (ast_type && ast_type->As<ast::type::Pointer>()) {
info->storage_class = info->storage_class =
ast_type->As<ast::type::PointerType>()->storage_class(); ast_type->As<ast::type::Pointer>()->storage_class();
} }
switch (inst.opcode()) { switch (inst.opcode()) {
case SpvOpUndef: case SpvOpUndef:
@ -3301,8 +3301,8 @@ ast::StorageClass FunctionEmitter::GetStorageClassForPointerValue(uint32_t id) {
const auto type_id = def_use_mgr_->GetDef(id)->type_id(); const auto type_id = def_use_mgr_->GetDef(id)->type_id();
if (type_id) { if (type_id) {
auto* ast_type = parser_impl_.ConvertType(type_id); auto* ast_type = parser_impl_.ConvertType(type_id);
if (ast_type && ast_type->Is<ast::type::PointerType>()) { if (ast_type && ast_type->Is<ast::type::Pointer>()) {
return ast_type->As<ast::type::PointerType>()->storage_class(); return ast_type->As<ast::type::Pointer>()->storage_class();
} }
} }
return ast::StorageClass::kNone; return ast::StorageClass::kNone;
@ -3310,13 +3310,13 @@ ast::StorageClass FunctionEmitter::GetStorageClassForPointerValue(uint32_t id) {
ast::type::Type* FunctionEmitter::RemapStorageClass(ast::type::Type* type, ast::type::Type* FunctionEmitter::RemapStorageClass(ast::type::Type* type,
uint32_t result_id) { uint32_t result_id) {
if (type->Is<ast::type::PointerType>()) { if (type->Is<ast::type::Pointer>()) {
// Remap an old-style storage buffer pointer to a new-style storage // Remap an old-style storage buffer pointer to a new-style storage
// buffer pointer. // buffer pointer.
const auto* ast_ptr_type = type->As<ast::type::PointerType>(); const auto* ast_ptr_type = type->As<ast::type::Pointer>();
const auto sc = GetStorageClassForPointerValue(result_id); const auto sc = GetStorageClassForPointerValue(result_id);
if (ast_ptr_type->storage_class() != sc) { if (ast_ptr_type->storage_class() != sc) {
return parser_impl_.get_module().create<ast::type::PointerType>( return parser_impl_.get_module().create<ast::type::Pointer>(
ast_ptr_type->type(), sc); ast_ptr_type->type(), sc);
} }
} }
@ -3558,7 +3558,7 @@ bool FunctionEmitter::EmitFunctionCall(const spvtools::opt::Instruction& inst) {
<< inst.PrettyPrint(); << inst.PrettyPrint();
} }
if (result_type->Is<ast::type::VoidType>()) { if (result_type->Is<ast::type::Void>()) {
return nullptr != AddStatementForInstruction( return nullptr != AddStatementForInstruction(
create<ast::CallStatement>(call_expr), inst); create<ast::CallStatement>(call_expr), inst);
} }
@ -3600,8 +3600,8 @@ TypedExpression FunctionEmitter::MakeSimpleSelect(
// - you can't select over pointers or pointer vectors, unless you also have // - you can't select over pointers or pointer vectors, unless you also have
// a VariablePointers* capability, which is not allowed in by WebGPU. // a VariablePointers* capability, which is not allowed in by WebGPU.
auto* op_ty = operand1.type; auto* op_ty = operand1.type;
if (op_ty->Is<ast::type::VectorType>() || op_ty->is_float_scalar() || if (op_ty->Is<ast::type::Vector>() || op_ty->is_float_scalar() ||
op_ty->is_integer_scalar() || op_ty->Is<ast::type::BoolType>()) { op_ty->is_integer_scalar() || op_ty->Is<ast::type::Bool>()) {
ast::ExpressionList params; ast::ExpressionList params;
params.push_back(operand1.expr); params.push_back(operand1.expr);
params.push_back(operand2.expr); params.push_back(operand2.expr);
@ -3711,14 +3711,13 @@ bool FunctionEmitter::EmitSampledImageAccess(
auto* lod_operand = MakeOperand(inst, arg_index).expr; auto* lod_operand = MakeOperand(inst, arg_index).expr;
// When sampling from a depth texture, the Lod operand must be an unsigned // When sampling from a depth texture, the Lod operand must be an unsigned
// integer. // integer.
if (ast::type::PointerType* type = if (ast::type::Pointer* type = parser_impl_.GetTypeForHandleVar(*image)) {
parser_impl_.GetTypeForHandleVar(*image)) { if (ast::type::Texture* texture_type =
if (ast::type::TextureType* texture_type = type->type()->As<ast::type::Texture>()) {
type->type()->As<ast::type::TextureType>()) { if (texture_type->Is<ast::type::DepthTexture>()) {
if (texture_type->Is<ast::type::DepthTextureType>()) {
// Convert it to an unsigned integer type. // Convert it to an unsigned integer type.
lod_operand = ast_module_.create<ast::TypeConstructorExpression>( lod_operand = ast_module_.create<ast::TypeConstructorExpression>(
ast_module_.create<ast::type::U32Type>(), ast_module_.create<ast::type::U32>(),
ast::ExpressionList{lod_operand}); ast::ExpressionList{lod_operand});
} }
} }
@ -3780,17 +3779,17 @@ ast::ExpressionList FunctionEmitter::MakeCoordinateOperandsForImageAccess(
if (!raw_coords.type) { if (!raw_coords.type) {
return {}; return {};
} }
ast::type::PointerType* type = parser_impl_.GetTypeForHandleVar(*image); ast::type::Pointer* type = parser_impl_.GetTypeForHandleVar(*image);
if (!parser_impl_.success()) { if (!parser_impl_.success()) {
Fail(); Fail();
return {}; return {};
} }
if (!type || !type->type()->Is<ast::type::TextureType>()) { if (!type || !type->type()->Is<ast::type::Texture>()) {
Fail() << "invalid texture type for " << image->PrettyPrint(); Fail() << "invalid texture type for " << image->PrettyPrint();
return {}; return {};
} }
ast::type::TextureDimension dim = ast::type::TextureDimension dim =
type->type()->As<ast::type::TextureType>()->dim(); type->type()->As<ast::type::Texture>()->dim();
// Number of regular coordinates. // Number of regular coordinates.
uint32_t num_axes = 0; uint32_t num_axes = 0;
bool is_arrayed = false; bool is_arrayed = false;
@ -3829,10 +3828,10 @@ ast::ExpressionList FunctionEmitter::MakeCoordinateOperandsForImageAccess(
assert(num_axes <= 3); assert(num_axes <= 3);
const auto num_coords_required = num_axes + (is_arrayed ? 1 : 0); const auto num_coords_required = num_axes + (is_arrayed ? 1 : 0);
uint32_t num_coords_supplied = 0; uint32_t num_coords_supplied = 0;
if (raw_coords.type->Is<ast::type::F32Type>()) { if (raw_coords.type->Is<ast::type::F32>()) {
num_coords_supplied = 1; num_coords_supplied = 1;
} else if (raw_coords.type->Is<ast::type::VectorType>()) { } else if (raw_coords.type->Is<ast::type::Vector>()) {
num_coords_supplied = raw_coords.type->As<ast::type::VectorType>()->size(); num_coords_supplied = raw_coords.type->As<ast::type::Vector>()->size();
} }
if (num_coords_supplied == 0) { if (num_coords_supplied == 0) {
Fail() << "bad or unsupported coordinate type for image access: " Fail() << "bad or unsupported coordinate type for image access: "
@ -3867,7 +3866,7 @@ ast::ExpressionList FunctionEmitter::MakeCoordinateOperandsForImageAccess(
Swizzle(num_axes)); Swizzle(num_axes));
// Convert it to an unsigned integer type. // Convert it to an unsigned integer type.
result.push_back(ast_module_.create<ast::TypeConstructorExpression>( result.push_back(ast_module_.create<ast::TypeConstructorExpression>(
ast_module_.create<ast::type::U32Type>(), ast_module_.create<ast::type::U32>(),
ast::ExpressionList{array_index})); ast::ExpressionList{array_index}));
} else { } else {
if (num_coords_supplied == num_coords_required) { if (num_coords_supplied == num_coords_required) {

View File

@ -441,7 +441,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer) {
)")) << ToString(fe.ast_body()); )")) << ToString(fe.ast_body());
} }
TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer_AliasType) { TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer_Alias) {
auto p = parser(test::Assemble( auto p = parser(test::Assemble(
std::string("OpDecorate %arr2uint ArrayStride 16\n") + Preamble() + R"( std::string("OpDecorate %arr2uint ArrayStride 16\n") + Preamble() + R"(
%ptr = OpTypePointer Function %arr2uint %ptr = OpTypePointer Function %arr2uint
@ -508,7 +508,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer_Null) {
)")) << ToString(fe.ast_body()); )")) << ToString(fe.ast_body());
} }
TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer_AliasType_Null) { TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer_Alias_Null) {
auto p = parser(test::Assemble( auto p = parser(test::Assemble(
std::string("OpDecorate %arr2uint ArrayStride 16\n") + Preamble() + R"( std::string("OpDecorate %arr2uint ArrayStride 16\n") + Preamble() + R"(
%ptr = OpTypePointer Function %arr2uint %ptr = OpTypePointer Function %arr2uint

View File

@ -196,7 +196,7 @@ ParserImpl::ParserImpl(Context* ctx, const std::vector<uint32_t>& spv_binary)
: Reader(ctx), : Reader(ctx),
spv_binary_(spv_binary), spv_binary_(spv_binary),
fail_stream_(&success_, &errors_), fail_stream_(&success_, &errors_),
bool_type_(ast_module_.create<ast::type::BoolType>()), bool_type_(ast_module_.create<ast::type::Bool>()),
namer_(fail_stream_), namer_(fail_stream_),
enum_converter_(fail_stream_), enum_converter_(fail_stream_),
tools_context_(kInputEnv) { tools_context_(kInputEnv) {
@ -285,7 +285,7 @@ ast::type::Type* ParserImpl::ConvertType(uint32_t type_id) {
switch (spirv_type->kind()) { switch (spirv_type->kind()) {
case spvtools::opt::analysis::Type::kVoid: case spvtools::opt::analysis::Type::kVoid:
return save(ast_module_.create<ast::type::VoidType>()); return save(ast_module_.create<ast::type::Void>());
case spvtools::opt::analysis::Type::kBool: case spvtools::opt::analysis::Type::kBool:
return save(bool_type_); return save(bool_type_);
case spvtools::opt::analysis::Type::kInteger: case spvtools::opt::analysis::Type::kInteger:
@ -315,7 +315,7 @@ ast::type::Type* ParserImpl::ConvertType(uint32_t type_id) {
case spvtools::opt::analysis::Type::kImage: case spvtools::opt::analysis::Type::kImage:
// Fake it for sampler and texture types. These are handled in an // Fake it for sampler and texture types. These are handled in an
// entirely different way. // entirely different way.
return save(ast_module_.create<ast::type::VoidType>()); return save(ast_module_.create<ast::type::Void>());
default: default:
break; break;
} }
@ -648,8 +648,8 @@ bool ParserImpl::RegisterEntryPoints() {
ast::type::Type* ParserImpl::ConvertType( ast::type::Type* ParserImpl::ConvertType(
const spvtools::opt::analysis::Integer* int_ty) { const spvtools::opt::analysis::Integer* int_ty) {
if (int_ty->width() == 32) { if (int_ty->width() == 32) {
ast::type::Type* signed_ty = ast_module_.create<ast::type::I32Type>(); ast::type::Type* signed_ty = ast_module_.create<ast::type::I32>();
ast::type::Type* unsigned_ty = ast_module_.create<ast::type::U32Type>(); ast::type::Type* unsigned_ty = ast_module_.create<ast::type::U32>();
signed_type_for_[unsigned_ty] = signed_ty; signed_type_for_[unsigned_ty] = signed_ty;
unsigned_type_for_[signed_ty] = unsigned_ty; unsigned_type_for_[signed_ty] = unsigned_ty;
return int_ty->IsSigned() ? signed_ty : unsigned_ty; return int_ty->IsSigned() ? signed_ty : unsigned_ty;
@ -661,7 +661,7 @@ ast::type::Type* ParserImpl::ConvertType(
ast::type::Type* ParserImpl::ConvertType( ast::type::Type* ParserImpl::ConvertType(
const spvtools::opt::analysis::Float* float_ty) { const spvtools::opt::analysis::Float* float_ty) {
if (float_ty->width() == 32) { if (float_ty->width() == 32) {
return ast_module_.create<ast::type::F32Type>(); return ast_module_.create<ast::type::F32>();
} }
Fail() << "unhandled float width: " << float_ty->width(); Fail() << "unhandled float width: " << float_ty->width();
return nullptr; return nullptr;
@ -674,16 +674,15 @@ ast::type::Type* ParserImpl::ConvertType(
if (ast_elem_ty == nullptr) { if (ast_elem_ty == nullptr) {
return nullptr; return nullptr;
} }
auto* this_ty = auto* this_ty = ast_module_.create<ast::type::Vector>(ast_elem_ty, num_elem);
ast_module_.create<ast::type::VectorType>(ast_elem_ty, num_elem);
// Generate the opposite-signedness vector type, if this type is integral. // Generate the opposite-signedness vector type, if this type is integral.
if (unsigned_type_for_.count(ast_elem_ty)) { if (unsigned_type_for_.count(ast_elem_ty)) {
auto* other_ty = ast_module_.create<ast::type::VectorType>( auto* other_ty = ast_module_.create<ast::type::Vector>(
unsigned_type_for_[ast_elem_ty], num_elem); unsigned_type_for_[ast_elem_ty], num_elem);
signed_type_for_[other_ty] = this_ty; signed_type_for_[other_ty] = this_ty;
unsigned_type_for_[this_ty] = other_ty; unsigned_type_for_[this_ty] = other_ty;
} else if (signed_type_for_.count(ast_elem_ty)) { } else if (signed_type_for_.count(ast_elem_ty)) {
auto* other_ty = ast_module_.create<ast::type::VectorType>( auto* other_ty = ast_module_.create<ast::type::Vector>(
signed_type_for_[ast_elem_ty], num_elem); signed_type_for_[ast_elem_ty], num_elem);
unsigned_type_for_[other_ty] = this_ty; unsigned_type_for_[other_ty] = this_ty;
signed_type_for_[this_ty] = other_ty; signed_type_for_[this_ty] = other_ty;
@ -701,7 +700,7 @@ ast::type::Type* ParserImpl::ConvertType(
if (ast_scalar_ty == nullptr) { if (ast_scalar_ty == nullptr) {
return nullptr; return nullptr;
} }
return ast_module_.create<ast::type::MatrixType>(ast_scalar_ty, num_rows, return ast_module_.create<ast::type::Matrix>(ast_scalar_ty, num_rows,
num_columns); num_columns);
} }
@ -711,7 +710,7 @@ ast::type::Type* ParserImpl::ConvertType(
if (ast_elem_ty == nullptr) { if (ast_elem_ty == nullptr) {
return nullptr; return nullptr;
} }
auto ast_type = std::make_unique<ast::type::ArrayType>(ast_elem_ty); auto ast_type = std::make_unique<ast::type::Array>(ast_elem_ty);
if (!ApplyArrayDecorations(rtarr_ty, ast_type.get())) { if (!ApplyArrayDecorations(rtarr_ty, ast_type.get())) {
return nullptr; return nullptr;
} }
@ -752,7 +751,7 @@ ast::type::Type* ParserImpl::ConvertType(
<< num_elem; << num_elem;
return nullptr; return nullptr;
} }
auto ast_type = std::make_unique<ast::type::ArrayType>( auto ast_type = std::make_unique<ast::type::Array>(
ast_elem_ty, static_cast<uint32_t>(num_elem)); ast_elem_ty, static_cast<uint32_t>(num_elem));
if (!ApplyArrayDecorations(arr_ty, ast_type.get())) { if (!ApplyArrayDecorations(arr_ty, ast_type.get())) {
return nullptr; return nullptr;
@ -765,7 +764,7 @@ ast::type::Type* ParserImpl::ConvertType(
bool ParserImpl::ApplyArrayDecorations( bool ParserImpl::ApplyArrayDecorations(
const spvtools::opt::analysis::Type* spv_type, const spvtools::opt::analysis::Type* spv_type,
ast::type::ArrayType* ast_type) { ast::type::Array* ast_type) {
const auto type_id = type_mgr_->GetId(spv_type); const auto type_id = type_mgr_->GetId(spv_type);
for (auto& decoration : this->GetDecorationsFor(type_id)) { for (auto& decoration : this->GetDecorationsFor(type_id)) {
if (decoration.size() == 2 && decoration[0] == SpvDecorationArrayStride) { if (decoration.size() == 2 && decoration[0] == SpvDecorationArrayStride) {
@ -886,8 +885,8 @@ ast::type::Type* ParserImpl::ConvertType(
namer_.SuggestSanitizedName(type_id, "S"); namer_.SuggestSanitizedName(type_id, "S");
auto* result = ast_module_.create<ast::type::StructType>( auto* result = ast_module_.create<ast::type::Struct>(namer_.GetName(type_id),
namer_.GetName(type_id), ast_struct); ast_struct);
id_to_type_[type_id] = result; id_to_type_[type_id] = result;
if (num_non_writable_members == members.size()) { if (num_non_writable_members == members.size()) {
read_only_struct_types_.insert(result); read_only_struct_types_.insert(result);
@ -927,8 +926,7 @@ ast::type::Type* ParserImpl::ConvertType(
ast_storage_class = ast::StorageClass::kStorageBuffer; ast_storage_class = ast::StorageClass::kStorageBuffer;
remap_buffer_block_type_.insert(type_id); remap_buffer_block_type_.insert(type_id);
} }
return ast_module_.create<ast::type::PointerType>(ast_elem_ty, return ast_module_.create<ast::type::Pointer>(ast_elem_ty, ast_storage_class);
ast_storage_class);
} }
bool ParserImpl::RegisterTypes() { bool ParserImpl::RegisterTypes() {
@ -975,15 +973,15 @@ bool ParserImpl::EmitScalarSpecConstants() {
case SpvOpSpecConstant: { case SpvOpSpecConstant: {
ast_type = ConvertType(inst.type_id()); ast_type = ConvertType(inst.type_id());
const uint32_t literal_value = inst.GetSingleWordInOperand(0); const uint32_t literal_value = inst.GetSingleWordInOperand(0);
if (ast_type->Is<ast::type::I32Type>()) { if (ast_type->Is<ast::type::I32>()) {
ast_expr = ast_expr =
create<ast::ScalarConstructorExpression>(create<ast::SintLiteral>( create<ast::ScalarConstructorExpression>(create<ast::SintLiteral>(
ast_type, static_cast<int32_t>(literal_value))); ast_type, static_cast<int32_t>(literal_value)));
} else if (ast_type->Is<ast::type::U32Type>()) { } else if (ast_type->Is<ast::type::U32>()) {
ast_expr = ast_expr =
create<ast::ScalarConstructorExpression>(create<ast::UintLiteral>( create<ast::ScalarConstructorExpression>(create<ast::UintLiteral>(
ast_type, static_cast<uint32_t>(literal_value))); ast_type, static_cast<uint32_t>(literal_value)));
} else if (ast_type->Is<ast::type::F32Type>()) { } else if (ast_type->Is<ast::type::F32>()) {
float float_value; float float_value;
// Copy the bits so we can read them as a float. // Copy the bits so we can read them as a float.
std::memcpy(&float_value, &literal_value, sizeof(float_value)); std::memcpy(&float_value, &literal_value, sizeof(float_value));
@ -1058,7 +1056,7 @@ void ParserImpl::MaybeGenerateAlias(uint32_t type_id,
} }
const auto name = namer_.GetName(type_id); const auto name = namer_.GetName(type_id);
auto* ast_alias_type = auto* ast_alias_type =
ast_module_.create<ast::type::AliasType>(name, ast_underlying_type); ast_module_.create<ast::type::Alias>(name, ast_underlying_type);
// Record this new alias as the AST type for this SPIR-V ID. // Record this new alias as the AST type for this SPIR-V ID.
id_to_type_[type_id] = ast_alias_type; id_to_type_[type_id] = ast_alias_type;
ast_module_.AddConstructedType(ast_alias_type); ast_module_.AddConstructedType(ast_alias_type);
@ -1116,15 +1114,15 @@ bool ParserImpl::EmitModuleScopeVariables() {
"SPIR-V type with ID: " "SPIR-V type with ID: "
<< var.type_id(); << var.type_id();
} }
if (!ast_type->Is<ast::type::PointerType>()) { if (!ast_type->Is<ast::type::Pointer>()) {
return Fail() << "variable with ID " << var.result_id() return Fail() << "variable with ID " << var.result_id()
<< " has non-pointer type " << var.type_id(); << " has non-pointer type " << var.type_id();
} }
} }
auto* ast_store_type = ast_type->As<ast::type::PointerType>()->type(); auto* ast_store_type = ast_type->As<ast::type::Pointer>()->type();
auto ast_storage_class = auto ast_storage_class =
ast_type->As<ast::type::PointerType>()->storage_class(); ast_type->As<ast::type::Pointer>()->storage_class();
auto* ast_var = auto* ast_var =
MakeVariable(var.result_id(), ast_storage_class, ast_store_type); MakeVariable(var.result_id(), ast_storage_class, ast_store_type);
if (var.NumInOperands() > 1) { if (var.NumInOperands() > 1) {
@ -1170,7 +1168,7 @@ ast::Variable* ParserImpl::MakeVariable(uint32_t id,
auto access = read_only_struct_types_.count(type) auto access = read_only_struct_types_.count(type)
? ast::AccessControl::kReadOnly ? ast::AccessControl::kReadOnly
: ast::AccessControl::kReadWrite; : ast::AccessControl::kReadWrite;
type = ast_module_.create<ast::type::AccessControlType>(access, type); type = ast_module_.create<ast::type::AccessControl>(access, type);
} }
auto* ast_var = create<ast::Variable>(namer_.Name(id), sc, type); auto* ast_var = create<ast::Variable>(namer_.Name(id), sc, type);
@ -1263,22 +1261,22 @@ TypedExpression ParserImpl::MakeConstantExpression(uint32_t id) {
// So canonicalization should map that way too. // So canonicalization should map that way too.
// Currently "null<type>" is missing from the WGSL parser. // Currently "null<type>" is missing from the WGSL parser.
// See https://bugs.chromium.org/p/tint/issues/detail?id=34 // See https://bugs.chromium.org/p/tint/issues/detail?id=34
if (ast_type->Is<ast::type::U32Type>()) { if (ast_type->Is<ast::type::U32>()) {
return {ast_type, return {ast_type,
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::UintLiteral>(ast_type, spirv_const->GetU32()))}; create<ast::UintLiteral>(ast_type, spirv_const->GetU32()))};
} }
if (ast_type->Is<ast::type::I32Type>()) { if (ast_type->Is<ast::type::I32>()) {
return {ast_type, return {ast_type,
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(ast_type, spirv_const->GetS32()))}; create<ast::SintLiteral>(ast_type, spirv_const->GetS32()))};
} }
if (ast_type->Is<ast::type::F32Type>()) { if (ast_type->Is<ast::type::F32>()) {
return {ast_type, return {ast_type,
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(ast_type, spirv_const->GetFloat()))}; create<ast::FloatLiteral>(ast_type, spirv_const->GetFloat()))};
} }
if (ast_type->Is<ast::type::BoolType>()) { if (ast_type->Is<ast::type::Bool>()) {
const bool value = spirv_const->AsNullConstant() const bool value = spirv_const->AsNullConstant()
? false ? false
: spirv_const->AsBoolConstant()->value(); : spirv_const->AsBoolConstant()->value();
@ -1335,24 +1333,24 @@ ast::Expression* ParserImpl::MakeNullValue(ast::type::Type* type) {
auto* original_type = type; auto* original_type = type;
type = type->UnwrapIfNeeded(); type = type->UnwrapIfNeeded();
if (type->Is<ast::type::BoolType>()) { if (type->Is<ast::type::Bool>()) {
return create<ast::ScalarConstructorExpression>( return create<ast::ScalarConstructorExpression>(
create<ast::BoolLiteral>(type, false)); create<ast::BoolLiteral>(type, false));
} }
if (type->Is<ast::type::U32Type>()) { if (type->Is<ast::type::U32>()) {
return create<ast::ScalarConstructorExpression>( return create<ast::ScalarConstructorExpression>(
create<ast::UintLiteral>(type, 0u)); create<ast::UintLiteral>(type, 0u));
} }
if (type->Is<ast::type::I32Type>()) { if (type->Is<ast::type::I32>()) {
return create<ast::ScalarConstructorExpression>( return create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(type, 0)); create<ast::SintLiteral>(type, 0));
} }
if (type->Is<ast::type::F32Type>()) { if (type->Is<ast::type::F32>()) {
return create<ast::ScalarConstructorExpression>( return create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(type, 0.0f)); create<ast::FloatLiteral>(type, 0.0f));
} }
if (type->Is<ast::type::VectorType>()) { if (type->Is<ast::type::Vector>()) {
const auto* vec_ty = type->As<ast::type::VectorType>(); const auto* vec_ty = type->As<ast::type::Vector>();
ast::ExpressionList ast_components; ast::ExpressionList ast_components;
for (size_t i = 0; i < vec_ty->size(); ++i) { for (size_t i = 0; i < vec_ty->size(); ++i) {
ast_components.emplace_back(MakeNullValue(vec_ty->type())); ast_components.emplace_back(MakeNullValue(vec_ty->type()));
@ -1360,11 +1358,11 @@ ast::Expression* ParserImpl::MakeNullValue(ast::type::Type* type) {
return create<ast::TypeConstructorExpression>(type, return create<ast::TypeConstructorExpression>(type,
std::move(ast_components)); std::move(ast_components));
} }
if (type->Is<ast::type::MatrixType>()) { if (type->Is<ast::type::Matrix>()) {
const auto* mat_ty = type->As<ast::type::MatrixType>(); const auto* mat_ty = type->As<ast::type::Matrix>();
// Matrix components are columns // Matrix components are columns
auto* column_ty = ast_module_.create<ast::type::VectorType>(mat_ty->type(), auto* column_ty =
mat_ty->rows()); ast_module_.create<ast::type::Vector>(mat_ty->type(), mat_ty->rows());
ast::ExpressionList ast_components; ast::ExpressionList ast_components;
for (size_t i = 0; i < mat_ty->columns(); ++i) { for (size_t i = 0; i < mat_ty->columns(); ++i) {
ast_components.emplace_back(MakeNullValue(column_ty)); ast_components.emplace_back(MakeNullValue(column_ty));
@ -1372,8 +1370,8 @@ ast::Expression* ParserImpl::MakeNullValue(ast::type::Type* type) {
return create<ast::TypeConstructorExpression>(type, return create<ast::TypeConstructorExpression>(type,
std::move(ast_components)); std::move(ast_components));
} }
if (type->Is<ast::type::ArrayType>()) { if (type->Is<ast::type::Array>()) {
auto* arr_ty = type->As<ast::type::ArrayType>(); auto* arr_ty = type->As<ast::type::Array>();
ast::ExpressionList ast_components; ast::ExpressionList ast_components;
for (size_t i = 0; i < arr_ty->size(); ++i) { for (size_t i = 0; i < arr_ty->size(); ++i) {
ast_components.emplace_back(MakeNullValue(arr_ty->type())); ast_components.emplace_back(MakeNullValue(arr_ty->type()));
@ -1381,8 +1379,8 @@ ast::Expression* ParserImpl::MakeNullValue(ast::type::Type* type) {
return create<ast::TypeConstructorExpression>(original_type, return create<ast::TypeConstructorExpression>(original_type,
std::move(ast_components)); std::move(ast_components));
} }
if (type->Is<ast::type::StructType>()) { if (type->Is<ast::type::Struct>()) {
auto* struct_ty = type->As<ast::type::StructType>(); auto* struct_ty = type->As<ast::type::Struct>();
ast::ExpressionList ast_components; ast::ExpressionList ast_components;
for (auto* member : struct_ty->impl()->members()) { for (auto* member : struct_ty->impl()->members()) {
ast_components.emplace_back(MakeNullValue(member->type())); ast_components.emplace_back(MakeNullValue(member->type()));
@ -1445,14 +1443,14 @@ ast::type::Type* ParserImpl::GetSignedIntMatchingShape(ast::type::Type* other) {
if (other == nullptr) { if (other == nullptr) {
Fail() << "no type provided"; Fail() << "no type provided";
} }
auto* i32 = ast_module_.create<ast::type::I32Type>(); auto* i32 = ast_module_.create<ast::type::I32>();
if (other->Is<ast::type::F32Type>() || other->Is<ast::type::U32Type>() || if (other->Is<ast::type::F32>() || other->Is<ast::type::U32>() ||
other->Is<ast::type::I32Type>()) { other->Is<ast::type::I32>()) {
return i32; return i32;
} }
auto* vec_ty = other->As<ast::type::VectorType>(); auto* vec_ty = other->As<ast::type::Vector>();
if (vec_ty) { if (vec_ty) {
return ast_module_.create<ast::type::VectorType>(i32, vec_ty->size()); return ast_module_.create<ast::type::Vector>(i32, vec_ty->size());
} }
Fail() << "required numeric scalar or vector, but got " << other->type_name(); Fail() << "required numeric scalar or vector, but got " << other->type_name();
return nullptr; return nullptr;
@ -1464,14 +1462,14 @@ ast::type::Type* ParserImpl::GetUnsignedIntMatchingShape(
Fail() << "no type provided"; Fail() << "no type provided";
return nullptr; return nullptr;
} }
auto* u32 = ast_module_.create<ast::type::U32Type>(); auto* u32 = ast_module_.create<ast::type::U32>();
if (other->Is<ast::type::F32Type>() || other->Is<ast::type::U32Type>() || if (other->Is<ast::type::F32>() || other->Is<ast::type::U32>() ||
other->Is<ast::type::I32Type>()) { other->Is<ast::type::I32>()) {
return u32; return u32;
} }
auto* vec_ty = other->As<ast::type::VectorType>(); auto* vec_ty = other->As<ast::type::Vector>();
if (vec_ty) { if (vec_ty) {
return ast_module_.create<ast::type::VectorType>(u32, vec_ty->size()); return ast_module_.create<ast::type::Vector>(u32, vec_ty->size());
} }
Fail() << "required numeric scalar or vector, but got " << other->type_name(); Fail() << "required numeric scalar or vector, but got " << other->type_name();
return nullptr; return nullptr;
@ -1603,7 +1601,7 @@ ParserImpl::GetMemoryObjectDeclarationForHandle(uint32_t id,
} }
} }
ast::type::PointerType* ParserImpl::GetTypeForHandleVar( ast::type::Pointer* ParserImpl::GetTypeForHandleVar(
const spvtools::opt::Instruction& var) { const spvtools::opt::Instruction& var) {
if (!success()) { if (!success()) {
return nullptr; return nullptr;
@ -1726,7 +1724,7 @@ ast::type::PointerType* ParserImpl::GetTypeForHandleVar(
// Construct the Tint handle type. // Construct the Tint handle type.
ast::type::Type* ast_store_type = nullptr; ast::type::Type* ast_store_type = nullptr;
if (usage.IsSampler()) { if (usage.IsSampler()) {
ast_store_type = ast_module_.create<ast::type::SamplerType>( ast_store_type = ast_module_.create<ast::type::Sampler>(
usage.IsComparisonSampler() ? ast::type::SamplerKind::kComparisonSampler usage.IsComparisonSampler() ? ast::type::SamplerKind::kComparisonSampler
: ast::type::SamplerKind::kSampler); : ast::type::SamplerKind::kSampler);
} else if (usage.IsTexture()) { } else if (usage.IsTexture()) {
@ -1757,13 +1755,13 @@ ast::type::PointerType* ParserImpl::GetTypeForHandleVar(
// OpImage variable with an OpImage*Dref* instruction. In WGSL we must // OpImage variable with an OpImage*Dref* instruction. In WGSL we must
// treat that as a depth texture. // treat that as a depth texture.
if (image_type->depth() || usage.IsDepthTexture()) { if (image_type->depth() || usage.IsDepthTexture()) {
ast_store_type = ast_module_.create<ast::type::DepthTextureType>(dim); ast_store_type = ast_module_.create<ast::type::DepthTexture>(dim);
} else if (image_type->is_multisampled()) { } else if (image_type->is_multisampled()) {
// Multisampled textures are never depth textures. // Multisampled textures are never depth textures.
ast_store_type = ast_module_.create<ast::type::MultisampledTextureType>( ast_store_type = ast_module_.create<ast::type::MultisampledTexture>(
dim, ast_sampled_component_type); dim, ast_sampled_component_type);
} else { } else {
ast_store_type = ast_module_.create<ast::type::SampledTextureType>( ast_store_type = ast_module_.create<ast::type::SampledTexture>(
dim, ast_sampled_component_type); dim, ast_sampled_component_type);
} }
} else { } else {
@ -1774,8 +1772,8 @@ ast::type::PointerType* ParserImpl::GetTypeForHandleVar(
if (format == ast::type::ImageFormat::kNone) { if (format == ast::type::ImageFormat::kNone) {
return nullptr; return nullptr;
} }
ast_store_type = ast_module_.create<ast::type::StorageTextureType>( ast_store_type =
dim, access, format); ast_module_.create<ast::type::StorageTexture>(dim, access, format);
} }
} else { } else {
Fail() << "unsupported: UniformConstant variable is not a recognized " Fail() << "unsupported: UniformConstant variable is not a recognized "
@ -1785,7 +1783,7 @@ ast::type::PointerType* ParserImpl::GetTypeForHandleVar(
} }
// Form the pointer type. // Form the pointer type.
auto* result = ast_module_.create<ast::type::PointerType>( auto* result = ast_module_.create<ast::type::Pointer>(
ast_store_type, ast::StorageClass::kUniformConstant); ast_store_type, ast::StorageClass::kUniformConstant);
// Remember it for later. // Remember it for later.
handle_type_[&var] = result; handle_type_[&var] = result;

View File

@ -357,7 +357,7 @@ class ParserImpl : Reader {
ast::type::Type* first_operand_type); ast::type::Type* first_operand_type);
/// @returns the registered boolean type. /// @returns the registered boolean type.
ast::type::Type* BoolType() const { return bool_type_; } ast::type::Type* Bool() const { return bool_type_; }
/// Bookkeeping used for tracking the "position" builtin variable. /// Bookkeeping used for tracking the "position" builtin variable.
struct BuiltInPositionInfo { struct BuiltInPositionInfo {
@ -433,7 +433,7 @@ class ParserImpl : Reader {
/// @param var the OpVariable instruction /// @param var the OpVariable instruction
/// @returns the Tint AST type for the poiner-to-{sampler|texture} or null on /// @returns the Tint AST type for the poiner-to-{sampler|texture} or null on
/// error /// error
ast::type::PointerType* GetTypeForHandleVar( ast::type::Pointer* GetTypeForHandleVar(
const spvtools::opt::Instruction& var); const spvtools::opt::Instruction& var);
/// Returns the SPIR-V instruction with the given ID, or nullptr. /// Returns the SPIR-V instruction with the given ID, or nullptr.
@ -484,7 +484,7 @@ class ParserImpl : Reader {
/// @param ast_type non-null; the AST type to apply decorations to /// @param ast_type non-null; the AST type to apply decorations to
/// @returns true on success. /// @returns true on success.
bool ApplyArrayDecorations(const spvtools::opt::analysis::Type* spv_type, bool ApplyArrayDecorations(const spvtools::opt::analysis::Type* spv_type,
ast::type::ArrayType* ast_type); ast::type::Array* ast_type);
/// Creates a new `ast::Node` owned by the Module. When the Module is /// Creates a new `ast::Node` owned by the Module. When the Module is
/// destructed, the `ast::Node` will also be destructed. /// destructed, the `ast::Node` will also be destructed.
@ -592,7 +592,7 @@ class ParserImpl : Reader {
// usages implied by usages of the memory-object-declaration. // usages implied by usages of the memory-object-declaration.
std::unordered_map<const spvtools::opt::Instruction*, Usage> handle_usage_; std::unordered_map<const spvtools::opt::Instruction*, Usage> handle_usage_;
// The inferred pointer type for the given handle variable. // The inferred pointer type for the given handle variable.
std::unordered_map<const spvtools::opt::Instruction*, ast::type::PointerType*> std::unordered_map<const spvtools::opt::Instruction*, ast::type::Pointer*>
handle_type_; handle_type_;
}; };

View File

@ -92,7 +92,7 @@ TEST_F(SpvParserTest, ConvertType_Void) {
EXPECT_TRUE(p->BuildInternalModule()); EXPECT_TRUE(p->BuildInternalModule());
auto* type = p->ConvertType(1); auto* type = p->ConvertType(1);
EXPECT_TRUE(type->Is<ast::type::VoidType>()); EXPECT_TRUE(type->Is<ast::type::Void>());
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
} }
@ -101,7 +101,7 @@ TEST_F(SpvParserTest, ConvertType_Bool) {
EXPECT_TRUE(p->BuildInternalModule()); EXPECT_TRUE(p->BuildInternalModule());
auto* type = p->ConvertType(100); auto* type = p->ConvertType(100);
EXPECT_TRUE(type->Is<ast::type::BoolType>()); EXPECT_TRUE(type->Is<ast::type::Bool>());
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
} }
@ -110,7 +110,7 @@ TEST_F(SpvParserTest, ConvertType_I32) {
EXPECT_TRUE(p->BuildInternalModule()); EXPECT_TRUE(p->BuildInternalModule());
auto* type = p->ConvertType(2); auto* type = p->ConvertType(2);
EXPECT_TRUE(type->Is<ast::type::I32Type>()); EXPECT_TRUE(type->Is<ast::type::I32>());
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
} }
@ -119,7 +119,7 @@ TEST_F(SpvParserTest, ConvertType_U32) {
EXPECT_TRUE(p->BuildInternalModule()); EXPECT_TRUE(p->BuildInternalModule());
auto* type = p->ConvertType(3); auto* type = p->ConvertType(3);
EXPECT_TRUE(type->Is<ast::type::U32Type>()); EXPECT_TRUE(type->Is<ast::type::U32>());
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
} }
@ -128,7 +128,7 @@ TEST_F(SpvParserTest, ConvertType_F32) {
EXPECT_TRUE(p->BuildInternalModule()); EXPECT_TRUE(p->BuildInternalModule());
auto* type = p->ConvertType(4); auto* type = p->ConvertType(4);
EXPECT_TRUE(type->Is<ast::type::F32Type>()); EXPECT_TRUE(type->Is<ast::type::F32>());
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
} }
@ -172,22 +172,19 @@ TEST_F(SpvParserTest, ConvertType_VecOverF32) {
EXPECT_TRUE(p->BuildInternalModule()); EXPECT_TRUE(p->BuildInternalModule());
auto* v2xf32 = p->ConvertType(20); auto* v2xf32 = p->ConvertType(20);
EXPECT_TRUE(v2xf32->Is<ast::type::VectorType>()); EXPECT_TRUE(v2xf32->Is<ast::type::Vector>());
EXPECT_TRUE( EXPECT_TRUE(v2xf32->As<ast::type::Vector>()->type()->Is<ast::type::F32>());
v2xf32->As<ast::type::VectorType>()->type()->Is<ast::type::F32Type>()); EXPECT_EQ(v2xf32->As<ast::type::Vector>()->size(), 2u);
EXPECT_EQ(v2xf32->As<ast::type::VectorType>()->size(), 2u);
auto* v3xf32 = p->ConvertType(30); auto* v3xf32 = p->ConvertType(30);
EXPECT_TRUE(v3xf32->Is<ast::type::VectorType>()); EXPECT_TRUE(v3xf32->Is<ast::type::Vector>());
EXPECT_TRUE( EXPECT_TRUE(v3xf32->As<ast::type::Vector>()->type()->Is<ast::type::F32>());
v3xf32->As<ast::type::VectorType>()->type()->Is<ast::type::F32Type>()); EXPECT_EQ(v3xf32->As<ast::type::Vector>()->size(), 3u);
EXPECT_EQ(v3xf32->As<ast::type::VectorType>()->size(), 3u);
auto* v4xf32 = p->ConvertType(40); auto* v4xf32 = p->ConvertType(40);
EXPECT_TRUE(v4xf32->Is<ast::type::VectorType>()); EXPECT_TRUE(v4xf32->Is<ast::type::Vector>());
EXPECT_TRUE( EXPECT_TRUE(v4xf32->As<ast::type::Vector>()->type()->Is<ast::type::F32>());
v4xf32->As<ast::type::VectorType>()->type()->Is<ast::type::F32Type>()); EXPECT_EQ(v4xf32->As<ast::type::Vector>()->size(), 4u);
EXPECT_EQ(v4xf32->As<ast::type::VectorType>()->size(), 4u);
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
} }
@ -202,22 +199,19 @@ TEST_F(SpvParserTest, ConvertType_VecOverI32) {
EXPECT_TRUE(p->BuildInternalModule()); EXPECT_TRUE(p->BuildInternalModule());
auto* v2xi32 = p->ConvertType(20); auto* v2xi32 = p->ConvertType(20);
EXPECT_TRUE(v2xi32->Is<ast::type::VectorType>()); EXPECT_TRUE(v2xi32->Is<ast::type::Vector>());
EXPECT_TRUE( EXPECT_TRUE(v2xi32->As<ast::type::Vector>()->type()->Is<ast::type::I32>());
v2xi32->As<ast::type::VectorType>()->type()->Is<ast::type::I32Type>()); EXPECT_EQ(v2xi32->As<ast::type::Vector>()->size(), 2u);
EXPECT_EQ(v2xi32->As<ast::type::VectorType>()->size(), 2u);
auto* v3xi32 = p->ConvertType(30); auto* v3xi32 = p->ConvertType(30);
EXPECT_TRUE(v3xi32->Is<ast::type::VectorType>()); EXPECT_TRUE(v3xi32->Is<ast::type::Vector>());
EXPECT_TRUE( EXPECT_TRUE(v3xi32->As<ast::type::Vector>()->type()->Is<ast::type::I32>());
v3xi32->As<ast::type::VectorType>()->type()->Is<ast::type::I32Type>()); EXPECT_EQ(v3xi32->As<ast::type::Vector>()->size(), 3u);
EXPECT_EQ(v3xi32->As<ast::type::VectorType>()->size(), 3u);
auto* v4xi32 = p->ConvertType(40); auto* v4xi32 = p->ConvertType(40);
EXPECT_TRUE(v4xi32->Is<ast::type::VectorType>()); EXPECT_TRUE(v4xi32->Is<ast::type::Vector>());
EXPECT_TRUE( EXPECT_TRUE(v4xi32->As<ast::type::Vector>()->type()->Is<ast::type::I32>());
v4xi32->As<ast::type::VectorType>()->type()->Is<ast::type::I32Type>()); EXPECT_EQ(v4xi32->As<ast::type::Vector>()->size(), 4u);
EXPECT_EQ(v4xi32->As<ast::type::VectorType>()->size(), 4u);
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
} }
@ -232,22 +226,19 @@ TEST_F(SpvParserTest, ConvertType_VecOverU32) {
EXPECT_TRUE(p->BuildInternalModule()); EXPECT_TRUE(p->BuildInternalModule());
auto* v2xu32 = p->ConvertType(20); auto* v2xu32 = p->ConvertType(20);
EXPECT_TRUE(v2xu32->Is<ast::type::VectorType>()); EXPECT_TRUE(v2xu32->Is<ast::type::Vector>());
EXPECT_TRUE( EXPECT_TRUE(v2xu32->As<ast::type::Vector>()->type()->Is<ast::type::U32>());
v2xu32->As<ast::type::VectorType>()->type()->Is<ast::type::U32Type>()); EXPECT_EQ(v2xu32->As<ast::type::Vector>()->size(), 2u);
EXPECT_EQ(v2xu32->As<ast::type::VectorType>()->size(), 2u);
auto* v3xu32 = p->ConvertType(30); auto* v3xu32 = p->ConvertType(30);
EXPECT_TRUE(v3xu32->Is<ast::type::VectorType>()); EXPECT_TRUE(v3xu32->Is<ast::type::Vector>());
EXPECT_TRUE( EXPECT_TRUE(v3xu32->As<ast::type::Vector>()->type()->Is<ast::type::U32>());
v3xu32->As<ast::type::VectorType>()->type()->Is<ast::type::U32Type>()); EXPECT_EQ(v3xu32->As<ast::type::Vector>()->size(), 3u);
EXPECT_EQ(v3xu32->As<ast::type::VectorType>()->size(), 3u);
auto* v4xu32 = p->ConvertType(40); auto* v4xu32 = p->ConvertType(40);
EXPECT_TRUE(v4xu32->Is<ast::type::VectorType>()); EXPECT_TRUE(v4xu32->Is<ast::type::Vector>());
EXPECT_TRUE( EXPECT_TRUE(v4xu32->As<ast::type::Vector>()->type()->Is<ast::type::U32>());
v4xu32->As<ast::type::VectorType>()->type()->Is<ast::type::U32Type>()); EXPECT_EQ(v4xu32->As<ast::type::Vector>()->size(), 4u);
EXPECT_EQ(v4xu32->As<ast::type::VectorType>()->size(), 4u);
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
} }
@ -287,67 +278,58 @@ TEST_F(SpvParserTest, ConvertType_MatrixOverF32) {
EXPECT_TRUE(p->BuildInternalModule()); EXPECT_TRUE(p->BuildInternalModule());
auto* m22 = p->ConvertType(22); auto* m22 = p->ConvertType(22);
EXPECT_TRUE(m22->Is<ast::type::MatrixType>()); EXPECT_TRUE(m22->Is<ast::type::Matrix>());
EXPECT_TRUE( EXPECT_TRUE(m22->As<ast::type::Matrix>()->type()->Is<ast::type::F32>());
m22->As<ast::type::MatrixType>()->type()->Is<ast::type::F32Type>()); EXPECT_EQ(m22->As<ast::type::Matrix>()->rows(), 2u);
EXPECT_EQ(m22->As<ast::type::MatrixType>()->rows(), 2u); EXPECT_EQ(m22->As<ast::type::Matrix>()->columns(), 2u);
EXPECT_EQ(m22->As<ast::type::MatrixType>()->columns(), 2u);
auto* m23 = p->ConvertType(23); auto* m23 = p->ConvertType(23);
EXPECT_TRUE(m23->Is<ast::type::MatrixType>()); EXPECT_TRUE(m23->Is<ast::type::Matrix>());
EXPECT_TRUE( EXPECT_TRUE(m23->As<ast::type::Matrix>()->type()->Is<ast::type::F32>());
m23->As<ast::type::MatrixType>()->type()->Is<ast::type::F32Type>()); EXPECT_EQ(m23->As<ast::type::Matrix>()->rows(), 2u);
EXPECT_EQ(m23->As<ast::type::MatrixType>()->rows(), 2u); EXPECT_EQ(m23->As<ast::type::Matrix>()->columns(), 3u);
EXPECT_EQ(m23->As<ast::type::MatrixType>()->columns(), 3u);
auto* m24 = p->ConvertType(24); auto* m24 = p->ConvertType(24);
EXPECT_TRUE(m24->Is<ast::type::MatrixType>()); EXPECT_TRUE(m24->Is<ast::type::Matrix>());
EXPECT_TRUE( EXPECT_TRUE(m24->As<ast::type::Matrix>()->type()->Is<ast::type::F32>());
m24->As<ast::type::MatrixType>()->type()->Is<ast::type::F32Type>()); EXPECT_EQ(m24->As<ast::type::Matrix>()->rows(), 2u);
EXPECT_EQ(m24->As<ast::type::MatrixType>()->rows(), 2u); EXPECT_EQ(m24->As<ast::type::Matrix>()->columns(), 4u);
EXPECT_EQ(m24->As<ast::type::MatrixType>()->columns(), 4u);
auto* m32 = p->ConvertType(32); auto* m32 = p->ConvertType(32);
EXPECT_TRUE(m32->Is<ast::type::MatrixType>()); EXPECT_TRUE(m32->Is<ast::type::Matrix>());
EXPECT_TRUE( EXPECT_TRUE(m32->As<ast::type::Matrix>()->type()->Is<ast::type::F32>());
m32->As<ast::type::MatrixType>()->type()->Is<ast::type::F32Type>()); EXPECT_EQ(m32->As<ast::type::Matrix>()->rows(), 3u);
EXPECT_EQ(m32->As<ast::type::MatrixType>()->rows(), 3u); EXPECT_EQ(m32->As<ast::type::Matrix>()->columns(), 2u);
EXPECT_EQ(m32->As<ast::type::MatrixType>()->columns(), 2u);
auto* m33 = p->ConvertType(33); auto* m33 = p->ConvertType(33);
EXPECT_TRUE(m33->Is<ast::type::MatrixType>()); EXPECT_TRUE(m33->Is<ast::type::Matrix>());
EXPECT_TRUE( EXPECT_TRUE(m33->As<ast::type::Matrix>()->type()->Is<ast::type::F32>());
m33->As<ast::type::MatrixType>()->type()->Is<ast::type::F32Type>()); EXPECT_EQ(m33->As<ast::type::Matrix>()->rows(), 3u);
EXPECT_EQ(m33->As<ast::type::MatrixType>()->rows(), 3u); EXPECT_EQ(m33->As<ast::type::Matrix>()->columns(), 3u);
EXPECT_EQ(m33->As<ast::type::MatrixType>()->columns(), 3u);
auto* m34 = p->ConvertType(34); auto* m34 = p->ConvertType(34);
EXPECT_TRUE(m34->Is<ast::type::MatrixType>()); EXPECT_TRUE(m34->Is<ast::type::Matrix>());
EXPECT_TRUE( EXPECT_TRUE(m34->As<ast::type::Matrix>()->type()->Is<ast::type::F32>());
m34->As<ast::type::MatrixType>()->type()->Is<ast::type::F32Type>()); EXPECT_EQ(m34->As<ast::type::Matrix>()->rows(), 3u);
EXPECT_EQ(m34->As<ast::type::MatrixType>()->rows(), 3u); EXPECT_EQ(m34->As<ast::type::Matrix>()->columns(), 4u);
EXPECT_EQ(m34->As<ast::type::MatrixType>()->columns(), 4u);
auto* m42 = p->ConvertType(42); auto* m42 = p->ConvertType(42);
EXPECT_TRUE(m42->Is<ast::type::MatrixType>()); EXPECT_TRUE(m42->Is<ast::type::Matrix>());
EXPECT_TRUE( EXPECT_TRUE(m42->As<ast::type::Matrix>()->type()->Is<ast::type::F32>());
m42->As<ast::type::MatrixType>()->type()->Is<ast::type::F32Type>()); EXPECT_EQ(m42->As<ast::type::Matrix>()->rows(), 4u);
EXPECT_EQ(m42->As<ast::type::MatrixType>()->rows(), 4u); EXPECT_EQ(m42->As<ast::type::Matrix>()->columns(), 2u);
EXPECT_EQ(m42->As<ast::type::MatrixType>()->columns(), 2u);
auto* m43 = p->ConvertType(43); auto* m43 = p->ConvertType(43);
EXPECT_TRUE(m43->Is<ast::type::MatrixType>()); EXPECT_TRUE(m43->Is<ast::type::Matrix>());
EXPECT_TRUE( EXPECT_TRUE(m43->As<ast::type::Matrix>()->type()->Is<ast::type::F32>());
m43->As<ast::type::MatrixType>()->type()->Is<ast::type::F32Type>()); EXPECT_EQ(m43->As<ast::type::Matrix>()->rows(), 4u);
EXPECT_EQ(m43->As<ast::type::MatrixType>()->rows(), 4u); EXPECT_EQ(m43->As<ast::type::Matrix>()->columns(), 3u);
EXPECT_EQ(m43->As<ast::type::MatrixType>()->columns(), 3u);
auto* m44 = p->ConvertType(44); auto* m44 = p->ConvertType(44);
EXPECT_TRUE(m44->Is<ast::type::MatrixType>()); EXPECT_TRUE(m44->Is<ast::type::Matrix>());
EXPECT_TRUE( EXPECT_TRUE(m44->As<ast::type::Matrix>()->type()->Is<ast::type::F32>());
m44->As<ast::type::MatrixType>()->type()->Is<ast::type::F32Type>()); EXPECT_EQ(m44->As<ast::type::Matrix>()->rows(), 4u);
EXPECT_EQ(m44->As<ast::type::MatrixType>()->rows(), 4u); EXPECT_EQ(m44->As<ast::type::Matrix>()->columns(), 4u);
EXPECT_EQ(m44->As<ast::type::MatrixType>()->columns(), 4u);
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
} }
@ -361,8 +343,8 @@ TEST_F(SpvParserTest, ConvertType_RuntimeArray) {
auto* type = p->ConvertType(10); auto* type = p->ConvertType(10);
ASSERT_NE(type, nullptr); ASSERT_NE(type, nullptr);
EXPECT_TRUE(type->Is<ast::type::ArrayType>()); EXPECT_TRUE(type->Is<ast::type::Array>());
auto* arr_type = type->As<ast::type::ArrayType>(); auto* arr_type = type->As<ast::type::Array>();
EXPECT_TRUE(arr_type->IsRuntimeArray()); EXPECT_TRUE(arr_type->IsRuntimeArray());
ASSERT_NE(arr_type, nullptr); ASSERT_NE(arr_type, nullptr);
EXPECT_EQ(arr_type->size(), 0u); EXPECT_EQ(arr_type->size(), 0u);
@ -370,7 +352,7 @@ TEST_F(SpvParserTest, ConvertType_RuntimeArray) {
EXPECT_FALSE(arr_type->has_array_stride()); EXPECT_FALSE(arr_type->has_array_stride());
auto* elem_type = arr_type->type(); auto* elem_type = arr_type->type();
ASSERT_NE(elem_type, nullptr); ASSERT_NE(elem_type, nullptr);
EXPECT_TRUE(elem_type->Is<ast::type::U32Type>()); EXPECT_TRUE(elem_type->Is<ast::type::U32>());
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
} }
@ -397,7 +379,7 @@ TEST_F(SpvParserTest, ConvertType_RuntimeArray_ArrayStride_Valid) {
EXPECT_TRUE(p->BuildInternalModule()); EXPECT_TRUE(p->BuildInternalModule());
auto* type = p->ConvertType(10); auto* type = p->ConvertType(10);
ASSERT_NE(type, nullptr); ASSERT_NE(type, nullptr);
auto* arr_type = type->As<ast::type::ArrayType>(); auto* arr_type = type->As<ast::type::Array>();
EXPECT_TRUE(arr_type->IsRuntimeArray()); EXPECT_TRUE(arr_type->IsRuntimeArray());
ASSERT_NE(arr_type, nullptr); ASSERT_NE(arr_type, nullptr);
EXPECT_EQ(arr_type->array_stride(), 64u); EXPECT_EQ(arr_type->array_stride(), 64u);
@ -443,8 +425,8 @@ TEST_F(SpvParserTest, ConvertType_Array) {
auto* type = p->ConvertType(10); auto* type = p->ConvertType(10);
ASSERT_NE(type, nullptr); ASSERT_NE(type, nullptr);
EXPECT_TRUE(type->Is<ast::type::ArrayType>()); EXPECT_TRUE(type->Is<ast::type::Array>());
auto* arr_type = type->As<ast::type::ArrayType>(); auto* arr_type = type->As<ast::type::Array>();
EXPECT_FALSE(arr_type->IsRuntimeArray()); EXPECT_FALSE(arr_type->IsRuntimeArray());
ASSERT_NE(arr_type, nullptr); ASSERT_NE(arr_type, nullptr);
EXPECT_EQ(arr_type->size(), 42u); EXPECT_EQ(arr_type->size(), 42u);
@ -452,7 +434,7 @@ TEST_F(SpvParserTest, ConvertType_Array) {
EXPECT_FALSE(arr_type->has_array_stride()); EXPECT_FALSE(arr_type->has_array_stride());
auto* elem_type = arr_type->type(); auto* elem_type = arr_type->type();
ASSERT_NE(elem_type, nullptr); ASSERT_NE(elem_type, nullptr);
EXPECT_TRUE(elem_type->Is<ast::type::U32Type>()); EXPECT_TRUE(elem_type->Is<ast::type::U32>());
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
} }
@ -531,8 +513,8 @@ TEST_F(SpvParserTest, ConvertType_ArrayStride_Valid) {
auto* type = p->ConvertType(10); auto* type = p->ConvertType(10);
ASSERT_NE(type, nullptr); ASSERT_NE(type, nullptr);
EXPECT_TRUE(type->Is<ast::type::ArrayType>()); EXPECT_TRUE(type->Is<ast::type::Array>());
auto* arr_type = type->As<ast::type::ArrayType>(); auto* arr_type = type->As<ast::type::Array>();
ASSERT_NE(arr_type, nullptr); ASSERT_NE(arr_type, nullptr);
ASSERT_EQ(arr_type->array_stride(), 8u); ASSERT_EQ(arr_type->array_stride(), 8u);
EXPECT_TRUE(arr_type->has_array_stride()); EXPECT_TRUE(arr_type->has_array_stride());
@ -581,9 +563,9 @@ TEST_F(SpvParserTest, ConvertType_StructTwoMembers) {
auto* type = p->ConvertType(10); auto* type = p->ConvertType(10);
ASSERT_NE(type, nullptr); ASSERT_NE(type, nullptr);
EXPECT_TRUE(type->Is<ast::type::StructType>()); EXPECT_TRUE(type->Is<ast::type::Struct>());
std::stringstream ss; std::stringstream ss;
type->As<ast::type::StructType>()->impl()->to_str(ss, 0); type->As<ast::type::Struct>()->impl()->to_str(ss, 0);
EXPECT_THAT(ss.str(), Eq(R"(Struct{ EXPECT_THAT(ss.str(), Eq(R"(Struct{
StructMember{field0: __u32} StructMember{field0: __u32}
StructMember{field1: __f32} StructMember{field1: __f32}
@ -602,9 +584,9 @@ TEST_F(SpvParserTest, ConvertType_StructWithBlockDecoration) {
auto* type = p->ConvertType(10); auto* type = p->ConvertType(10);
ASSERT_NE(type, nullptr); ASSERT_NE(type, nullptr);
EXPECT_TRUE(type->Is<ast::type::StructType>()); EXPECT_TRUE(type->Is<ast::type::Struct>());
std::stringstream ss; std::stringstream ss;
type->As<ast::type::StructType>()->impl()->to_str(ss, 0); type->As<ast::type::Struct>()->impl()->to_str(ss, 0);
EXPECT_THAT(ss.str(), Eq(R"(Struct{ EXPECT_THAT(ss.str(), Eq(R"(Struct{
[[block]] [[block]]
StructMember{field0: __u32} StructMember{field0: __u32}
@ -627,9 +609,9 @@ TEST_F(SpvParserTest, ConvertType_StructWithMemberDecorations) {
auto* type = p->ConvertType(10); auto* type = p->ConvertType(10);
ASSERT_NE(type, nullptr); ASSERT_NE(type, nullptr);
EXPECT_TRUE(type->Is<ast::type::StructType>()); EXPECT_TRUE(type->Is<ast::type::Struct>());
std::stringstream ss; std::stringstream ss;
type->As<ast::type::StructType>()->impl()->to_str(ss, 0); type->As<ast::type::Struct>()->impl()->to_str(ss, 0);
EXPECT_THAT(ss.str(), Eq(R"(Struct{ EXPECT_THAT(ss.str(), Eq(R"(Struct{
StructMember{[[ offset 0 ]] field0: __f32} StructMember{[[ offset 0 ]] field0: __f32}
StructMember{[[ offset 8 ]] field1: __vec_2__f32} StructMember{[[ offset 8 ]] field1: __vec_2__f32}
@ -676,10 +658,10 @@ TEST_F(SpvParserTest, ConvertType_PointerInput) {
EXPECT_TRUE(p->BuildInternalModule()); EXPECT_TRUE(p->BuildInternalModule());
auto* type = p->ConvertType(3); auto* type = p->ConvertType(3);
EXPECT_TRUE(type->Is<ast::type::PointerType>()); EXPECT_TRUE(type->Is<ast::type::Pointer>());
auto* ptr_ty = type->As<ast::type::PointerType>(); auto* ptr_ty = type->As<ast::type::Pointer>();
EXPECT_NE(ptr_ty, nullptr); EXPECT_NE(ptr_ty, nullptr);
EXPECT_TRUE(ptr_ty->type()->Is<ast::type::F32Type>()); EXPECT_TRUE(ptr_ty->type()->Is<ast::type::F32>());
EXPECT_EQ(ptr_ty->storage_class(), ast::StorageClass::kInput); EXPECT_EQ(ptr_ty->storage_class(), ast::StorageClass::kInput);
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
} }
@ -692,10 +674,10 @@ TEST_F(SpvParserTest, ConvertType_PointerOutput) {
EXPECT_TRUE(p->BuildInternalModule()); EXPECT_TRUE(p->BuildInternalModule());
auto* type = p->ConvertType(3); auto* type = p->ConvertType(3);
EXPECT_TRUE(type->Is<ast::type::PointerType>()); EXPECT_TRUE(type->Is<ast::type::Pointer>());
auto* ptr_ty = type->As<ast::type::PointerType>(); auto* ptr_ty = type->As<ast::type::Pointer>();
EXPECT_NE(ptr_ty, nullptr); EXPECT_NE(ptr_ty, nullptr);
EXPECT_TRUE(ptr_ty->type()->Is<ast::type::F32Type>()); EXPECT_TRUE(ptr_ty->type()->Is<ast::type::F32>());
EXPECT_EQ(ptr_ty->storage_class(), ast::StorageClass::kOutput); EXPECT_EQ(ptr_ty->storage_class(), ast::StorageClass::kOutput);
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
} }
@ -708,10 +690,10 @@ TEST_F(SpvParserTest, ConvertType_PointerUniform) {
EXPECT_TRUE(p->BuildInternalModule()); EXPECT_TRUE(p->BuildInternalModule());
auto* type = p->ConvertType(3); auto* type = p->ConvertType(3);
EXPECT_TRUE(type->Is<ast::type::PointerType>()); EXPECT_TRUE(type->Is<ast::type::Pointer>());
auto* ptr_ty = type->As<ast::type::PointerType>(); auto* ptr_ty = type->As<ast::type::Pointer>();
EXPECT_NE(ptr_ty, nullptr); EXPECT_NE(ptr_ty, nullptr);
EXPECT_TRUE(ptr_ty->type()->Is<ast::type::F32Type>()); EXPECT_TRUE(ptr_ty->type()->Is<ast::type::F32>());
EXPECT_EQ(ptr_ty->storage_class(), ast::StorageClass::kUniform); EXPECT_EQ(ptr_ty->storage_class(), ast::StorageClass::kUniform);
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
} }
@ -724,10 +706,10 @@ TEST_F(SpvParserTest, ConvertType_PointerWorkgroup) {
EXPECT_TRUE(p->BuildInternalModule()); EXPECT_TRUE(p->BuildInternalModule());
auto* type = p->ConvertType(3); auto* type = p->ConvertType(3);
EXPECT_TRUE(type->Is<ast::type::PointerType>()); EXPECT_TRUE(type->Is<ast::type::Pointer>());
auto* ptr_ty = type->As<ast::type::PointerType>(); auto* ptr_ty = type->As<ast::type::Pointer>();
EXPECT_NE(ptr_ty, nullptr); EXPECT_NE(ptr_ty, nullptr);
EXPECT_TRUE(ptr_ty->type()->Is<ast::type::F32Type>()); EXPECT_TRUE(ptr_ty->type()->Is<ast::type::F32>());
EXPECT_EQ(ptr_ty->storage_class(), ast::StorageClass::kWorkgroup); EXPECT_EQ(ptr_ty->storage_class(), ast::StorageClass::kWorkgroup);
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
} }
@ -740,10 +722,10 @@ TEST_F(SpvParserTest, ConvertType_PointerUniformConstant) {
EXPECT_TRUE(p->BuildInternalModule()); EXPECT_TRUE(p->BuildInternalModule());
auto* type = p->ConvertType(3); auto* type = p->ConvertType(3);
EXPECT_TRUE(type->Is<ast::type::PointerType>()); EXPECT_TRUE(type->Is<ast::type::Pointer>());
auto* ptr_ty = type->As<ast::type::PointerType>(); auto* ptr_ty = type->As<ast::type::Pointer>();
EXPECT_NE(ptr_ty, nullptr); EXPECT_NE(ptr_ty, nullptr);
EXPECT_TRUE(ptr_ty->type()->Is<ast::type::F32Type>()); EXPECT_TRUE(ptr_ty->type()->Is<ast::type::F32>());
EXPECT_EQ(ptr_ty->storage_class(), ast::StorageClass::kUniformConstant); EXPECT_EQ(ptr_ty->storage_class(), ast::StorageClass::kUniformConstant);
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
} }
@ -756,10 +738,10 @@ TEST_F(SpvParserTest, ConvertType_PointerStorageBuffer) {
EXPECT_TRUE(p->BuildInternalModule()); EXPECT_TRUE(p->BuildInternalModule());
auto* type = p->ConvertType(3); auto* type = p->ConvertType(3);
EXPECT_TRUE(type->Is<ast::type::PointerType>()); EXPECT_TRUE(type->Is<ast::type::Pointer>());
auto* ptr_ty = type->As<ast::type::PointerType>(); auto* ptr_ty = type->As<ast::type::Pointer>();
EXPECT_NE(ptr_ty, nullptr); EXPECT_NE(ptr_ty, nullptr);
EXPECT_TRUE(ptr_ty->type()->Is<ast::type::F32Type>()); EXPECT_TRUE(ptr_ty->type()->Is<ast::type::F32>());
EXPECT_EQ(ptr_ty->storage_class(), ast::StorageClass::kStorageBuffer); EXPECT_EQ(ptr_ty->storage_class(), ast::StorageClass::kStorageBuffer);
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
} }
@ -772,10 +754,10 @@ TEST_F(SpvParserTest, ConvertType_PointerImage) {
EXPECT_TRUE(p->BuildInternalModule()); EXPECT_TRUE(p->BuildInternalModule());
auto* type = p->ConvertType(3); auto* type = p->ConvertType(3);
EXPECT_TRUE(type->Is<ast::type::PointerType>()); EXPECT_TRUE(type->Is<ast::type::Pointer>());
auto* ptr_ty = type->As<ast::type::PointerType>(); auto* ptr_ty = type->As<ast::type::Pointer>();
EXPECT_NE(ptr_ty, nullptr); EXPECT_NE(ptr_ty, nullptr);
EXPECT_TRUE(ptr_ty->type()->Is<ast::type::F32Type>()); EXPECT_TRUE(ptr_ty->type()->Is<ast::type::F32>());
EXPECT_EQ(ptr_ty->storage_class(), ast::StorageClass::kImage); EXPECT_EQ(ptr_ty->storage_class(), ast::StorageClass::kImage);
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
} }
@ -788,10 +770,10 @@ TEST_F(SpvParserTest, ConvertType_PointerPrivate) {
EXPECT_TRUE(p->BuildInternalModule()); EXPECT_TRUE(p->BuildInternalModule());
auto* type = p->ConvertType(3); auto* type = p->ConvertType(3);
EXPECT_TRUE(type->Is<ast::type::PointerType>()); EXPECT_TRUE(type->Is<ast::type::Pointer>());
auto* ptr_ty = type->As<ast::type::PointerType>(); auto* ptr_ty = type->As<ast::type::Pointer>();
EXPECT_NE(ptr_ty, nullptr); EXPECT_NE(ptr_ty, nullptr);
EXPECT_TRUE(ptr_ty->type()->Is<ast::type::F32Type>()); EXPECT_TRUE(ptr_ty->type()->Is<ast::type::F32>());
EXPECT_EQ(ptr_ty->storage_class(), ast::StorageClass::kPrivate); EXPECT_EQ(ptr_ty->storage_class(), ast::StorageClass::kPrivate);
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
} }
@ -804,10 +786,10 @@ TEST_F(SpvParserTest, ConvertType_PointerFunction) {
EXPECT_TRUE(p->BuildInternalModule()); EXPECT_TRUE(p->BuildInternalModule());
auto* type = p->ConvertType(3); auto* type = p->ConvertType(3);
EXPECT_TRUE(type->Is<ast::type::PointerType>()); EXPECT_TRUE(type->Is<ast::type::Pointer>());
auto* ptr_ty = type->As<ast::type::PointerType>(); auto* ptr_ty = type->As<ast::type::Pointer>();
EXPECT_NE(ptr_ty, nullptr); EXPECT_NE(ptr_ty, nullptr);
EXPECT_TRUE(ptr_ty->type()->Is<ast::type::F32Type>()); EXPECT_TRUE(ptr_ty->type()->Is<ast::type::F32>());
EXPECT_EQ(ptr_ty->storage_class(), ast::StorageClass::kFunction); EXPECT_EQ(ptr_ty->storage_class(), ast::StorageClass::kFunction);
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
} }
@ -823,17 +805,17 @@ TEST_F(SpvParserTest, ConvertType_PointerToPointer) {
auto* type = p->ConvertType(3); auto* type = p->ConvertType(3);
EXPECT_NE(type, nullptr); EXPECT_NE(type, nullptr);
EXPECT_TRUE(type->Is<ast::type::PointerType>()); EXPECT_TRUE(type->Is<ast::type::Pointer>());
auto* ptr_ty = type->As<ast::type::PointerType>(); auto* ptr_ty = type->As<ast::type::Pointer>();
EXPECT_NE(ptr_ty, nullptr); EXPECT_NE(ptr_ty, nullptr);
EXPECT_EQ(ptr_ty->storage_class(), ast::StorageClass::kInput); EXPECT_EQ(ptr_ty->storage_class(), ast::StorageClass::kInput);
EXPECT_TRUE(ptr_ty->type()->Is<ast::type::PointerType>()); EXPECT_TRUE(ptr_ty->type()->Is<ast::type::Pointer>());
auto* ptr_ptr_ty = ptr_ty->type()->As<ast::type::PointerType>(); auto* ptr_ptr_ty = ptr_ty->type()->As<ast::type::Pointer>();
EXPECT_NE(ptr_ptr_ty, nullptr); EXPECT_NE(ptr_ptr_ty, nullptr);
EXPECT_EQ(ptr_ptr_ty->storage_class(), ast::StorageClass::kOutput); EXPECT_EQ(ptr_ptr_ty->storage_class(), ast::StorageClass::kOutput);
EXPECT_TRUE(ptr_ptr_ty->type()->Is<ast::type::F32Type>()); EXPECT_TRUE(ptr_ptr_ty->type()->Is<ast::type::F32>());
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
} }
@ -846,7 +828,7 @@ TEST_F(SpvParserTest, ConvertType_Sampler_PretendVoid) {
EXPECT_TRUE(p->BuildInternalModule()); EXPECT_TRUE(p->BuildInternalModule());
auto* type = p->ConvertType(1); auto* type = p->ConvertType(1);
EXPECT_TRUE(type->Is<ast::type::VoidType>()); EXPECT_TRUE(type->Is<ast::type::Void>());
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
} }
@ -859,7 +841,7 @@ TEST_F(SpvParserTest, ConvertType_Image_PretendVoid) {
EXPECT_TRUE(p->BuildInternalModule()); EXPECT_TRUE(p->BuildInternalModule());
auto* type = p->ConvertType(1); auto* type = p->ConvertType(1);
EXPECT_TRUE(type->Is<ast::type::VoidType>()); EXPECT_TRUE(type->Is<ast::type::Void>());
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
} }
@ -872,7 +854,7 @@ TEST_F(SpvParserTest, ConvertType_SampledImage_PretendVoid) {
EXPECT_TRUE(p->BuildInternalModule()); EXPECT_TRUE(p->BuildInternalModule());
auto* type = p->ConvertType(1); auto* type = p->ConvertType(1);
EXPECT_TRUE(type->Is<ast::type::VoidType>()); EXPECT_TRUE(type->Is<ast::type::Void>());
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
} }

View File

@ -318,7 +318,7 @@ Expect<bool> ParserImpl::expect_global_decl() {
return Failure::kErrored; return Failure::kErrored;
auto* type = module_.unique_type(std::move(str.value)); auto* type = module_.unique_type(std::move(str.value));
register_constructed(type->As<ast::type::StructType>()->name(), type); register_constructed(type->As<ast::type::Struct>()->name(), type);
module_.AddConstructedType(type); module_.AddConstructedType(type);
return true; return true;
} }
@ -471,8 +471,7 @@ Maybe<ast::type::Type*> ParserImpl::texture_sampler_types() {
if (subtype.errored) if (subtype.errored)
return Failure::kErrored; return Failure::kErrored;
return module_.create<ast::type::SampledTextureType>(dim.value, return module_.create<ast::type::SampledTexture>(dim.value, subtype.value);
subtype.value);
} }
auto ms_dim = multisampled_texture_type(); auto ms_dim = multisampled_texture_type();
@ -483,7 +482,7 @@ Maybe<ast::type::Type*> ParserImpl::texture_sampler_types() {
if (subtype.errored) if (subtype.errored)
return Failure::kErrored; return Failure::kErrored;
return module_.create<ast::type::MultisampledTextureType>(ms_dim.value, return module_.create<ast::type::MultisampledTexture>(ms_dim.value,
subtype.value); subtype.value);
} }
@ -497,7 +496,7 @@ Maybe<ast::type::Type*> ParserImpl::texture_sampler_types() {
if (format.errored) if (format.errored)
return Failure::kErrored; return Failure::kErrored;
return module_.create<ast::type::StorageTextureType>( return module_.create<ast::type::StorageTexture>(
storage->first, storage->second, format.value); storage->first, storage->second, format.value);
} }
@ -509,11 +508,10 @@ Maybe<ast::type::Type*> ParserImpl::texture_sampler_types() {
// | SAMPLER_COMPARISON // | SAMPLER_COMPARISON
Maybe<ast::type::Type*> ParserImpl::sampler_type() { Maybe<ast::type::Type*> ParserImpl::sampler_type() {
if (match(Token::Type::kSampler)) if (match(Token::Type::kSampler))
return module_.create<ast::type::SamplerType>( return module_.create<ast::type::Sampler>(ast::type::SamplerKind::kSampler);
ast::type::SamplerKind::kSampler);
if (match(Token::Type::kComparisonSampler)) if (match(Token::Type::kComparisonSampler))
return module_.create<ast::type::SamplerType>( return module_.create<ast::type::Sampler>(
ast::type::SamplerKind::kComparisonSampler); ast::type::SamplerKind::kComparisonSampler);
return Failure::kNoMatch; return Failure::kNoMatch;
@ -642,19 +640,19 @@ ParserImpl::storage_texture_type() {
// | TEXTURE_DEPTH_CUBE_ARRAY // | TEXTURE_DEPTH_CUBE_ARRAY
Maybe<ast::type::Type*> ParserImpl::depth_texture_type() { Maybe<ast::type::Type*> ParserImpl::depth_texture_type() {
if (match(Token::Type::kTextureDepth2d)) if (match(Token::Type::kTextureDepth2d))
return module_.create<ast::type::DepthTextureType>( return module_.create<ast::type::DepthTexture>(
ast::type::TextureDimension::k2d); ast::type::TextureDimension::k2d);
if (match(Token::Type::kTextureDepth2dArray)) if (match(Token::Type::kTextureDepth2dArray))
return module_.create<ast::type::DepthTextureType>( return module_.create<ast::type::DepthTexture>(
ast::type::TextureDimension::k2dArray); ast::type::TextureDimension::k2dArray);
if (match(Token::Type::kTextureDepthCube)) if (match(Token::Type::kTextureDepthCube))
return module_.create<ast::type::DepthTextureType>( return module_.create<ast::type::DepthTexture>(
ast::type::TextureDimension::kCube); ast::type::TextureDimension::kCube);
if (match(Token::Type::kTextureDepthCubeArray)) if (match(Token::Type::kTextureDepthCubeArray))
return module_.create<ast::type::DepthTextureType>( return module_.create<ast::type::DepthTexture>(
ast::type::TextureDimension::kCubeArray); ast::type::TextureDimension::kCubeArray);
return Failure::kNoMatch; return Failure::kNoMatch;
@ -840,7 +838,7 @@ Expect<ParserImpl::TypedIdentifier> ParserImpl::expect_variable_ident_decl(
for (auto* deco : access_decos) { for (auto* deco : access_decos) {
// If we have an access control decoration then we take it and wrap our // If we have an access control decoration then we take it and wrap our
// type up with that decoration // type up with that decoration
ty = module_.create<ast::type::AccessControlType>( ty = module_.create<ast::type::AccessControl>(
deco->As<ast::AccessDecoration>()->value(), ty); deco->As<ast::AccessDecoration>()->value(), ty);
} }
@ -900,7 +898,7 @@ Maybe<ast::type::Type*> ParserImpl::type_alias() {
if (!type.matched) if (!type.matched)
return add_error(peek(), "invalid type alias"); return add_error(peek(), "invalid type alias");
auto* alias = module_.create<ast::type::AliasType>(name.value, type.value); auto* alias = module_.create<ast::type::Alias>(name.value, type.value);
register_constructed(name.value, alias); register_constructed(name.value, alias);
return alias; return alias;
@ -958,16 +956,16 @@ Maybe<ast::type::Type*> ParserImpl::type_decl(ast::DecorationList& decos) {
} }
if (match(Token::Type::kBool)) if (match(Token::Type::kBool))
return module_.create<ast::type::BoolType>(); return module_.create<ast::type::Bool>();
if (match(Token::Type::kF32)) if (match(Token::Type::kF32))
return module_.create<ast::type::F32Type>(); return module_.create<ast::type::F32>();
if (match(Token::Type::kI32)) if (match(Token::Type::kI32))
return module_.create<ast::type::I32Type>(); return module_.create<ast::type::I32>();
if (match(Token::Type::kU32)) if (match(Token::Type::kU32))
return module_.create<ast::type::U32Type>(); return module_.create<ast::type::U32>();
if (t.IsVec2() || t.IsVec3() || t.IsVec4()) { if (t.IsVec2() || t.IsVec3() || t.IsVec4()) {
next(); // Consume the peek next(); // Consume the peek
@ -1025,7 +1023,7 @@ Expect<ast::type::Type*> ParserImpl::expect_type_decl_pointer() {
if (subtype.errored) if (subtype.errored)
return Failure::kErrored; return Failure::kErrored;
return module_.create<ast::type::PointerType>(subtype.value, sc.value); return module_.create<ast::type::Pointer>(subtype.value, sc.value);
}); });
} }
@ -1042,7 +1040,7 @@ Expect<ast::type::Type*> ParserImpl::expect_type_decl_vector(Token t) {
if (subtype.errored) if (subtype.errored)
return Failure::kErrored; return Failure::kErrored;
return module_.create<ast::type::VectorType>(subtype.value, count); return module_.create<ast::type::Vector>(subtype.value, count);
} }
Expect<ast::type::Type*> ParserImpl::expect_type_decl_array( Expect<ast::type::Type*> ParserImpl::expect_type_decl_array(
@ -1062,7 +1060,7 @@ Expect<ast::type::Type*> ParserImpl::expect_type_decl_array(
size = val.value; size = val.value;
} }
auto ty = std::make_unique<ast::type::ArrayType>(subtype.value, size); auto ty = std::make_unique<ast::type::Array>(subtype.value, size);
ty->set_decorations(std::move(decos)); ty->set_decorations(std::move(decos));
return module_.unique_type(std::move(ty)); return module_.unique_type(std::move(ty));
}); });
@ -1088,7 +1086,7 @@ Expect<ast::type::Type*> ParserImpl::expect_type_decl_matrix(Token t) {
if (subtype.errored) if (subtype.errored)
return Failure::kErrored; return Failure::kErrored;
return module_.create<ast::type::MatrixType>(subtype.value, rows, columns); return module_.create<ast::type::Matrix>(subtype.value, rows, columns);
} }
// storage_class // storage_class
@ -1135,7 +1133,7 @@ Expect<ast::StorageClass> ParserImpl::expect_storage_class(
// struct_decl // struct_decl
// : struct_decoration_decl* STRUCT IDENT struct_body_decl // : struct_decoration_decl* STRUCT IDENT struct_body_decl
Maybe<std::unique_ptr<ast::type::StructType>> ParserImpl::struct_decl( Maybe<std::unique_ptr<ast::type::Struct>> ParserImpl::struct_decl(
ast::DecorationList& decos) { ast::DecorationList& decos) {
auto t = peek(); auto t = peek();
auto source = t.source(); auto source = t.source();
@ -1155,7 +1153,7 @@ Maybe<std::unique_ptr<ast::type::StructType>> ParserImpl::struct_decl(
if (struct_decos.errored) if (struct_decos.errored)
return Failure::kErrored; return Failure::kErrored;
return std::make_unique<ast::type::StructType>( return std::make_unique<ast::type::Struct>(
name.value, create<ast::Struct>(source, std::move(struct_decos.value), name.value, create<ast::Struct>(source, std::move(struct_decos.value),
std::move(body.value))); std::move(body.value)));
} }
@ -1256,7 +1254,7 @@ Maybe<ast::Function*> ParserImpl::function_decl(ast::DecorationList& decos) {
// | VOID // | VOID
Maybe<ast::type::Type*> ParserImpl::function_type_decl() { Maybe<ast::type::Type*> ParserImpl::function_type_decl() {
if (match(Token::Type::kVoid)) if (match(Token::Type::kVoid))
return module_.create<ast::type::VoidType>(); return module_.create<ast::type::Void>();
return type_decl(); return type_decl();
} }
@ -2615,19 +2613,19 @@ Maybe<ast::AssignmentStatement*> ParserImpl::assignment_stmt() {
Maybe<ast::Literal*> ParserImpl::const_literal() { Maybe<ast::Literal*> ParserImpl::const_literal() {
auto t = peek(); auto t = peek();
if (match(Token::Type::kTrue)) { if (match(Token::Type::kTrue)) {
auto* type = module_.create<ast::type::BoolType>(); auto* type = module_.create<ast::type::Bool>();
return create<ast::BoolLiteral>(type, true); return create<ast::BoolLiteral>(type, true);
} }
if (match(Token::Type::kFalse)) { if (match(Token::Type::kFalse)) {
auto* type = module_.create<ast::type::BoolType>(); auto* type = module_.create<ast::type::Bool>();
return create<ast::BoolLiteral>(type, false); return create<ast::BoolLiteral>(type, false);
} }
if (match(Token::Type::kSintLiteral)) { if (match(Token::Type::kSintLiteral)) {
auto* type = module_.create<ast::type::I32Type>(); auto* type = module_.create<ast::type::I32>();
return create<ast::SintLiteral>(type, t.to_i32()); return create<ast::SintLiteral>(type, t.to_i32());
} }
if (match(Token::Type::kUintLiteral)) { if (match(Token::Type::kUintLiteral)) {
auto* type = module_.create<ast::type::U32Type>(); auto* type = module_.create<ast::type::U32>();
return create<ast::UintLiteral>(type, t.to_u32()); return create<ast::UintLiteral>(type, t.to_u32());
} }
if (match(Token::Type::kFloatLiteral)) { if (match(Token::Type::kFloatLiteral)) {
@ -2636,7 +2634,7 @@ Maybe<ast::Literal*> ParserImpl::const_literal() {
next(); // Consume 'f' next(); // Consume 'f'
add_error(p.source(), "float literals must not be suffixed with 'f'"); add_error(p.source(), "float literals must not be suffixed with 'f'");
} }
auto* type = module_.create<ast::type::F32Type>(); auto* type = module_.create<ast::type::F32>();
return create<ast::FloatLiteral>(type, t.to_f32()); return create<ast::FloatLiteral>(type, t.to_f32());
} }
return Failure::kNoMatch; return Failure::kNoMatch;

View File

@ -34,7 +34,6 @@
#include "src/ast/constructor_expression.h" #include "src/ast/constructor_expression.h"
#include "src/ast/continue_statement.h" #include "src/ast/continue_statement.h"
#include "src/ast/else_statement.h" #include "src/ast/else_statement.h"
#include "src/ast/switch_statement.h"
#include "src/ast/function.h" #include "src/ast/function.h"
#include "src/ast/if_statement.h" #include "src/ast/if_statement.h"
#include "src/ast/literal.h" #include "src/ast/literal.h"
@ -48,6 +47,7 @@
#include "src/ast/struct_decoration.h" #include "src/ast/struct_decoration.h"
#include "src/ast/struct_member.h" #include "src/ast/struct_member.h"
#include "src/ast/struct_member_decoration.h" #include "src/ast/struct_member_decoration.h"
#include "src/ast/switch_statement.h"
#include "src/ast/type/storage_texture_type.h" #include "src/ast/type/storage_texture_type.h"
#include "src/ast/type/struct_type.h" #include "src/ast/type/struct_type.h"
#include "src/ast/type/texture_type.h" #include "src/ast/type/texture_type.h"
@ -353,7 +353,7 @@ class ParserImpl {
/// `struct_decoration_decl*` provided as |decos|. /// `struct_decoration_decl*` provided as |decos|.
/// @returns the struct type or nullptr on error /// @returns the struct type or nullptr on error
/// @param decos the list of decorations for the struct declaration. /// @param decos the list of decorations for the struct declaration.
Maybe<std::unique_ptr<ast::type::StructType>> struct_decl( Maybe<std::unique_ptr<ast::type::Struct>> struct_decl(
ast::DecorationList& decos); ast::DecorationList& decos);
/// Parses a `struct_body_decl` grammar element, erroring on parse failure. /// Parses a `struct_body_decl` grammar element, erroring on parse failure.
/// @returns the struct members /// @returns the struct members

View File

@ -35,8 +35,8 @@ TEST_F(ParserImplTest, ConstExpr_TypeDecl) {
ASSERT_TRUE(e->Is<ast::TypeConstructorExpression>()); ASSERT_TRUE(e->Is<ast::TypeConstructorExpression>());
auto* t = e->As<ast::TypeConstructorExpression>(); auto* t = e->As<ast::TypeConstructorExpression>();
ASSERT_TRUE(t->type()->Is<ast::type::VectorType>()); ASSERT_TRUE(t->type()->Is<ast::type::Vector>());
EXPECT_EQ(t->type()->As<ast::type::VectorType>()->size(), 2u); EXPECT_EQ(t->type()->As<ast::type::Vector>()->size(), 2u);
ASSERT_EQ(t->values().size(), 2u); ASSERT_EQ(t->values().size(), 2u);
auto& v = t->values(); auto& v = t->values();

View File

@ -36,10 +36,9 @@ TEST_F(ParserImplTest, DepthTextureType_2d) {
EXPECT_TRUE(t.matched); EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored); EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr); ASSERT_NE(t.value, nullptr);
ASSERT_TRUE(t->Is<ast::type::TextureType>()); ASSERT_TRUE(t->Is<ast::type::Texture>());
ASSERT_TRUE( ASSERT_TRUE(t->As<ast::type::Texture>()->Is<ast::type::DepthTexture>());
t->As<ast::type::TextureType>()->Is<ast::type::DepthTextureType>()); EXPECT_EQ(t->As<ast::type::Texture>()->dim(),
EXPECT_EQ(t->As<ast::type::TextureType>()->dim(),
ast::type::TextureDimension::k2d); ast::type::TextureDimension::k2d);
EXPECT_FALSE(p->has_error()); EXPECT_FALSE(p->has_error());
} }
@ -50,10 +49,9 @@ TEST_F(ParserImplTest, DepthTextureType_2dArray) {
EXPECT_TRUE(t.matched); EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored); EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr); ASSERT_NE(t.value, nullptr);
ASSERT_TRUE(t->Is<ast::type::TextureType>()); ASSERT_TRUE(t->Is<ast::type::Texture>());
ASSERT_TRUE( ASSERT_TRUE(t->As<ast::type::Texture>()->Is<ast::type::DepthTexture>());
t->As<ast::type::TextureType>()->Is<ast::type::DepthTextureType>()); EXPECT_EQ(t->As<ast::type::Texture>()->dim(),
EXPECT_EQ(t->As<ast::type::TextureType>()->dim(),
ast::type::TextureDimension::k2dArray); ast::type::TextureDimension::k2dArray);
EXPECT_FALSE(p->has_error()); EXPECT_FALSE(p->has_error());
} }
@ -64,10 +62,9 @@ TEST_F(ParserImplTest, DepthTextureType_Cube) {
EXPECT_TRUE(t.matched); EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored); EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr); ASSERT_NE(t.value, nullptr);
ASSERT_TRUE(t->Is<ast::type::TextureType>()); ASSERT_TRUE(t->Is<ast::type::Texture>());
ASSERT_TRUE( ASSERT_TRUE(t->As<ast::type::Texture>()->Is<ast::type::DepthTexture>());
t->As<ast::type::TextureType>()->Is<ast::type::DepthTextureType>()); EXPECT_EQ(t->As<ast::type::Texture>()->dim(),
EXPECT_EQ(t->As<ast::type::TextureType>()->dim(),
ast::type::TextureDimension::kCube); ast::type::TextureDimension::kCube);
EXPECT_FALSE(p->has_error()); EXPECT_FALSE(p->has_error());
} }
@ -78,10 +75,9 @@ TEST_F(ParserImplTest, DepthTextureType_CubeArray) {
EXPECT_TRUE(t.matched); EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored); EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr); ASSERT_NE(t.value, nullptr);
ASSERT_TRUE(t->Is<ast::type::TextureType>()); ASSERT_TRUE(t->Is<ast::type::Texture>());
ASSERT_TRUE( ASSERT_TRUE(t->As<ast::type::Texture>()->Is<ast::type::DepthTexture>());
t->As<ast::type::TextureType>()->Is<ast::type::DepthTextureType>()); EXPECT_EQ(t->As<ast::type::Texture>()->dim(),
EXPECT_EQ(t->As<ast::type::TextureType>()->dim(),
ast::type::TextureDimension::kCubeArray); ast::type::TextureDimension::kCubeArray);
EXPECT_FALSE(p->has_error()); EXPECT_FALSE(p->has_error());
} }

View File

@ -39,14 +39,14 @@ TEST_F(ParserImplTest, FunctionDecl) {
EXPECT_EQ(f->name(), "main"); EXPECT_EQ(f->name(), "main");
ASSERT_NE(f->return_type(), nullptr); ASSERT_NE(f->return_type(), nullptr);
EXPECT_TRUE(f->return_type()->Is<ast::type::VoidType>()); EXPECT_TRUE(f->return_type()->Is<ast::type::Void>());
ASSERT_EQ(f->params().size(), 2u); ASSERT_EQ(f->params().size(), 2u);
EXPECT_EQ(f->params()[0]->name(), "a"); EXPECT_EQ(f->params()[0]->name(), "a");
EXPECT_EQ(f->params()[1]->name(), "b"); EXPECT_EQ(f->params()[1]->name(), "b");
ASSERT_NE(f->return_type(), nullptr); ASSERT_NE(f->return_type(), nullptr);
EXPECT_TRUE(f->return_type()->Is<ast::type::VoidType>()); EXPECT_TRUE(f->return_type()->Is<ast::type::Void>());
auto* body = f->body(); auto* body = f->body();
ASSERT_EQ(body->size(), 1u); ASSERT_EQ(body->size(), 1u);
@ -67,10 +67,10 @@ TEST_F(ParserImplTest, FunctionDecl_DecorationList) {
EXPECT_EQ(f->name(), "main"); EXPECT_EQ(f->name(), "main");
ASSERT_NE(f->return_type(), nullptr); ASSERT_NE(f->return_type(), nullptr);
EXPECT_TRUE(f->return_type()->Is<ast::type::VoidType>()); EXPECT_TRUE(f->return_type()->Is<ast::type::Void>());
ASSERT_EQ(f->params().size(), 0u); ASSERT_EQ(f->params().size(), 0u);
ASSERT_NE(f->return_type(), nullptr); ASSERT_NE(f->return_type(), nullptr);
EXPECT_TRUE(f->return_type()->Is<ast::type::VoidType>()); EXPECT_TRUE(f->return_type()->Is<ast::type::Void>());
auto& decorations = f->decorations(); auto& decorations = f->decorations();
ASSERT_EQ(decorations.size(), 1u); ASSERT_EQ(decorations.size(), 1u);
@ -105,10 +105,10 @@ fn main() -> void { return; })");
EXPECT_EQ(f->name(), "main"); EXPECT_EQ(f->name(), "main");
ASSERT_NE(f->return_type(), nullptr); ASSERT_NE(f->return_type(), nullptr);
EXPECT_TRUE(f->return_type()->Is<ast::type::VoidType>()); EXPECT_TRUE(f->return_type()->Is<ast::type::Void>());
ASSERT_EQ(f->params().size(), 0u); ASSERT_EQ(f->params().size(), 0u);
ASSERT_NE(f->return_type(), nullptr); ASSERT_NE(f->return_type(), nullptr);
EXPECT_TRUE(f->return_type()->Is<ast::type::VoidType>()); EXPECT_TRUE(f->return_type()->Is<ast::type::Void>());
auto& decorations = f->decorations(); auto& decorations = f->decorations();
ASSERT_EQ(decorations.size(), 2u); ASSERT_EQ(decorations.size(), 2u);
@ -150,10 +150,10 @@ fn main() -> void { return; })");
EXPECT_EQ(f->name(), "main"); EXPECT_EQ(f->name(), "main");
ASSERT_NE(f->return_type(), nullptr); ASSERT_NE(f->return_type(), nullptr);
EXPECT_TRUE(f->return_type()->Is<ast::type::VoidType>()); EXPECT_TRUE(f->return_type()->Is<ast::type::Void>());
ASSERT_EQ(f->params().size(), 0u); ASSERT_EQ(f->params().size(), 0u);
ASSERT_NE(f->return_type(), nullptr); ASSERT_NE(f->return_type(), nullptr);
EXPECT_TRUE(f->return_type()->Is<ast::type::VoidType>()); EXPECT_TRUE(f->return_type()->Is<ast::type::Void>());
auto& decos = f->decorations(); auto& decos = f->decorations();
ASSERT_EQ(decos.size(), 2u); ASSERT_EQ(decos.size(), 2u);

View File

@ -36,7 +36,7 @@ TEST_F(ParserImplTest, FunctionHeader) {
ASSERT_EQ(f->params().size(), 2u); ASSERT_EQ(f->params().size(), 2u);
EXPECT_EQ(f->params()[0]->name(), "a"); EXPECT_EQ(f->params()[0]->name(), "a");
EXPECT_EQ(f->params()[1]->name(), "b"); EXPECT_EQ(f->params()[1]->name(), "b");
EXPECT_TRUE(f->return_type()->Is<ast::type::VoidType>()); EXPECT_TRUE(f->return_type()->Is<ast::type::Void>());
} }
TEST_F(ParserImplTest, FunctionHeader_MissingIdent) { TEST_F(ParserImplTest, FunctionHeader_MissingIdent) {

View File

@ -30,7 +30,7 @@ TEST_F(ParserImplTest, FunctionTypeDecl_Void) {
auto p = parser("void"); auto p = parser("void");
auto& mod = p->get_module(); auto& mod = p->get_module();
auto* v = mod.create<ast::type::VoidType>(); auto* v = mod.create<ast::type::Void>();
auto e = p->function_type_decl(); auto e = p->function_type_decl();
EXPECT_TRUE(e.matched); EXPECT_TRUE(e.matched);
@ -43,8 +43,8 @@ TEST_F(ParserImplTest, FunctionTypeDecl_Type) {
auto p = parser("vec2<f32>"); auto p = parser("vec2<f32>");
auto& mod = p->get_module(); auto& mod = p->get_module();
auto* f32 = mod.create<ast::type::F32Type>(); auto* f32 = mod.create<ast::type::F32>();
auto* vec2 = mod.create<ast::type::VectorType>(f32, 2); auto* vec2 = mod.create<ast::type::Vector>(f32, 2);
auto e = p->function_type_decl(); auto e = p->function_type_decl();
EXPECT_TRUE(e.matched); EXPECT_TRUE(e.matched);

View File

@ -35,7 +35,7 @@ TEST_F(ParserImplTest, GlobalConstantDecl) {
EXPECT_TRUE(e->is_const()); EXPECT_TRUE(e->is_const());
EXPECT_EQ(e->name(), "a"); EXPECT_EQ(e->name(), "a");
ASSERT_NE(e->type(), nullptr); ASSERT_NE(e->type(), nullptr);
EXPECT_TRUE(e->type()->Is<ast::type::F32Type>()); EXPECT_TRUE(e->type()->Is<ast::type::F32>());
EXPECT_EQ(e->source().range.begin.line, 1u); EXPECT_EQ(e->source().range.begin.line, 1u);
EXPECT_EQ(e->source().range.begin.column, 7u); EXPECT_EQ(e->source().range.begin.column, 7u);

View File

@ -88,8 +88,8 @@ TEST_F(ParserImplTest, GlobalDecl_TypeAlias) {
auto& m = p->get_module(); auto& m = p->get_module();
ASSERT_EQ(m.constructed_types().size(), 1u); ASSERT_EQ(m.constructed_types().size(), 1u);
ASSERT_TRUE(m.constructed_types()[0]->Is<ast::type::AliasType>()); ASSERT_TRUE(m.constructed_types()[0]->Is<ast::type::Alias>());
EXPECT_EQ(m.constructed_types()[0]->As<ast::type::AliasType>()->name(), "A"); EXPECT_EQ(m.constructed_types()[0]->As<ast::type::Alias>()->name(), "A");
} }
TEST_F(ParserImplTest, GlobalDecl_TypeAlias_StructIdent) { TEST_F(ParserImplTest, GlobalDecl_TypeAlias_StructIdent) {
@ -103,12 +103,12 @@ type B = A;)");
auto& m = p->get_module(); auto& m = p->get_module();
ASSERT_EQ(m.constructed_types().size(), 2u); ASSERT_EQ(m.constructed_types().size(), 2u);
ASSERT_TRUE(m.constructed_types()[0]->Is<ast::type::StructType>()); ASSERT_TRUE(m.constructed_types()[0]->Is<ast::type::Struct>());
auto* str = m.constructed_types()[0]->As<ast::type::StructType>(); auto* str = m.constructed_types()[0]->As<ast::type::Struct>();
EXPECT_EQ(str->name(), "A"); EXPECT_EQ(str->name(), "A");
ASSERT_TRUE(m.constructed_types()[1]->Is<ast::type::AliasType>()); ASSERT_TRUE(m.constructed_types()[1]->Is<ast::type::Alias>());
auto* alias = m.constructed_types()[1]->As<ast::type::AliasType>(); auto* alias = m.constructed_types()[1]->As<ast::type::Alias>();
EXPECT_EQ(alias->name(), "B"); EXPECT_EQ(alias->name(), "B");
EXPECT_EQ(alias->type(), str); EXPECT_EQ(alias->type(), str);
} }
@ -164,9 +164,9 @@ TEST_F(ParserImplTest, GlobalDecl_ParsesStruct) {
auto* t = m.constructed_types()[0]; auto* t = m.constructed_types()[0];
ASSERT_NE(t, nullptr); ASSERT_NE(t, nullptr);
ASSERT_TRUE(t->Is<ast::type::StructType>()); ASSERT_TRUE(t->Is<ast::type::Struct>());
auto* str = t->As<ast::type::StructType>(); auto* str = t->As<ast::type::Struct>();
EXPECT_EQ(str->name(), "A"); EXPECT_EQ(str->name(), "A");
EXPECT_EQ(str->impl()->members().size(), 2u); EXPECT_EQ(str->impl()->members().size(), 2u);
} }
@ -183,16 +183,16 @@ TEST_F(ParserImplTest, GlobalDecl_Struct_WithStride) {
auto* t = m.constructed_types()[0]; auto* t = m.constructed_types()[0];
ASSERT_NE(t, nullptr); ASSERT_NE(t, nullptr);
ASSERT_TRUE(t->Is<ast::type::StructType>()); ASSERT_TRUE(t->Is<ast::type::Struct>());
auto* str = t->As<ast::type::StructType>(); auto* str = t->As<ast::type::Struct>();
EXPECT_EQ(str->name(), "A"); EXPECT_EQ(str->name(), "A");
EXPECT_EQ(str->impl()->members().size(), 1u); EXPECT_EQ(str->impl()->members().size(), 1u);
EXPECT_FALSE(str->IsBlockDecorated()); EXPECT_FALSE(str->IsBlockDecorated());
const auto* ty = str->impl()->members()[0]->type(); const auto* ty = str->impl()->members()[0]->type();
ASSERT_TRUE(ty->Is<ast::type::ArrayType>()); ASSERT_TRUE(ty->Is<ast::type::Array>());
const auto* arr = ty->As<ast::type::ArrayType>(); const auto* arr = ty->As<ast::type::Array>();
EXPECT_TRUE(arr->has_array_stride()); EXPECT_TRUE(arr->has_array_stride());
EXPECT_EQ(arr->array_stride(), 4u); EXPECT_EQ(arr->array_stride(), 4u);
} }
@ -207,9 +207,9 @@ TEST_F(ParserImplTest, GlobalDecl_Struct_WithDecoration) {
auto* t = m.constructed_types()[0]; auto* t = m.constructed_types()[0];
ASSERT_NE(t, nullptr); ASSERT_NE(t, nullptr);
ASSERT_TRUE(t->Is<ast::type::StructType>()); ASSERT_TRUE(t->Is<ast::type::Struct>());
auto* str = t->As<ast::type::StructType>(); auto* str = t->As<ast::type::Struct>();
EXPECT_EQ(str->name(), "A"); EXPECT_EQ(str->name(), "A");
EXPECT_EQ(str->impl()->members().size(), 1u); EXPECT_EQ(str->impl()->members().size(), 1u);
EXPECT_TRUE(str->IsBlockDecorated()); EXPECT_TRUE(str->IsBlockDecorated());

View File

@ -37,7 +37,7 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithoutConstructor) {
ASSERT_NE(e.value, nullptr); ASSERT_NE(e.value, nullptr);
EXPECT_EQ(e->name(), "a"); EXPECT_EQ(e->name(), "a");
EXPECT_TRUE(e->type()->Is<ast::type::F32Type>()); EXPECT_TRUE(e->type()->Is<ast::type::F32>());
EXPECT_EQ(e->storage_class(), ast::StorageClass::kOutput); EXPECT_EQ(e->storage_class(), ast::StorageClass::kOutput);
EXPECT_EQ(e->source().range.begin.line, 1u); EXPECT_EQ(e->source().range.begin.line, 1u);
@ -61,7 +61,7 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithConstructor) {
ASSERT_NE(e.value, nullptr); ASSERT_NE(e.value, nullptr);
EXPECT_EQ(e->name(), "a"); EXPECT_EQ(e->name(), "a");
EXPECT_TRUE(e->type()->Is<ast::type::F32Type>()); EXPECT_TRUE(e->type()->Is<ast::type::F32>());
EXPECT_EQ(e->storage_class(), ast::StorageClass::kOutput); EXPECT_EQ(e->storage_class(), ast::StorageClass::kOutput);
EXPECT_EQ(e->source().range.begin.line, 1u); EXPECT_EQ(e->source().range.begin.line, 1u);
@ -90,7 +90,7 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithDecoration) {
EXPECT_EQ(e->name(), "a"); EXPECT_EQ(e->name(), "a");
ASSERT_NE(e->type(), nullptr); ASSERT_NE(e->type(), nullptr);
EXPECT_TRUE(e->type()->Is<ast::type::F32Type>()); EXPECT_TRUE(e->type()->Is<ast::type::F32>());
EXPECT_EQ(e->storage_class(), ast::StorageClass::kOutput); EXPECT_EQ(e->storage_class(), ast::StorageClass::kOutput);
EXPECT_EQ(e->source().range.begin.line, 1u); EXPECT_EQ(e->source().range.begin.line, 1u);
@ -124,7 +124,7 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithDecoration_MulitpleGroups) {
EXPECT_EQ(e->name(), "a"); EXPECT_EQ(e->name(), "a");
ASSERT_NE(e->type(), nullptr); ASSERT_NE(e->type(), nullptr);
EXPECT_TRUE(e->type()->Is<ast::type::F32Type>()); EXPECT_TRUE(e->type()->Is<ast::type::F32>());
EXPECT_EQ(e->storage_class(), ast::StorageClass::kOutput); EXPECT_EQ(e->storage_class(), ast::StorageClass::kOutput);
EXPECT_EQ(e->source().range.begin.line, 1u); EXPECT_EQ(e->source().range.begin.line, 1u);

View File

@ -31,7 +31,7 @@ TEST_F(ParserImplTest, ParamList_Single) {
auto p = parser("a : i32"); auto p = parser("a : i32");
auto& mod = p->get_module(); auto& mod = p->get_module();
auto* i32 = mod.create<ast::type::I32Type>(); auto* i32 = mod.create<ast::type::I32>();
auto e = p->expect_param_list(); auto e = p->expect_param_list();
ASSERT_FALSE(p->has_error()) << p->error(); ASSERT_FALSE(p->has_error()) << p->error();
@ -52,9 +52,9 @@ TEST_F(ParserImplTest, ParamList_Multiple) {
auto p = parser("a : i32, b: f32, c: vec2<f32>"); auto p = parser("a : i32, b: f32, c: vec2<f32>");
auto& mod = p->get_module(); auto& mod = p->get_module();
auto* i32 = mod.create<ast::type::I32Type>(); auto* i32 = mod.create<ast::type::I32>();
auto* f32 = mod.create<ast::type::F32Type>(); auto* f32 = mod.create<ast::type::F32>();
auto* vec2 = mod.create<ast::type::VectorType>(f32, 2); auto* vec2 = mod.create<ast::type::Vector>(f32, 2);
auto e = p->expect_param_list(); auto e = p->expect_param_list();
ASSERT_FALSE(p->has_error()) << p->error(); ASSERT_FALSE(p->has_error()) << p->error();

View File

@ -194,7 +194,7 @@ TEST_F(ParserImplTest, PrimaryExpression_Cast) {
auto p = parser("f32(1)"); auto p = parser("f32(1)");
auto& mod = p->get_module(); auto& mod = p->get_module();
auto* f32 = mod.create<ast::type::F32Type>(); auto* f32 = mod.create<ast::type::F32>();
auto e = p->primary_expression(); auto e = p->primary_expression();
EXPECT_TRUE(e.matched); EXPECT_TRUE(e.matched);
@ -216,7 +216,7 @@ TEST_F(ParserImplTest, PrimaryExpression_Bitcast) {
auto p = parser("bitcast<f32>(1)"); auto p = parser("bitcast<f32>(1)");
auto& mod = p->get_module(); auto& mod = p->get_module();
auto* f32 = mod.create<ast::type::F32Type>(); auto* f32 = mod.create<ast::type::F32>();
auto e = p->primary_expression(); auto e = p->primary_expression();
EXPECT_TRUE(e.matched); EXPECT_TRUE(e.matched);

Some files were not shown because too many files have changed in this diff Show More