Cleanup: Remove unnecessary namespace prefixes

No need to prefix with `ast::` when you're in the ast namespace already.

Change-Id: Iac6cd3a215c05a80ee2035d582500f1d6c882a06
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34320
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton 2020-11-30 23:30:58 +00:00
parent acf7643518
commit 03ae9a397f
65 changed files with 684 additions and 706 deletions

View File

@ -44,7 +44,7 @@ TEST_F(ArrayAccessorExpressionTest, CreateWithSource) {
TEST_F(ArrayAccessorExpressionTest, IsArrayAccessor) { TEST_F(ArrayAccessorExpressionTest, IsArrayAccessor) {
ArrayAccessorExpression exp; ArrayAccessorExpression exp;
EXPECT_TRUE(exp.Is<ast::ArrayAccessorExpression>()); EXPECT_TRUE(exp.Is<ArrayAccessorExpression>());
} }
TEST_F(ArrayAccessorExpressionTest, IsValid) { TEST_F(ArrayAccessorExpressionTest, IsValid) {

View File

@ -24,8 +24,8 @@ namespace {
using AssignmentStatementTest = TestHelper; using AssignmentStatementTest = TestHelper;
TEST_F(AssignmentStatementTest, Creation) { TEST_F(AssignmentStatementTest, Creation) {
auto* lhs = create<ast::IdentifierExpression>("lhs"); auto* lhs = create<IdentifierExpression>("lhs");
auto* rhs = create<ast::IdentifierExpression>("rhs"); auto* rhs = create<IdentifierExpression>("rhs");
AssignmentStatement stmt(lhs, rhs); AssignmentStatement stmt(lhs, rhs);
EXPECT_EQ(stmt.lhs(), lhs); EXPECT_EQ(stmt.lhs(), lhs);
@ -33,8 +33,8 @@ TEST_F(AssignmentStatementTest, Creation) {
} }
TEST_F(AssignmentStatementTest, CreationWithSource) { TEST_F(AssignmentStatementTest, CreationWithSource) {
auto* lhs = create<ast::IdentifierExpression>("lhs"); auto* lhs = create<IdentifierExpression>("lhs");
auto* rhs = create<ast::IdentifierExpression>("rhs"); auto* rhs = create<IdentifierExpression>("rhs");
AssignmentStatement stmt(Source{Source::Location{20, 2}}, lhs, rhs); AssignmentStatement stmt(Source{Source::Location{20, 2}}, lhs, rhs);
auto src = stmt.source(); auto src = stmt.source();
@ -43,23 +43,23 @@ TEST_F(AssignmentStatementTest, CreationWithSource) {
} }
TEST_F(AssignmentStatementTest, IsAssign) { TEST_F(AssignmentStatementTest, IsAssign) {
auto* lhs = create<ast::IdentifierExpression>("lhs"); auto* lhs = create<IdentifierExpression>("lhs");
auto* rhs = create<ast::IdentifierExpression>("rhs"); auto* rhs = create<IdentifierExpression>("rhs");
AssignmentStatement stmt(lhs, rhs); AssignmentStatement stmt(lhs, rhs);
EXPECT_TRUE(stmt.Is<AssignmentStatement>()); EXPECT_TRUE(stmt.Is<AssignmentStatement>());
} }
TEST_F(AssignmentStatementTest, IsValid) { TEST_F(AssignmentStatementTest, IsValid) {
auto* lhs = create<ast::IdentifierExpression>("lhs"); auto* lhs = create<IdentifierExpression>("lhs");
auto* rhs = create<ast::IdentifierExpression>("rhs"); auto* rhs = create<IdentifierExpression>("rhs");
AssignmentStatement stmt(lhs, rhs); AssignmentStatement stmt(lhs, rhs);
EXPECT_TRUE(stmt.IsValid()); EXPECT_TRUE(stmt.IsValid());
} }
TEST_F(AssignmentStatementTest, IsValid_MissingLHS) { TEST_F(AssignmentStatementTest, IsValid_MissingLHS) {
auto* rhs = create<ast::IdentifierExpression>("rhs"); auto* rhs = create<IdentifierExpression>("rhs");
AssignmentStatement stmt; AssignmentStatement stmt;
stmt.set_rhs(rhs); stmt.set_rhs(rhs);
@ -67,7 +67,7 @@ TEST_F(AssignmentStatementTest, IsValid_MissingLHS) {
} }
TEST_F(AssignmentStatementTest, IsValid_MissingRHS) { TEST_F(AssignmentStatementTest, IsValid_MissingRHS) {
auto* lhs = create<ast::IdentifierExpression>("lhs"); auto* lhs = create<IdentifierExpression>("lhs");
AssignmentStatement stmt; AssignmentStatement stmt;
stmt.set_lhs(lhs); stmt.set_lhs(lhs);
@ -75,22 +75,22 @@ TEST_F(AssignmentStatementTest, IsValid_MissingRHS) {
} }
TEST_F(AssignmentStatementTest, IsValid_InvalidLHS) { TEST_F(AssignmentStatementTest, IsValid_InvalidLHS) {
auto* lhs = create<ast::IdentifierExpression>(""); auto* lhs = create<IdentifierExpression>("");
auto* rhs = create<ast::IdentifierExpression>("rhs"); auto* rhs = create<IdentifierExpression>("rhs");
AssignmentStatement stmt(lhs, rhs); AssignmentStatement stmt(lhs, rhs);
EXPECT_FALSE(stmt.IsValid()); EXPECT_FALSE(stmt.IsValid());
} }
TEST_F(AssignmentStatementTest, IsValid_InvalidRHS) { TEST_F(AssignmentStatementTest, IsValid_InvalidRHS) {
auto* lhs = create<ast::IdentifierExpression>("lhs"); auto* lhs = create<IdentifierExpression>("lhs");
auto* rhs = create<ast::IdentifierExpression>(""); auto* rhs = create<IdentifierExpression>("");
AssignmentStatement stmt(lhs, rhs); AssignmentStatement stmt(lhs, rhs);
EXPECT_FALSE(stmt.IsValid()); EXPECT_FALSE(stmt.IsValid());
} }
TEST_F(AssignmentStatementTest, ToStr) { TEST_F(AssignmentStatementTest, ToStr) {
auto* lhs = create<ast::IdentifierExpression>("lhs"); auto* lhs = create<IdentifierExpression>("lhs");
auto* rhs = create<ast::IdentifierExpression>("rhs"); auto* rhs = create<IdentifierExpression>("rhs");
AssignmentStatement stmt(lhs, rhs); AssignmentStatement stmt(lhs, rhs);
std::ostringstream out; std::ostringstream out;

View File

@ -48,7 +48,7 @@ TEST_F(BinaryExpressionTest, Creation_WithSource) {
TEST_F(BinaryExpressionTest, IsBinaryal) { TEST_F(BinaryExpressionTest, IsBinaryal) {
BinaryExpression r; BinaryExpression r;
EXPECT_TRUE(r.Is<ast::BinaryExpression>()); EXPECT_TRUE(r.Is<BinaryExpression>());
} }
TEST_F(BinaryExpressionTest, IsValid) { TEST_F(BinaryExpressionTest, IsValid) {

View File

@ -45,7 +45,7 @@ TEST_F(BitcastExpressionTest, CreateWithSource) {
TEST_F(BitcastExpressionTest, IsBitcast) { TEST_F(BitcastExpressionTest, IsBitcast) {
BitcastExpression exp; BitcastExpression exp;
EXPECT_TRUE(exp.Is<ast::BitcastExpression>()); EXPECT_TRUE(exp.Is<BitcastExpression>());
} }
TEST_F(BitcastExpressionTest, IsValid) { TEST_F(BitcastExpressionTest, IsValid) {

View File

@ -38,12 +38,12 @@ class BlockStatement : public Castable<BlockStatement, Statement> {
/// Appends a statement to the block /// Appends a statement to the block
/// @param stmt the statement to append /// @param stmt the statement to append
void append(ast::Statement* stmt) { statements_.push_back(stmt); } void append(Statement* stmt) { statements_.push_back(stmt); }
/// Insert a statement to the block /// Insert a statement to the block
/// @param index the index to insert at /// @param index the index to insert at
/// @param stmt the statement to insert /// @param stmt the statement to insert
void insert(size_t index, ast::Statement* stmt) { void insert(size_t index, Statement* stmt) {
auto offset = static_cast<decltype(statements_)::difference_type>(index); auto offset = static_cast<decltype(statements_)::difference_type>(index);
statements_.insert(statements_.begin() + offset, stmt); statements_.insert(statements_.begin() + offset, stmt);
} }
@ -54,36 +54,34 @@ class BlockStatement : public Castable<BlockStatement, Statement> {
size_t size() const { return statements_.size(); } size_t size() const { return statements_.size(); }
/// @returns the last statement in the block or nullptr if block empty /// @returns the last statement in the block or nullptr if block empty
const ast::Statement* last() const { const Statement* last() const {
return statements_.empty() ? nullptr : statements_.back(); return statements_.empty() ? nullptr : statements_.back();
} }
/// @returns the last statement in the block or nullptr if block empty /// @returns the last statement in the block or nullptr if block empty
ast::Statement* last() { Statement* last() {
return statements_.empty() ? nullptr : statements_.back(); return statements_.empty() ? nullptr : statements_.back();
} }
/// Retrieves the statement at |idx| /// Retrieves the statement at |idx|
/// @param idx the index. The index is not bounds checked. /// @param idx the index. The index is not bounds checked.
/// @returns the statement at |idx| /// @returns the statement at |idx|
const ast::Statement* get(size_t idx) const { return statements_[idx]; } const Statement* get(size_t idx) const { return statements_[idx]; }
/// Retrieves the statement at |idx| /// Retrieves the statement at |idx|
/// @param idx the index. The index is not bounds checked. /// @param idx the index. The index is not bounds checked.
/// @returns the statement at |idx| /// @returns the statement at |idx|
ast::Statement* operator[](size_t idx) { return statements_[idx]; } Statement* operator[](size_t idx) { return statements_[idx]; }
/// Retrieves the statement at |idx| /// Retrieves the statement at |idx|
/// @param idx the index. The index is not bounds checked. /// @param idx the index. The index is not bounds checked.
/// @returns the statement at |idx| /// @returns the statement at |idx|
const ast::Statement* operator[](size_t idx) const { const Statement* operator[](size_t idx) const { return statements_[idx]; }
return statements_[idx];
}
/// @returns the beginning iterator /// @returns the beginning iterator
std::vector<ast::Statement*>::const_iterator begin() const { std::vector<Statement*>::const_iterator begin() const {
return statements_.begin(); return statements_.begin();
} }
/// @returns the ending iterator /// @returns the ending iterator
std::vector<ast::Statement*>::const_iterator end() const { std::vector<Statement*>::const_iterator end() const {
return statements_.end(); return statements_.end();
} }
@ -98,7 +96,7 @@ class BlockStatement : public Castable<BlockStatement, Statement> {
private: private:
BlockStatement(const BlockStatement&) = delete; BlockStatement(const BlockStatement&) = delete;
std::vector<ast::Statement*> statements_; std::vector<Statement*> statements_;
}; };
} // namespace ast } // namespace ast

View File

@ -17,7 +17,7 @@
namespace tint { namespace tint {
namespace ast { namespace ast {
BoolLiteral::BoolLiteral(ast::type::Type* type, bool value) BoolLiteral::BoolLiteral(type::Type* type, bool value)
: Base(type), value_(value) {} : Base(type), value_(value) {}
BoolLiteral::~BoolLiteral() = default; BoolLiteral::~BoolLiteral() = default;

View File

@ -28,7 +28,7 @@ class BoolLiteral : public Castable<BoolLiteral, Literal> {
/// Constructor /// Constructor
/// @param type the type of the literal /// @param type the type of the literal
/// @param value the bool literals value /// @param value the bool literals value
BoolLiteral(ast::type::Type* type, bool value); BoolLiteral(type::Type* type, bool value);
~BoolLiteral() override; ~BoolLiteral() override;
/// @returns true if the bool literal is true /// @returns true if the bool literal is true

View File

@ -28,7 +28,7 @@ namespace {
using BoolLiteralTest = TestHelper; using BoolLiteralTest = TestHelper;
TEST_F(BoolLiteralTest, True) { TEST_F(BoolLiteralTest, True) {
ast::type::BoolType bool_type; type::BoolType 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) {
ast::type::BoolType bool_type; type::BoolType 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) {
ast::type::BoolType bool_type; type::BoolType 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) {
ast::type::BoolType bool_type; type::BoolType 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,27 +18,26 @@ namespace tint {
namespace ast { namespace ast {
TypesBuilder::TypesBuilder(Module* mod) TypesBuilder::TypesBuilder(Module* mod)
: bool_(mod->create<ast::type::BoolType>()), : bool_(mod->create<type::BoolType>()),
f32(mod->create<ast::type::F32Type>()), f32(mod->create<type::F32Type>()),
i32(mod->create<ast::type::I32Type>()), i32(mod->create<type::I32Type>()),
u32(mod->create<ast::type::U32Type>()), u32(mod->create<type::U32Type>()),
void_(mod->create<ast::type::VoidType>()), void_(mod->create<type::VoidType>()),
mod_(mod) {} mod_(mod) {}
Builder::Builder(tint::Context* c, tint::ast::Module* m) Builder::Builder(Context* c, Module* m) : ctx(c), mod(m), ty(m) {}
: ctx(c), mod(m), ty(m) {}
Builder::~Builder() = default; Builder::~Builder() = default;
ast::Variable* Builder::Var(const std::string& name, Variable* Builder::Var(const std::string& name,
ast::StorageClass storage, StorageClass storage,
ast::type::Type* type) { type::Type* type) {
auto* var = create<ast::Variable>(name, storage, type); auto* var = create<Variable>(name, storage, type);
OnVariableBuilt(var); OnVariableBuilt(var);
return var; return var;
} }
BuilderWithContextAndModule::BuilderWithContextAndModule() BuilderWithContextAndModule::BuilderWithContextAndModule()
: Builder(new Context(), new ast::Module()) {} : Builder(new Context(), new Module()) {}
BuilderWithContextAndModule::~BuilderWithContextAndModule() { BuilderWithContextAndModule::~BuilderWithContextAndModule() {
delete ctx; delete ctx;
delete mod; delete mod;

View File

@ -43,7 +43,7 @@
namespace tint { namespace tint {
namespace ast { namespace ast {
/// TypesBuilder holds basic `ast::tint` types and methods for constructing /// TypesBuilder holds basic `tint` types and methods for constructing
/// complex types. /// complex types.
class TypesBuilder { class TypesBuilder {
public: public:
@ -52,104 +52,104 @@ class TypesBuilder {
explicit TypesBuilder(Module* mod); explicit TypesBuilder(Module* mod);
/// A boolean type /// A boolean type
ast::type::BoolType* const bool_; type::BoolType* const bool_;
/// A f32 type /// A f32 type
ast::type::F32Type* const f32; type::F32Type* const f32;
/// A i32 type /// A i32 type
ast::type::I32Type* const i32; type::I32Type* const i32;
/// A u32 type /// A u32 type
ast::type::U32Type* const u32; type::U32Type* const u32;
/// A void type /// A void type
ast::type::VoidType* const void_; type::VoidType* 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>
ast::type::Type* Of() const { type::Type* Of() const {
return CToAST<T>::get(this); return CToAST<T>::get(this);
} }
/// @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>
ast::type::VectorType* vec2() const { type::VectorType* vec2() const {
return mod_->create<ast::type::VectorType>(Of<T>(), 2); return mod_->create<type::VectorType>(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>
ast::type::VectorType* vec3() const { type::VectorType* vec3() const {
return mod_->create<ast::type::VectorType>(Of<T>(), 3); return mod_->create<type::VectorType>(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>
ast::type::Type* vec4() const { type::Type* vec4() const {
return mod_->create<ast::type::VectorType>(Of<T>(), 4); return mod_->create<type::VectorType>(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>
ast::type::MatrixType* mat2x2() const { type::MatrixType* mat2x2() const {
return mod_->create<ast::type::MatrixType>(Of<T>(), 2, 2); return mod_->create<type::MatrixType>(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>
ast::type::MatrixType* mat2x3() const { type::MatrixType* mat2x3() const {
return mod_->create<ast::type::MatrixType>(Of<T>(), 3, 2); return mod_->create<type::MatrixType>(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>
ast::type::MatrixType* mat2x4() const { type::MatrixType* mat2x4() const {
return mod_->create<ast::type::MatrixType>(Of<T>(), 4, 2); return mod_->create<type::MatrixType>(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>
ast::type::MatrixType* mat3x2() const { type::MatrixType* mat3x2() const {
return mod_->create<ast::type::MatrixType>(Of<T>(), 2, 3); return mod_->create<type::MatrixType>(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>
ast::type::MatrixType* mat3x3() const { type::MatrixType* mat3x3() const {
return mod_->create<ast::type::MatrixType>(Of<T>(), 3, 3); return mod_->create<type::MatrixType>(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>
ast::type::MatrixType* mat3x4() const { type::MatrixType* mat3x4() const {
return mod_->create<ast::type::MatrixType>(Of<T>(), 4, 3); return mod_->create<type::MatrixType>(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>
ast::type::MatrixType* mat4x2() const { type::MatrixType* mat4x2() const {
return mod_->create<ast::type::MatrixType>(Of<T>(), 2, 4); return mod_->create<type::MatrixType>(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>
ast::type::MatrixType* mat4x3() const { type::MatrixType* mat4x3() const {
return mod_->create<ast::type::MatrixType>(Of<T>(), 3, 4); return mod_->create<type::MatrixType>(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>
ast::type::MatrixType* mat4x4() const { type::MatrixType* mat4x4() const {
return mod_->create<ast::type::MatrixType>(Of<T>(), 4, 4); return mod_->create<type::MatrixType>(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`
ast::type::ArrayType* array(ast::type::Type* subtype, uint32_t n) const { type::ArrayType* array(type::Type* subtype, uint32_t n) const {
return mod_->create<ast::type::ArrayType>(subtype, n); return mod_->create<type::ArrayType>(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>
ast::type::ArrayType* array() const { type::ArrayType* array() const {
return array(Of<T>(), N); return array(Of<T>(), N);
} }
@ -158,7 +158,7 @@ class TypesBuilder {
/// contains a single static `get()` method for obtaining the corresponding /// contains a single static `get()` method for obtaining the corresponding
/// AST type for the C type `T`. /// AST type for the C type `T`.
/// `get()` has the signature: /// `get()` has the signature:
/// `static ast::type::Type* get(Types* t)` /// `static type::Type* get(Types* t)`
template <typename T> template <typename T>
struct CToAST {}; struct CToAST {};
@ -188,78 +188,78 @@ class Builder {
/// Constructor /// Constructor
/// @param ctx the context to use in the builder /// @param ctx the context to use in the builder
/// @param mod the module to use in the builder /// @param mod the module to use in the builder
explicit Builder(tint::Context* ctx, tint::ast::Module* mod); explicit Builder(Context* ctx, Module* mod);
virtual ~Builder(); virtual ~Builder();
/// @param expr the expression /// @param expr the expression
/// @return expr /// @return expr
ast::Expression* Expr(ast::Expression* expr) { return expr; } Expression* Expr(Expression* expr) { return expr; }
/// @param name the identifier name /// @param name the identifier name
/// @return an IdentifierExpression with the given name /// @return an IdentifierExpression with the given name
ast::IdentifierExpression* Expr(const std::string& name) { IdentifierExpression* Expr(const std::string& name) {
return create<ast::IdentifierExpression>(name); return create<IdentifierExpression>(name);
} }
/// @param name the identifier name /// @param name the identifier name
/// @return an IdentifierExpression with the given name /// @return an IdentifierExpression with the given name
ast::IdentifierExpression* Expr(const char* name) { IdentifierExpression* Expr(const char* name) {
return create<ast::IdentifierExpression>(name); return create<IdentifierExpression>(name);
} }
/// @param value the boolean value /// @param value the boolean value
/// @return a Scalar constructor for the given value /// @return a Scalar constructor for the given value
ast::ScalarConstructorExpression* Expr(bool value) { ScalarConstructorExpression* Expr(bool value) {
return create<ast::ScalarConstructorExpression>(Literal(value)); return create<ScalarConstructorExpression>(Literal(value));
} }
/// @param value the float value /// @param value the float value
/// @return a Scalar constructor for the given value /// @return a Scalar constructor for the given value
ast::ScalarConstructorExpression* Expr(f32 value) { ScalarConstructorExpression* Expr(f32 value) {
return create<ast::ScalarConstructorExpression>(Literal(value)); return create<ScalarConstructorExpression>(Literal(value));
} }
/// @param value the integer value /// @param value the integer value
/// @return a Scalar constructor for the given value /// @return a Scalar constructor for the given value
ast::ScalarConstructorExpression* Expr(i32 value) { ScalarConstructorExpression* Expr(i32 value) {
return create<ast::ScalarConstructorExpression>(Literal(value)); return create<ScalarConstructorExpression>(Literal(value));
} }
/// @param value the unsigned int value /// @param value the unsigned int value
/// @return a Scalar constructor for the given value /// @return a Scalar constructor for the given value
ast::ScalarConstructorExpression* Expr(u32 value) { ScalarConstructorExpression* Expr(u32 value) {
return create<ast::ScalarConstructorExpression>(Literal(value)); return create<ScalarConstructorExpression>(Literal(value));
} }
/// Converts `arg` to an `ast::Expression` using `Expr()`, then appends it to /// Converts `arg` to an `Expression` using `Expr()`, then appends it to
/// `list`. /// `list`.
/// @param list the list to append too /// @param list the list to append too
/// @param arg the arg to create /// @param arg the arg to create
template <typename ARG> template <typename ARG>
void Append(ast::ExpressionList& list, ARG&& arg) { void Append(ExpressionList& list, ARG&& arg) {
list.emplace_back(Expr(std::forward<ARG>(arg))); list.emplace_back(Expr(std::forward<ARG>(arg)));
} }
/// Converts `arg0` and `args` to `ast::Expression`s using `Expr()`, /// Converts `arg0` and `args` to `Expression`s using `Expr()`,
/// then appends them to `list`. /// then appends them to `list`.
/// @param list the list to append too /// @param list the list to append too
/// @param arg0 the first argument /// @param arg0 the first argument
/// @param args the rest of the arguments /// @param args the rest of the arguments
template <typename ARG0, typename... ARGS> template <typename ARG0, typename... ARGS>
void Append(ast::ExpressionList& list, ARG0&& arg0, ARGS&&... args) { void Append(ExpressionList& list, ARG0&& arg0, ARGS&&... args) {
Append(list, std::forward<ARG0>(arg0)); Append(list, std::forward<ARG0>(arg0));
Append(list, std::forward<ARGS>(args)...); Append(list, std::forward<ARGS>(args)...);
} }
/// @return an empty list of expressions, /// @return an empty list of expressions,
ast::ExpressionList ExprList() { return {}; } ExpressionList ExprList() { return {}; }
/// @param args the list of expressions /// @param args the list of expressions
/// @return the list of expressions converted to `ast::Expression`s using /// @return the list of expressions converted to `Expression`s using
/// `Expr()`, /// `Expr()`,
template <typename... ARGS> template <typename... ARGS>
ast::ExpressionList ExprList(ARGS&&... args) { ExpressionList ExprList(ARGS&&... args) {
ast::ExpressionList list; ExpressionList list;
list.reserve(sizeof...(args)); list.reserve(sizeof...(args));
Append(list, std::forward<ARGS>(args)...); Append(list, std::forward<ARGS>(args)...);
return list; return list;
@ -267,185 +267,175 @@ class Builder {
/// @param val the boolan value /// @param val the boolan value
/// @return a boolean literal with the given value /// @return a boolean literal with the given value
ast::BoolLiteral* Literal(bool val) { BoolLiteral* Literal(bool val) { return create<BoolLiteral>(ty.bool_, val); }
return create<ast::BoolLiteral>(ty.bool_, val);
}
/// @param val the float value /// @param val the float value
/// @return a float literal with the given value /// @return a float literal with the given value
ast::FloatLiteral* Literal(f32 val) { FloatLiteral* Literal(f32 val) { return create<FloatLiteral>(ty.f32, val); }
return create<ast::FloatLiteral>(ty.f32, val);
}
/// @param val the unsigned int value /// @param val the unsigned int value
/// @return a UintLiteral with the given value /// @return a UintLiteral with the given value
ast::UintLiteral* Literal(u32 val) { UintLiteral* Literal(u32 val) { return create<UintLiteral>(ty.u32, val); }
return create<ast::UintLiteral>(ty.u32, val);
}
/// @param val the integer value /// @param val the integer value
/// @return the SintLiteral with the given value /// @return the SintLiteral with the given value
ast::SintLiteral* Literal(i32 val) { SintLiteral* Literal(i32 val) { return create<SintLiteral>(ty.i32, val); }
return create<ast::SintLiteral>(ty.i32, val);
}
/// @param args the arguments for the type constructor /// @param args the arguments for the type constructor
/// @return an `ast::TypeConstructorExpression` of type `ty`, with the values /// @return an `TypeConstructorExpression` of type `ty`, with the values
/// of `args` converted to `ast::Expression`s using `Expr()` /// of `args` converted to `Expression`s using `Expr()`
template <typename T, typename... ARGS> template <typename T, typename... ARGS>
ast::TypeConstructorExpression* Construct(ARGS&&... args) { TypeConstructorExpression* Construct(ARGS&&... args) {
return create<ast::TypeConstructorExpression>( return create<TypeConstructorExpression>(
ty.Of<T>(), ExprList(std::forward<ARGS>(args)...)); ty.Of<T>(), ExprList(std::forward<ARGS>(args)...));
} }
/// @param type the type to construct /// @param type the type to construct
/// @param args the arguments for the constructor /// @param args the arguments for the constructor
/// @return an `ast::TypeConstructorExpression` of `type` constructed with the /// @return an `TypeConstructorExpression` of `type` constructed with the
/// values `args`. /// values `args`.
template <typename... ARGS> template <typename... ARGS>
ast::TypeConstructorExpression* Construct(ast::type::Type* type, TypeConstructorExpression* Construct(type::Type* type, ARGS&&... args) {
ARGS&&... args) { return create<TypeConstructorExpression>(
return create<ast::TypeConstructorExpression>(
type, ExprList(std::forward<ARGS>(args)...)); type, ExprList(std::forward<ARGS>(args)...));
} }
/// @param args the arguments for the vector constructor /// @param args the arguments for the vector constructor
/// @return an `ast::TypeConstructorExpression` of a 2-element vector of type /// @return an `TypeConstructorExpression` of a 2-element vector of type
/// `T`, constructed with the values `args`. /// `T`, constructed with the values `args`.
template <typename T, typename... ARGS> template <typename T, typename... ARGS>
ast::TypeConstructorExpression* vec2(ARGS&&... args) { TypeConstructorExpression* vec2(ARGS&&... args) {
return create<ast::TypeConstructorExpression>( return create<TypeConstructorExpression>(
ty.vec2<T>(), ExprList(std::forward<ARGS>(args)...)); ty.vec2<T>(), ExprList(std::forward<ARGS>(args)...));
} }
/// @param args the arguments for the vector constructor /// @param args the arguments for the vector constructor
/// @return an `ast::TypeConstructorExpression` of a 3-element vector of type /// @return an `TypeConstructorExpression` of a 3-element vector of type
/// `T`, constructed with the values `args`. /// `T`, constructed with the values `args`.
template <typename T, typename... ARGS> template <typename T, typename... ARGS>
ast::TypeConstructorExpression* vec3(ARGS&&... args) { TypeConstructorExpression* vec3(ARGS&&... args) {
return create<ast::TypeConstructorExpression>( return create<TypeConstructorExpression>(
ty.vec3<T>(), ExprList(std::forward<ARGS>(args)...)); ty.vec3<T>(), ExprList(std::forward<ARGS>(args)...));
} }
/// @param args the arguments for the vector constructor /// @param args the arguments for the vector constructor
/// @return an `ast::TypeConstructorExpression` of a 4-element vector of type /// @return an `TypeConstructorExpression` of a 4-element vector of type
/// `T`, constructed with the values `args`. /// `T`, constructed with the values `args`.
template <typename T, typename... ARGS> template <typename T, typename... ARGS>
ast::TypeConstructorExpression* vec4(ARGS&&... args) { TypeConstructorExpression* vec4(ARGS&&... args) {
return create<ast::TypeConstructorExpression>( return create<TypeConstructorExpression>(
ty.vec4<T>(), ExprList(std::forward<ARGS>(args)...)); ty.vec4<T>(), ExprList(std::forward<ARGS>(args)...));
} }
/// @param args the arguments for the matrix constructor /// @param args the arguments for the matrix constructor
/// @return an `ast::TypeConstructorExpression` of a 2x2 matrix of type /// @return an `TypeConstructorExpression` of a 2x2 matrix of type
/// `T`, constructed with the values `args`. /// `T`, constructed with the values `args`.
template <typename T, typename... ARGS> template <typename T, typename... ARGS>
ast::TypeConstructorExpression* mat2x2(ARGS&&... args) { TypeConstructorExpression* mat2x2(ARGS&&... args) {
return create<ast::TypeConstructorExpression>( return create<TypeConstructorExpression>(
ty.mat2x2<T>(), ExprList(std::forward<ARGS>(args)...)); ty.mat2x2<T>(), ExprList(std::forward<ARGS>(args)...));
} }
/// @param args the arguments for the matrix constructor /// @param args the arguments for the matrix constructor
/// @return an `ast::TypeConstructorExpression` of a 2x3 matrix of type /// @return an `TypeConstructorExpression` of a 2x3 matrix of type
/// `T`, constructed with the values `args`. /// `T`, constructed with the values `args`.
template <typename T, typename... ARGS> template <typename T, typename... ARGS>
ast::TypeConstructorExpression* mat2x3(ARGS&&... args) { TypeConstructorExpression* mat2x3(ARGS&&... args) {
return create<ast::TypeConstructorExpression>( return create<TypeConstructorExpression>(
ty.mat2x3<T>(), ExprList(std::forward<ARGS>(args)...)); ty.mat2x3<T>(), ExprList(std::forward<ARGS>(args)...));
} }
/// @param args the arguments for the matrix constructor /// @param args the arguments for the matrix constructor
/// @return an `ast::TypeConstructorExpression` of a 2x4 matrix of type /// @return an `TypeConstructorExpression` of a 2x4 matrix of type
/// `T`, constructed with the values `args`. /// `T`, constructed with the values `args`.
template <typename T, typename... ARGS> template <typename T, typename... ARGS>
ast::TypeConstructorExpression* mat2x4(ARGS&&... args) { TypeConstructorExpression* mat2x4(ARGS&&... args) {
return create<ast::TypeConstructorExpression>( return create<TypeConstructorExpression>(
ty.mat2x4<T>(), ExprList(std::forward<ARGS>(args)...)); ty.mat2x4<T>(), ExprList(std::forward<ARGS>(args)...));
} }
/// @param args the arguments for the matrix constructor /// @param args the arguments for the matrix constructor
/// @return an `ast::TypeConstructorExpression` of a 3x2 matrix of type /// @return an `TypeConstructorExpression` of a 3x2 matrix of type
/// `T`, constructed with the values `args`. /// `T`, constructed with the values `args`.
template <typename T, typename... ARGS> template <typename T, typename... ARGS>
ast::TypeConstructorExpression* mat3x2(ARGS&&... args) { TypeConstructorExpression* mat3x2(ARGS&&... args) {
return create<ast::TypeConstructorExpression>( return create<TypeConstructorExpression>(
ty.mat3x2<T>(), ExprList(std::forward<ARGS>(args)...)); ty.mat3x2<T>(), ExprList(std::forward<ARGS>(args)...));
} }
/// @param args the arguments for the matrix constructor /// @param args the arguments for the matrix constructor
/// @return an `ast::TypeConstructorExpression` of a 3x3 matrix of type /// @return an `TypeConstructorExpression` of a 3x3 matrix of type
/// `T`, constructed with the values `args`. /// `T`, constructed with the values `args`.
template <typename T, typename... ARGS> template <typename T, typename... ARGS>
ast::TypeConstructorExpression* mat3x3(ARGS&&... args) { TypeConstructorExpression* mat3x3(ARGS&&... args) {
return create<ast::TypeConstructorExpression>( return create<TypeConstructorExpression>(
ty.mat3x3<T>(), ExprList(std::forward<ARGS>(args)...)); ty.mat3x3<T>(), ExprList(std::forward<ARGS>(args)...));
} }
/// @param args the arguments for the matrix constructor /// @param args the arguments for the matrix constructor
/// @return an `ast::TypeConstructorExpression` of a 3x4 matrix of type /// @return an `TypeConstructorExpression` of a 3x4 matrix of type
/// `T`, constructed with the values `args`. /// `T`, constructed with the values `args`.
template <typename T, typename... ARGS> template <typename T, typename... ARGS>
ast::TypeConstructorExpression* mat3x4(ARGS&&... args) { TypeConstructorExpression* mat3x4(ARGS&&... args) {
return create<ast::TypeConstructorExpression>( return create<TypeConstructorExpression>(
ty.mat3x4<T>(), ExprList(std::forward<ARGS>(args)...)); ty.mat3x4<T>(), ExprList(std::forward<ARGS>(args)...));
} }
/// @param args the arguments for the matrix constructor /// @param args the arguments for the matrix constructor
/// @return an `ast::TypeConstructorExpression` of a 4x2 matrix of type /// @return an `TypeConstructorExpression` of a 4x2 matrix of type
/// `T`, constructed with the values `args`. /// `T`, constructed with the values `args`.
template <typename T, typename... ARGS> template <typename T, typename... ARGS>
ast::TypeConstructorExpression* mat4x2(ARGS&&... args) { TypeConstructorExpression* mat4x2(ARGS&&... args) {
return create<ast::TypeConstructorExpression>( return create<TypeConstructorExpression>(
ty.mat4x2<T>(), ExprList(std::forward<ARGS>(args)...)); ty.mat4x2<T>(), ExprList(std::forward<ARGS>(args)...));
} }
/// @param args the arguments for the matrix constructor /// @param args the arguments for the matrix constructor
/// @return an `ast::TypeConstructorExpression` of a 4x3 matrix of type /// @return an `TypeConstructorExpression` of a 4x3 matrix of type
/// `T`, constructed with the values `args`. /// `T`, constructed with the values `args`.
template <typename T, typename... ARGS> template <typename T, typename... ARGS>
ast::TypeConstructorExpression* mat4x3(ARGS&&... args) { TypeConstructorExpression* mat4x3(ARGS&&... args) {
return create<ast::TypeConstructorExpression>( return create<TypeConstructorExpression>(
ty.mat4x3<T>(), ExprList(std::forward<ARGS>(args)...)); ty.mat4x3<T>(), ExprList(std::forward<ARGS>(args)...));
} }
/// @param args the arguments for the matrix constructor /// @param args the arguments for the matrix constructor
/// @return an `ast::TypeConstructorExpression` of a 4x4 matrix of type /// @return an `TypeConstructorExpression` of a 4x4 matrix of type
/// `T`, constructed with the values `args`. /// `T`, constructed with the values `args`.
template <typename T, typename... ARGS> template <typename T, typename... ARGS>
ast::TypeConstructorExpression* mat4x4(ARGS&&... args) { TypeConstructorExpression* mat4x4(ARGS&&... args) {
return create<ast::TypeConstructorExpression>( return create<TypeConstructorExpression>(
ty.mat4x4<T>(), ExprList(std::forward<ARGS>(args)...)); ty.mat4x4<T>(), ExprList(std::forward<ARGS>(args)...));
} }
/// @param args the arguments for the array constructor /// @param args the arguments for the array constructor
/// @return an `ast::TypeConstructorExpression` of a 4x4 matrix of type /// @return an `TypeConstructorExpression` of a 4x4 matrix of type
/// `T`, constructed with the values `args`. /// `T`, constructed with the values `args`.
template <typename T, int N = 0, typename... ARGS> template <typename T, int N = 0, typename... ARGS>
ast::TypeConstructorExpression* array(ARGS&&... args) { TypeConstructorExpression* array(ARGS&&... args) {
return create<ast::TypeConstructorExpression>( return create<TypeConstructorExpression>(
ty.array<T, N>(), ExprList(std::forward<ARGS>(args)...)); ty.array<T, N>(), ExprList(std::forward<ARGS>(args)...));
} }
/// @param name the variable name /// @param name the variable name
/// @param storage the variable storage class /// @param storage the variable storage class
/// @param type the variable type /// @param type the variable type
/// @returns a `ast::Variable` with the given name, storage and type /// @returns a `Variable` with the given name, storage and type
ast::Variable* Var(const std::string& name, Variable* Var(const std::string& name,
ast::StorageClass storage, StorageClass storage,
ast::type::Type* type); type::Type* type);
/// @param func the function name /// @param func the function name
/// @param args the function call arguments /// @param args the function call arguments
/// @returns a `ast::CallExpression` to the function `func`, with the /// @returns a `CallExpression` to the function `func`, with the
/// arguments of `args` converted to `ast::Expression`s using `Expr()`. /// arguments of `args` converted to `Expression`s using `Expr()`.
template <typename... ARGS> template <typename... ARGS>
ast::CallExpression Call(const std::string& func, ARGS&&... args) { CallExpression Call(const std::string& func, ARGS&&... args) {
return ast::CallExpression{Expr(func), return CallExpression{Expr(func), ExprList(std::forward<ARGS>(args)...)};
ExprList(std::forward<ARGS>(args)...)};
} }
/// Creates a new `ast::Node` owned by the Module. When the Module is /// Creates a new `Node` owned by the Module. When the Module is
/// destructed, the `ast::Node` will also be destructed. /// destructed, the `Node` will also be destructed.
/// @param args the arguments to pass to the type constructor /// @param args the arguments to pass to the type constructor
/// @returns the node pointer /// @returns the node pointer
template <typename T, typename... ARGS> template <typename T, typename... ARGS>
@ -454,15 +444,15 @@ class Builder {
} }
/// The builder module /// The builder module
tint::Context* const ctx; Context* const ctx;
/// The builder module /// The builder module
tint::ast::Module* const mod; Module* const mod;
/// The builder types /// The builder types
const TypesBuilder ty; const TypesBuilder ty;
protected: protected:
/// Called whenever a new variable is built with `Var()`. /// Called whenever a new variable is built with `Var()`.
virtual void OnVariableBuilt(ast::Variable*) {} virtual void OnVariableBuilt(Variable*) {}
}; };
/// BuilderWithContextAndModule is a `Builder` that constructs and owns its /// BuilderWithContextAndModule is a `Builder` that constructs and owns its
@ -477,23 +467,23 @@ class BuilderWithContextAndModule : public Builder {
// Various template specializations for TypesBuilder::CToAST. // Various template specializations for TypesBuilder::CToAST.
template <> template <>
struct TypesBuilder::CToAST<Builder::i32> { struct TypesBuilder::CToAST<Builder::i32> {
static ast::type::Type* get(const TypesBuilder* t) { return t->i32; } static type::Type* get(const TypesBuilder* t) { return t->i32; }
}; };
template <> template <>
struct TypesBuilder::CToAST<Builder::u32> { struct TypesBuilder::CToAST<Builder::u32> {
static ast::type::Type* get(const TypesBuilder* t) { return t->u32; } static type::Type* get(const TypesBuilder* t) { return t->u32; }
}; };
template <> template <>
struct TypesBuilder::CToAST<Builder::f32> { struct TypesBuilder::CToAST<Builder::f32> {
static ast::type::Type* get(const TypesBuilder* t) { return t->f32; } static type::Type* get(const TypesBuilder* t) { return t->f32; }
}; };
template <> template <>
struct TypesBuilder::CToAST<bool> { struct TypesBuilder::CToAST<bool> {
static ast::type::Type* get(const TypesBuilder* t) { return t->bool_; } static type::Type* get(const TypesBuilder* t) { return t->bool_; }
}; };
template <> template <>
struct TypesBuilder::CToAST<void> { struct TypesBuilder::CToAST<void> {
static ast::type::Type* get(const TypesBuilder* t) { return t->void_; } static type::Type* get(const TypesBuilder* t) { return t->void_; }
}; };
//! @endcond //! @endcond

View File

@ -49,7 +49,7 @@ TEST_F(CallExpressionTest, Creation_WithSource) {
TEST_F(CallExpressionTest, IsCall) { TEST_F(CallExpressionTest, IsCall) {
auto* func = create<IdentifierExpression>("func"); auto* func = create<IdentifierExpression>("func");
CallExpression stmt(func, {}); CallExpression stmt(func, {});
EXPECT_TRUE(stmt.Is<ast::CallExpression>()); EXPECT_TRUE(stmt.Is<CallExpression>());
} }
TEST_F(CallExpressionTest, IsValid) { TEST_F(CallExpressionTest, IsValid) {

View File

@ -25,8 +25,8 @@ namespace {
using CallStatementTest = TestHelper; using CallStatementTest = TestHelper;
TEST_F(CallStatementTest, Creation) { TEST_F(CallStatementTest, Creation) {
auto* expr = create<ast::CallExpression>( auto* expr = create<CallExpression>(create<IdentifierExpression>("func"),
create<ast::IdentifierExpression>("func"), ExpressionList{}); ExpressionList{});
CallStatement c(expr); CallStatement c(expr);
EXPECT_EQ(c.expr(), expr); EXPECT_EQ(c.expr(), expr);
@ -38,8 +38,8 @@ TEST_F(CallStatementTest, IsCall) {
} }
TEST_F(CallStatementTest, IsValid) { TEST_F(CallStatementTest, IsValid) {
CallStatement c(create<ast::CallExpression>( CallStatement c(create<CallExpression>(create<IdentifierExpression>("func"),
create<ast::IdentifierExpression>("func"), ExpressionList{})); ExpressionList{}));
EXPECT_TRUE(c.IsValid()); EXPECT_TRUE(c.IsValid());
} }
@ -49,13 +49,13 @@ TEST_F(CallStatementTest, IsValid_MissingExpr) {
} }
TEST_F(CallStatementTest, IsValid_InvalidExpr) { TEST_F(CallStatementTest, IsValid_InvalidExpr) {
CallStatement c(create<ast::CallExpression>()); CallStatement c(create<CallExpression>());
EXPECT_FALSE(c.IsValid()); EXPECT_FALSE(c.IsValid());
} }
TEST_F(CallStatementTest, ToStr) { TEST_F(CallStatementTest, ToStr) {
CallStatement c(create<ast::CallExpression>( CallStatement c(create<CallExpression>(create<IdentifierExpression>("func"),
create<ast::IdentifierExpression>("func"), ExpressionList{})); ExpressionList{}));
std::ostringstream out; std::ostringstream out;
c.to_str(out, 2); c.to_str(out, 2);

View File

@ -29,7 +29,7 @@ namespace {
using CaseStatementTest = TestHelper; using CaseStatementTest = TestHelper;
TEST_F(CaseStatementTest, Creation_i32) { TEST_F(CaseStatementTest, Creation_i32) {
ast::type::I32Type i32; type::I32Type 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) {
ast::type::U32Type u32; type::U32Type 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) {
ast::type::I32Type i32; type::I32Type i32;
CaseSelectorList b; CaseSelectorList b;
b.push_back(create<SintLiteral>(&i32, 2)); b.push_back(create<SintLiteral>(&i32, 2));
@ -82,33 +82,33 @@ TEST_F(CaseStatementTest, IsDefault_WithoutSelectors) {
auto* body = create<BlockStatement>(); auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>()); body->append(create<DiscardStatement>());
CaseStatement c(create<ast::BlockStatement>()); CaseStatement c(create<BlockStatement>());
c.set_body(body); c.set_body(body);
EXPECT_TRUE(c.IsDefault()); EXPECT_TRUE(c.IsDefault());
} }
TEST_F(CaseStatementTest, IsDefault_WithSelectors) { TEST_F(CaseStatementTest, IsDefault_WithSelectors) {
ast::type::I32Type i32; type::I32Type i32;
CaseSelectorList b; CaseSelectorList b;
b.push_back(create<SintLiteral>(&i32, 2)); b.push_back(create<SintLiteral>(&i32, 2));
CaseStatement c(create<ast::BlockStatement>()); CaseStatement c(create<BlockStatement>());
c.set_selectors(b); c.set_selectors(b);
EXPECT_FALSE(c.IsDefault()); EXPECT_FALSE(c.IsDefault());
} }
TEST_F(CaseStatementTest, IsCase) { TEST_F(CaseStatementTest, IsCase) {
CaseStatement c(create<ast::BlockStatement>()); CaseStatement c(create<BlockStatement>());
EXPECT_TRUE(c.Is<ast::CaseStatement>()); EXPECT_TRUE(c.Is<CaseStatement>());
} }
TEST_F(CaseStatementTest, IsValid) { TEST_F(CaseStatementTest, IsValid) {
CaseStatement c(create<ast::BlockStatement>()); CaseStatement c(create<BlockStatement>());
EXPECT_TRUE(c.IsValid()); EXPECT_TRUE(c.IsValid());
} }
TEST_F(CaseStatementTest, IsValid_NullBodyStatement) { TEST_F(CaseStatementTest, IsValid_NullBodyStatement) {
ast::type::I32Type i32; type::I32Type i32;
CaseSelectorList b; CaseSelectorList b;
b.push_back(create<SintLiteral>(&i32, 2)); b.push_back(create<SintLiteral>(&i32, 2));
@ -121,19 +121,19 @@ TEST_F(CaseStatementTest, IsValid_NullBodyStatement) {
} }
TEST_F(CaseStatementTest, IsValid_InvalidBodyStatement) { TEST_F(CaseStatementTest, IsValid_InvalidBodyStatement) {
ast::type::I32Type i32; type::I32Type i32;
CaseSelectorList b; CaseSelectorList b;
b.push_back(create<SintLiteral>(&i32, 2)); b.push_back(create<SintLiteral>(&i32, 2));
auto* body = create<BlockStatement>(); auto* body = create<BlockStatement>();
body->append(create<IfStatement>(nullptr, create<ast::BlockStatement>())); body->append(create<IfStatement>(nullptr, create<BlockStatement>()));
CaseStatement c({b}, body); CaseStatement c({b}, body);
EXPECT_FALSE(c.IsValid()); EXPECT_FALSE(c.IsValid());
} }
TEST_F(CaseStatementTest, ToStr_WithSelectors_i32) { TEST_F(CaseStatementTest, ToStr_WithSelectors_i32) {
ast::type::I32Type i32; type::I32Type 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) {
ast::type::U32Type u32; type::U32Type 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) {
ast::type::I32Type i32; type::I32Type i32;
CaseSelectorList b; CaseSelectorList b;
b.push_back(create<SintLiteral>(&i32, 1)); b.push_back(create<SintLiteral>(&i32, 1));

View File

@ -77,7 +77,7 @@ TEST_F(DecoratedVariableTest, WithDecorations) {
VariableDecorationList decos; VariableDecorationList decos;
decos.push_back(create<LocationDecoration>(1, Source{})); decos.push_back(create<LocationDecoration>(1, Source{}));
decos.push_back(create<BuiltinDecoration>(ast::Builtin::kPosition, Source{})); decos.push_back(create<BuiltinDecoration>(Builtin::kPosition, Source{}));
decos.push_back(create<ConstantIdDecoration>(1200, Source{})); decos.push_back(create<ConstantIdDecoration>(1200, Source{}));
dv.set_decorations(decos); dv.set_decorations(decos);
@ -108,7 +108,7 @@ TEST_F(DecoratedVariableTest, IsValid) {
TEST_F(DecoratedVariableTest, IsDecorated) { TEST_F(DecoratedVariableTest, IsDecorated) {
DecoratedVariable dv; DecoratedVariable dv;
EXPECT_TRUE(dv.Is<ast::DecoratedVariable>()); EXPECT_TRUE(dv.Is<DecoratedVariable>());
} }
TEST_F(DecoratedVariableTest, to_str) { TEST_F(DecoratedVariableTest, to_str) {

View File

@ -28,7 +28,7 @@ namespace {
using ElseStatementTest = TestHelper; using ElseStatementTest = TestHelper;
TEST_F(ElseStatementTest, Creation) { TEST_F(ElseStatementTest, Creation) {
ast::type::BoolType bool_type; type::BoolType 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) {
ast::type::BoolType bool_type; type::BoolType 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>());
@ -97,14 +97,14 @@ TEST_F(ElseStatementTest, IsValid_InvalidCondition) {
TEST_F(ElseStatementTest, IsValid_InvalidBodyStatement) { TEST_F(ElseStatementTest, IsValid_InvalidBodyStatement) {
auto* body = create<BlockStatement>(); auto* body = create<BlockStatement>();
body->append(create<IfStatement>(nullptr, create<ast::BlockStatement>())); body->append(create<IfStatement>(nullptr, create<BlockStatement>()));
ElseStatement e(body); ElseStatement e(body);
EXPECT_FALSE(e.IsValid()); EXPECT_FALSE(e.IsValid());
} }
TEST_F(ElseStatementTest, ToStr) { TEST_F(ElseStatementTest, ToStr) {
ast::type::BoolType bool_type; type::BoolType 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

@ -38,7 +38,7 @@ TEST_F(ExpressionTest, set_result_type) {
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<ast::type::I32Type>()); EXPECT_TRUE(e.result_type()->Is<type::I32Type>());
} }
TEST_F(ExpressionTest, set_result_type_alias) { TEST_F(ExpressionTest, set_result_type_alias) {
@ -49,7 +49,7 @@ TEST_F(ExpressionTest, set_result_type_alias) {
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<ast::type::I32Type>()); EXPECT_TRUE(e.result_type()->Is<type::I32Type>());
} }
} // namespace } // namespace

View File

@ -20,7 +20,7 @@
namespace tint { namespace tint {
namespace ast { namespace ast {
FloatLiteral::FloatLiteral(ast::type::Type* type, float value) FloatLiteral::FloatLiteral(type::Type* type, float value)
: Base(type), value_(value) {} : Base(type), value_(value) {}
FloatLiteral::~FloatLiteral() = default; FloatLiteral::~FloatLiteral() = default;

View File

@ -28,7 +28,7 @@ class FloatLiteral : public Castable<FloatLiteral, Literal> {
/// Constructor /// Constructor
/// @param type the type of the literal /// @param type the type of the literal
/// @param value the float literals value /// @param value the float literals value
FloatLiteral(ast::type::Type* type, float value); FloatLiteral(type::Type* type, float value);
~FloatLiteral() override; ~FloatLiteral() override;
/// @returns the float literal value /// @returns the float literal value

View File

@ -28,14 +28,14 @@ namespace {
using FloatLiteralTest = TestHelper; using FloatLiteralTest = TestHelper;
TEST_F(FloatLiteralTest, Value) { TEST_F(FloatLiteralTest, Value) {
ast::type::F32Type f32; type::F32Type 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) {
ast::type::F32Type f32; type::F32Type 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) {
ast::type::F32Type f32; type::F32Type 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) {
ast::type::F32Type f32; type::F32Type 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

@ -62,13 +62,13 @@ std::tuple<uint32_t, uint32_t, uint32_t> Function::workgroup_size() const {
return {1, 1, 1}; return {1, 1, 1};
} }
ast::PipelineStage Function::pipeline_stage() const { PipelineStage Function::pipeline_stage() const {
for (auto* deco : decorations_) { for (auto* deco : decorations_) {
if (auto* stage = deco->As<StageDecoration>()) { if (auto* stage = deco->As<StageDecoration>()) {
return stage->value(); return stage->value();
} }
} }
return ast::PipelineStage::kNone; return PipelineStage::kNone;
} }
void Function::add_referenced_module_variable(Variable* var) { void Function::add_referenced_module_variable(Variable* var) {
@ -85,7 +85,7 @@ Function::referenced_location_variables() const {
std::vector<std::pair<Variable*, LocationDecoration*>> ret; std::vector<std::pair<Variable*, LocationDecoration*>> ret;
for (auto* var : referenced_module_variables()) { for (auto* var : referenced_module_variables()) {
if (auto* decos = var->As<ast::DecoratedVariable>()) { if (auto* decos = var->As<DecoratedVariable>()) {
for (auto* deco : decos->decorations()) { for (auto* deco : decos->decorations()) {
if (auto* location = deco->As<LocationDecoration>()) { if (auto* location = deco->As<LocationDecoration>()) {
ret.push_back({var, location}); ret.push_back({var, location});
@ -102,17 +102,17 @@ Function::referenced_uniform_variables() const {
std::vector<std::pair<Variable*, Function::BindingInfo>> ret; std::vector<std::pair<Variable*, Function::BindingInfo>> ret;
for (auto* var : referenced_module_variables()) { for (auto* var : referenced_module_variables()) {
if (!var->Is<ast::DecoratedVariable>() || if (!var->Is<DecoratedVariable>() ||
var->storage_class() != ast::StorageClass::kUniform) { var->storage_class() != StorageClass::kUniform) {
continue; continue;
} }
BindingDecoration* binding = nullptr; BindingDecoration* binding = nullptr;
SetDecoration* set = nullptr; SetDecoration* set = nullptr;
for (auto* deco : var->As<ast::DecoratedVariable>()->decorations()) { for (auto* deco : var->As<DecoratedVariable>()->decorations()) {
if (auto* b = deco->As<ast::BindingDecoration>()) { if (auto* b = deco->As<BindingDecoration>()) {
binding = b; binding = b;
} else if (auto* s = deco->As<ast::SetDecoration>()) { } else if (auto* s = deco->As<SetDecoration>()) {
set = s; set = s;
} }
} }
@ -130,17 +130,17 @@ Function::referenced_storagebuffer_variables() const {
std::vector<std::pair<Variable*, Function::BindingInfo>> ret; std::vector<std::pair<Variable*, Function::BindingInfo>> ret;
for (auto* var : referenced_module_variables()) { for (auto* var : referenced_module_variables()) {
if (!var->Is<ast::DecoratedVariable>() || if (!var->Is<DecoratedVariable>() ||
var->storage_class() != ast::StorageClass::kStorageBuffer) { var->storage_class() != StorageClass::kStorageBuffer) {
continue; continue;
} }
BindingDecoration* binding = nullptr; BindingDecoration* binding = nullptr;
SetDecoration* set = nullptr; SetDecoration* set = nullptr;
for (auto* deco : var->As<ast::DecoratedVariable>()->decorations()) { for (auto* deco : var->As<DecoratedVariable>()->decorations()) {
if (auto* b = deco->As<ast::BindingDecoration>()) { if (auto* b = deco->As<BindingDecoration>()) {
binding = b; binding = b;
} else if (auto* s = deco->As<ast::SetDecoration>()) { } else if (auto* s = deco->As<SetDecoration>()) {
set = s; set = s;
} }
} }
@ -158,10 +158,10 @@ Function::referenced_builtin_variables() const {
std::vector<std::pair<Variable*, BuiltinDecoration*>> ret; std::vector<std::pair<Variable*, BuiltinDecoration*>> ret;
for (auto* var : referenced_module_variables()) { for (auto* var : referenced_module_variables()) {
if (!var->Is<ast::DecoratedVariable>()) { if (!var->Is<DecoratedVariable>()) {
continue; continue;
} }
for (auto* deco : var->As<ast::DecoratedVariable>()->decorations()) { for (auto* deco : var->As<DecoratedVariable>()->decorations()) {
if (auto* builtin = deco->As<BuiltinDecoration>()) { if (auto* builtin = deco->As<BuiltinDecoration>()) {
ret.push_back({var, builtin}); ret.push_back({var, builtin});
break; break;
@ -282,18 +282,18 @@ 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<ast::DecoratedVariable>() || if (!var->Is<DecoratedVariable>() ||
!unwrapped_type->Is<ast::type::SamplerType>() || !unwrapped_type->Is<type::SamplerType>() ||
unwrapped_type->As<ast::type::SamplerType>()->kind() != kind) { unwrapped_type->As<type::SamplerType>()->kind() != kind) {
continue; continue;
} }
BindingDecoration* binding = nullptr; BindingDecoration* binding = nullptr;
SetDecoration* set = nullptr; SetDecoration* set = nullptr;
for (auto* deco : var->As<ast::DecoratedVariable>()->decorations()) { for (auto* deco : var->As<DecoratedVariable>()->decorations()) {
if (auto* b = deco->As<ast::BindingDecoration>()) { if (auto* b = deco->As<BindingDecoration>()) {
binding = b; binding = b;
} else if (auto* s = deco->As<ast::SetDecoration>()) { } else if (auto* s = deco->As<SetDecoration>()) {
set = s; set = s;
} }
} }
@ -312,24 +312,23 @@ 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<ast::DecoratedVariable>() || if (!var->Is<DecoratedVariable>() ||
!unwrapped_type->Is<ast::type::TextureType>()) { !unwrapped_type->Is<type::TextureType>()) {
continue; continue;
} }
if ((multisampled && if ((multisampled &&
!unwrapped_type->Is<ast::type::MultisampledTextureType>()) || !unwrapped_type->Is<type::MultisampledTextureType>()) ||
(!multisampled && (!multisampled && !unwrapped_type->Is<type::SampledTextureType>())) {
!unwrapped_type->Is<ast::type::SampledTextureType>())) {
continue; continue;
} }
BindingDecoration* binding = nullptr; BindingDecoration* binding = nullptr;
SetDecoration* set = nullptr; SetDecoration* set = nullptr;
for (auto* deco : var->As<ast::DecoratedVariable>()->decorations()) { for (auto* deco : var->As<DecoratedVariable>()->decorations()) {
if (auto* b = deco->As<ast::BindingDecoration>()) { if (auto* b = deco->As<BindingDecoration>()) {
binding = b; binding = b;
} else if (auto* s = deco->As<ast::SetDecoration>()) { } else if (auto* s = deco->As<SetDecoration>()) {
set = s; set = s;
} }
} }

View File

@ -91,7 +91,7 @@ class Function : public Castable<Function, Node> {
/// Sets the function decorations /// Sets the function decorations
/// @param decos the decorations to set. This will overwrite any existing /// @param decos the decorations to set. This will overwrite any existing
/// decorations /// decorations
void set_decorations(ast::FunctionDecorationList decos) { void set_decorations(FunctionDecorationList decos) {
decorations_ = std::move(decos); decorations_ = std::move(decos);
} }
/// Adds a decoration to the function /// Adds a decoration to the function
@ -107,12 +107,10 @@ class Function : public Castable<Function, Node> {
std::tuple<uint32_t, uint32_t, uint32_t> workgroup_size() const; std::tuple<uint32_t, uint32_t, uint32_t> workgroup_size() const;
/// @returns the functions pipeline stage or None if not set /// @returns the functions pipeline stage or None if not set
ast::PipelineStage pipeline_stage() const; PipelineStage pipeline_stage() const;
/// @returns true if this function is an entry point /// @returns true if this function is an entry point
bool IsEntryPoint() const { bool IsEntryPoint() const { return pipeline_stage() != PipelineStage::kNone; }
return pipeline_stage() != ast::PipelineStage::kNone;
}
/// Adds the given variable to the list of referenced module variables if it /// Adds the given variable to the list of referenced module variables if it
/// is not already included. /// is not already included.

View File

@ -40,7 +40,7 @@ TEST_F(FunctionTest, Creation) {
params.push_back(create<Variable>("var", StorageClass::kNone, &i32)); params.push_back(create<Variable>("var", StorageClass::kNone, &i32));
auto* var = params[0]; auto* var = params[0];
Function f("func", params, &void_type, create<ast::BlockStatement>()); Function f("func", params, &void_type, create<BlockStatement>());
EXPECT_EQ(f.name(), "func"); EXPECT_EQ(f.name(), "func");
ASSERT_EQ(f.params().size(), 1u); ASSERT_EQ(f.params().size(), 1u);
EXPECT_EQ(f.return_type(), &void_type); EXPECT_EQ(f.return_type(), &void_type);
@ -55,7 +55,7 @@ TEST_F(FunctionTest, Creation_WithSource) {
params.push_back(create<Variable>("var", StorageClass::kNone, &i32)); params.push_back(create<Variable>("var", StorageClass::kNone, &i32));
Function f(Source{Source::Location{20, 2}}, "func", params, &void_type, Function f(Source{Source::Location{20, 2}}, "func", params, &void_type,
create<ast::BlockStatement>()); create<BlockStatement>());
auto src = f.source(); auto src = f.source();
EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.line, 20u);
EXPECT_EQ(src.range.begin.column, 2u); EXPECT_EQ(src.range.begin.column, 2u);
@ -66,7 +66,7 @@ TEST_F(FunctionTest, AddDuplicateReferencedVariables) {
type::I32Type i32; type::I32Type i32;
Variable v("var", StorageClass::kInput, &i32); Variable v("var", StorageClass::kInput, &i32);
Function f("func", VariableList{}, &void_type, create<ast::BlockStatement>()); Function f("func", VariableList{}, &void_type, create<BlockStatement>());
f.add_referenced_module_variable(&v); f.add_referenced_module_variable(&v);
ASSERT_EQ(f.referenced_module_variables().size(), 1u); ASSERT_EQ(f.referenced_module_variables().size(), 1u);
@ -85,25 +85,23 @@ TEST_F(FunctionTest, GetReferenceLocations) {
type::VoidType void_type; type::VoidType void_type;
type::I32Type i32; type::I32Type i32;
DecoratedVariable loc1( DecoratedVariable loc1(create<Variable>("loc1", StorageClass::kInput, &i32));
create<ast::Variable>("loc1", StorageClass::kInput, &i32)); loc1.set_decorations({create<LocationDecoration>(0, Source{})});
loc1.set_decorations({create<ast::LocationDecoration>(0, Source{})});
DecoratedVariable loc2( DecoratedVariable loc2(create<Variable>("loc2", StorageClass::kInput, &i32));
create<ast::Variable>("loc2", StorageClass::kInput, &i32)); loc2.set_decorations({create<LocationDecoration>(1, Source{})});
loc2.set_decorations({create<ast::LocationDecoration>(1, Source{})});
DecoratedVariable builtin1( DecoratedVariable builtin1(
create<ast::Variable>("builtin1", StorageClass::kInput, &i32)); create<Variable>("builtin1", StorageClass::kInput, &i32));
builtin1.set_decorations( builtin1.set_decorations(
{create<ast::BuiltinDecoration>(ast::Builtin::kPosition, Source{})}); {create<BuiltinDecoration>(Builtin::kPosition, Source{})});
DecoratedVariable builtin2( DecoratedVariable builtin2(
create<ast::Variable>("builtin2", StorageClass::kInput, &i32)); create<Variable>("builtin2", StorageClass::kInput, &i32));
builtin2.set_decorations( builtin2.set_decorations(
{create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth, Source{})}); {create<BuiltinDecoration>(Builtin::kFragDepth, Source{})});
Function f("func", VariableList{}, &void_type, create<ast::BlockStatement>()); Function f("func", VariableList{}, &void_type, create<BlockStatement>());
f.add_referenced_module_variable(&loc1); f.add_referenced_module_variable(&loc1);
f.add_referenced_module_variable(&builtin1); f.add_referenced_module_variable(&builtin1);
@ -123,25 +121,23 @@ TEST_F(FunctionTest, GetReferenceBuiltins) {
type::VoidType void_type; type::VoidType void_type;
type::I32Type i32; type::I32Type i32;
DecoratedVariable loc1( DecoratedVariable loc1(create<Variable>("loc1", StorageClass::kInput, &i32));
create<ast::Variable>("loc1", StorageClass::kInput, &i32)); loc1.set_decorations({create<LocationDecoration>(0, Source{})});
loc1.set_decorations({create<ast::LocationDecoration>(0, Source{})});
DecoratedVariable loc2( DecoratedVariable loc2(create<Variable>("loc2", StorageClass::kInput, &i32));
create<ast::Variable>("loc2", StorageClass::kInput, &i32)); loc2.set_decorations({create<LocationDecoration>(1, Source{})});
loc2.set_decorations({create<ast::LocationDecoration>(1, Source{})});
DecoratedVariable builtin1( DecoratedVariable builtin1(
create<ast::Variable>("builtin1", StorageClass::kInput, &i32)); create<Variable>("builtin1", StorageClass::kInput, &i32));
builtin1.set_decorations( builtin1.set_decorations(
{create<ast::BuiltinDecoration>(ast::Builtin::kPosition, Source{})}); {create<BuiltinDecoration>(Builtin::kPosition, Source{})});
DecoratedVariable builtin2( DecoratedVariable builtin2(
create<ast::Variable>("builtin2", StorageClass::kInput, &i32)); create<Variable>("builtin2", StorageClass::kInput, &i32));
builtin2.set_decorations( builtin2.set_decorations(
{create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth, Source{})}); {create<BuiltinDecoration>(Builtin::kFragDepth, Source{})});
Function f("func", VariableList{}, &void_type, create<ast::BlockStatement>()); Function f("func", VariableList{}, &void_type, create<BlockStatement>());
f.add_referenced_module_variable(&loc1); f.add_referenced_module_variable(&loc1);
f.add_referenced_module_variable(&builtin1); f.add_referenced_module_variable(&builtin1);
@ -152,14 +148,14 @@ TEST_F(FunctionTest, GetReferenceBuiltins) {
auto ref_locs = f.referenced_builtin_variables(); auto ref_locs = f.referenced_builtin_variables();
ASSERT_EQ(ref_locs.size(), 2u); ASSERT_EQ(ref_locs.size(), 2u);
EXPECT_EQ(ref_locs[0].first, &builtin1); EXPECT_EQ(ref_locs[0].first, &builtin1);
EXPECT_EQ(ref_locs[0].second->value(), ast::Builtin::kPosition); EXPECT_EQ(ref_locs[0].second->value(), Builtin::kPosition);
EXPECT_EQ(ref_locs[1].first, &builtin2); EXPECT_EQ(ref_locs[1].first, &builtin2);
EXPECT_EQ(ref_locs[1].second->value(), ast::Builtin::kFragDepth); EXPECT_EQ(ref_locs[1].second->value(), Builtin::kFragDepth);
} }
TEST_F(FunctionTest, AddDuplicateEntryPoints) { TEST_F(FunctionTest, AddDuplicateEntryPoints) {
ast::type::VoidType void_type; type::VoidType void_type;
Function f("func", VariableList{}, &void_type, create<ast::BlockStatement>()); Function f("func", VariableList{}, &void_type, create<BlockStatement>());
f.add_ancestor_entry_point("main"); f.add_ancestor_entry_point("main");
ASSERT_EQ(1u, f.ancestor_entry_points().size()); ASSERT_EQ(1u, f.ancestor_entry_points().size());
@ -177,10 +173,10 @@ TEST_F(FunctionTest, IsValid) {
VariableList params; VariableList params;
params.push_back(create<Variable>("var", StorageClass::kNone, &i32)); params.push_back(create<Variable>("var", StorageClass::kNone, &i32));
auto* block = create<ast::BlockStatement>(); auto* block = create<BlockStatement>();
block->append(create<DiscardStatement>()); block->append(create<DiscardStatement>());
Function f("func", params, &void_type, create<ast::BlockStatement>()); Function f("func", params, &void_type, create<BlockStatement>());
f.set_body(block); f.set_body(block);
EXPECT_TRUE(f.IsValid()); EXPECT_TRUE(f.IsValid());
} }
@ -192,7 +188,7 @@ TEST_F(FunctionTest, IsValid_EmptyName) {
VariableList params; VariableList params;
params.push_back(create<Variable>("var", StorageClass::kNone, &i32)); params.push_back(create<Variable>("var", StorageClass::kNone, &i32));
Function f("", params, &void_type, create<ast::BlockStatement>()); Function f("", params, &void_type, create<BlockStatement>());
EXPECT_FALSE(f.IsValid()); EXPECT_FALSE(f.IsValid());
} }
@ -202,7 +198,7 @@ TEST_F(FunctionTest, IsValid_MissingReturnType) {
VariableList params; VariableList params;
params.push_back(create<Variable>("var", StorageClass::kNone, &i32)); params.push_back(create<Variable>("var", StorageClass::kNone, &i32));
Function f("func", params, nullptr, create<ast::BlockStatement>()); Function f("func", params, nullptr, create<BlockStatement>());
EXPECT_FALSE(f.IsValid()); EXPECT_FALSE(f.IsValid());
} }
@ -214,7 +210,7 @@ TEST_F(FunctionTest, IsValid_NullParam) {
params.push_back(create<Variable>("var", StorageClass::kNone, &i32)); params.push_back(create<Variable>("var", StorageClass::kNone, &i32));
params.push_back(nullptr); params.push_back(nullptr);
Function f("func", params, &void_type, create<ast::BlockStatement>()); Function f("func", params, &void_type, create<BlockStatement>());
EXPECT_FALSE(f.IsValid()); EXPECT_FALSE(f.IsValid());
} }
@ -224,7 +220,7 @@ TEST_F(FunctionTest, IsValid_InvalidParam) {
VariableList params; VariableList params;
params.push_back(create<Variable>("var", StorageClass::kNone, nullptr)); params.push_back(create<Variable>("var", StorageClass::kNone, nullptr));
Function f("func", params, &void_type, create<ast::BlockStatement>()); Function f("func", params, &void_type, create<BlockStatement>());
EXPECT_FALSE(f.IsValid()); EXPECT_FALSE(f.IsValid());
} }
@ -235,11 +231,11 @@ TEST_F(FunctionTest, IsValid_NullBodyStatement) {
VariableList params; VariableList params;
params.push_back(create<Variable>("var", StorageClass::kNone, &i32)); params.push_back(create<Variable>("var", StorageClass::kNone, &i32));
auto* block = create<ast::BlockStatement>(); auto* block = create<BlockStatement>();
block->append(create<DiscardStatement>()); block->append(create<DiscardStatement>());
block->append(nullptr); block->append(nullptr);
Function f("func", params, &void_type, create<ast::BlockStatement>()); Function f("func", params, &void_type, create<BlockStatement>());
f.set_body(block); f.set_body(block);
EXPECT_FALSE(f.IsValid()); EXPECT_FALSE(f.IsValid());
} }
@ -251,11 +247,11 @@ TEST_F(FunctionTest, IsValid_InvalidBodyStatement) {
VariableList params; VariableList params;
params.push_back(create<Variable>("var", StorageClass::kNone, &i32)); params.push_back(create<Variable>("var", StorageClass::kNone, &i32));
auto* block = create<ast::BlockStatement>(); auto* block = create<BlockStatement>();
block->append(create<DiscardStatement>()); block->append(create<DiscardStatement>());
block->append(nullptr); block->append(nullptr);
Function f("func", params, &void_type, create<ast::BlockStatement>()); Function f("func", params, &void_type, create<BlockStatement>());
f.set_body(block); f.set_body(block);
EXPECT_FALSE(f.IsValid()); EXPECT_FALSE(f.IsValid());
} }
@ -264,10 +260,10 @@ TEST_F(FunctionTest, ToStr) {
type::VoidType void_type; type::VoidType void_type;
type::I32Type i32; type::I32Type i32;
auto* block = create<ast::BlockStatement>(); auto* block = create<BlockStatement>();
block->append(create<DiscardStatement>()); block->append(create<DiscardStatement>());
Function f("func", {}, &void_type, create<ast::BlockStatement>()); Function f("func", {}, &void_type, create<BlockStatement>());
f.set_body(block); f.set_body(block);
std::ostringstream out; std::ostringstream out;
@ -284,10 +280,10 @@ TEST_F(FunctionTest, ToStr_WithDecoration) {
type::VoidType void_type; type::VoidType void_type;
type::I32Type i32; type::I32Type i32;
auto* block = create<ast::BlockStatement>(); auto* block = create<BlockStatement>();
block->append(create<DiscardStatement>()); block->append(create<DiscardStatement>());
Function f("func", {}, &void_type, create<ast::BlockStatement>()); Function f("func", {}, &void_type, create<BlockStatement>());
f.set_body(block); f.set_body(block);
f.add_decoration(create<WorkgroupDecoration>(2, 4, 6, Source{})); f.add_decoration(create<WorkgroupDecoration>(2, 4, 6, Source{}));
@ -309,10 +305,10 @@ TEST_F(FunctionTest, ToStr_WithParams) {
VariableList params; VariableList params;
params.push_back(create<Variable>("var", StorageClass::kNone, &i32)); params.push_back(create<Variable>("var", StorageClass::kNone, &i32));
auto* block = create<ast::BlockStatement>(); auto* block = create<BlockStatement>();
block->append(create<DiscardStatement>()); block->append(create<DiscardStatement>());
Function f("func", params, &void_type, create<ast::BlockStatement>()); Function f("func", params, &void_type, create<BlockStatement>());
f.set_body(block); f.set_body(block);
std::ostringstream out; std::ostringstream out;
@ -334,7 +330,7 @@ TEST_F(FunctionTest, ToStr_WithParams) {
TEST_F(FunctionTest, TypeName) { TEST_F(FunctionTest, TypeName) {
type::VoidType void_type; type::VoidType void_type;
Function f("func", {}, &void_type, create<ast::BlockStatement>()); Function f("func", {}, &void_type, create<BlockStatement>());
EXPECT_EQ(f.type_name(), "__func__void"); EXPECT_EQ(f.type_name(), "__func__void");
} }
@ -347,7 +343,7 @@ TEST_F(FunctionTest, TypeName_WithParams) {
params.push_back(create<Variable>("var1", StorageClass::kNone, &i32)); params.push_back(create<Variable>("var1", StorageClass::kNone, &i32));
params.push_back(create<Variable>("var2", StorageClass::kNone, &f32)); params.push_back(create<Variable>("var2", StorageClass::kNone, &f32));
Function f("func", params, &void_type, create<ast::BlockStatement>()); Function f("func", params, &void_type, create<BlockStatement>());
EXPECT_EQ(f.type_name(), "__func__void__i32__f32"); EXPECT_EQ(f.type_name(), "__func__void__i32__f32");
} }
@ -355,10 +351,10 @@ TEST_F(FunctionTest, GetLastStatement) {
type::VoidType void_type; type::VoidType void_type;
VariableList params; VariableList params;
auto* body = create<ast::BlockStatement>(); auto* body = create<BlockStatement>();
auto* stmt = create<DiscardStatement>(); auto* stmt = create<DiscardStatement>();
body->append(stmt); body->append(stmt);
Function f("func", params, &void_type, create<ast::BlockStatement>()); Function f("func", params, &void_type, create<BlockStatement>());
f.set_body(body); f.set_body(body);
EXPECT_EQ(f.get_last_statement(), stmt); EXPECT_EQ(f.get_last_statement(), stmt);
@ -368,8 +364,8 @@ TEST_F(FunctionTest, GetLastStatement_nullptr) {
type::VoidType void_type; type::VoidType void_type;
VariableList params; VariableList params;
auto* body = create<ast::BlockStatement>(); auto* body = create<BlockStatement>();
Function f("func", params, &void_type, create<ast::BlockStatement>()); Function f("func", params, &void_type, create<BlockStatement>());
f.set_body(body); f.set_body(body);
EXPECT_EQ(f.get_last_statement(), nullptr); EXPECT_EQ(f.get_last_statement(), nullptr);
@ -377,7 +373,7 @@ TEST_F(FunctionTest, GetLastStatement_nullptr) {
TEST_F(FunctionTest, WorkgroupSize_NoneSet) { TEST_F(FunctionTest, WorkgroupSize_NoneSet) {
type::VoidType void_type; type::VoidType void_type;
Function f("f", {}, &void_type, create<ast::BlockStatement>()); Function f("f", {}, &void_type, create<BlockStatement>());
uint32_t x = 0; uint32_t x = 0;
uint32_t y = 0; uint32_t y = 0;
uint32_t z = 0; uint32_t z = 0;
@ -389,7 +385,7 @@ TEST_F(FunctionTest, WorkgroupSize_NoneSet) {
TEST_F(FunctionTest, WorkgroupSize) { TEST_F(FunctionTest, WorkgroupSize) {
type::VoidType void_type; type::VoidType void_type;
Function f("f", {}, &void_type, create<ast::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{}));
uint32_t x = 0; uint32_t x = 0;

View File

@ -38,7 +38,7 @@ TEST_F(IdentifierExpressionTest, Creation_WithSource) {
TEST_F(IdentifierExpressionTest, IsIdentifier) { TEST_F(IdentifierExpressionTest, IsIdentifier) {
IdentifierExpression i("ident"); IdentifierExpression i("ident");
EXPECT_TRUE(i.Is<ast::IdentifierExpression>()); EXPECT_TRUE(i.Is<IdentifierExpression>());
} }
TEST_F(IdentifierExpressionTest, IsValid) { TEST_F(IdentifierExpressionTest, IsValid) {

View File

@ -17,7 +17,7 @@
namespace tint { namespace tint {
namespace ast { namespace ast {
IntLiteral::IntLiteral(ast::type::Type* type) : Base(type) {} IntLiteral::IntLiteral(type::Type* type) : Base(type) {}
IntLiteral::~IntLiteral() = default; IntLiteral::~IntLiteral() = default;

View File

@ -30,7 +30,7 @@ class IntLiteral : public Castable<IntLiteral, Literal> {
protected: protected:
/// Constructor /// Constructor
/// @param type the type of the literal /// @param type the type of the literal
explicit IntLiteral(ast::type::Type* type); explicit IntLiteral(type::Type* type);
}; };
} // namespace ast } // namespace ast

View File

@ -30,13 +30,13 @@ namespace {
using IntLiteralTest = TestHelper; using IntLiteralTest = TestHelper;
TEST_F(IntLiteralTest, Sint_IsInt) { TEST_F(IntLiteralTest, Sint_IsInt) {
ast::type::I32Type i32; type::I32Type 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) {
ast::type::I32Type i32; type::I32Type i32;
UintLiteral i{&i32, 42}; UintLiteral i{&i32, 42};
EXPECT_TRUE(i.Is<IntLiteral>()); EXPECT_TRUE(i.Is<IntLiteral>());
} }

View File

@ -240,28 +240,28 @@ TextureSignature::~TextureSignature() = default;
TextureSignature::Parameters::Index::Index() = default; TextureSignature::Parameters::Index::Index() = default;
TextureSignature::Parameters::Index::Index(const Index&) = default; TextureSignature::Parameters::Index::Index(const Index&) = default;
bool IsCoarseDerivative(ast::Intrinsic i) { bool IsCoarseDerivative(Intrinsic i) {
return i == Intrinsic::kDpdxCoarse || i == Intrinsic::kDpdyCoarse || return i == Intrinsic::kDpdxCoarse || i == Intrinsic::kDpdyCoarse ||
i == Intrinsic::kFwidthCoarse; i == Intrinsic::kFwidthCoarse;
} }
bool IsFineDerivative(ast::Intrinsic i) { bool IsFineDerivative(Intrinsic i) {
return i == Intrinsic::kDpdxFine || i == Intrinsic::kDpdyFine || return i == Intrinsic::kDpdxFine || i == Intrinsic::kDpdyFine ||
i == Intrinsic::kFwidthFine; i == Intrinsic::kFwidthFine;
} }
bool IsDerivative(ast::Intrinsic i) { bool IsDerivative(Intrinsic i) {
return i == Intrinsic::kDpdx || i == Intrinsic::kDpdy || return i == Intrinsic::kDpdx || i == Intrinsic::kDpdy ||
i == Intrinsic::kFwidth || IsCoarseDerivative(i) || i == Intrinsic::kFwidth || IsCoarseDerivative(i) ||
IsFineDerivative(i); IsFineDerivative(i);
} }
bool IsFloatClassificationIntrinsic(ast::Intrinsic i) { bool IsFloatClassificationIntrinsic(Intrinsic i) {
return i == Intrinsic::kIsFinite || i == Intrinsic::kIsInf || return i == Intrinsic::kIsFinite || i == Intrinsic::kIsInf ||
i == Intrinsic::kIsNan || i == Intrinsic::kIsNormal; i == Intrinsic::kIsNan || i == Intrinsic::kIsNormal;
} }
bool IsTextureIntrinsic(ast::Intrinsic i) { bool IsTextureIntrinsic(Intrinsic i) {
return i == Intrinsic::kTextureLoad || i == Intrinsic::kTextureSample || return i == Intrinsic::kTextureLoad || i == Intrinsic::kTextureSample ||
i == Intrinsic::kTextureSampleLevel || i == Intrinsic::kTextureSampleLevel ||
i == Intrinsic::kTextureSampleBias || i == Intrinsic::kTextureSampleBias ||

View File

@ -161,27 +161,27 @@ struct TextureSignature : public Signature {
/// Determines if the given |name| is a coarse derivative /// Determines if the given |name| is a coarse derivative
/// @param i the intrinsic /// @param i the intrinsic
/// @returns true if the given derivative is coarse. /// @returns true if the given derivative is coarse.
bool IsCoarseDerivative(ast::Intrinsic i); bool IsCoarseDerivative(Intrinsic i);
/// Determines if the given |name| is a fine derivative /// Determines if the given |name| is a fine derivative
/// @param i the intrinsic /// @param i the intrinsic
/// @returns true if the given derivative is fine. /// @returns true if the given derivative is fine.
bool IsFineDerivative(ast::Intrinsic i); bool IsFineDerivative(Intrinsic i);
/// Determine if the given |name| is a derivative intrinsic /// Determine if the given |name| is a derivative intrinsic
/// @param i the intrinsic /// @param i the intrinsic
/// @returns true if the given |name| is a derivative intrinsic /// @returns true if the given |name| is a derivative intrinsic
bool IsDerivative(ast::Intrinsic i); bool IsDerivative(Intrinsic i);
/// Determines if the given |name| is a float classification intrinsic /// Determines if the given |name| is a float classification intrinsic
/// @param i the intrinsic /// @param i the intrinsic
/// @returns true if the given |name| is a float intrinsic /// @returns true if the given |name| is a float intrinsic
bool IsFloatClassificationIntrinsic(ast::Intrinsic i); bool IsFloatClassificationIntrinsic(Intrinsic i);
/// Determines if the given |name| is a texture operation intrinsic /// Determines if the given |name| is a texture operation intrinsic
/// @param i the intrinsic /// @param i the intrinsic
/// @returns true if the given |name| is a texture operation intrinsic /// @returns true if the given |name| is a texture operation intrinsic
bool IsTextureIntrinsic(ast::Intrinsic i); bool IsTextureIntrinsic(Intrinsic i);
} // namespace intrinsic } // namespace intrinsic
} // namespace ast } // namespace ast

View File

@ -26,11 +26,11 @@ TextureOverloadCase::TextureOverloadCase(
ValidTextureOverload o, ValidTextureOverload o,
const char* d, const char* d,
TextureKind tk, TextureKind tk,
ast::type::SamplerKind sk, type::SamplerKind sk,
ast::type::TextureDimension td, type::TextureDimension td,
TextureDataType tdt, TextureDataType tdt,
const char* f, const char* f,
std::function<ast::ExpressionList(ast::Builder*)> a) std::function<ExpressionList(Builder*)> a)
: overload(o), : overload(o),
description(d), description(d),
texture_kind(tk), texture_kind(tk),
@ -49,11 +49,11 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" s : sampler,\n" " s : sampler,\n"
" coords : f32) -> vec4<f32>", " coords : f32) -> vec4<f32>",
TextureKind::kRegular, TextureKind::kRegular,
ast::type::SamplerKind::kSampler, type::SamplerKind::kSampler,
ast::type::TextureDimension::k1d, type::TextureDimension::k1d,
TextureDataType::kF32, TextureDataType::kF32,
"textureSample", "textureSample",
[](ast::Builder* b) { [](Builder* b) {
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
1.0f); // coords 1.0f); // coords
@ -66,11 +66,11 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" coords : f32,\n" " coords : f32,\n"
" array_index : u32) -> vec4<f32>", " array_index : u32) -> vec4<f32>",
TextureKind::kRegular, TextureKind::kRegular,
ast::type::SamplerKind::kSampler, type::SamplerKind::kSampler,
ast::type::TextureDimension::k1dArray, type::TextureDimension::k1dArray,
TextureDataType::kF32, TextureDataType::kF32,
"textureSample", "textureSample",
[](ast::Builder* b) { [](Builder* b) {
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
1.0f, // coords 1.0f, // coords
@ -83,12 +83,12 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" s : sampler,\n" " s : sampler,\n"
" coords : vec2<f32>) -> vec4<f32>", " coords : vec2<f32>) -> vec4<f32>",
TextureKind::kRegular, TextureKind::kRegular,
ast::type::SamplerKind::kSampler, type::SamplerKind::kSampler,
ast::type::TextureDimension::k2d, type::TextureDimension::k2d,
TextureDataType::kF32, TextureDataType::kF32,
"textureSample", "textureSample",
[](ast::Builder* b) { [](Builder* b) {
using f32 = ast::Builder::f32; using f32 = Builder::f32;
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
b->vec2<f32>(1.f, 2.f)); // coords b->vec2<f32>(1.f, 2.f)); // coords
@ -101,13 +101,13 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" coords : vec2<f32>\n" " coords : vec2<f32>\n"
" offset : vec2<i32>) -> vec4<f32>", " offset : vec2<i32>) -> vec4<f32>",
TextureKind::kRegular, TextureKind::kRegular,
ast::type::SamplerKind::kSampler, type::SamplerKind::kSampler,
ast::type::TextureDimension::k2d, type::TextureDimension::k2d,
TextureDataType::kF32, TextureDataType::kF32,
"textureSample", "textureSample",
[](ast::Builder* b) { [](Builder* b) {
using f32 = ast::Builder::f32; using f32 = Builder::f32;
using i32 = ast::Builder::i32; using i32 = Builder::i32;
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
b->vec2<f32>(1.f, 2.f), // coords b->vec2<f32>(1.f, 2.f), // coords
@ -121,12 +121,12 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" coords : vec2<f32>,\n" " coords : vec2<f32>,\n"
" array_index : u32) -> vec4<f32>", " array_index : u32) -> vec4<f32>",
TextureKind::kRegular, TextureKind::kRegular,
ast::type::SamplerKind::kSampler, type::SamplerKind::kSampler,
ast::type::TextureDimension::k2dArray, type::TextureDimension::k2dArray,
TextureDataType::kF32, TextureDataType::kF32,
"textureSample", "textureSample",
[](ast::Builder* b) { [](Builder* b) {
using f32 = ast::Builder::f32; using f32 = Builder::f32;
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
b->vec2<f32>(1.f, 2.f), // coords b->vec2<f32>(1.f, 2.f), // coords
@ -141,13 +141,13 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" array_index : u32\n" " array_index : u32\n"
" offset : vec2<i32>) -> vec4<f32>", " offset : vec2<i32>) -> vec4<f32>",
TextureKind::kRegular, TextureKind::kRegular,
ast::type::SamplerKind::kSampler, type::SamplerKind::kSampler,
ast::type::TextureDimension::k2dArray, type::TextureDimension::k2dArray,
TextureDataType::kF32, TextureDataType::kF32,
"textureSample", "textureSample",
[](ast::Builder* b) { [](Builder* b) {
using f32 = ast::Builder::f32; using f32 = Builder::f32;
using i32 = ast::Builder::i32; using i32 = Builder::i32;
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
b->vec2<f32>(1.f, 2.f), // coords b->vec2<f32>(1.f, 2.f), // coords
@ -161,12 +161,12 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" s : sampler,\n" " s : sampler,\n"
" coords : vec3<f32>) -> vec4<f32>", " coords : vec3<f32>) -> vec4<f32>",
TextureKind::kRegular, TextureKind::kRegular,
ast::type::SamplerKind::kSampler, type::SamplerKind::kSampler,
ast::type::TextureDimension::k3d, type::TextureDimension::k3d,
TextureDataType::kF32, TextureDataType::kF32,
"textureSample", "textureSample",
[](ast::Builder* b) { [](Builder* b) {
using f32 = ast::Builder::f32; using f32 = Builder::f32;
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
b->vec3<f32>(1.f, 2.f, 3.f)); // coords b->vec3<f32>(1.f, 2.f, 3.f)); // coords
@ -179,13 +179,13 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" coords : vec3<f32>\n" " coords : vec3<f32>\n"
" offset : vec3<i32>) -> vec4<f32>", " offset : vec3<i32>) -> vec4<f32>",
TextureKind::kRegular, TextureKind::kRegular,
ast::type::SamplerKind::kSampler, type::SamplerKind::kSampler,
ast::type::TextureDimension::k3d, type::TextureDimension::k3d,
TextureDataType::kF32, TextureDataType::kF32,
"textureSample", "textureSample",
[](ast::Builder* b) { [](Builder* b) {
using f32 = ast::Builder::f32; using f32 = Builder::f32;
using i32 = ast::Builder::i32; using i32 = Builder::i32;
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
b->vec3<f32>(1.f, 2.f, 3.f), // coords b->vec3<f32>(1.f, 2.f, 3.f), // coords
@ -198,12 +198,12 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" s : sampler,\n" " s : sampler,\n"
" coords : vec3<f32>) -> vec4<f32>", " coords : vec3<f32>) -> vec4<f32>",
TextureKind::kRegular, TextureKind::kRegular,
ast::type::SamplerKind::kSampler, type::SamplerKind::kSampler,
ast::type::TextureDimension::kCube, type::TextureDimension::kCube,
TextureDataType::kF32, TextureDataType::kF32,
"textureSample", "textureSample",
[](ast::Builder* b) { [](Builder* b) {
using f32 = ast::Builder::f32; using f32 = Builder::f32;
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
b->vec3<f32>(1.f, 2.f, 3.f)); // coords b->vec3<f32>(1.f, 2.f, 3.f)); // coords
@ -216,12 +216,12 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" coords : vec3<f32>,\n" " coords : vec3<f32>,\n"
" array_index : u32) -> vec4<f32>", " array_index : u32) -> vec4<f32>",
TextureKind::kRegular, TextureKind::kRegular,
ast::type::SamplerKind::kSampler, type::SamplerKind::kSampler,
ast::type::TextureDimension::kCubeArray, type::TextureDimension::kCubeArray,
TextureDataType::kF32, TextureDataType::kF32,
"textureSample", "textureSample",
[](ast::Builder* b) { [](Builder* b) {
using f32 = ast::Builder::f32; using f32 = Builder::f32;
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
b->vec3<f32>(1.f, 2.f, 3.f), // coords b->vec3<f32>(1.f, 2.f, 3.f), // coords
@ -234,12 +234,12 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" s : sampler,\n" " s : sampler,\n"
" coords : vec2<f32>) -> f32", " coords : vec2<f32>) -> f32",
TextureKind::kDepth, TextureKind::kDepth,
ast::type::SamplerKind::kSampler, type::SamplerKind::kSampler,
ast::type::TextureDimension::k2d, type::TextureDimension::k2d,
TextureDataType::kF32, TextureDataType::kF32,
"textureSample", "textureSample",
[](ast::Builder* b) { [](Builder* b) {
using f32 = ast::Builder::f32; using f32 = Builder::f32;
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
b->vec2<f32>(1.f, 2.f)); // coords b->vec2<f32>(1.f, 2.f)); // coords
@ -252,13 +252,13 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" coords : vec2<f32>\n" " coords : vec2<f32>\n"
" offset : vec2<i32>) -> f32", " offset : vec2<i32>) -> f32",
TextureKind::kDepth, TextureKind::kDepth,
ast::type::SamplerKind::kSampler, type::SamplerKind::kSampler,
ast::type::TextureDimension::k2d, type::TextureDimension::k2d,
TextureDataType::kF32, TextureDataType::kF32,
"textureSample", "textureSample",
[](ast::Builder* b) { [](Builder* b) {
using f32 = ast::Builder::f32; using f32 = Builder::f32;
using i32 = ast::Builder::i32; using i32 = Builder::i32;
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
b->vec2<f32>(1.f, 2.f), // coords b->vec2<f32>(1.f, 2.f), // coords
@ -272,12 +272,12 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" coords : vec2<f32>,\n" " coords : vec2<f32>,\n"
" array_index : u32) -> f32", " array_index : u32) -> f32",
TextureKind::kDepth, TextureKind::kDepth,
ast::type::SamplerKind::kSampler, type::SamplerKind::kSampler,
ast::type::TextureDimension::k2dArray, type::TextureDimension::k2dArray,
TextureDataType::kF32, TextureDataType::kF32,
"textureSample", "textureSample",
[](ast::Builder* b) { [](Builder* b) {
using f32 = ast::Builder::f32; using f32 = Builder::f32;
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
b->vec2<f32>(1.f, 2.f), // coords b->vec2<f32>(1.f, 2.f), // coords
@ -292,13 +292,13 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" array_index : u32\n" " array_index : u32\n"
" offset : vec2<i32>) -> f32", " offset : vec2<i32>) -> f32",
TextureKind::kDepth, TextureKind::kDepth,
ast::type::SamplerKind::kSampler, type::SamplerKind::kSampler,
ast::type::TextureDimension::k2dArray, type::TextureDimension::k2dArray,
TextureDataType::kF32, TextureDataType::kF32,
"textureSample", "textureSample",
[](ast::Builder* b) { [](Builder* b) {
using f32 = ast::Builder::f32; using f32 = Builder::f32;
using i32 = ast::Builder::i32; using i32 = Builder::i32;
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
b->vec2<f32>(1.f, 2.f), // coords b->vec2<f32>(1.f, 2.f), // coords
@ -312,12 +312,12 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" s : sampler,\n" " s : sampler,\n"
" coords : vec3<f32>) -> f32", " coords : vec3<f32>) -> f32",
TextureKind::kDepth, TextureKind::kDepth,
ast::type::SamplerKind::kSampler, type::SamplerKind::kSampler,
ast::type::TextureDimension::kCube, type::TextureDimension::kCube,
TextureDataType::kF32, TextureDataType::kF32,
"textureSample", "textureSample",
[](ast::Builder* b) { [](Builder* b) {
using f32 = ast::Builder::f32; using f32 = Builder::f32;
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
b->vec3<f32>(1.f, 2.f, 3.f)); // coords b->vec3<f32>(1.f, 2.f, 3.f)); // coords
@ -330,12 +330,12 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" coords : vec3<f32>,\n" " coords : vec3<f32>,\n"
" array_index : u32) -> f32", " array_index : u32) -> f32",
TextureKind::kDepth, TextureKind::kDepth,
ast::type::SamplerKind::kSampler, type::SamplerKind::kSampler,
ast::type::TextureDimension::kCubeArray, type::TextureDimension::kCubeArray,
TextureDataType::kF32, TextureDataType::kF32,
"textureSample", "textureSample",
[](ast::Builder* b) { [](Builder* b) {
using f32 = ast::Builder::f32; using f32 = Builder::f32;
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
b->vec3<f32>(1.f, 2.f, 3.f), // coords b->vec3<f32>(1.f, 2.f, 3.f), // coords
@ -349,12 +349,12 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" coords : vec2<f32>,\n" " coords : vec2<f32>,\n"
" bias : f32) -> vec4<f32>", " bias : f32) -> vec4<f32>",
TextureKind::kRegular, TextureKind::kRegular,
ast::type::SamplerKind::kSampler, type::SamplerKind::kSampler,
ast::type::TextureDimension::k2d, type::TextureDimension::k2d,
TextureDataType::kF32, TextureDataType::kF32,
"textureSampleBias", "textureSampleBias",
[](ast::Builder* b) { [](Builder* b) {
using f32 = ast::Builder::f32; using f32 = Builder::f32;
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
b->vec2<f32>(1.f, 2.f), // coords b->vec2<f32>(1.f, 2.f), // coords
@ -369,13 +369,13 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" bias : f32,\n" " bias : f32,\n"
" offset : vec2<i32>) -> vec4<f32>", " offset : vec2<i32>) -> vec4<f32>",
TextureKind::kRegular, TextureKind::kRegular,
ast::type::SamplerKind::kSampler, type::SamplerKind::kSampler,
ast::type::TextureDimension::k2d, type::TextureDimension::k2d,
TextureDataType::kF32, TextureDataType::kF32,
"textureSampleBias", "textureSampleBias",
[](ast::Builder* b) { [](Builder* b) {
using f32 = ast::Builder::f32; using f32 = Builder::f32;
using i32 = ast::Builder::i32; using i32 = Builder::i32;
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
b->vec2<f32>(1.f, 2.f), // coords b->vec2<f32>(1.f, 2.f), // coords
@ -391,12 +391,12 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" array_index : u32,\n" " array_index : u32,\n"
" bias : f32) -> vec4<f32>", " bias : f32) -> vec4<f32>",
TextureKind::kRegular, TextureKind::kRegular,
ast::type::SamplerKind::kSampler, type::SamplerKind::kSampler,
ast::type::TextureDimension::k2dArray, type::TextureDimension::k2dArray,
TextureDataType::kF32, TextureDataType::kF32,
"textureSampleBias", "textureSampleBias",
[](ast::Builder* b) { [](Builder* b) {
using f32 = ast::Builder::f32; using f32 = Builder::f32;
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
b->vec2<f32>(1.f, 2.f), // coords b->vec2<f32>(1.f, 2.f), // coords
@ -413,13 +413,13 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" bias : f32,\n" " bias : f32,\n"
" offset : vec2<i32>) -> vec4<f32>", " offset : vec2<i32>) -> vec4<f32>",
TextureKind::kRegular, TextureKind::kRegular,
ast::type::SamplerKind::kSampler, type::SamplerKind::kSampler,
ast::type::TextureDimension::k2dArray, type::TextureDimension::k2dArray,
TextureDataType::kF32, TextureDataType::kF32,
"textureSampleBias", "textureSampleBias",
[](ast::Builder* b) { [](Builder* b) {
using f32 = ast::Builder::f32; using f32 = Builder::f32;
using i32 = ast::Builder::i32; using i32 = Builder::i32;
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
b->vec2<f32>(1.f, 2.f), // coords b->vec2<f32>(1.f, 2.f), // coords
@ -435,12 +435,12 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" coords : vec3<f32>,\n" " coords : vec3<f32>,\n"
" bias : f32) -> vec4<f32>", " bias : f32) -> vec4<f32>",
TextureKind::kRegular, TextureKind::kRegular,
ast::type::SamplerKind::kSampler, type::SamplerKind::kSampler,
ast::type::TextureDimension::k3d, type::TextureDimension::k3d,
TextureDataType::kF32, TextureDataType::kF32,
"textureSampleBias", "textureSampleBias",
[](ast::Builder* b) { [](Builder* b) {
using f32 = ast::Builder::f32; using f32 = Builder::f32;
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
b->vec3<f32>(1.f, 2.f, 3.f), // coords b->vec3<f32>(1.f, 2.f, 3.f), // coords
@ -455,13 +455,13 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" bias : f32,\n" " bias : f32,\n"
" offset : vec3<i32>) -> vec4<f32>", " offset : vec3<i32>) -> vec4<f32>",
TextureKind::kRegular, TextureKind::kRegular,
ast::type::SamplerKind::kSampler, type::SamplerKind::kSampler,
ast::type::TextureDimension::k3d, type::TextureDimension::k3d,
TextureDataType::kF32, TextureDataType::kF32,
"textureSampleBias", "textureSampleBias",
[](ast::Builder* b) { [](Builder* b) {
using f32 = ast::Builder::f32; using f32 = Builder::f32;
using i32 = ast::Builder::i32; using i32 = Builder::i32;
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
b->vec3<f32>(1.f, 2.f, 3.f), // coords b->vec3<f32>(1.f, 2.f, 3.f), // coords
@ -476,12 +476,12 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" coords : vec3<f32>,\n" " coords : vec3<f32>,\n"
" bias : f32) -> vec4<f32>", " bias : f32) -> vec4<f32>",
TextureKind::kRegular, TextureKind::kRegular,
ast::type::SamplerKind::kSampler, type::SamplerKind::kSampler,
ast::type::TextureDimension::kCube, type::TextureDimension::kCube,
TextureDataType::kF32, TextureDataType::kF32,
"textureSampleBias", "textureSampleBias",
[](ast::Builder* b) { [](Builder* b) {
using f32 = ast::Builder::f32; using f32 = Builder::f32;
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
b->vec3<f32>(1.f, 2.f, 3.f), // coords b->vec3<f32>(1.f, 2.f, 3.f), // coords
@ -496,12 +496,12 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" array_index : u32,\n" " array_index : u32,\n"
" bias : f32) -> vec4<f32>", " bias : f32) -> vec4<f32>",
TextureKind::kRegular, TextureKind::kRegular,
ast::type::SamplerKind::kSampler, type::SamplerKind::kSampler,
ast::type::TextureDimension::kCubeArray, type::TextureDimension::kCubeArray,
TextureDataType::kF32, TextureDataType::kF32,
"textureSampleBias", "textureSampleBias",
[](ast::Builder* b) { [](Builder* b) {
using f32 = ast::Builder::f32; using f32 = Builder::f32;
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
b->vec3<f32>(1.f, 2.f, 3.f), // coords b->vec3<f32>(1.f, 2.f, 3.f), // coords
@ -516,12 +516,12 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" coords : vec2<f32>,\n" " coords : vec2<f32>,\n"
" level : f32) -> vec4<f32>", " level : f32) -> vec4<f32>",
TextureKind::kRegular, TextureKind::kRegular,
ast::type::SamplerKind::kSampler, type::SamplerKind::kSampler,
ast::type::TextureDimension::k2d, type::TextureDimension::k2d,
TextureDataType::kF32, TextureDataType::kF32,
"textureSampleLevel", "textureSampleLevel",
[](ast::Builder* b) { [](Builder* b) {
using f32 = ast::Builder::f32; using f32 = Builder::f32;
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
b->vec2<f32>(1.f, 2.f), // coords b->vec2<f32>(1.f, 2.f), // coords
@ -536,13 +536,13 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" level : f32,\n" " level : f32,\n"
" offset : vec2<i32>) -> vec4<f32>", " offset : vec2<i32>) -> vec4<f32>",
TextureKind::kRegular, TextureKind::kRegular,
ast::type::SamplerKind::kSampler, type::SamplerKind::kSampler,
ast::type::TextureDimension::k2d, type::TextureDimension::k2d,
TextureDataType::kF32, TextureDataType::kF32,
"textureSampleLevel", "textureSampleLevel",
[](ast::Builder* b) { [](Builder* b) {
using f32 = ast::Builder::f32; using f32 = Builder::f32;
using i32 = ast::Builder::i32; using i32 = Builder::i32;
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
b->vec2<f32>(1.f, 2.f), // coords b->vec2<f32>(1.f, 2.f), // coords
@ -558,12 +558,12 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" array_index : u32,\n" " array_index : u32,\n"
" level : f32) -> vec4<f32>", " level : f32) -> vec4<f32>",
TextureKind::kRegular, TextureKind::kRegular,
ast::type::SamplerKind::kSampler, type::SamplerKind::kSampler,
ast::type::TextureDimension::k2dArray, type::TextureDimension::k2dArray,
TextureDataType::kF32, TextureDataType::kF32,
"textureSampleLevel", "textureSampleLevel",
[](ast::Builder* b) { [](Builder* b) {
using f32 = ast::Builder::f32; using f32 = Builder::f32;
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
b->vec2<f32>(1.f, 2.f), // coords b->vec2<f32>(1.f, 2.f), // coords
@ -580,13 +580,13 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" level : f32,\n" " level : f32,\n"
" offset : vec2<i32>) -> vec4<f32>", " offset : vec2<i32>) -> vec4<f32>",
TextureKind::kRegular, TextureKind::kRegular,
ast::type::SamplerKind::kSampler, type::SamplerKind::kSampler,
ast::type::TextureDimension::k2dArray, type::TextureDimension::k2dArray,
TextureDataType::kF32, TextureDataType::kF32,
"textureSampleLevel", "textureSampleLevel",
[](ast::Builder* b) { [](Builder* b) {
using f32 = ast::Builder::f32; using f32 = Builder::f32;
using i32 = ast::Builder::i32; using i32 = Builder::i32;
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
b->vec2<f32>(1.f, 2.f), // coords b->vec2<f32>(1.f, 2.f), // coords
@ -602,12 +602,12 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" coords : vec3<f32>,\n" " coords : vec3<f32>,\n"
" level : f32) -> vec4<f32>", " level : f32) -> vec4<f32>",
TextureKind::kRegular, TextureKind::kRegular,
ast::type::SamplerKind::kSampler, type::SamplerKind::kSampler,
ast::type::TextureDimension::k3d, type::TextureDimension::k3d,
TextureDataType::kF32, TextureDataType::kF32,
"textureSampleLevel", "textureSampleLevel",
[](ast::Builder* b) { [](Builder* b) {
using f32 = ast::Builder::f32; using f32 = Builder::f32;
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
b->vec3<f32>(1.f, 2.f, 3.f), // coords b->vec3<f32>(1.f, 2.f, 3.f), // coords
@ -622,13 +622,13 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" level : f32,\n" " level : f32,\n"
" offset : vec3<i32>) -> vec4<f32>", " offset : vec3<i32>) -> vec4<f32>",
TextureKind::kRegular, TextureKind::kRegular,
ast::type::SamplerKind::kSampler, type::SamplerKind::kSampler,
ast::type::TextureDimension::k3d, type::TextureDimension::k3d,
TextureDataType::kF32, TextureDataType::kF32,
"textureSampleLevel", "textureSampleLevel",
[](ast::Builder* b) { [](Builder* b) {
using f32 = ast::Builder::f32; using f32 = Builder::f32;
using i32 = ast::Builder::i32; using i32 = Builder::i32;
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
b->vec3<f32>(1.f, 2.f, 3.f), // coords b->vec3<f32>(1.f, 2.f, 3.f), // coords
@ -643,12 +643,12 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" coords : vec3<f32>,\n" " coords : vec3<f32>,\n"
" level : f32) -> vec4<f32>", " level : f32) -> vec4<f32>",
TextureKind::kRegular, TextureKind::kRegular,
ast::type::SamplerKind::kSampler, type::SamplerKind::kSampler,
ast::type::TextureDimension::kCube, type::TextureDimension::kCube,
TextureDataType::kF32, TextureDataType::kF32,
"textureSampleLevel", "textureSampleLevel",
[](ast::Builder* b) { [](Builder* b) {
using f32 = ast::Builder::f32; using f32 = Builder::f32;
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
b->vec3<f32>(1.f, 2.f, 3.f), // coords b->vec3<f32>(1.f, 2.f, 3.f), // coords
@ -663,12 +663,12 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" array_index : u32,\n" " array_index : u32,\n"
" level : f32) -> vec4<f32>", " level : f32) -> vec4<f32>",
TextureKind::kRegular, TextureKind::kRegular,
ast::type::SamplerKind::kSampler, type::SamplerKind::kSampler,
ast::type::TextureDimension::kCubeArray, type::TextureDimension::kCubeArray,
TextureDataType::kF32, TextureDataType::kF32,
"textureSampleLevel", "textureSampleLevel",
[](ast::Builder* b) { [](Builder* b) {
using f32 = ast::Builder::f32; using f32 = Builder::f32;
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
b->vec3<f32>(1.f, 2.f, 3.f), // coords b->vec3<f32>(1.f, 2.f, 3.f), // coords
@ -683,12 +683,12 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" coords : vec2<f32>,\n" " coords : vec2<f32>,\n"
" level : u32) -> f32", " level : u32) -> f32",
TextureKind::kDepth, TextureKind::kDepth,
ast::type::SamplerKind::kSampler, type::SamplerKind::kSampler,
ast::type::TextureDimension::k2d, type::TextureDimension::k2d,
TextureDataType::kF32, TextureDataType::kF32,
"textureSampleLevel", "textureSampleLevel",
[](ast::Builder* b) { [](Builder* b) {
using f32 = ast::Builder::f32; using f32 = Builder::f32;
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
b->vec2<f32>(1.f, 2.f), // coords b->vec2<f32>(1.f, 2.f), // coords
@ -703,13 +703,13 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" level : u32,\n" " level : u32,\n"
" offset : vec2<i32>) -> f32", " offset : vec2<i32>) -> f32",
TextureKind::kDepth, TextureKind::kDepth,
ast::type::SamplerKind::kSampler, type::SamplerKind::kSampler,
ast::type::TextureDimension::k2d, type::TextureDimension::k2d,
TextureDataType::kF32, TextureDataType::kF32,
"textureSampleLevel", "textureSampleLevel",
[](ast::Builder* b) { [](Builder* b) {
using f32 = ast::Builder::f32; using f32 = Builder::f32;
using i32 = ast::Builder::i32; using i32 = Builder::i32;
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
b->vec2<f32>(1.f, 2.f), // coords b->vec2<f32>(1.f, 2.f), // coords
@ -725,12 +725,12 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" array_index : u32,\n" " array_index : u32,\n"
" level : u32) -> f32", " level : u32) -> f32",
TextureKind::kDepth, TextureKind::kDepth,
ast::type::SamplerKind::kSampler, type::SamplerKind::kSampler,
ast::type::TextureDimension::k2dArray, type::TextureDimension::k2dArray,
TextureDataType::kF32, TextureDataType::kF32,
"textureSampleLevel", "textureSampleLevel",
[](ast::Builder* b) { [](Builder* b) {
using f32 = ast::Builder::f32; using f32 = Builder::f32;
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
b->vec2<f32>(1.f, 2.f), // coords b->vec2<f32>(1.f, 2.f), // coords
@ -747,13 +747,13 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" level : u32,\n" " level : u32,\n"
" offset : vec2<i32>) -> f32", " offset : vec2<i32>) -> f32",
TextureKind::kDepth, TextureKind::kDepth,
ast::type::SamplerKind::kSampler, type::SamplerKind::kSampler,
ast::type::TextureDimension::k2dArray, type::TextureDimension::k2dArray,
TextureDataType::kF32, TextureDataType::kF32,
"textureSampleLevel", "textureSampleLevel",
[](ast::Builder* b) { [](Builder* b) {
using f32 = ast::Builder::f32; using f32 = Builder::f32;
using i32 = ast::Builder::i32; using i32 = Builder::i32;
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
b->vec2<f32>(1.f, 2.f), // coords b->vec2<f32>(1.f, 2.f), // coords
@ -769,12 +769,12 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" coords : vec3<f32>,\n" " coords : vec3<f32>,\n"
" level : u32) -> f32", " level : u32) -> f32",
TextureKind::kDepth, TextureKind::kDepth,
ast::type::SamplerKind::kSampler, type::SamplerKind::kSampler,
ast::type::TextureDimension::kCube, type::TextureDimension::kCube,
TextureDataType::kF32, TextureDataType::kF32,
"textureSampleLevel", "textureSampleLevel",
[](ast::Builder* b) { [](Builder* b) {
using f32 = ast::Builder::f32; using f32 = Builder::f32;
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
b->vec3<f32>(1.f, 2.f, 3.f), // coords b->vec3<f32>(1.f, 2.f, 3.f), // coords
@ -789,12 +789,12 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" array_index : u32,\n" " array_index : u32,\n"
" level : u32) -> f32", " level : u32) -> f32",
TextureKind::kDepth, TextureKind::kDepth,
ast::type::SamplerKind::kSampler, type::SamplerKind::kSampler,
ast::type::TextureDimension::kCubeArray, type::TextureDimension::kCubeArray,
TextureDataType::kF32, TextureDataType::kF32,
"textureSampleLevel", "textureSampleLevel",
[](ast::Builder* b) { [](Builder* b) {
using f32 = ast::Builder::f32; using f32 = Builder::f32;
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
b->vec3<f32>(1.f, 2.f, 3.f), // coords b->vec3<f32>(1.f, 2.f, 3.f), // coords
@ -810,12 +810,12 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" ddx : vec2<f32>,\n" " ddx : vec2<f32>,\n"
" ddy : vec2<f32>) -> vec4<f32>", " ddy : vec2<f32>) -> vec4<f32>",
TextureKind::kRegular, TextureKind::kRegular,
ast::type::SamplerKind::kSampler, type::SamplerKind::kSampler,
ast::type::TextureDimension::k2d, type::TextureDimension::k2d,
TextureDataType::kF32, TextureDataType::kF32,
"textureSampleGrad", "textureSampleGrad",
[](ast::Builder* b) { [](Builder* b) {
using f32 = ast::Builder::f32; using f32 = Builder::f32;
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
b->vec2<f32>(1.0f, 2.0f), // coords b->vec2<f32>(1.0f, 2.0f), // coords
@ -832,13 +832,13 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" ddy : vec2<f32>,\n" " ddy : vec2<f32>,\n"
" offset : vec2<i32>) -> vec4<f32>", " offset : vec2<i32>) -> vec4<f32>",
TextureKind::kRegular, TextureKind::kRegular,
ast::type::SamplerKind::kSampler, type::SamplerKind::kSampler,
ast::type::TextureDimension::k2d, type::TextureDimension::k2d,
TextureDataType::kF32, TextureDataType::kF32,
"textureSampleGrad", "textureSampleGrad",
[](ast::Builder* b) { [](Builder* b) {
using f32 = ast::Builder::f32; using f32 = Builder::f32;
using i32 = ast::Builder::i32; using i32 = Builder::i32;
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
b->vec2<f32>(1.f, 2.f), // coords b->vec2<f32>(1.f, 2.f), // coords
@ -856,12 +856,12 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" ddx : vec2<f32>,\n" " ddx : vec2<f32>,\n"
" ddy : vec2<f32>) -> vec4<f32>", " ddy : vec2<f32>) -> vec4<f32>",
TextureKind::kRegular, TextureKind::kRegular,
ast::type::SamplerKind::kSampler, type::SamplerKind::kSampler,
ast::type::TextureDimension::k2dArray, type::TextureDimension::k2dArray,
TextureDataType::kF32, TextureDataType::kF32,
"textureSampleGrad", "textureSampleGrad",
[](ast::Builder* b) { [](Builder* b) {
using f32 = ast::Builder::f32; using f32 = Builder::f32;
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
b->vec2<f32>(1.f, 2.f), // coords b->vec2<f32>(1.f, 2.f), // coords
@ -880,13 +880,13 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" ddy : vec2<f32>,\n" " ddy : vec2<f32>,\n"
" offset : vec2<i32>) -> vec4<f32>", " offset : vec2<i32>) -> vec4<f32>",
TextureKind::kRegular, TextureKind::kRegular,
ast::type::SamplerKind::kSampler, type::SamplerKind::kSampler,
ast::type::TextureDimension::k2dArray, type::TextureDimension::k2dArray,
TextureDataType::kF32, TextureDataType::kF32,
"textureSampleGrad", "textureSampleGrad",
[](ast::Builder* b) { [](Builder* b) {
using f32 = ast::Builder::f32; using f32 = Builder::f32;
using i32 = ast::Builder::i32; using i32 = Builder::i32;
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
b->vec2<f32>(1.f, 2.f), // coords b->vec2<f32>(1.f, 2.f), // coords
@ -904,12 +904,12 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" ddx : vec3<f32>,\n" " ddx : vec3<f32>,\n"
" ddy : vec3<f32>) -> vec4<f32>", " ddy : vec3<f32>) -> vec4<f32>",
TextureKind::kRegular, TextureKind::kRegular,
ast::type::SamplerKind::kSampler, type::SamplerKind::kSampler,
ast::type::TextureDimension::k3d, type::TextureDimension::k3d,
TextureDataType::kF32, TextureDataType::kF32,
"textureSampleGrad", "textureSampleGrad",
[](ast::Builder* b) { [](Builder* b) {
using f32 = ast::Builder::f32; using f32 = Builder::f32;
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
b->vec3<f32>(1.f, 2.f, 3.f), // coords b->vec3<f32>(1.f, 2.f, 3.f), // coords
@ -926,13 +926,13 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" ddy : vec3<f32>,\n" " ddy : vec3<f32>,\n"
" offset : vec3<i32>) -> vec4<f32>", " offset : vec3<i32>) -> vec4<f32>",
TextureKind::kRegular, TextureKind::kRegular,
ast::type::SamplerKind::kSampler, type::SamplerKind::kSampler,
ast::type::TextureDimension::k3d, type::TextureDimension::k3d,
TextureDataType::kF32, TextureDataType::kF32,
"textureSampleGrad", "textureSampleGrad",
[](ast::Builder* b) { [](Builder* b) {
using f32 = ast::Builder::f32; using f32 = Builder::f32;
using i32 = ast::Builder::i32; using i32 = Builder::i32;
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
b->vec3<f32>(1.f, 2.f, 3.f), // coords b->vec3<f32>(1.f, 2.f, 3.f), // coords
@ -949,12 +949,12 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" ddx : vec3<f32>,\n" " ddx : vec3<f32>,\n"
" ddy : vec3<f32>) -> vec4<f32>", " ddy : vec3<f32>) -> vec4<f32>",
TextureKind::kRegular, TextureKind::kRegular,
ast::type::SamplerKind::kSampler, type::SamplerKind::kSampler,
ast::type::TextureDimension::kCube, type::TextureDimension::kCube,
TextureDataType::kF32, TextureDataType::kF32,
"textureSampleGrad", "textureSampleGrad",
[](ast::Builder* b) { [](Builder* b) {
using f32 = ast::Builder::f32; using f32 = Builder::f32;
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
b->vec3<f32>(1.f, 2.f, 3.f), // coords b->vec3<f32>(1.f, 2.f, 3.f), // coords
@ -971,12 +971,12 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" ddx : vec3<f32>,\n" " ddx : vec3<f32>,\n"
" ddy : vec3<f32>) -> vec4<f32>", " ddy : vec3<f32>) -> vec4<f32>",
TextureKind::kRegular, TextureKind::kRegular,
ast::type::SamplerKind::kSampler, type::SamplerKind::kSampler,
ast::type::TextureDimension::kCubeArray, type::TextureDimension::kCubeArray,
TextureDataType::kF32, TextureDataType::kF32,
"textureSampleGrad", "textureSampleGrad",
[](ast::Builder* b) { [](Builder* b) {
using f32 = ast::Builder::f32; using f32 = Builder::f32;
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
b->vec3<f32>(1.f, 2.f, 3.f), // coords b->vec3<f32>(1.f, 2.f, 3.f), // coords
@ -992,12 +992,12 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" coords : vec2<f32>,\n" " coords : vec2<f32>,\n"
" depth_ref : f32) -> f32", " depth_ref : f32) -> f32",
TextureKind::kDepth, TextureKind::kDepth,
ast::type::SamplerKind::kComparisonSampler, type::SamplerKind::kComparisonSampler,
ast::type::TextureDimension::k2d, type::TextureDimension::k2d,
TextureDataType::kF32, TextureDataType::kF32,
"textureSampleCompare", "textureSampleCompare",
[](ast::Builder* b) { [](Builder* b) {
using f32 = ast::Builder::f32; using f32 = Builder::f32;
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
b->vec2<f32>(1.f, 2.f), // coords b->vec2<f32>(1.f, 2.f), // coords
@ -1012,13 +1012,13 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" depth_ref : f32,\n" " depth_ref : f32,\n"
" offset : vec2<i32>) -> f32", " offset : vec2<i32>) -> f32",
TextureKind::kDepth, TextureKind::kDepth,
ast::type::SamplerKind::kComparisonSampler, type::SamplerKind::kComparisonSampler,
ast::type::TextureDimension::k2d, type::TextureDimension::k2d,
TextureDataType::kF32, TextureDataType::kF32,
"textureSampleCompare", "textureSampleCompare",
[](ast::Builder* b) { [](Builder* b) {
using f32 = ast::Builder::f32; using f32 = Builder::f32;
using i32 = ast::Builder::i32; using i32 = Builder::i32;
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
b->vec2<f32>(1.f, 2.f), // coords b->vec2<f32>(1.f, 2.f), // coords
@ -1034,12 +1034,12 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" array_index : u32,\n" " array_index : u32,\n"
" depth_ref : f32) -> f32", " depth_ref : f32) -> f32",
TextureKind::kDepth, TextureKind::kDepth,
ast::type::SamplerKind::kComparisonSampler, type::SamplerKind::kComparisonSampler,
ast::type::TextureDimension::k2dArray, type::TextureDimension::k2dArray,
TextureDataType::kF32, TextureDataType::kF32,
"textureSampleCompare", "textureSampleCompare",
[](ast::Builder* b) { [](Builder* b) {
using f32 = ast::Builder::f32; using f32 = Builder::f32;
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
b->vec2<f32>(1.f, 2.f), // coords b->vec2<f32>(1.f, 2.f), // coords
@ -1056,13 +1056,13 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" depth_ref : f32,\n" " depth_ref : f32,\n"
" offset : vec2<i32>) -> f32", " offset : vec2<i32>) -> f32",
TextureKind::kDepth, TextureKind::kDepth,
ast::type::SamplerKind::kComparisonSampler, type::SamplerKind::kComparisonSampler,
ast::type::TextureDimension::k2dArray, type::TextureDimension::k2dArray,
TextureDataType::kF32, TextureDataType::kF32,
"textureSampleCompare", "textureSampleCompare",
[](ast::Builder* b) { [](Builder* b) {
using f32 = ast::Builder::f32; using f32 = Builder::f32;
using i32 = ast::Builder::i32; using i32 = Builder::i32;
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
b->vec2<f32>(1.f, 2.f), // coords b->vec2<f32>(1.f, 2.f), // coords
@ -1078,12 +1078,12 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" coords : vec3<f32>,\n" " coords : vec3<f32>,\n"
" depth_ref : f32) -> f32", " depth_ref : f32) -> f32",
TextureKind::kDepth, TextureKind::kDepth,
ast::type::SamplerKind::kComparisonSampler, type::SamplerKind::kComparisonSampler,
ast::type::TextureDimension::kCube, type::TextureDimension::kCube,
TextureDataType::kF32, TextureDataType::kF32,
"textureSampleCompare", "textureSampleCompare",
[](ast::Builder* b) { [](Builder* b) {
using f32 = ast::Builder::f32; using f32 = Builder::f32;
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
b->vec3<f32>(1.f, 2.f, 3.f), // coords b->vec3<f32>(1.f, 2.f, 3.f), // coords
@ -1098,12 +1098,12 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" array_index : u32,\n" " array_index : u32,\n"
" depth_ref : f32) -> f32", " depth_ref : f32) -> f32",
TextureKind::kDepth, TextureKind::kDepth,
ast::type::SamplerKind::kComparisonSampler, type::SamplerKind::kComparisonSampler,
ast::type::TextureDimension::kCubeArray, type::TextureDimension::kCubeArray,
TextureDataType::kF32, TextureDataType::kF32,
"textureSampleCompare", "textureSampleCompare",
[](ast::Builder* b) { [](Builder* b) {
using f32 = ast::Builder::f32; using f32 = Builder::f32;
return b->ExprList("texture", // t return b->ExprList("texture", // t
"sampler", // s "sampler", // s
b->vec3<f32>(1.f, 2.f, 3.f), // coords b->vec3<f32>(1.f, 2.f, 3.f), // coords

View File

@ -121,11 +121,11 @@ struct TextureOverloadCase {
TextureOverloadCase(ValidTextureOverload, TextureOverloadCase(ValidTextureOverload,
const char*, const char*,
TextureKind, TextureKind,
ast::type::SamplerKind, type::SamplerKind,
ast::type::TextureDimension, type::TextureDimension,
TextureDataType, TextureDataType,
const char*, const char*,
std::function<ast::ExpressionList(ast::Builder*)>); std::function<ExpressionList(Builder*)>);
/// Copy constructor /// Copy constructor
TextureOverloadCase(const TextureOverloadCase&); TextureOverloadCase(const TextureOverloadCase&);
/// Destructor /// Destructor
@ -141,15 +141,15 @@ struct TextureOverloadCase {
/// The texture kind for the texture parameter /// The texture kind for the texture parameter
TextureKind texture_kind; TextureKind texture_kind;
/// The sampler kind for the sampler parameter /// The sampler kind for the sampler parameter
ast::type::SamplerKind sampler_kind; type::SamplerKind sampler_kind;
/// The dimensions of the texture parameter /// The dimensions of the texture parameter
ast::type::TextureDimension texture_dimension; type::TextureDimension texture_dimension;
/// The data type of the texture parameter /// The data type of the texture parameter
TextureDataType texture_data_type; TextureDataType texture_data_type;
/// Name of the function. e.g. `textureSample`, `textureSampleGrad`, etc /// Name of the function. e.g. `textureSample`, `textureSampleGrad`, etc
const char* function; const char* function;
/// A function that builds the AST arguments for the overload /// A function that builds the AST arguments for the overload
std::function<ast::ExpressionList(ast::Builder*)> args; std::function<ExpressionList(Builder*)> args;
}; };
inline std::ostream& operator<<(std::ostream& out, inline std::ostream& operator<<(std::ostream& out,

View File

@ -17,7 +17,7 @@
namespace tint { namespace tint {
namespace ast { namespace ast {
Literal::Literal(ast::type::Type* type) : type_(type) {} Literal::Literal(type::Type* type) : type_(type) {}
Literal::~Literal() = default; Literal::~Literal() = default;

View File

@ -29,7 +29,7 @@ class Literal : public Castable<Literal, Node> {
~Literal() override; ~Literal() override;
/// @returns the type of the literal /// @returns the type of the literal
ast::type::Type* type() const { return type_; } type::Type* type() const { return type_; }
/// @returns true if the node is valid /// @returns true if the node is valid
bool IsValid() const override; bool IsValid() const override;
@ -48,10 +48,10 @@ class Literal : public Castable<Literal, Node> {
protected: protected:
/// Constructor /// Constructor
/// @param type the type of the literal /// @param type the type of the literal
explicit Literal(ast::type::Type* type); explicit Literal(type::Type* type);
private: private:
ast::type::Type* type_ = nullptr; type::Type* type_ = nullptr;
}; };
} // namespace ast } // namespace ast

View File

@ -46,7 +46,7 @@ TEST_F(MemberAccessorExpressionTest, Creation_WithSource) {
TEST_F(MemberAccessorExpressionTest, IsMemberAccessor) { TEST_F(MemberAccessorExpressionTest, IsMemberAccessor) {
MemberAccessorExpression stmt; MemberAccessorExpression stmt;
EXPECT_TRUE(stmt.Is<ast::MemberAccessorExpression>()); EXPECT_TRUE(stmt.Is<MemberAccessorExpression>());
} }
TEST_F(MemberAccessorExpressionTest, IsValid) { TEST_F(MemberAccessorExpressionTest, IsValid) {

View File

@ -37,7 +37,7 @@ Function* Module::FindFunctionByName(const std::string& name) const {
} }
Function* Module::FindFunctionByNameAndStage(const std::string& name, Function* Module::FindFunctionByNameAndStage(const std::string& name,
ast::PipelineStage stage) const { PipelineStage stage) const {
for (auto* func : functions_) { for (auto* func : functions_) {
if (func->name() == name && func->pipeline_stage() == stage) { if (func->name() == name && func->pipeline_stage() == stage) {
return func; return func;
@ -56,17 +56,17 @@ bool Module::IsValid() const {
if (ty == nullptr) { if (ty == nullptr) {
return false; return false;
} }
if (ty->Is<ast::type::AliasType>()) { if (ty->Is<type::AliasType>()) {
auto* alias = ty->As<ast::type::AliasType>(); auto* alias = ty->As<type::AliasType>();
if (alias->type() == nullptr) { if (alias->type() == nullptr) {
return false; return false;
} }
if (alias->type()->Is<ast::type::StructType>() && if (alias->type()->Is<type::StructType>() &&
alias->type()->As<ast::type::StructType>()->name().empty()) { alias->type()->As<type::StructType>()->name().empty()) {
return false; return false;
} }
} else if (ty->Is<ast::type::StructType>()) { } else if (ty->Is<type::StructType>()) {
auto* str = ty->As<ast::type::StructType>(); auto* str = ty->As<type::StructType>();
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<ast::type::AliasType>()) { if (ty->Is<type::AliasType>()) {
auto* alias = ty->As<ast::type::AliasType>(); auto* alias = ty->As<type::AliasType>();
out << alias->name() << " -> " << alias->type()->type_name() << std::endl; out << alias->name() << " -> " << alias->type()->type_name() << std::endl;
if (alias->type()->Is<ast::type::StructType>()) { if (alias->type()->Is<type::StructType>()) {
alias->type()->As<ast::type::StructType>()->impl()->to_str(out, indent); alias->type()->As<type::StructType>()->impl()->to_str(out, indent);
} }
} else if (ty->Is<ast::type::StructType>()) { } else if (ty->Is<type::StructType>()) {
auto* str = ty->As<ast::type::StructType>(); auto* str = ty->As<type::StructType>();
out << str->name() << " "; out << str->name() << " ";
str->impl()->to_str(out, indent); str->impl()->to_str(out, indent);
} }

View File

@ -76,7 +76,7 @@ class Module {
/// @param stage the pipeline stage /// @param stage the pipeline stage
/// @returns the associated function or nullptr if none exists /// @returns the associated function or nullptr if none exists
Function* FindFunctionByNameAndStage(const std::string& name, Function* FindFunctionByNameAndStage(const std::string& name,
ast::PipelineStage stage) const; PipelineStage stage) const;
/// @returns true if all required fields in the AST are present. /// @returns true if all required fields in the AST are present.
bool IsValid() const; bool IsValid() const;
@ -84,23 +84,23 @@ class Module {
/// @returns a string representation of the module /// @returns a string representation of the module
std::string to_str() const; std::string to_str() const;
/// Creates a new `ast::Node` owned by the Module. When the Module is /// Creates a new `Node` owned by the Module. When the Module is
/// destructed, the `ast::Node` will also be destructed. /// destructed, the `Node` will also be destructed.
/// @param args the arguments to pass to the type constructor /// @param args the arguments to pass to the type constructor
/// @returns the node pointer /// @returns the node pointer
template <typename T, typename... ARGS> template <typename T, typename... ARGS>
EnableIfIsType<T, ast::Node>* create(ARGS&&... args) { EnableIfIsType<T, Node>* create(ARGS&&... args) {
static_assert(std::is_base_of<ast::Node, T>::value, static_assert(std::is_base_of<Node, T>::value,
"T does not derive from ast::Node"); "T does not derive from Node");
auto uptr = std::make_unique<T>(std::forward<ARGS>(args)...); auto uptr = std::make_unique<T>(std::forward<ARGS>(args)...);
auto ptr = uptr.get(); auto ptr = uptr.get();
ast_nodes_.emplace_back(std::move(uptr)); ast_nodes_.emplace_back(std::move(uptr));
return ptr; return ptr;
} }
/// Creates a new `ast::Type` owned by the Module. /// Creates a new `Type` owned by the Module.
/// When the Module is destructed, owned Module and the returned /// When the Module is destructed, owned Module and the returned
/// `ast::Type` will also be destructed. /// `Type` will also be destructed.
/// Types are unique (de-aliased), and so calling create() for the same `T` /// Types are unique (de-aliased), and so calling create() for the same `T`
/// and arguments will return the same pointer. /// and arguments will return the same pointer.
/// @warning Use this method to acquire a type only if all of its type /// @warning Use this method to acquire a type only if all of its type
@ -111,28 +111,27 @@ class Module {
/// @param args the arguments to pass to the type constructor /// @param args the arguments to pass to the type constructor
/// @returns the de-aliased type pointer /// @returns the de-aliased type pointer
template <typename T, typename... ARGS> template <typename T, typename... ARGS>
EnableIfIsType<T, ast::type::Type>* create(ARGS&&... args) { EnableIfIsType<T, type::Type>* create(ARGS&&... args) {
static_assert(std::is_base_of<ast::type::Type, T>::value, static_assert(std::is_base_of<type::Type, T>::value,
"T does not derive from ast::type::Type"); "T does not derive from type::Type");
return type_mgr_.Get<T>(std::forward<ARGS>(args)...); return type_mgr_.Get<T>(std::forward<ARGS>(args)...);
} }
/// Moves the type `ty` to the Module, returning a pointer to the unique /// Moves the type `ty` to the Module, returning a pointer to the unique
/// (de-aliased) type. /// (de-aliased) type.
/// When the Module is destructed, the returned `ast::Type` will also be /// When the Module is destructed, the returned `Type` will also be
/// destructed. /// destructed.
/// @see create() /// @see create()
/// @param ty the type to add to the module /// @param ty the type to add to the module
/// @returns the de-aliased type pointer /// @returns the de-aliased type pointer
template <typename T> template <typename T>
EnableIfIsType<T, ast::type::Type>* unique_type(std::unique_ptr<T> ty) { EnableIfIsType<T, type::Type>* unique_type(std::unique_ptr<T> ty) {
return static_cast<T*>(type_mgr_.Get(std::move(ty))); return static_cast<T*>(type_mgr_.Get(std::move(ty)));
} }
/// Returns all the declared types in the module /// Returns all the declared types in the module
/// @returns the mapping from name string to type. /// @returns the mapping from name string to type.
const std::unordered_map<std::string, std::unique_ptr<ast::type::Type>>& const std::unordered_map<std::string, std::unique_ptr<type::Type>>& types() {
types() {
return type_mgr_.types(); return type_mgr_.types();
} }
@ -143,8 +142,8 @@ class Module {
// The constructed types are owned by the type manager // The constructed types are owned by the type manager
std::vector<type::Type*> constructed_types_; std::vector<type::Type*> constructed_types_;
FunctionList functions_; FunctionList functions_;
std::vector<std::unique_ptr<ast::Node>> ast_nodes_; std::vector<std::unique_ptr<Node>> ast_nodes_;
ast::TypeManager type_mgr_; TypeManager type_mgr_;
}; };
} // namespace ast } // namespace ast

View File

@ -48,8 +48,8 @@ TEST_F(ModuleTest, LookupFunction) {
type::F32Type f32; type::F32Type f32;
Module m; Module m;
auto* func = create<Function>("main", VariableList{}, &f32, auto* func =
create<ast::BlockStatement>()); create<Function>("main", VariableList{}, &f32, create<BlockStatement>());
m.AddFunction(func); m.AddFunction(func);
EXPECT_EQ(func, m.FindFunctionByName("main")); EXPECT_EQ(func, m.FindFunctionByName("main"));
} }
@ -124,8 +124,8 @@ TEST_F(ModuleTest, IsValid_Struct_EmptyName) {
TEST_F(ModuleTest, IsValid_Function) { TEST_F(ModuleTest, IsValid_Function) {
type::F32Type f32; type::F32Type f32;
auto* func = create<Function>("main", VariableList(), &f32, auto* func =
create<ast::BlockStatement>()); create<Function>("main", VariableList(), &f32, create<BlockStatement>());
Module m; Module m;
m.AddFunction(func); m.AddFunction(func);

View File

@ -17,7 +17,7 @@
namespace tint { namespace tint {
namespace ast { namespace ast {
NullLiteral::NullLiteral(ast::type::Type* type) : Base(type) {} NullLiteral::NullLiteral(type::Type* type) : Base(type) {}
NullLiteral::~NullLiteral() = default; NullLiteral::~NullLiteral() = default;

View File

@ -27,7 +27,7 @@ class NullLiteral : public Castable<NullLiteral, Literal> {
public: public:
/// Constructor /// Constructor
/// @param type the type /// @param type the type
explicit NullLiteral(ast::type::Type* type); explicit NullLiteral(type::Type* type);
~NullLiteral() override; ~NullLiteral() override;
/// @returns the name for this literal. This name is unique to this value. /// @returns the name for this literal. This name is unique to this value.

View File

@ -28,7 +28,7 @@ namespace {
using NullLiteralTest = TestHelper; using NullLiteralTest = TestHelper;
TEST_F(NullLiteralTest, Is) { TEST_F(NullLiteralTest, Is) {
ast::type::I32Type i32; type::I32Type 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) {
ast::type::I32Type i32; type::I32Type 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) {
ast::type::I32Type i32; type::I32Type 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) {
ast::type::BoolType bool_type; type::BoolType 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) {
ast::type::BoolType bool_type; type::BoolType 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) {
ast::type::BoolType bool_type; type::BoolType 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) {
ast::type::BoolType bool_type; type::BoolType 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

@ -17,7 +17,7 @@
namespace tint { namespace tint {
namespace ast { namespace ast {
SintLiteral::SintLiteral(ast::type::Type* type, int32_t value) SintLiteral::SintLiteral(type::Type* type, int32_t value)
: Base(type), value_(value) {} : Base(type), value_(value) {}
SintLiteral::~SintLiteral() = default; SintLiteral::~SintLiteral() = default;

View File

@ -28,7 +28,7 @@ class SintLiteral : public Castable<SintLiteral, IntLiteral> {
/// Constructor /// Constructor
/// @param type the type /// @param type the type
/// @param value the signed int literals value /// @param value the signed int literals value
SintLiteral(ast::type::Type* type, int32_t value); SintLiteral(type::Type* type, int32_t value);
~SintLiteral() override; ~SintLiteral() override;
/// Updates the literals value /// Updates the literals value

View File

@ -29,14 +29,14 @@ namespace {
using SintLiteralTest = TestHelper; using SintLiteralTest = TestHelper;
TEST_F(SintLiteralTest, Value) { TEST_F(SintLiteralTest, Value) {
ast::type::I32Type i32; type::I32Type 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) {
ast::type::I32Type i32; type::I32Type 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) {
ast::type::I32Type i32; type::I32Type 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) {
ast::type::I32Type i32; type::I32Type 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) {
ast::type::U32Type u32; type::U32Type 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

@ -17,7 +17,7 @@
namespace tint { namespace tint {
namespace ast { namespace ast {
StageDecoration::StageDecoration(ast::PipelineStage stage, const Source& source) StageDecoration::StageDecoration(PipelineStage stage, const Source& source)
: Base(source), stage_(stage) {} : Base(source), stage_(stage) {}
StageDecoration::~StageDecoration() = default; StageDecoration::~StageDecoration() = default;

View File

@ -27,11 +27,11 @@ class StageDecoration : public Castable<StageDecoration, FunctionDecoration> {
/// constructor /// constructor
/// @param stage the pipeline stage /// @param stage the pipeline stage
/// @param source the source of this decoration /// @param source the source of this decoration
StageDecoration(ast::PipelineStage stage, const Source& source); StageDecoration(PipelineStage stage, const Source& source);
~StageDecoration() override; ~StageDecoration() override;
/// @returns the stage /// @returns the stage
ast::PipelineStage value() const { return stage_; } PipelineStage value() const { return stage_; }
/// Outputs the decoration to the given stream /// Outputs the decoration to the given stream
/// @param out the stream to write to /// @param out the stream to write to
@ -39,7 +39,7 @@ class StageDecoration : public Castable<StageDecoration, FunctionDecoration> {
void to_str(std::ostream& out, size_t indent) const override; void to_str(std::ostream& out, size_t indent) const override;
private: private:
ast::PipelineStage stage_ = ast::PipelineStage::kNone; PipelineStage stage_ = PipelineStage::kNone;
}; };
} // namespace ast } // namespace ast

View File

@ -26,19 +26,19 @@ namespace {
using StageDecorationTest = TestHelper; using StageDecorationTest = TestHelper;
TEST_F(StageDecorationTest, Creation_1param) { TEST_F(StageDecorationTest, Creation_1param) {
StageDecoration d{ast::PipelineStage::kFragment, Source{}}; StageDecoration d{PipelineStage::kFragment, Source{}};
EXPECT_EQ(d.value(), ast::PipelineStage::kFragment); EXPECT_EQ(d.value(), PipelineStage::kFragment);
} }
TEST_F(StageDecorationTest, Is) { TEST_F(StageDecorationTest, Is) {
StageDecoration sd{ast::PipelineStage::kFragment, Source{}}; StageDecoration sd{PipelineStage::kFragment, Source{}};
Decoration* d = &sd; Decoration* d = &sd;
EXPECT_FALSE(d->Is<WorkgroupDecoration>()); EXPECT_FALSE(d->Is<WorkgroupDecoration>());
EXPECT_TRUE(d->Is<StageDecoration>()); EXPECT_TRUE(d->Is<StageDecoration>());
} }
TEST_F(StageDecorationTest, ToStr) { TEST_F(StageDecorationTest, ToStr) {
StageDecoration d{ast::PipelineStage::kFragment, Source{}}; StageDecoration d{PipelineStage::kFragment, Source{}};
std::ostringstream out; std::ostringstream out;
d.to_str(out, 0); d.to_str(out, 0);
EXPECT_EQ(out.str(), R"(StageDecoration{fragment} EXPECT_EQ(out.str(), R"(StageDecoration{fragment}

View File

@ -41,7 +41,7 @@ StructMember::~StructMember() = default;
bool StructMember::has_offset_decoration() const { bool StructMember::has_offset_decoration() const {
for (auto* deco : decorations_) { for (auto* deco : decorations_) {
if (deco->Is<ast::StructMemberOffsetDecoration>()) { if (deco->Is<StructMemberOffsetDecoration>()) {
return true; return true;
} }
} }
@ -50,7 +50,7 @@ bool StructMember::has_offset_decoration() const {
uint32_t StructMember::offset() const { uint32_t StructMember::offset() const {
for (auto* deco : decorations_) { for (auto* deco : decorations_) {
if (auto* offset = deco->As<ast::StructMemberOffsetDecoration>()) { if (auto* offset = deco->As<StructMemberOffsetDecoration>()) {
return offset->offset(); return offset->offset();
} }
} }

View File

@ -29,7 +29,7 @@ TEST_F(StructMemberOffsetDecorationTest, Creation) {
TEST_F(StructMemberOffsetDecorationTest, Is) { TEST_F(StructMemberOffsetDecorationTest, Is) {
StructMemberOffsetDecoration d{2, Source{}}; StructMemberOffsetDecoration d{2, Source{}};
EXPECT_TRUE(d.Is<ast::StructMemberOffsetDecoration>()); EXPECT_TRUE(d.Is<StructMemberOffsetDecoration>());
} }
} // namespace } // namespace

View File

@ -36,7 +36,7 @@ TEST_F(StructMemberTest, Creation) {
EXPECT_EQ(st.name(), "a"); EXPECT_EQ(st.name(), "a");
EXPECT_EQ(st.type(), &i32); EXPECT_EQ(st.type(), &i32);
EXPECT_EQ(st.decorations().size(), 1u); EXPECT_EQ(st.decorations().size(), 1u);
EXPECT_TRUE(st.decorations()[0]->Is<ast::StructMemberOffsetDecoration>()); EXPECT_TRUE(st.decorations()[0]->Is<StructMemberOffsetDecoration>());
EXPECT_EQ(st.source().range.begin.line, 0u); EXPECT_EQ(st.source().range.begin.line, 0u);
EXPECT_EQ(st.source().range.begin.column, 0u); EXPECT_EQ(st.source().range.begin.column, 0u);
EXPECT_EQ(st.source().range.end.line, 0u); EXPECT_EQ(st.source().range.end.line, 0u);

View File

@ -29,14 +29,14 @@ namespace {
using SwitchStatementTest = TestHelper; using SwitchStatementTest = TestHelper;
TEST_F(SwitchStatementTest, Creation) { TEST_F(SwitchStatementTest, Creation) {
ast::type::I32Type i32; type::I32Type i32;
CaseSelectorList lit; CaseSelectorList lit;
lit.push_back(create<SintLiteral>(&i32, 1)); lit.push_back(create<SintLiteral>(&i32, 1));
auto* ident = create<IdentifierExpression>("ident"); auto* ident = create<IdentifierExpression>("ident");
CaseStatementList body; CaseStatementList body;
auto* case_stmt = create<CaseStatement>(lit, create<ast::BlockStatement>()); auto* case_stmt = create<CaseStatement>(lit, create<BlockStatement>());
body.push_back(case_stmt); body.push_back(case_stmt);
SwitchStatement stmt(ident, body); SwitchStatement stmt(ident, body);
@ -61,27 +61,27 @@ TEST_F(SwitchStatementTest, IsSwitch) {
} }
TEST_F(SwitchStatementTest, IsValid) { TEST_F(SwitchStatementTest, IsValid) {
ast::type::I32Type i32; type::I32Type i32;
CaseSelectorList lit; CaseSelectorList lit;
lit.push_back(create<SintLiteral>(&i32, 2)); lit.push_back(create<SintLiteral>(&i32, 2));
auto* ident = create<IdentifierExpression>("ident"); auto* ident = create<IdentifierExpression>("ident");
CaseStatementList body; CaseStatementList body;
body.push_back(create<CaseStatement>(lit, create<ast::BlockStatement>())); body.push_back(create<CaseStatement>(lit, create<BlockStatement>()));
SwitchStatement stmt(ident, body); SwitchStatement stmt(ident, body);
EXPECT_TRUE(stmt.IsValid()); EXPECT_TRUE(stmt.IsValid());
} }
TEST_F(SwitchStatementTest, IsValid_Null_Condition) { TEST_F(SwitchStatementTest, IsValid_Null_Condition) {
ast::type::I32Type i32; type::I32Type i32;
CaseSelectorList lit; CaseSelectorList lit;
lit.push_back(create<SintLiteral>(&i32, 2)); lit.push_back(create<SintLiteral>(&i32, 2));
CaseStatementList body; CaseStatementList body;
body.push_back(create<CaseStatement>(lit, create<ast::BlockStatement>())); body.push_back(create<CaseStatement>(lit, create<BlockStatement>()));
SwitchStatement stmt; SwitchStatement stmt;
stmt.set_body(body); stmt.set_body(body);
@ -89,28 +89,28 @@ TEST_F(SwitchStatementTest, IsValid_Null_Condition) {
} }
TEST_F(SwitchStatementTest, IsValid_Invalid_Condition) { TEST_F(SwitchStatementTest, IsValid_Invalid_Condition) {
ast::type::I32Type i32; type::I32Type i32;
CaseSelectorList lit; CaseSelectorList lit;
lit.push_back(create<SintLiteral>(&i32, 2)); lit.push_back(create<SintLiteral>(&i32, 2));
auto* ident = create<IdentifierExpression>(""); auto* ident = create<IdentifierExpression>("");
CaseStatementList body; CaseStatementList body;
body.push_back(create<CaseStatement>(lit, create<ast::BlockStatement>())); body.push_back(create<CaseStatement>(lit, create<BlockStatement>()));
SwitchStatement stmt(ident, body); SwitchStatement stmt(ident, body);
EXPECT_FALSE(stmt.IsValid()); EXPECT_FALSE(stmt.IsValid());
} }
TEST_F(SwitchStatementTest, IsValid_Null_BodyStatement) { TEST_F(SwitchStatementTest, IsValid_Null_BodyStatement) {
ast::type::I32Type i32; type::I32Type i32;
CaseSelectorList lit; CaseSelectorList lit;
lit.push_back(create<SintLiteral>(&i32, 2)); lit.push_back(create<SintLiteral>(&i32, 2));
auto* ident = create<IdentifierExpression>("ident"); auto* ident = create<IdentifierExpression>("ident");
CaseStatementList body; CaseStatementList body;
body.push_back(create<CaseStatement>(lit, create<ast::BlockStatement>())); body.push_back(create<CaseStatement>(lit, create<BlockStatement>()));
body.push_back(nullptr); body.push_back(nullptr);
SwitchStatement stmt(ident, body); SwitchStatement stmt(ident, body);
@ -120,7 +120,7 @@ TEST_F(SwitchStatementTest, IsValid_Null_BodyStatement) {
TEST_F(SwitchStatementTest, IsValid_Invalid_BodyStatement) { TEST_F(SwitchStatementTest, IsValid_Invalid_BodyStatement) {
auto* ident = create<IdentifierExpression>("ident"); auto* ident = create<IdentifierExpression>("ident");
auto* case_body = create<ast::BlockStatement>(); auto* case_body = create<BlockStatement>();
case_body->append(nullptr); case_body->append(nullptr);
CaseStatementList body; CaseStatementList body;
@ -145,14 +145,14 @@ TEST_F(SwitchStatementTest, ToStr_Empty) {
} }
TEST_F(SwitchStatementTest, ToStr) { TEST_F(SwitchStatementTest, ToStr) {
ast::type::I32Type i32; type::I32Type i32;
CaseSelectorList lit; CaseSelectorList lit;
lit.push_back(create<SintLiteral>(&i32, 2)); lit.push_back(create<SintLiteral>(&i32, 2));
auto* ident = create<IdentifierExpression>("ident"); auto* ident = create<IdentifierExpression>("ident");
CaseStatementList body; CaseStatementList body;
body.push_back(create<CaseStatement>(lit, create<ast::BlockStatement>())); body.push_back(create<CaseStatement>(lit, create<BlockStatement>()));
SwitchStatement stmt(ident, body); SwitchStatement stmt(ident, body);
std::ostringstream out; std::ostringstream out;

View File

@ -31,8 +31,8 @@ class TestHelperBase : public BASE {
TestHelperBase() {} TestHelperBase() {}
~TestHelperBase() = default; ~TestHelperBase() = default;
/// Creates a new `ast::Node` owned by the Module. When the Module is /// Creates a new `Node` owned by the Module. When the Module is
/// destructed, the `ast::Node` will also be destructed. /// destructed, the `Node` will also be destructed.
/// @param args the arguments to pass to the type constructor /// @param args the arguments to pass to the type constructor
/// @returns the node pointer /// @returns the node pointer
template <typename T, typename... ARGS> template <typename T, typename... ARGS>

View File

@ -136,9 +136,9 @@ TEST_F(AccessControlTypeTest, MinBufferBindingSizeStruct) {
deco.push_back(create<StructMemberOffsetDecoration>(4, Source{})); deco.push_back(create<StructMemberOffsetDecoration>(4, Source{}));
members.push_back(create<StructMember>("bar", &u32, deco)); members.push_back(create<StructMember>("bar", &u32, deco));
ast::StructDecorationList decos; StructDecorationList decos;
auto* str = create<ast::Struct>(decos, members); auto* str = create<Struct>(decos, members);
StructType struct_type("struct_type", str); StructType struct_type("struct_type", str);
AccessControlType at{AccessControl::kReadOnly, &struct_type}; AccessControlType at{AccessControl::kReadOnly, &struct_type};
EXPECT_EQ(16u, at.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, at.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
@ -185,9 +185,9 @@ TEST_F(AccessControlTypeTest, BaseAlignmentStruct) {
deco.push_back(create<StructMemberOffsetDecoration>(4, Source{})); deco.push_back(create<StructMemberOffsetDecoration>(4, Source{}));
members.push_back(create<StructMember>("bar", &u32, deco)); members.push_back(create<StructMember>("bar", &u32, deco));
} }
ast::StructDecorationList decos; StructDecorationList decos;
auto* str = create<ast::Struct>(decos, members); auto* str = create<Struct>(decos, members);
StructType struct_type("struct_type", str); StructType struct_type("struct_type", str);
AccessControlType at{AccessControl::kReadOnly, &struct_type}; AccessControlType at{AccessControl::kReadOnly, &struct_type};
EXPECT_EQ(16u, at.BaseAlignment(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, at.BaseAlignment(MemoryLayout::kUniformBuffer));

View File

@ -201,9 +201,9 @@ TEST_F(AliasTypeTest, MinBufferBindingSizeStruct) {
deco.push_back(create<StructMemberOffsetDecoration>(4, Source{})); deco.push_back(create<StructMemberOffsetDecoration>(4, Source{}));
members.push_back(create<StructMember>("bar", &u32, deco)); members.push_back(create<StructMember>("bar", &u32, deco));
} }
ast::StructDecorationList decos; StructDecorationList decos;
auto* str = create<ast::Struct>(decos, members); auto* str = create<Struct>(decos, members);
StructType struct_type("struct_type", str); StructType struct_type("struct_type", str);
AliasType alias{"alias", &struct_type}; AliasType alias{"alias", &struct_type};
EXPECT_EQ(16u, alias.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, alias.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
@ -250,9 +250,9 @@ TEST_F(AliasTypeTest, BaseAlignmentStruct) {
deco.push_back(create<StructMemberOffsetDecoration>(4, Source{})); deco.push_back(create<StructMemberOffsetDecoration>(4, Source{}));
members.push_back(create<StructMember>("bar", &u32, deco)); members.push_back(create<StructMember>("bar", &u32, deco));
} }
ast::StructDecorationList decos; StructDecorationList decos;
auto* str = create<ast::Struct>(decos, members); auto* str = create<Struct>(decos, members);
StructType struct_type("struct_type", str); StructType struct_type("struct_type", str);
AliasType alias{"alias", &struct_type}; AliasType alias{"alias", &struct_type};
EXPECT_EQ(16u, alias.BaseAlignment(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, alias.BaseAlignment(MemoryLayout::kUniformBuffer));

View File

@ -65,7 +65,7 @@ uint64_t ArrayType::BaseAlignment(MemoryLayout mem_layout) const {
uint32_t ArrayType::array_stride() const { uint32_t ArrayType::array_stride() const {
for (auto* deco : decos_) { for (auto* deco : decos_) {
if (auto* stride = deco->As<ast::StrideDecoration>()) { if (auto* stride = deco->As<StrideDecoration>()) {
return stride->stride(); return stride->stride();
} }
} }
@ -74,7 +74,7 @@ uint32_t ArrayType::array_stride() const {
bool ArrayType::has_array_stride() const { bool ArrayType::has_array_stride() const {
for (auto* deco : decos_) { for (auto* deco : decos_) {
if (deco->Is<ast::StrideDecoration>()) { if (deco->Is<StrideDecoration>()) {
return true; return true;
} }
} }

View File

@ -57,9 +57,7 @@ class ArrayType : public Castable<ArrayType, Type> {
/// Sets the array decorations /// Sets the array decorations
/// @param decos the decorations to set /// @param decos the decorations to set
void set_decorations(ast::ArrayDecorationList decos) { void set_decorations(ArrayDecorationList decos) { decos_ = std::move(decos); }
decos_ = std::move(decos);
}
/// @returns the array decorations /// @returns the array decorations
const ArrayDecorationList& decorations() const { return decos_; } const ArrayDecorationList& decorations() const { return decos_; }
@ -79,7 +77,7 @@ class ArrayType : public Castable<ArrayType, Type> {
private: private:
Type* subtype_ = nullptr; Type* subtype_ = nullptr;
uint32_t size_ = 0; uint32_t size_ = 0;
ast::ArrayDecorationList decos_; ArrayDecorationList decos_;
}; };
} // namespace type } // namespace type

View File

@ -93,7 +93,7 @@ TEST_F(StorageTextureTypeTest, TypeName) {
TEST_F(StorageTextureTypeTest, F32Type) { TEST_F(StorageTextureTypeTest, F32Type) {
Context ctx; Context ctx;
ast::Module mod; Module mod;
Type* s = mod.create<StorageTextureType>(TextureDimension::k2dArray, Type* s = mod.create<StorageTextureType>(TextureDimension::k2dArray,
AccessControl::kReadOnly, AccessControl::kReadOnly,
ImageFormat::kRgba32Float); ImageFormat::kRgba32Float);
@ -108,7 +108,7 @@ TEST_F(StorageTextureTypeTest, F32Type) {
TEST_F(StorageTextureTypeTest, U32Type) { TEST_F(StorageTextureTypeTest, U32Type) {
Context ctx; Context ctx;
ast::Module mod; Module mod;
Type* s = mod.create<StorageTextureType>(TextureDimension::k2dArray, Type* s = mod.create<StorageTextureType>(TextureDimension::k2dArray,
AccessControl::kReadOnly, AccessControl::kReadOnly,
ImageFormat::kRg32Uint); ImageFormat::kRg32Uint);
@ -122,7 +122,7 @@ TEST_F(StorageTextureTypeTest, U32Type) {
TEST_F(StorageTextureTypeTest, I32Type) { TEST_F(StorageTextureTypeTest, I32Type) {
Context ctx; Context ctx;
ast::Module mod; Module mod;
Type* s = mod.create<StorageTextureType>(TextureDimension::k2dArray, Type* s = mod.create<StorageTextureType>(TextureDimension::k2dArray,
AccessControl::kReadOnly, AccessControl::kReadOnly,
ImageFormat::kRgba32Sint); ImageFormat::kRgba32Sint);

View File

@ -85,9 +85,9 @@ TEST_F(StructTypeTest, MinBufferBindingSize) {
deco.push_back(create<StructMemberOffsetDecoration>(4, Source{})); deco.push_back(create<StructMemberOffsetDecoration>(4, Source{}));
members.push_back(create<StructMember>("bar", &u32, deco)); members.push_back(create<StructMember>("bar", &u32, deco));
} }
ast::StructDecorationList decos; StructDecorationList decos;
auto* str = create<ast::Struct>(decos, members); auto* str = create<Struct>(decos, members);
StructType struct_type("struct_type", str); StructType struct_type("struct_type", str);
EXPECT_EQ(16u, EXPECT_EQ(16u,
struct_type.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); struct_type.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
@ -119,9 +119,9 @@ TEST_F(StructTypeTest, MinBufferBindingSizeArray) {
deco.push_back(create<StructMemberOffsetDecoration>(8, Source{})); deco.push_back(create<StructMemberOffsetDecoration>(8, Source{}));
members.push_back(create<StructMember>("bar", &arr, deco)); members.push_back(create<StructMember>("bar", &arr, deco));
} }
ast::StructDecorationList decos; StructDecorationList decos;
auto* str = create<ast::Struct>(decos, members); auto* str = create<Struct>(decos, members);
StructType struct_type("struct_type", str); StructType struct_type("struct_type", str);
EXPECT_EQ(32u, EXPECT_EQ(32u,
struct_type.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); struct_type.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
@ -154,9 +154,9 @@ TEST_F(StructTypeTest, MinBufferBindingSizeRuntimeArray) {
deco.push_back(create<StructMemberOffsetDecoration>(8, Source{})); deco.push_back(create<StructMemberOffsetDecoration>(8, Source{}));
members.push_back(create<StructMember>("bar", &u32, deco)); members.push_back(create<StructMember>("bar", &u32, deco));
} }
ast::StructDecorationList decos; StructDecorationList decos;
auto* str = create<ast::Struct>(decos, members); auto* str = create<Struct>(decos, members);
StructType struct_type("struct_type", str); StructType struct_type("struct_type", str);
EXPECT_EQ(12u, EXPECT_EQ(12u,
struct_type.MinBufferBindingSize(MemoryLayout::kStorageBuffer)); struct_type.MinBufferBindingSize(MemoryLayout::kStorageBuffer));
@ -172,9 +172,9 @@ TEST_F(StructTypeTest, MinBufferBindingSizeVec2) {
deco.push_back(create<StructMemberOffsetDecoration>(0, Source{})); deco.push_back(create<StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<StructMember>("foo", &vec2, deco)); members.push_back(create<StructMember>("foo", &vec2, deco));
} }
ast::StructDecorationList decos; StructDecorationList decos;
auto* str = create<ast::Struct>(decos, members); auto* str = create<Struct>(decos, members);
StructType struct_type("struct_type", str); StructType struct_type("struct_type", str);
EXPECT_EQ(16u, EXPECT_EQ(16u,
struct_type.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); struct_type.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
@ -191,9 +191,9 @@ TEST_F(StructTypeTest, MinBufferBindingSizeVec3) {
deco.push_back(create<StructMemberOffsetDecoration>(0, Source{})); deco.push_back(create<StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<StructMember>("foo", &vec3, deco)); members.push_back(create<StructMember>("foo", &vec3, deco));
} }
ast::StructDecorationList decos; StructDecorationList decos;
auto* str = create<ast::Struct>(decos, members); auto* str = create<Struct>(decos, members);
StructType struct_type("struct_type", str); StructType struct_type("struct_type", str);
EXPECT_EQ(16u, EXPECT_EQ(16u,
struct_type.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); struct_type.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
@ -211,9 +211,9 @@ TEST_F(StructTypeTest, MinBufferBindingSizeVec4) {
deco.push_back(create<StructMemberOffsetDecoration>(0, Source{})); deco.push_back(create<StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<StructMember>("foo", &vec4, deco)); members.push_back(create<StructMember>("foo", &vec4, deco));
} }
ast::StructDecorationList decos; StructDecorationList decos;
auto* str = create<ast::Struct>(decos, members); auto* str = create<Struct>(decos, members);
StructType struct_type("struct_type", str); StructType struct_type("struct_type", str);
EXPECT_EQ(16u, EXPECT_EQ(16u,
struct_type.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); struct_type.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
@ -235,9 +235,9 @@ TEST_F(StructTypeTest, BaseAlignment) {
deco.push_back(create<StructMemberOffsetDecoration>(4, Source{})); deco.push_back(create<StructMemberOffsetDecoration>(4, Source{}));
members.push_back(create<StructMember>("bar", &u32, deco)); members.push_back(create<StructMember>("bar", &u32, deco));
} }
ast::StructDecorationList decos; StructDecorationList decos;
auto* str = create<ast::Struct>(decos, members); auto* str = create<Struct>(decos, members);
StructType struct_type("struct_type", str); StructType 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));
@ -268,9 +268,9 @@ TEST_F(StructTypeTest, BaseAlignmentArray) {
deco.push_back(create<StructMemberOffsetDecoration>(8, Source{})); deco.push_back(create<StructMemberOffsetDecoration>(8, Source{}));
members.push_back(create<StructMember>("bar", &arr, deco)); members.push_back(create<StructMember>("bar", &arr, deco));
} }
ast::StructDecorationList decos; StructDecorationList decos;
auto* str = create<ast::Struct>(decos, members); auto* str = create<Struct>(decos, members);
StructType struct_type("struct_type", str); StructType 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));
@ -301,9 +301,9 @@ TEST_F(StructTypeTest, BaseAlignmentRuntimeArray) {
deco.push_back(create<StructMemberOffsetDecoration>(8, Source{})); deco.push_back(create<StructMemberOffsetDecoration>(8, Source{}));
members.push_back(create<StructMember>("bar", &u32, deco)); members.push_back(create<StructMember>("bar", &u32, deco));
} }
ast::StructDecorationList decos; StructDecorationList decos;
auto* str = create<ast::Struct>(decos, members); auto* str = create<Struct>(decos, members);
StructType struct_type("struct_type", str); StructType struct_type("struct_type", str);
EXPECT_EQ(4u, struct_type.BaseAlignment(MemoryLayout::kStorageBuffer)); EXPECT_EQ(4u, struct_type.BaseAlignment(MemoryLayout::kStorageBuffer));
} }
@ -318,9 +318,9 @@ TEST_F(StructTypeTest, BaseAlignmentVec2) {
deco.push_back(create<StructMemberOffsetDecoration>(0, Source{})); deco.push_back(create<StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<StructMember>("foo", &vec2, deco)); members.push_back(create<StructMember>("foo", &vec2, deco));
} }
ast::StructDecorationList decos; StructDecorationList decos;
auto* str = create<ast::Struct>(decos, members); auto* str = create<Struct>(decos, members);
StructType struct_type("struct_type", str); StructType 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));
@ -336,9 +336,9 @@ TEST_F(StructTypeTest, BaseAlignmentVec3) {
deco.push_back(create<StructMemberOffsetDecoration>(0, Source{})); deco.push_back(create<StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<StructMember>("foo", &vec3, deco)); members.push_back(create<StructMember>("foo", &vec3, deco));
} }
ast::StructDecorationList decos; StructDecorationList decos;
auto* str = create<ast::Struct>(decos, members); auto* str = create<Struct>(decos, members);
StructType struct_type("struct_type", str); StructType 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));
@ -354,9 +354,9 @@ TEST_F(StructTypeTest, BaseAlignmentVec4) {
deco.push_back(create<StructMemberOffsetDecoration>(0, Source{})); deco.push_back(create<StructMemberOffsetDecoration>(0, Source{}));
members.push_back(create<StructMember>("foo", &vec4, deco)); members.push_back(create<StructMember>("foo", &vec4, deco));
} }
ast::StructDecorationList decos; StructDecorationList decos;
auto* str = create<ast::Struct>(decos, members); auto* str = create<Struct>(decos, members);
StructType struct_type("struct_type", str); StructType 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,7 +53,7 @@ TEST_F(TypeConstructorExpressionTest, Creation_WithSource) {
TEST_F(TypeConstructorExpressionTest, IsTypeConstructor) { TEST_F(TypeConstructorExpressionTest, IsTypeConstructor) {
TypeConstructorExpression t; TypeConstructorExpression t;
EXPECT_TRUE(t.Is<ast::TypeConstructorExpression>()); EXPECT_TRUE(t.Is<TypeConstructorExpression>());
} }
TEST_F(TypeConstructorExpressionTest, IsValid) { TEST_F(TypeConstructorExpressionTest, IsValid) {

View File

@ -27,7 +27,7 @@ void TypeManager::Reset() {
types_.clear(); types_.clear();
} }
ast::type::Type* TypeManager::Get(std::unique_ptr<ast::type::Type> type) { type::Type* TypeManager::Get(std::unique_ptr<type::Type> type) {
auto name = type->type_name(); auto name = type->type_name();
if (types_.find(name) == types_.end()) { if (types_.find(name) == types_.end()) {

View File

@ -39,7 +39,7 @@ class TypeManager {
/// Get the given type from the type manager /// Get the given type from the type manager
/// @param type The type to register /// @param type The type to register
/// @return the pointer to the registered type /// @return the pointer to the registered type
ast::type::Type* Get(std::unique_ptr<ast::type::Type> type); type::Type* Get(std::unique_ptr<type::Type> type);
/// Get the given type `T` from the type manager /// Get the given type `T` from the type manager
/// @param args the arguments to pass to the type constructor /// @param args the arguments to pass to the type constructor
@ -52,13 +52,12 @@ class TypeManager {
/// Returns the type map /// Returns the type map
/// @returns the mapping from name string to type. /// @returns the mapping from name string to type.
const std::unordered_map<std::string, std::unique_ptr<ast::type::Type>>& const std::unordered_map<std::string, std::unique_ptr<type::Type>>& types() {
types() {
return types_; return types_;
} }
private: private:
std::unordered_map<std::string, std::unique_ptr<ast::type::Type>> types_; std::unordered_map<std::string, std::unique_ptr<type::Type>> types_;
}; };
} // namespace ast } // namespace ast

View File

@ -20,51 +20,53 @@
#include "src/ast/type/u32_type.h" #include "src/ast/type/u32_type.h"
namespace tint { namespace tint {
namespace ast {
namespace { namespace {
using TypeManagerTest = testing::Test; using TypeManagerTest = testing::Test;
TEST_F(TypeManagerTest, GetUnregistered) { TEST_F(TypeManagerTest, GetUnregistered) {
ast::TypeManager tm; TypeManager tm;
auto* t = tm.Get(std::make_unique<ast::type::I32Type>()); auto* t = tm.Get(std::make_unique<type::I32Type>());
ASSERT_NE(t, nullptr); ASSERT_NE(t, nullptr);
EXPECT_TRUE(t->Is<ast::type::I32Type>()); EXPECT_TRUE(t->Is<type::I32Type>());
} }
TEST_F(TypeManagerTest, GetSameTypeReturnsSamePtr) { TEST_F(TypeManagerTest, GetSameTypeReturnsSamePtr) {
ast::TypeManager tm; TypeManager tm;
auto* t = tm.Get(std::make_unique<ast::type::I32Type>()); auto* t = tm.Get(std::make_unique<type::I32Type>());
ASSERT_NE(t, nullptr); ASSERT_NE(t, nullptr);
EXPECT_TRUE(t->Is<ast::type::I32Type>()); EXPECT_TRUE(t->Is<type::I32Type>());
auto* t2 = tm.Get(std::make_unique<ast::type::I32Type>()); auto* t2 = tm.Get(std::make_unique<type::I32Type>());
EXPECT_EQ(t, t2); EXPECT_EQ(t, t2);
} }
TEST_F(TypeManagerTest, GetDifferentTypeReturnsDifferentPtr) { TEST_F(TypeManagerTest, GetDifferentTypeReturnsDifferentPtr) {
ast::TypeManager tm; TypeManager tm;
auto* t = tm.Get(std::make_unique<ast::type::I32Type>()); auto* t = tm.Get(std::make_unique<type::I32Type>());
ASSERT_NE(t, nullptr); ASSERT_NE(t, nullptr);
EXPECT_TRUE(t->Is<ast::type::I32Type>()); EXPECT_TRUE(t->Is<type::I32Type>());
auto* t2 = tm.Get(std::make_unique<ast::type::U32Type>()); auto* t2 = tm.Get(std::make_unique<type::U32Type>());
ASSERT_NE(t2, nullptr); ASSERT_NE(t2, nullptr);
EXPECT_NE(t, t2); EXPECT_NE(t, t2);
EXPECT_TRUE(t2->Is<ast::type::U32Type>()); EXPECT_TRUE(t2->Is<type::U32Type>());
} }
TEST_F(TypeManagerTest, ResetClearsPreviousData) { TEST_F(TypeManagerTest, ResetClearsPreviousData) {
ast::TypeManager tm; TypeManager tm;
auto* t = tm.Get(std::make_unique<ast::type::I32Type>()); auto* t = tm.Get(std::make_unique<type::I32Type>());
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<ast::type::I32Type>()); auto* t2 = tm.Get(std::make_unique<type::I32Type>());
ASSERT_NE(t2, nullptr); ASSERT_NE(t2, nullptr);
} }
} // namespace } // namespace
} // namespace ast
} // namespace tint } // namespace tint

View File

@ -17,7 +17,7 @@
namespace tint { namespace tint {
namespace ast { namespace ast {
UintLiteral::UintLiteral(ast::type::Type* type, uint32_t value) UintLiteral::UintLiteral(type::Type* type, uint32_t value)
: Base(type), value_(value) {} : Base(type), value_(value) {}
UintLiteral::~UintLiteral() = default; UintLiteral::~UintLiteral() = default;

View File

@ -28,7 +28,7 @@ class UintLiteral : public Castable<UintLiteral, IntLiteral> {
/// Constructor /// Constructor
/// @param type the type of the literal /// @param type the type of the literal
/// @param value the uint literals value /// @param value the uint literals value
UintLiteral(ast::type::Type* type, uint32_t value); UintLiteral(type::Type* type, uint32_t value);
~UintLiteral() override; ~UintLiteral() override;
/// Updates the literals value /// Updates the literals value

View File

@ -28,14 +28,14 @@ namespace {
using UintLiteralTest = TestHelper; using UintLiteralTest = TestHelper;
TEST_F(UintLiteralTest, Value) { TEST_F(UintLiteralTest, Value) {
ast::type::U32Type u32; type::U32Type 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) {
ast::type::U32Type u32; type::U32Type 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) {
ast::type::U32Type u32; type::U32Type u32;
UintLiteral i{&u32, 42}; UintLiteral i{&u32, 42};
EXPECT_EQ(i.to_str(), "42"); EXPECT_EQ(i.to_str(), "42");

View File

@ -43,7 +43,7 @@ TEST_F(UnaryOpExpressionTest, Creation_WithSource) {
TEST_F(UnaryOpExpressionTest, IsUnaryOp) { TEST_F(UnaryOpExpressionTest, IsUnaryOp) {
UnaryOpExpression u; UnaryOpExpression u;
EXPECT_TRUE(u.Is<ast::UnaryOpExpression>()); EXPECT_TRUE(u.Is<UnaryOpExpression>());
} }
TEST_F(UnaryOpExpressionTest, IsValid) { TEST_F(UnaryOpExpressionTest, IsValid) {