ast: Remove expression constructors that don't take a Source

Parsers need fixing up.

Bug: tint:396
Bug: tint:390
Change-Id: I7f823e2489101b43c1b21a6b89c248695a3f35b7
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/35160
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton 2020-12-12 01:38:13 +00:00 committed by Commit Bot service account
parent 5ed161b2d9
commit 1ff59cd0e2
133 changed files with 3646 additions and 2969 deletions

View File

@ -22,10 +22,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::ArrayAccessorExpression);
namespace tint {
namespace ast {
ArrayAccessorExpression::ArrayAccessorExpression(Expression* array,
Expression* idx_expr)
: Base(), array_(array), idx_expr_(idx_expr) {}
ArrayAccessorExpression::ArrayAccessorExpression(const Source& source,
Expression* array,
Expression* idx_expr)
@ -38,8 +34,8 @@ ArrayAccessorExpression::~ArrayAccessorExpression() = default;
ArrayAccessorExpression* ArrayAccessorExpression::Clone(
CloneContext* ctx) const {
return ctx->mod->create<ArrayAccessorExpression>(ctx->Clone(array_),
ctx->Clone(idx_expr_));
return ctx->mod->create<ArrayAccessorExpression>(
ctx->Clone(source()), ctx->Clone(array_), ctx->Clone(idx_expr_));
}
bool ArrayAccessorExpression::IsValid() const {

View File

@ -28,10 +28,6 @@ namespace ast {
class ArrayAccessorExpression
: public Castable<ArrayAccessorExpression, Expression> {
public:
/// Constructor
/// @param array the array
/// @param idx_expr the index expression
ArrayAccessorExpression(Expression* array, Expression* idx_expr);
/// Constructor
/// @param source the array accessor source
/// @param array the array

View File

@ -24,17 +24,21 @@ namespace {
using ArrayAccessorExpressionTest = TestHelper;
TEST_F(ArrayAccessorExpressionTest, Create) {
auto* ary = create<IdentifierExpression>(mod.RegisterSymbol("ary"), "ary");
auto* idx = create<IdentifierExpression>(mod.RegisterSymbol("idx"), "idx");
auto* ary =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("ary"), "ary");
auto* idx =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("idx"), "idx");
ArrayAccessorExpression exp(ary, idx);
ArrayAccessorExpression exp(Source{}, ary, idx);
ASSERT_EQ(exp.array(), ary);
ASSERT_EQ(exp.idx_expr(), idx);
}
TEST_F(ArrayAccessorExpressionTest, CreateWithSource) {
auto* ary = create<IdentifierExpression>(mod.RegisterSymbol("ary"), "ary");
auto* idx = create<IdentifierExpression>(mod.RegisterSymbol("idx"), "idx");
auto* ary =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("ary"), "ary");
auto* idx =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("idx"), "idx");
ArrayAccessorExpression exp(Source{Source::Location{20, 2}}, ary, idx);
auto src = exp.source();
@ -43,54 +47,66 @@ TEST_F(ArrayAccessorExpressionTest, CreateWithSource) {
}
TEST_F(ArrayAccessorExpressionTest, IsArrayAccessor) {
auto* ary = create<IdentifierExpression>(mod.RegisterSymbol("ary"), "ary");
auto* idx = create<IdentifierExpression>(mod.RegisterSymbol("idx"), "idx");
auto* ary =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("ary"), "ary");
auto* idx =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("idx"), "idx");
ArrayAccessorExpression exp(ary, idx);
ArrayAccessorExpression exp(Source{}, ary, idx);
EXPECT_TRUE(exp.Is<ArrayAccessorExpression>());
}
TEST_F(ArrayAccessorExpressionTest, IsValid) {
auto* ary = create<IdentifierExpression>(mod.RegisterSymbol("ary"), "ary");
auto* idx = create<IdentifierExpression>(mod.RegisterSymbol("idx"), "idx");
auto* ary =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("ary"), "ary");
auto* idx =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("idx"), "idx");
ArrayAccessorExpression exp(ary, idx);
ArrayAccessorExpression exp(Source{}, ary, idx);
EXPECT_TRUE(exp.IsValid());
}
TEST_F(ArrayAccessorExpressionTest, IsValid_MissingArray) {
auto* idx = create<IdentifierExpression>(mod.RegisterSymbol("idx"), "idx");
auto* idx =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("idx"), "idx");
ArrayAccessorExpression exp(nullptr, idx);
ArrayAccessorExpression exp(Source{}, nullptr, idx);
EXPECT_FALSE(exp.IsValid());
}
TEST_F(ArrayAccessorExpressionTest, IsValid_MissingIndex) {
auto* ary = create<IdentifierExpression>(mod.RegisterSymbol("ary"), "ary");
auto* ary =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("ary"), "ary");
ArrayAccessorExpression exp(ary, nullptr);
ArrayAccessorExpression exp(Source{}, ary, nullptr);
EXPECT_FALSE(exp.IsValid());
}
TEST_F(ArrayAccessorExpressionTest, IsValid_InvalidArray) {
auto* ary = create<IdentifierExpression>(mod.RegisterSymbol(""), "");
auto* idx = create<IdentifierExpression>(mod.RegisterSymbol("idx"), "idx");
ArrayAccessorExpression exp(ary, idx);
auto* ary =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol(""), "");
auto* idx =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("idx"), "idx");
ArrayAccessorExpression exp(Source{}, ary, idx);
EXPECT_FALSE(exp.IsValid());
}
TEST_F(ArrayAccessorExpressionTest, IsValid_InvalidIndex) {
auto* ary = create<IdentifierExpression>(mod.RegisterSymbol("ary"), "ary");
auto* idx = create<IdentifierExpression>(mod.RegisterSymbol(""), "");
ArrayAccessorExpression exp(ary, idx);
auto* ary =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("ary"), "ary");
auto* idx =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol(""), "");
ArrayAccessorExpression exp(Source{}, ary, idx);
EXPECT_FALSE(exp.IsValid());
}
TEST_F(ArrayAccessorExpressionTest, ToStr) {
auto* ary = create<IdentifierExpression>(mod.RegisterSymbol("ary"), "ary");
auto* idx = create<IdentifierExpression>(mod.RegisterSymbol("idx"), "idx");
auto* ary =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("ary"), "ary");
auto* idx =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("idx"), "idx");
ArrayAccessorExpression exp(ary, idx);
ArrayAccessorExpression exp(Source{}, ary, idx);
std::ostringstream out;
exp.to_str(out, 2);

View File

@ -24,8 +24,10 @@ namespace {
using AssignmentStatementTest = TestHelper;
TEST_F(AssignmentStatementTest, Creation) {
auto* lhs = create<IdentifierExpression>(mod.RegisterSymbol("lhs"), "lhs");
auto* rhs = create<IdentifierExpression>(mod.RegisterSymbol("rhs"), "rhs");
auto* lhs =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("lhs"), "lhs");
auto* rhs =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("rhs"), "rhs");
AssignmentStatement stmt(lhs, rhs);
EXPECT_EQ(stmt.lhs(), lhs);
@ -33,8 +35,10 @@ TEST_F(AssignmentStatementTest, Creation) {
}
TEST_F(AssignmentStatementTest, CreationWithSource) {
auto* lhs = create<IdentifierExpression>(mod.RegisterSymbol("lhs"), "lhs");
auto* rhs = create<IdentifierExpression>(mod.RegisterSymbol("rhs"), "rhs");
auto* lhs =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("lhs"), "lhs");
auto* rhs =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("rhs"), "rhs");
AssignmentStatement stmt(Source{Source::Location{20, 2}}, lhs, rhs);
auto src = stmt.source();
@ -43,52 +47,64 @@ TEST_F(AssignmentStatementTest, CreationWithSource) {
}
TEST_F(AssignmentStatementTest, IsAssign) {
auto* lhs = create<IdentifierExpression>(mod.RegisterSymbol("lhs"), "lhs");
auto* rhs = create<IdentifierExpression>(mod.RegisterSymbol("rhs"), "rhs");
auto* lhs =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("lhs"), "lhs");
auto* rhs =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("rhs"), "rhs");
AssignmentStatement stmt(lhs, rhs);
EXPECT_TRUE(stmt.Is<AssignmentStatement>());
}
TEST_F(AssignmentStatementTest, IsValid) {
auto* lhs = create<IdentifierExpression>(mod.RegisterSymbol("lhs"), "lhs");
auto* rhs = create<IdentifierExpression>(mod.RegisterSymbol("rhs"), "rhs");
auto* lhs =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("lhs"), "lhs");
auto* rhs =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("rhs"), "rhs");
AssignmentStatement stmt(lhs, rhs);
EXPECT_TRUE(stmt.IsValid());
}
TEST_F(AssignmentStatementTest, IsValid_MissingLHS) {
auto* rhs = create<IdentifierExpression>(mod.RegisterSymbol("rhs"), "rhs");
auto* rhs =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("rhs"), "rhs");
AssignmentStatement stmt(nullptr, rhs);
EXPECT_FALSE(stmt.IsValid());
}
TEST_F(AssignmentStatementTest, IsValid_MissingRHS) {
auto* lhs = create<IdentifierExpression>(mod.RegisterSymbol("lhs"), "lhs");
auto* lhs =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("lhs"), "lhs");
AssignmentStatement stmt(lhs, nullptr);
EXPECT_FALSE(stmt.IsValid());
}
TEST_F(AssignmentStatementTest, IsValid_InvalidLHS) {
auto* lhs = create<IdentifierExpression>(mod.RegisterSymbol(""), "");
auto* rhs = create<IdentifierExpression>(mod.RegisterSymbol("rhs"), "rhs");
auto* lhs =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol(""), "");
auto* rhs =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("rhs"), "rhs");
AssignmentStatement stmt(lhs, rhs);
EXPECT_FALSE(stmt.IsValid());
}
TEST_F(AssignmentStatementTest, IsValid_InvalidRHS) {
auto* lhs = create<IdentifierExpression>(mod.RegisterSymbol("lhs"), "lhs");
auto* rhs = create<IdentifierExpression>(mod.RegisterSymbol(""), "");
auto* lhs =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("lhs"), "lhs");
auto* rhs =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol(""), "");
AssignmentStatement stmt(lhs, rhs);
EXPECT_FALSE(stmt.IsValid());
}
TEST_F(AssignmentStatementTest, ToStr) {
auto* lhs = create<IdentifierExpression>(mod.RegisterSymbol("lhs"), "lhs");
auto* rhs = create<IdentifierExpression>(mod.RegisterSymbol("rhs"), "rhs");
auto* lhs =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("lhs"), "lhs");
auto* rhs =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("rhs"), "rhs");
AssignmentStatement stmt(lhs, rhs);
std::ostringstream out;

View File

@ -22,11 +22,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::BinaryExpression);
namespace tint {
namespace ast {
BinaryExpression::BinaryExpression(BinaryOp op,
Expression* lhs,
Expression* rhs)
: Base(), op_(op), lhs_(lhs), rhs_(rhs) {}
BinaryExpression::BinaryExpression(const Source& source,
BinaryOp op,
Expression* lhs,

View File

@ -50,11 +50,6 @@ enum class BinaryOp {
/// An binary expression
class BinaryExpression : public Castable<BinaryExpression, Expression> {
public:
/// Constructor
/// @param op the operation type
/// @param lhs the left side of the expression
/// @param rhs the right side of the expression
BinaryExpression(BinaryOp op, Expression* lhs, Expression* rhs);
/// Constructor
/// @param source the binary expression source
/// @param op the operation type

View File

@ -26,18 +26,22 @@ namespace {
using BinaryExpressionTest = TestHelper;
TEST_F(BinaryExpressionTest, Creation) {
auto* lhs = create<IdentifierExpression>(mod.RegisterSymbol("lhs"), "lhs");
auto* rhs = create<IdentifierExpression>(mod.RegisterSymbol("rhs"), "rhs");
auto* lhs =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("lhs"), "lhs");
auto* rhs =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("rhs"), "rhs");
BinaryExpression r(BinaryOp::kEqual, lhs, rhs);
BinaryExpression r(Source{}, BinaryOp::kEqual, lhs, rhs);
EXPECT_EQ(r.lhs(), lhs);
EXPECT_EQ(r.rhs(), rhs);
EXPECT_EQ(r.op(), BinaryOp::kEqual);
}
TEST_F(BinaryExpressionTest, Creation_WithSource) {
auto* lhs = create<IdentifierExpression>(mod.RegisterSymbol("lhs"), "lhs");
auto* rhs = create<IdentifierExpression>(mod.RegisterSymbol("rhs"), "rhs");
auto* lhs =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("lhs"), "lhs");
auto* rhs =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("rhs"), "rhs");
BinaryExpression r(Source{Source::Location{20, 2}}, BinaryOp::kEqual, lhs,
rhs);
@ -47,64 +51,78 @@ TEST_F(BinaryExpressionTest, Creation_WithSource) {
}
TEST_F(BinaryExpressionTest, IsBinary) {
auto* lhs = create<IdentifierExpression>(mod.RegisterSymbol("lhs"), "lhs");
auto* rhs = create<IdentifierExpression>(mod.RegisterSymbol("rhs"), "rhs");
auto* lhs =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("lhs"), "lhs");
auto* rhs =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("rhs"), "rhs");
BinaryExpression r(BinaryOp::kEqual, lhs, rhs);
BinaryExpression r(Source{}, BinaryOp::kEqual, lhs, rhs);
EXPECT_TRUE(r.Is<BinaryExpression>());
}
TEST_F(BinaryExpressionTest, IsValid) {
auto* lhs = create<IdentifierExpression>(mod.RegisterSymbol("lhs"), "lhs");
auto* rhs = create<IdentifierExpression>(mod.RegisterSymbol("rhs"), "rhs");
auto* lhs =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("lhs"), "lhs");
auto* rhs =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("rhs"), "rhs");
BinaryExpression r(BinaryOp::kEqual, lhs, rhs);
BinaryExpression r(Source{}, BinaryOp::kEqual, lhs, rhs);
EXPECT_TRUE(r.IsValid());
}
TEST_F(BinaryExpressionTest, IsValid_Null_LHS) {
auto* rhs = create<IdentifierExpression>(mod.RegisterSymbol("rhs"), "rhs");
auto* rhs =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("rhs"), "rhs");
BinaryExpression r(BinaryOp::kEqual, nullptr, rhs);
BinaryExpression r(Source{}, BinaryOp::kEqual, nullptr, rhs);
EXPECT_FALSE(r.IsValid());
}
TEST_F(BinaryExpressionTest, IsValid_Invalid_LHS) {
auto* lhs = create<IdentifierExpression>(mod.RegisterSymbol(""), "");
auto* rhs = create<IdentifierExpression>(mod.RegisterSymbol("rhs"), "rhs");
auto* lhs =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol(""), "");
auto* rhs =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("rhs"), "rhs");
BinaryExpression r(BinaryOp::kEqual, lhs, rhs);
BinaryExpression r(Source{}, BinaryOp::kEqual, lhs, rhs);
EXPECT_FALSE(r.IsValid());
}
TEST_F(BinaryExpressionTest, IsValid_Null_RHS) {
auto* lhs = create<IdentifierExpression>(mod.RegisterSymbol("lhs"), "lhs");
auto* lhs =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("lhs"), "lhs");
BinaryExpression r(BinaryOp::kEqual, lhs, nullptr);
BinaryExpression r(Source{}, BinaryOp::kEqual, lhs, nullptr);
EXPECT_FALSE(r.IsValid());
}
TEST_F(BinaryExpressionTest, IsValid_Invalid_RHS) {
auto* lhs = create<IdentifierExpression>(mod.RegisterSymbol("lhs"), "lhs");
auto* rhs = create<IdentifierExpression>(mod.RegisterSymbol(""), "");
auto* lhs =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("lhs"), "lhs");
auto* rhs =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol(""), "");
BinaryExpression r(BinaryOp::kEqual, lhs, rhs);
BinaryExpression r(Source{}, BinaryOp::kEqual, lhs, rhs);
EXPECT_FALSE(r.IsValid());
}
TEST_F(BinaryExpressionTest, IsValid_Binary_None) {
auto* lhs = create<IdentifierExpression>(mod.RegisterSymbol("lhs"), "lhs");
auto* rhs = create<IdentifierExpression>(mod.RegisterSymbol("rhs"), "rhs");
auto* lhs =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("lhs"), "lhs");
auto* rhs =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("rhs"), "rhs");
BinaryExpression r(BinaryOp::kNone, lhs, rhs);
BinaryExpression r(Source{}, BinaryOp::kNone, lhs, rhs);
EXPECT_FALSE(r.IsValid());
}
TEST_F(BinaryExpressionTest, ToStr) {
auto* lhs = create<IdentifierExpression>(mod.RegisterSymbol("lhs"), "lhs");
auto* rhs = create<IdentifierExpression>(mod.RegisterSymbol("rhs"), "rhs");
auto* lhs =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("lhs"), "lhs");
auto* rhs =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("rhs"), "rhs");
BinaryExpression r(BinaryOp::kEqual, lhs, rhs);
BinaryExpression r(Source{}, BinaryOp::kEqual, lhs, rhs);
std::ostringstream out;
r.to_str(out, 2);
EXPECT_EQ(demangle(out.str()), R"( Binary[not set]{

View File

@ -22,9 +22,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::BitcastExpression);
namespace tint {
namespace ast {
BitcastExpression::BitcastExpression(type::Type* type, Expression* expr)
: Base(), type_(type), expr_(expr) {}
BitcastExpression::BitcastExpression(const Source& source,
type::Type* type,
Expression* expr)

View File

@ -28,10 +28,6 @@ namespace ast {
/// A bitcast expression
class BitcastExpression : public Castable<BitcastExpression, Expression> {
public:
/// Constructor
/// @param type the type
/// @param expr the expr
BitcastExpression(type::Type* type, Expression* expr);
/// Constructor
/// @param source the bitcast expression source
/// @param type the type

View File

@ -26,16 +26,18 @@ using BitcastExpressionTest = TestHelper;
TEST_F(BitcastExpressionTest, Create) {
type::F32 f32;
auto* expr = create<IdentifierExpression>(mod.RegisterSymbol("expr"), "expr");
auto* expr = create<IdentifierExpression>(Source{},
mod.RegisterSymbol("expr"), "expr");
BitcastExpression exp(&f32, expr);
BitcastExpression exp(Source{}, &f32, expr);
ASSERT_EQ(exp.type(), &f32);
ASSERT_EQ(exp.expr(), expr);
}
TEST_F(BitcastExpressionTest, CreateWithSource) {
type::F32 f32;
auto* expr = create<IdentifierExpression>(mod.RegisterSymbol("expr"), "expr");
auto* expr = create<IdentifierExpression>(Source{},
mod.RegisterSymbol("expr"), "expr");
BitcastExpression exp(Source{Source::Location{20, 2}}, &f32, expr);
auto src = exp.source();
@ -45,46 +47,51 @@ TEST_F(BitcastExpressionTest, CreateWithSource) {
TEST_F(BitcastExpressionTest, IsBitcast) {
type::F32 f32;
auto* expr = create<IdentifierExpression>(mod.RegisterSymbol("expr"), "expr");
auto* expr = create<IdentifierExpression>(Source{},
mod.RegisterSymbol("expr"), "expr");
BitcastExpression exp(&f32, expr);
BitcastExpression exp(Source{}, &f32, expr);
EXPECT_TRUE(exp.Is<BitcastExpression>());
}
TEST_F(BitcastExpressionTest, IsValid) {
type::F32 f32;
auto* expr = create<IdentifierExpression>(mod.RegisterSymbol("expr"), "expr");
auto* expr = create<IdentifierExpression>(Source{},
mod.RegisterSymbol("expr"), "expr");
BitcastExpression exp(&f32, expr);
BitcastExpression exp(Source{}, &f32, expr);
EXPECT_TRUE(exp.IsValid());
}
TEST_F(BitcastExpressionTest, IsValid_MissingType) {
auto* expr = create<IdentifierExpression>(mod.RegisterSymbol("expr"), "expr");
auto* expr = create<IdentifierExpression>(Source{},
mod.RegisterSymbol("expr"), "expr");
BitcastExpression exp(nullptr, expr);
BitcastExpression exp(Source{}, nullptr, expr);
EXPECT_FALSE(exp.IsValid());
}
TEST_F(BitcastExpressionTest, IsValid_MissingExpr) {
type::F32 f32;
BitcastExpression exp(&f32, nullptr);
BitcastExpression exp(Source{}, &f32, nullptr);
EXPECT_FALSE(exp.IsValid());
}
TEST_F(BitcastExpressionTest, IsValid_InvalidExpr) {
type::F32 f32;
auto* expr = create<IdentifierExpression>(mod.RegisterSymbol(""), "");
BitcastExpression e(&f32, expr);
auto* expr =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol(""), "");
BitcastExpression e(Source{}, &f32, expr);
EXPECT_FALSE(e.IsValid());
}
TEST_F(BitcastExpressionTest, ToStr) {
type::F32 f32;
auto* expr = create<IdentifierExpression>(mod.RegisterSymbol("expr"), "expr");
auto* expr = create<IdentifierExpression>(Source{},
mod.RegisterSymbol("expr"), "expr");
BitcastExpression exp(&f32, expr);
BitcastExpression exp(Source{}, &f32, expr);
std::ostringstream out;
exp.to_str(out, 2);

View File

@ -206,37 +206,39 @@ class Builder {
/// @param name the identifier name
/// @return an IdentifierExpression with the given name
IdentifierExpression* Expr(const std::string& name) {
return create<IdentifierExpression>(mod->RegisterSymbol(name), name);
return create<IdentifierExpression>(Source{}, mod->RegisterSymbol(name),
name);
}
/// @param name the identifier name
/// @return an IdentifierExpression with the given name
IdentifierExpression* Expr(const char* name) {
return create<IdentifierExpression>(mod->RegisterSymbol(name), name);
return create<IdentifierExpression>(Source{}, mod->RegisterSymbol(name),
name);
}
/// @param value the boolean value
/// @return a Scalar constructor for the given value
ScalarConstructorExpression* Expr(bool value) {
return create<ScalarConstructorExpression>(Literal(value));
return create<ScalarConstructorExpression>(Source{}, Literal(value));
}
/// @param value the float value
/// @return a Scalar constructor for the given value
ScalarConstructorExpression* Expr(f32 value) {
return create<ScalarConstructorExpression>(Literal(value));
return create<ScalarConstructorExpression>(Source{}, Literal(value));
}
/// @param value the integer value
/// @return a Scalar constructor for the given value
ScalarConstructorExpression* Expr(i32 value) {
return create<ScalarConstructorExpression>(Literal(value));
return create<ScalarConstructorExpression>(Source{}, Literal(value));
}
/// @param value the unsigned int value
/// @return a Scalar constructor for the given value
ScalarConstructorExpression* Expr(u32 value) {
return create<ScalarConstructorExpression>(Literal(value));
return create<ScalarConstructorExpression>(Source{}, Literal(value));
}
/// Converts `arg` to an `Expression` using `Expr()`, then appends it to
@ -303,7 +305,7 @@ class Builder {
template <typename T, typename... ARGS>
TypeConstructorExpression* Construct(ARGS&&... args) {
return create<TypeConstructorExpression>(
ty.Of<T>(), ExprList(std::forward<ARGS>(args)...));
Source{}, ty.Of<T>(), ExprList(std::forward<ARGS>(args)...));
}
/// @param type the type to construct
@ -313,7 +315,7 @@ class Builder {
template <typename... ARGS>
TypeConstructorExpression* Construct(type::Type* type, ARGS&&... args) {
return create<TypeConstructorExpression>(
type, ExprList(std::forward<ARGS>(args)...));
Source{}, type, ExprList(std::forward<ARGS>(args)...));
}
/// @param args the arguments for the vector constructor
@ -322,7 +324,7 @@ class Builder {
template <typename T, typename... ARGS>
TypeConstructorExpression* vec2(ARGS&&... args) {
return create<TypeConstructorExpression>(
ty.vec2<T>(), ExprList(std::forward<ARGS>(args)...));
Source{}, ty.vec2<T>(), ExprList(std::forward<ARGS>(args)...));
}
/// @param args the arguments for the vector constructor
@ -331,7 +333,7 @@ class Builder {
template <typename T, typename... ARGS>
TypeConstructorExpression* vec3(ARGS&&... args) {
return create<TypeConstructorExpression>(
ty.vec3<T>(), ExprList(std::forward<ARGS>(args)...));
Source{}, ty.vec3<T>(), ExprList(std::forward<ARGS>(args)...));
}
/// @param args the arguments for the vector constructor
@ -340,7 +342,7 @@ class Builder {
template <typename T, typename... ARGS>
TypeConstructorExpression* vec4(ARGS&&... args) {
return create<TypeConstructorExpression>(
ty.vec4<T>(), ExprList(std::forward<ARGS>(args)...));
Source{}, ty.vec4<T>(), ExprList(std::forward<ARGS>(args)...));
}
/// @param args the arguments for the matrix constructor
@ -349,7 +351,7 @@ class Builder {
template <typename T, typename... ARGS>
TypeConstructorExpression* mat2x2(ARGS&&... args) {
return create<TypeConstructorExpression>(
ty.mat2x2<T>(), ExprList(std::forward<ARGS>(args)...));
Source{}, ty.mat2x2<T>(), ExprList(std::forward<ARGS>(args)...));
}
/// @param args the arguments for the matrix constructor
@ -358,7 +360,7 @@ class Builder {
template <typename T, typename... ARGS>
TypeConstructorExpression* mat2x3(ARGS&&... args) {
return create<TypeConstructorExpression>(
ty.mat2x3<T>(), ExprList(std::forward<ARGS>(args)...));
Source{}, ty.mat2x3<T>(), ExprList(std::forward<ARGS>(args)...));
}
/// @param args the arguments for the matrix constructor
@ -367,7 +369,7 @@ class Builder {
template <typename T, typename... ARGS>
TypeConstructorExpression* mat2x4(ARGS&&... args) {
return create<TypeConstructorExpression>(
ty.mat2x4<T>(), ExprList(std::forward<ARGS>(args)...));
Source{}, ty.mat2x4<T>(), ExprList(std::forward<ARGS>(args)...));
}
/// @param args the arguments for the matrix constructor
@ -376,7 +378,7 @@ class Builder {
template <typename T, typename... ARGS>
TypeConstructorExpression* mat3x2(ARGS&&... args) {
return create<TypeConstructorExpression>(
ty.mat3x2<T>(), ExprList(std::forward<ARGS>(args)...));
Source{}, ty.mat3x2<T>(), ExprList(std::forward<ARGS>(args)...));
}
/// @param args the arguments for the matrix constructor
@ -385,7 +387,7 @@ class Builder {
template <typename T, typename... ARGS>
TypeConstructorExpression* mat3x3(ARGS&&... args) {
return create<TypeConstructorExpression>(
ty.mat3x3<T>(), ExprList(std::forward<ARGS>(args)...));
Source{}, ty.mat3x3<T>(), ExprList(std::forward<ARGS>(args)...));
}
/// @param args the arguments for the matrix constructor
@ -394,7 +396,7 @@ class Builder {
template <typename T, typename... ARGS>
TypeConstructorExpression* mat3x4(ARGS&&... args) {
return create<TypeConstructorExpression>(
ty.mat3x4<T>(), ExprList(std::forward<ARGS>(args)...));
Source{}, ty.mat3x4<T>(), ExprList(std::forward<ARGS>(args)...));
}
/// @param args the arguments for the matrix constructor
@ -403,7 +405,7 @@ class Builder {
template <typename T, typename... ARGS>
TypeConstructorExpression* mat4x2(ARGS&&... args) {
return create<TypeConstructorExpression>(
ty.mat4x2<T>(), ExprList(std::forward<ARGS>(args)...));
Source{}, ty.mat4x2<T>(), ExprList(std::forward<ARGS>(args)...));
}
/// @param args the arguments for the matrix constructor
@ -412,7 +414,7 @@ class Builder {
template <typename T, typename... ARGS>
TypeConstructorExpression* mat4x3(ARGS&&... args) {
return create<TypeConstructorExpression>(
ty.mat4x3<T>(), ExprList(std::forward<ARGS>(args)...));
Source{}, ty.mat4x3<T>(), ExprList(std::forward<ARGS>(args)...));
}
/// @param args the arguments for the matrix constructor
@ -421,7 +423,7 @@ class Builder {
template <typename T, typename... ARGS>
TypeConstructorExpression* mat4x4(ARGS&&... args) {
return create<TypeConstructorExpression>(
ty.mat4x4<T>(), ExprList(std::forward<ARGS>(args)...));
Source{}, ty.mat4x4<T>(), ExprList(std::forward<ARGS>(args)...));
}
/// @param args the arguments for the array constructor
@ -430,7 +432,7 @@ class Builder {
template <typename T, int N = 0, typename... ARGS>
TypeConstructorExpression* array(ARGS&&... args) {
return create<TypeConstructorExpression>(
ty.array<T, N>(), ExprList(std::forward<ARGS>(args)...));
Source{}, ty.array<T, N>(), ExprList(std::forward<ARGS>(args)...));
}
/// @param name the variable name
@ -481,7 +483,8 @@ class Builder {
/// arguments of `args` converted to `Expression`s using `Expr()`.
template <typename... ARGS>
CallExpression Call(const std::string& func, ARGS&&... args) {
return CallExpression{Expr(func), ExprList(std::forward<ARGS>(args)...)};
return CallExpression(Source{}, Expr(func),
ExprList(std::forward<ARGS>(args)...));
}
/// @param lhs the left hand argument to the addition operation
@ -489,7 +492,7 @@ class Builder {
/// @returns a `BinaryExpression` summing the arguments `lhs` and `rhs`
template <typename LHS, typename RHS>
Expression* Add(LHS&& lhs, RHS&& rhs) {
return create<BinaryExpression>(ast::BinaryOp::kAdd,
return create<BinaryExpression>(Source{}, ast::BinaryOp::kAdd,
Expr(std::forward<LHS>(lhs)),
Expr(std::forward<RHS>(rhs)));
}
@ -499,7 +502,7 @@ class Builder {
/// @returns a `BinaryExpression` subtracting `rhs` from `lhs`
template <typename LHS, typename RHS>
Expression* Sub(LHS&& lhs, RHS&& rhs) {
return create<BinaryExpression>(ast::BinaryOp::kSubtract,
return create<BinaryExpression>(Source{}, ast::BinaryOp::kSubtract,
Expr(std::forward<LHS>(lhs)),
Expr(std::forward<RHS>(rhs)));
}
@ -509,8 +512,8 @@ class Builder {
/// @returns a `ArrayAccessorExpression` that indexes `arr` with `idx`
template <typename ARR, typename IDX>
Expression* Index(ARR&& arr, IDX&& idx) {
return create<ArrayAccessorExpression>(Expr(std::forward<ARR>(arr)),
Expr(std::forward<IDX>(idx)));
return create<ArrayAccessorExpression>(
Source{}, Expr(std::forward<ARR>(arr)), Expr(std::forward<IDX>(idx)));
}
/// Creates a new `Node` owned by the Module. When the Module is

View File

@ -22,9 +22,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::CallExpression);
namespace tint {
namespace ast {
CallExpression::CallExpression(Expression* func, ExpressionList params)
: Base(), func_(func), params_(params) {}
CallExpression::CallExpression(const Source& source,
Expression* func,
ExpressionList params)

View File

@ -27,10 +27,6 @@ namespace ast {
/// A call expression
class CallExpression : public Castable<CallExpression, Expression> {
public:
/// Constructor
/// @param func the function
/// @param params the parameters
CallExpression(Expression* func, ExpressionList params);
/// Constructor
/// @param source the call expression source
/// @param func the function

View File

@ -24,14 +24,15 @@ namespace {
using CallExpressionTest = TestHelper;
TEST_F(CallExpressionTest, Creation) {
auto* func = create<IdentifierExpression>(mod.RegisterSymbol("func"), "func");
auto* func = create<IdentifierExpression>(Source{},
mod.RegisterSymbol("func"), "func");
ExpressionList params;
params.push_back(
create<IdentifierExpression>(mod.RegisterSymbol("param1"), "param1"));
params.push_back(
create<IdentifierExpression>(mod.RegisterSymbol("param2"), "param2"));
params.push_back(create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("param1"), "param1"));
params.push_back(create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("param2"), "param2"));
CallExpression stmt(func, params);
CallExpression stmt(Source{}, func, params);
EXPECT_EQ(stmt.func(), func);
const auto& vec = stmt.params();
@ -41,7 +42,8 @@ TEST_F(CallExpressionTest, Creation) {
}
TEST_F(CallExpressionTest, Creation_WithSource) {
auto* func = create<IdentifierExpression>(mod.RegisterSymbol("func"), "func");
auto* func = create<IdentifierExpression>(Source{},
mod.RegisterSymbol("func"), "func");
CallExpression stmt(Source{Source::Location{20, 2}}, func, {});
auto src = stmt.source();
EXPECT_EQ(src.range.begin.line, 20u);
@ -49,57 +51,64 @@ TEST_F(CallExpressionTest, Creation_WithSource) {
}
TEST_F(CallExpressionTest, IsCall) {
auto* func = create<IdentifierExpression>(mod.RegisterSymbol("func"), "func");
CallExpression stmt(func, {});
auto* func = create<IdentifierExpression>(Source{},
mod.RegisterSymbol("func"), "func");
CallExpression stmt(Source{}, func, {});
EXPECT_TRUE(stmt.Is<CallExpression>());
}
TEST_F(CallExpressionTest, IsValid) {
auto* func = create<IdentifierExpression>(mod.RegisterSymbol("func"), "func");
CallExpression stmt(func, {});
auto* func = create<IdentifierExpression>(Source{},
mod.RegisterSymbol("func"), "func");
CallExpression stmt(Source{}, func, {});
EXPECT_TRUE(stmt.IsValid());
}
TEST_F(CallExpressionTest, IsValid_MissingFunction) {
CallExpression stmt(nullptr, {});
CallExpression stmt(Source{}, nullptr, {});
EXPECT_FALSE(stmt.IsValid());
}
TEST_F(CallExpressionTest, IsValid_NullParam) {
auto* func = create<IdentifierExpression>(mod.RegisterSymbol("func"), "func");
auto* func = create<IdentifierExpression>(Source{},
mod.RegisterSymbol("func"), "func");
ExpressionList params;
params.push_back(
create<IdentifierExpression>(mod.RegisterSymbol("param1"), "param1"));
params.push_back(create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("param1"), "param1"));
params.push_back(nullptr);
params.push_back(
create<IdentifierExpression>(mod.RegisterSymbol("param2"), "param2"));
params.push_back(create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("param2"), "param2"));
CallExpression stmt(func, params);
CallExpression stmt(Source{}, func, params);
EXPECT_FALSE(stmt.IsValid());
}
TEST_F(CallExpressionTest, IsValid_InvalidFunction) {
auto* func = create<IdentifierExpression>(mod.RegisterSymbol(""), "");
auto* func =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol(""), "");
ExpressionList params;
params.push_back(
create<IdentifierExpression>(mod.RegisterSymbol("param1"), "param1"));
params.push_back(create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("param1"), "param1"));
CallExpression stmt(func, params);
CallExpression stmt(Source{}, func, params);
EXPECT_FALSE(stmt.IsValid());
}
TEST_F(CallExpressionTest, IsValid_InvalidParam) {
auto* func = create<IdentifierExpression>(mod.RegisterSymbol("func"), "func");
auto* func = create<IdentifierExpression>(Source{},
mod.RegisterSymbol("func"), "func");
ExpressionList params;
params.push_back(create<IdentifierExpression>(mod.RegisterSymbol(""), ""));
params.push_back(
create<IdentifierExpression>(Source{}, mod.RegisterSymbol(""), ""));
CallExpression stmt(func, params);
CallExpression stmt(Source{}, func, params);
EXPECT_FALSE(stmt.IsValid());
}
TEST_F(CallExpressionTest, ToStr_NoParams) {
auto* func = create<IdentifierExpression>(mod.RegisterSymbol("func"), "func");
CallExpression stmt(func, {});
auto* func = create<IdentifierExpression>(Source{},
mod.RegisterSymbol("func"), "func");
CallExpression stmt(Source{}, func, {});
std::ostringstream out;
stmt.to_str(out, 2);
EXPECT_EQ(demangle(out.str()), R"( Call[not set]{
@ -111,14 +120,15 @@ TEST_F(CallExpressionTest, ToStr_NoParams) {
}
TEST_F(CallExpressionTest, ToStr_WithParams) {
auto* func = create<IdentifierExpression>(mod.RegisterSymbol("func"), "func");
auto* func = create<IdentifierExpression>(Source{},
mod.RegisterSymbol("func"), "func");
ExpressionList params;
params.push_back(
create<IdentifierExpression>(mod.RegisterSymbol("param1"), "param1"));
params.push_back(
create<IdentifierExpression>(mod.RegisterSymbol("param2"), "param2"));
params.push_back(create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("param1"), "param1"));
params.push_back(create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("param2"), "param2"));
CallExpression stmt(func, params);
CallExpression stmt(Source{}, func, params);
std::ostringstream out;
stmt.to_str(out, 2);
EXPECT_EQ(demangle(out.str()), R"( Call[not set]{

View File

@ -25,9 +25,11 @@ namespace {
using CallStatementTest = TestHelper;
TEST_F(CallStatementTest, Creation) {
auto* expr = create<CallExpression>(
create<IdentifierExpression>(mod.RegisterSymbol("func"), "func"),
ExpressionList{});
auto* expr =
create<CallExpression>(Source{},
create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("func"), "func"),
ExpressionList{});
CallStatement c(expr);
EXPECT_EQ(c.expr(), expr);
@ -39,9 +41,11 @@ TEST_F(CallStatementTest, IsCall) {
}
TEST_F(CallStatementTest, IsValid) {
CallStatement c(create<CallExpression>(
create<IdentifierExpression>(mod.RegisterSymbol("func"), "func"),
ExpressionList{}));
CallStatement c(
create<CallExpression>(Source{},
create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("func"), "func"),
ExpressionList{}));
EXPECT_TRUE(c.IsValid());
}
@ -51,15 +55,17 @@ TEST_F(CallStatementTest, IsValid_MissingExpr) {
}
TEST_F(CallStatementTest, IsValid_InvalidExpr) {
CallExpression stmt(nullptr, {});
CallExpression stmt(Source{}, nullptr, {});
CallStatement c(&stmt);
EXPECT_FALSE(c.IsValid());
}
TEST_F(CallStatementTest, ToStr) {
CallStatement c(create<CallExpression>(
create<IdentifierExpression>(mod.RegisterSymbol("func"), "func"),
ExpressionList{}));
CallStatement c(
create<CallExpression>(Source{},
create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("func"), "func"),
ExpressionList{}));
std::ostringstream out;
c.to_str(out, 2);

View File

@ -21,8 +21,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::ConstructorExpression);
namespace tint {
namespace ast {
ConstructorExpression::ConstructorExpression() = default;
ConstructorExpression::~ConstructorExpression() = default;
ConstructorExpression::ConstructorExpression(ConstructorExpression&&) = default;

View File

@ -27,8 +27,6 @@ class ConstructorExpression
~ConstructorExpression() override;
protected:
/// Constructor
ConstructorExpression();
/// Constructor
/// @param source the constructor source
explicit ConstructorExpression(const Source& source);

View File

@ -30,7 +30,7 @@ using ElseStatementTest = TestHelper;
TEST_F(ElseStatementTest, Creation) {
type::Bool bool_type;
auto* cond = create<ScalarConstructorExpression>(
create<BoolLiteral>(Source{}, &bool_type, true));
Source{}, create<BoolLiteral>(Source{}, &bool_type, true));
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
@ -57,7 +57,7 @@ TEST_F(ElseStatementTest, IsElse) {
TEST_F(ElseStatementTest, HasCondition) {
type::Bool bool_type;
auto* cond = create<ScalarConstructorExpression>(
create<BoolLiteral>(Source{}, &bool_type, true));
Source{}, create<BoolLiteral>(Source{}, &bool_type, true));
ElseStatement e(cond, create<BlockStatement>());
EXPECT_TRUE(e.HasCondition());
}
@ -90,7 +90,7 @@ TEST_F(ElseStatementTest, IsValid_WithNullBodyStatement) {
}
TEST_F(ElseStatementTest, IsValid_InvalidCondition) {
auto* cond = create<ScalarConstructorExpression>(nullptr);
auto* cond = create<ScalarConstructorExpression>(Source{}, nullptr);
ElseStatement e(cond, create<BlockStatement>());
EXPECT_FALSE(e.IsValid());
}
@ -107,7 +107,7 @@ TEST_F(ElseStatementTest, IsValid_InvalidBodyStatement) {
TEST_F(ElseStatementTest, ToStr) {
type::Bool bool_type;
auto* cond = create<ScalarConstructorExpression>(
create<BoolLiteral>(Source{}, &bool_type, true));
Source{}, create<BoolLiteral>(Source{}, &bool_type, true));
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());

View File

@ -19,8 +19,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::Expression);
namespace tint {
namespace ast {
Expression::Expression() = default;
Expression::Expression(const Source& source) : Base(source) {}
Expression::Expression(Expression&&) = default;

View File

@ -43,8 +43,6 @@ class Expression : public Castable<Expression, Node> {
}
protected:
/// Constructor
Expression();
/// Constructor
/// @param source the source of the expression
explicit Expression(const Source& source);

View File

@ -24,7 +24,7 @@ namespace {
class Expr : public Expression {
public:
Expr() : Expression() {}
Expr() : Expression(Source{}) {}
Expr* Clone(CloneContext*) const override { return nullptr; }
bool IsValid() const override { return true; }

View File

@ -22,9 +22,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::IdentifierExpression);
namespace tint {
namespace ast {
IdentifierExpression::IdentifierExpression(Symbol sym, const std::string& name)
: Base(), sym_(sym), name_(name) {}
IdentifierExpression::IdentifierExpression(const Source& source,
Symbol sym,
const std::string& name)

View File

@ -29,10 +29,6 @@ namespace ast {
/// An identifier expression
class IdentifierExpression : public Castable<IdentifierExpression, Expression> {
public:
/// Constructor
/// @param sym the symbol for the identifier
/// @param name the name
explicit IdentifierExpression(Symbol sym, const std::string& name);
/// Constructor
/// @param source the source
/// @param sym the symbol for the identifier

View File

@ -23,7 +23,7 @@ namespace {
using IdentifierExpressionTest = TestHelper;
TEST_F(IdentifierExpressionTest, Creation) {
IdentifierExpression i(mod.RegisterSymbol("ident"), "ident");
IdentifierExpression i(Source{}, mod.RegisterSymbol("ident"), "ident");
EXPECT_EQ(i.symbol(), Symbol(1));
EXPECT_EQ(i.name(), "ident");
}
@ -40,17 +40,17 @@ TEST_F(IdentifierExpressionTest, Creation_WithSource) {
}
TEST_F(IdentifierExpressionTest, IsIdentifier) {
IdentifierExpression i(mod.RegisterSymbol("ident"), "ident");
IdentifierExpression i(Source{}, mod.RegisterSymbol("ident"), "ident");
EXPECT_TRUE(i.Is<IdentifierExpression>());
}
TEST_F(IdentifierExpressionTest, IsValid) {
IdentifierExpression i(mod.RegisterSymbol("ident"), "ident");
IdentifierExpression i(Source{}, mod.RegisterSymbol("ident"), "ident");
EXPECT_TRUE(i.IsValid());
}
TEST_F(IdentifierExpressionTest, ToStr) {
IdentifierExpression i(mod.RegisterSymbol("ident"), "ident");
IdentifierExpression i(Source{}, mod.RegisterSymbol("ident"), "ident");
std::ostringstream out;
i.to_str(out, 2);
EXPECT_EQ(demangle(out.str()), R"( Identifier[not set]{ident}

View File

@ -25,7 +25,8 @@ namespace {
using IfStatementTest = TestHelper;
TEST_F(IfStatementTest, Creation) {
auto* cond = create<IdentifierExpression>(mod.RegisterSymbol("cond"), "cond");
auto* cond = create<IdentifierExpression>(Source{},
mod.RegisterSymbol("cond"), "cond");
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
@ -43,7 +44,8 @@ TEST_F(IfStatementTest, IsIf) {
}
TEST_F(IfStatementTest, IsValid) {
auto* cond = create<IdentifierExpression>(mod.RegisterSymbol("cond"), "cond");
auto* cond = create<IdentifierExpression>(Source{},
mod.RegisterSymbol("cond"), "cond");
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
@ -52,18 +54,19 @@ TEST_F(IfStatementTest, IsValid) {
}
TEST_F(IfStatementTest, IsValid_WithElseStatements) {
auto* cond = create<IdentifierExpression>(mod.RegisterSymbol("cond"), "cond");
auto* cond = create<IdentifierExpression>(Source{},
mod.RegisterSymbol("cond"), "cond");
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
IfStatement stmt(
Source{}, cond, body,
{
create<ElseStatement>(create<IdentifierExpression>(
mod.RegisterSymbol("Ident"), "Ident"),
create<BlockStatement>()),
create<ElseStatement>(create<BlockStatement>()),
});
IfStatement stmt(Source{}, cond, body,
{
create<ElseStatement>(
create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("Ident"), "Ident"),
create<BlockStatement>()),
create<ElseStatement>(create<BlockStatement>()),
});
EXPECT_TRUE(stmt.IsValid());
}
@ -76,7 +79,8 @@ TEST_F(IfStatementTest, IsValid_MissingCondition) {
}
TEST_F(IfStatementTest, IsValid_InvalidCondition) {
auto* cond = create<IdentifierExpression>(mod.RegisterSymbol(""), "");
auto* cond =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol(""), "");
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
@ -85,7 +89,8 @@ TEST_F(IfStatementTest, IsValid_InvalidCondition) {
}
TEST_F(IfStatementTest, IsValid_NullBodyStatement) {
auto* cond = create<IdentifierExpression>(mod.RegisterSymbol("cond"), "cond");
auto* cond = create<IdentifierExpression>(Source{},
mod.RegisterSymbol("cond"), "cond");
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
body->append(nullptr);
@ -95,7 +100,8 @@ TEST_F(IfStatementTest, IsValid_NullBodyStatement) {
}
TEST_F(IfStatementTest, IsValid_InvalidBodyStatement) {
auto* cond = create<IdentifierExpression>(mod.RegisterSymbol("cond"), "cond");
auto* cond = create<IdentifierExpression>(Source{},
mod.RegisterSymbol("cond"), "cond");
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
body->append(create<IfStatement>(Source{}, nullptr, create<BlockStatement>(),
@ -106,7 +112,26 @@ TEST_F(IfStatementTest, IsValid_InvalidBodyStatement) {
}
TEST_F(IfStatementTest, IsValid_NullElseStatement) {
auto* cond = create<IdentifierExpression>(mod.RegisterSymbol("cond"), "cond");
auto* cond = create<IdentifierExpression>(Source{},
mod.RegisterSymbol("cond"), "cond");
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
IfStatement stmt(Source{}, cond, body,
{
create<ElseStatement>(
create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("Ident"), "Ident"),
create<BlockStatement>()),
create<ElseStatement>(create<BlockStatement>()),
nullptr,
});
EXPECT_FALSE(stmt.IsValid());
}
TEST_F(IfStatementTest, IsValid_InvalidElseStatement) {
auto* cond = create<IdentifierExpression>(Source{},
mod.RegisterSymbol("cond"), "cond");
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
@ -114,30 +139,15 @@ TEST_F(IfStatementTest, IsValid_NullElseStatement) {
Source{}, cond, body,
{
create<ElseStatement>(create<IdentifierExpression>(
mod.RegisterSymbol("Ident"), "Ident"),
Source{}, mod.RegisterSymbol(""), ""),
create<BlockStatement>()),
create<ElseStatement>(create<BlockStatement>()),
nullptr,
});
EXPECT_FALSE(stmt.IsValid());
}
TEST_F(IfStatementTest, IsValid_InvalidElseStatement) {
auto* cond = create<IdentifierExpression>(mod.RegisterSymbol("cond"), "cond");
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
IfStatement stmt(Source{}, cond, body,
{
create<ElseStatement>(create<IdentifierExpression>(
mod.RegisterSymbol(""), ""),
create<BlockStatement>()),
});
EXPECT_FALSE(stmt.IsValid());
}
TEST_F(IfStatementTest, IsValid_MultipleElseWiththoutCondition) {
auto* cond = create<IdentifierExpression>(mod.RegisterSymbol("cond"), "cond");
auto* cond = create<IdentifierExpression>(Source{},
mod.RegisterSymbol("cond"), "cond");
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
@ -150,23 +160,25 @@ TEST_F(IfStatementTest, IsValid_MultipleElseWiththoutCondition) {
}
TEST_F(IfStatementTest, IsValid_ElseNotLast) {
auto* cond = create<IdentifierExpression>(mod.RegisterSymbol("cond"), "cond");
auto* cond = create<IdentifierExpression>(Source{},
mod.RegisterSymbol("cond"), "cond");
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
IfStatement stmt(
Source{}, cond, body,
{
create<ElseStatement>(create<BlockStatement>()),
create<ElseStatement>(create<IdentifierExpression>(
mod.RegisterSymbol("ident"), "ident"),
create<BlockStatement>()),
});
IfStatement stmt(Source{}, cond, body,
{
create<ElseStatement>(create<BlockStatement>()),
create<ElseStatement>(
create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("ident"), "ident"),
create<BlockStatement>()),
});
EXPECT_FALSE(stmt.IsValid());
}
TEST_F(IfStatementTest, ToStr) {
auto* cond = create<IdentifierExpression>(mod.RegisterSymbol("cond"), "cond");
auto* cond = create<IdentifierExpression>(Source{},
mod.RegisterSymbol("cond"), "cond");
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
@ -186,7 +198,8 @@ TEST_F(IfStatementTest, ToStr) {
}
TEST_F(IfStatementTest, ToStr_WithElseStatements) {
auto* cond = create<IdentifierExpression>(mod.RegisterSymbol("cond"), "cond");
auto* cond = create<IdentifierExpression>(Source{},
mod.RegisterSymbol("cond"), "cond");
auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>());
@ -197,14 +210,14 @@ TEST_F(IfStatementTest, ToStr_WithElseStatements) {
else_body->append(create<DiscardStatement>());
else_body->append(create<DiscardStatement>());
IfStatement stmt(
Source{}, cond, body,
{
create<ElseStatement>(create<IdentifierExpression>(
mod.RegisterSymbol("ident"), "ident"),
else_if_body),
create<ElseStatement>(else_body),
});
IfStatement stmt(Source{}, cond, body,
{
create<ElseStatement>(
create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("ident"), "ident"),
else_if_body),
create<ElseStatement>(else_body),
});
std::ostringstream out;
stmt.to_str(out, 2);

View File

@ -22,10 +22,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::MemberAccessorExpression);
namespace tint {
namespace ast {
MemberAccessorExpression::MemberAccessorExpression(Expression* structure,
IdentifierExpression* member)
: Base(), struct_(structure), member_(member) {}
MemberAccessorExpression::MemberAccessorExpression(const Source& source,
Expression* structure,
IdentifierExpression* member)

View File

@ -29,10 +29,6 @@ namespace ast {
class MemberAccessorExpression
: public Castable<MemberAccessorExpression, Expression> {
public:
/// Constructor
/// @param structure the structure
/// @param member the member
MemberAccessorExpression(Expression* structure, IdentifierExpression* member);
/// Constructor
/// @param source the member accessor expression source
/// @param structure the structure

View File

@ -26,21 +26,21 @@ namespace {
using MemberAccessorExpressionTest = TestHelper;
TEST_F(MemberAccessorExpressionTest, Creation) {
auto* str = create<IdentifierExpression>(mod.RegisterSymbol("structure"),
"structure");
auto* mem =
create<IdentifierExpression>(mod.RegisterSymbol("member"), "member");
auto* str = create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("structure"), "structure");
auto* mem = create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("member"), "member");
MemberAccessorExpression stmt(str, mem);
MemberAccessorExpression stmt(Source{}, str, mem);
EXPECT_EQ(stmt.structure(), str);
EXPECT_EQ(stmt.member(), mem);
}
TEST_F(MemberAccessorExpressionTest, Creation_WithSource) {
auto* str = create<IdentifierExpression>(mod.RegisterSymbol("structure"),
"structure");
auto* mem =
create<IdentifierExpression>(mod.RegisterSymbol("member"), "member");
auto* str = create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("structure"), "structure");
auto* mem = create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("member"), "member");
MemberAccessorExpression stmt(Source{Source::Location{20, 2}}, str, mem);
auto src = stmt.source();
@ -49,66 +49,68 @@ TEST_F(MemberAccessorExpressionTest, Creation_WithSource) {
}
TEST_F(MemberAccessorExpressionTest, IsMemberAccessor) {
auto* str = create<IdentifierExpression>(mod.RegisterSymbol("structure"),
"structure");
auto* mem =
create<IdentifierExpression>(mod.RegisterSymbol("member"), "member");
auto* str = create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("structure"), "structure");
auto* mem = create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("member"), "member");
MemberAccessorExpression stmt(str, mem);
MemberAccessorExpression stmt(Source{}, str, mem);
EXPECT_TRUE(stmt.Is<MemberAccessorExpression>());
}
TEST_F(MemberAccessorExpressionTest, IsValid) {
auto* str = create<IdentifierExpression>(mod.RegisterSymbol("structure"),
"structure");
auto* mem =
create<IdentifierExpression>(mod.RegisterSymbol("member"), "member");
auto* str = create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("structure"), "structure");
auto* mem = create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("member"), "member");
MemberAccessorExpression stmt(str, mem);
MemberAccessorExpression stmt(Source{}, str, mem);
EXPECT_TRUE(stmt.IsValid());
}
TEST_F(MemberAccessorExpressionTest, IsValid_NullStruct) {
auto* mem =
create<IdentifierExpression>(mod.RegisterSymbol("member"), "member");
auto* mem = create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("member"), "member");
MemberAccessorExpression stmt(nullptr, mem);
MemberAccessorExpression stmt(Source{}, nullptr, mem);
EXPECT_FALSE(stmt.IsValid());
}
TEST_F(MemberAccessorExpressionTest, IsValid_InvalidStruct) {
auto* str = create<IdentifierExpression>(mod.RegisterSymbol(""), "");
auto* mem =
create<IdentifierExpression>(mod.RegisterSymbol("member"), "member");
auto* str =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol(""), "");
auto* mem = create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("member"), "member");
MemberAccessorExpression stmt(str, mem);
MemberAccessorExpression stmt(Source{}, str, mem);
EXPECT_FALSE(stmt.IsValid());
}
TEST_F(MemberAccessorExpressionTest, IsValid_NullMember) {
auto* str = create<IdentifierExpression>(mod.RegisterSymbol("structure"),
"structure");
auto* str = create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("structure"), "structure");
MemberAccessorExpression stmt(str, nullptr);
MemberAccessorExpression stmt(Source{}, str, nullptr);
EXPECT_FALSE(stmt.IsValid());
}
TEST_F(MemberAccessorExpressionTest, IsValid_InvalidMember) {
auto* str = create<IdentifierExpression>(mod.RegisterSymbol("structure"),
"structure");
auto* mem = create<IdentifierExpression>(mod.RegisterSymbol(""), "");
auto* str = create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("structure"), "structure");
auto* mem =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol(""), "");
MemberAccessorExpression stmt(str, mem);
MemberAccessorExpression stmt(Source{}, str, mem);
EXPECT_FALSE(stmt.IsValid());
}
TEST_F(MemberAccessorExpressionTest, ToStr) {
auto* str = create<IdentifierExpression>(mod.RegisterSymbol("structure"),
"structure");
auto* mem =
create<IdentifierExpression>(mod.RegisterSymbol("member"), "member");
auto* str = create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("structure"), "structure");
auto* mem = create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("member"), "member");
MemberAccessorExpression stmt(str, mem);
MemberAccessorExpression stmt(Source{}, str, mem);
std::ostringstream out;
stmt.to_str(out, 2);
EXPECT_EQ(demangle(out.str()), R"( MemberAccessor[not set]{

View File

@ -26,7 +26,8 @@ namespace {
using ReturnStatementTest = TestHelper;
TEST_F(ReturnStatementTest, Creation) {
auto* expr = create<IdentifierExpression>(mod.RegisterSymbol("expr"), "expr");
auto* expr = create<IdentifierExpression>(Source{},
mod.RegisterSymbol("expr"), "expr");
ReturnStatement r(Source{}, expr);
EXPECT_EQ(r.value(), expr);
@ -50,7 +51,8 @@ TEST_F(ReturnStatementTest, HasValue_WithoutValue) {
}
TEST_F(ReturnStatementTest, HasValue_WithValue) {
auto* expr = create<IdentifierExpression>(mod.RegisterSymbol("expr"), "expr");
auto* expr = create<IdentifierExpression>(Source{},
mod.RegisterSymbol("expr"), "expr");
ReturnStatement r(Source{}, expr);
EXPECT_TRUE(r.has_value());
}
@ -61,19 +63,22 @@ TEST_F(ReturnStatementTest, IsValid_WithoutValue) {
}
TEST_F(ReturnStatementTest, IsValid_WithValue) {
auto* expr = create<IdentifierExpression>(mod.RegisterSymbol("expr"), "expr");
auto* expr = create<IdentifierExpression>(Source{},
mod.RegisterSymbol("expr"), "expr");
ReturnStatement r(Source{}, expr);
EXPECT_TRUE(r.IsValid());
}
TEST_F(ReturnStatementTest, IsValid_InvalidValue) {
auto* expr = create<IdentifierExpression>(mod.RegisterSymbol(""), "");
auto* expr =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol(""), "");
ReturnStatement r(Source{}, expr);
EXPECT_FALSE(r.IsValid());
}
TEST_F(ReturnStatementTest, ToStr_WithValue) {
auto* expr = create<IdentifierExpression>(mod.RegisterSymbol("expr"), "expr");
auto* expr = create<IdentifierExpression>(Source{},
mod.RegisterSymbol("expr"), "expr");
ReturnStatement r(Source{}, expr);
std::ostringstream out;
r.to_str(out, 2);

View File

@ -22,9 +22,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::ScalarConstructorExpression);
namespace tint {
namespace ast {
ScalarConstructorExpression::ScalarConstructorExpression(Literal* literal)
: literal_(literal) {}
ScalarConstructorExpression::ScalarConstructorExpression(const Source& source,
Literal* litearl)
: Base(source), literal_(litearl) {}

View File

@ -28,9 +28,6 @@ namespace ast {
class ScalarConstructorExpression
: public Castable<ScalarConstructorExpression, ConstructorExpression> {
public:
/// Constructor
/// @param literal the const literal
explicit ScalarConstructorExpression(Literal* literal);
/// Constructor
/// @param source the constructor source
/// @param literal the const literal

View File

@ -27,7 +27,7 @@ using ScalarConstructorExpressionTest = TestHelper;
TEST_F(ScalarConstructorExpressionTest, Creation) {
type::Bool bool_type;
auto* b = create<BoolLiteral>(Source{}, &bool_type, true);
ScalarConstructorExpression c(b);
ScalarConstructorExpression c(Source{}, b);
EXPECT_EQ(c.literal(), b);
}
@ -43,19 +43,19 @@ TEST_F(ScalarConstructorExpressionTest, Creation_WithSource) {
TEST_F(ScalarConstructorExpressionTest, IsValid) {
type::Bool bool_type;
auto* b = create<BoolLiteral>(Source{}, &bool_type, true);
ScalarConstructorExpression c(b);
ScalarConstructorExpression c(Source{}, b);
EXPECT_TRUE(c.IsValid());
}
TEST_F(ScalarConstructorExpressionTest, IsValid_MissingLiteral) {
ScalarConstructorExpression c(nullptr);
ScalarConstructorExpression c(Source{}, nullptr);
EXPECT_FALSE(c.IsValid());
}
TEST_F(ScalarConstructorExpressionTest, ToStr) {
type::Bool bool_type;
auto* b = create<BoolLiteral>(Source{}, &bool_type, true);
ScalarConstructorExpression c(b);
ScalarConstructorExpression c(Source{}, b);
std::ostringstream out;
c.to_str(out, 2);
EXPECT_EQ(out.str(), R"( ScalarConstructor[not set]{true}

View File

@ -34,8 +34,8 @@ TEST_F(SwitchStatementTest, Creation) {
CaseSelectorList lit;
lit.push_back(create<SintLiteral>(Source{}, &i32, 1));
auto* ident =
create<IdentifierExpression>(mod.RegisterSymbol("ident"), "ident");
auto* ident = create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("ident"), "ident");
CaseStatementList body;
auto* case_stmt = create<CaseStatement>(lit, create<BlockStatement>());
body.push_back(case_stmt);
@ -47,8 +47,8 @@ TEST_F(SwitchStatementTest, Creation) {
}
TEST_F(SwitchStatementTest, Creation_WithSource) {
auto* ident =
create<IdentifierExpression>(mod.RegisterSymbol("ident"), "ident");
auto* ident = create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("ident"), "ident");
SwitchStatement stmt(Source{Source::Location{20, 2}}, ident,
CaseStatementList());
@ -63,8 +63,8 @@ TEST_F(SwitchStatementTest, IsSwitch) {
CaseSelectorList lit;
lit.push_back(create<SintLiteral>(Source{}, &i32, 2));
auto* ident =
create<IdentifierExpression>(mod.RegisterSymbol("ident"), "ident");
auto* ident = create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("ident"), "ident");
CaseStatementList body;
body.push_back(create<CaseStatement>(lit, create<BlockStatement>()));
@ -78,8 +78,8 @@ TEST_F(SwitchStatementTest, IsValid) {
CaseSelectorList lit;
lit.push_back(create<SintLiteral>(Source{}, &i32, 2));
auto* ident =
create<IdentifierExpression>(mod.RegisterSymbol("ident"), "ident");
auto* ident = create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("ident"), "ident");
CaseStatementList body;
body.push_back(create<CaseStatement>(lit, create<BlockStatement>()));
@ -106,7 +106,8 @@ TEST_F(SwitchStatementTest, IsValid_Invalid_Condition) {
CaseSelectorList lit;
lit.push_back(create<SintLiteral>(Source{}, &i32, 2));
auto* ident = create<IdentifierExpression>(mod.RegisterSymbol(""), "");
auto* ident =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol(""), "");
CaseStatementList body;
body.push_back(create<CaseStatement>(lit, create<BlockStatement>()));
@ -120,8 +121,8 @@ TEST_F(SwitchStatementTest, IsValid_Null_BodyStatement) {
CaseSelectorList lit;
lit.push_back(create<SintLiteral>(Source{}, &i32, 2));
auto* ident =
create<IdentifierExpression>(mod.RegisterSymbol("ident"), "ident");
auto* ident = create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("ident"), "ident");
CaseStatementList body;
body.push_back(create<CaseStatement>(lit, create<BlockStatement>()));
body.push_back(nullptr);
@ -131,8 +132,8 @@ TEST_F(SwitchStatementTest, IsValid_Null_BodyStatement) {
}
TEST_F(SwitchStatementTest, IsValid_Invalid_BodyStatement) {
auto* ident =
create<IdentifierExpression>(mod.RegisterSymbol("ident"), "ident");
auto* ident = create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("ident"), "ident");
auto* case_body = create<BlockStatement>();
case_body->append(nullptr);
@ -145,8 +146,8 @@ TEST_F(SwitchStatementTest, IsValid_Invalid_BodyStatement) {
}
TEST_F(SwitchStatementTest, ToStr_Empty) {
auto* ident =
create<IdentifierExpression>(mod.RegisterSymbol("ident"), "ident");
auto* ident = create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("ident"), "ident");
SwitchStatement stmt(ident, {});
std::ostringstream out;
@ -165,8 +166,8 @@ TEST_F(SwitchStatementTest, ToStr) {
CaseSelectorList lit;
lit.push_back(create<SintLiteral>(Source{}, &i32, 2));
auto* ident =
create<IdentifierExpression>(mod.RegisterSymbol("ident"), "ident");
auto* ident = create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("ident"), "ident");
CaseStatementList body;
body.push_back(create<CaseStatement>(lit, create<BlockStatement>()));

View File

@ -22,10 +22,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::TypeConstructorExpression);
namespace tint {
namespace ast {
TypeConstructorExpression::TypeConstructorExpression(type::Type* type,
ExpressionList values)
: Base(), type_(type), values_(std::move(values)) {}
TypeConstructorExpression::TypeConstructorExpression(const Source& source,
type::Type* type,
ExpressionList values)

View File

@ -28,10 +28,6 @@ namespace ast {
class TypeConstructorExpression
: public Castable<TypeConstructorExpression, ConstructorExpression> {
public:
/// Constructor
/// @param type the type
/// @param values the values
TypeConstructorExpression(type::Type* type, ExpressionList values);
/// Constructor
/// @param source the constructor source
/// @param type the type

View File

@ -32,10 +32,10 @@ using TypeConstructorExpressionTest = TestHelper;
TEST_F(TypeConstructorExpressionTest, Creation) {
type::F32 f32;
ExpressionList expr;
expr.push_back(
create<IdentifierExpression>(mod.RegisterSymbol("expr"), "expr"));
expr.push_back(create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("expr"), "expr"));
TypeConstructorExpression t(&f32, expr);
TypeConstructorExpression t(Source{}, &f32, expr);
EXPECT_EQ(t.type(), &f32);
ASSERT_EQ(t.values().size(), 1u);
EXPECT_EQ(t.values()[0], expr[0]);
@ -44,8 +44,8 @@ TEST_F(TypeConstructorExpressionTest, Creation) {
TEST_F(TypeConstructorExpressionTest, Creation_WithSource) {
type::F32 f32;
ExpressionList expr;
expr.push_back(
create<IdentifierExpression>(mod.RegisterSymbol("expr"), "expr"));
expr.push_back(create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("expr"), "expr"));
TypeConstructorExpression t(Source{Source::Location{20, 2}}, &f32, expr);
auto src = t.source();
@ -56,20 +56,20 @@ TEST_F(TypeConstructorExpressionTest, Creation_WithSource) {
TEST_F(TypeConstructorExpressionTest, IsTypeConstructor) {
type::F32 f32;
ExpressionList expr;
expr.push_back(
create<IdentifierExpression>(mod.RegisterSymbol("expr"), "expr"));
expr.push_back(create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("expr"), "expr"));
TypeConstructorExpression t(&f32, expr);
TypeConstructorExpression t(Source{}, &f32, expr);
EXPECT_TRUE(t.Is<TypeConstructorExpression>());
}
TEST_F(TypeConstructorExpressionTest, IsValid) {
type::F32 f32;
ExpressionList expr;
expr.push_back(
create<IdentifierExpression>(mod.RegisterSymbol("expr"), "expr"));
expr.push_back(create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("expr"), "expr"));
TypeConstructorExpression t(&f32, expr);
TypeConstructorExpression t(Source{}, &f32, expr);
EXPECT_TRUE(t.IsValid());
}
@ -77,36 +77,37 @@ TEST_F(TypeConstructorExpressionTest, IsValid_EmptyValue) {
type::F32 f32;
ExpressionList expr;
TypeConstructorExpression t(&f32, expr);
TypeConstructorExpression t(Source{}, &f32, expr);
EXPECT_TRUE(t.IsValid());
}
TEST_F(TypeConstructorExpressionTest, IsValid_NullType) {
ExpressionList expr;
expr.push_back(
create<IdentifierExpression>(mod.RegisterSymbol("expr"), "expr"));
expr.push_back(create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("expr"), "expr"));
TypeConstructorExpression t(nullptr, expr);
TypeConstructorExpression t(Source{}, nullptr, expr);
EXPECT_FALSE(t.IsValid());
}
TEST_F(TypeConstructorExpressionTest, IsValid_NullValue) {
type::F32 f32;
ExpressionList expr;
expr.push_back(
create<IdentifierExpression>(mod.RegisterSymbol("expr"), "expr"));
expr.push_back(create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("expr"), "expr"));
expr.push_back(nullptr);
TypeConstructorExpression t(&f32, expr);
TypeConstructorExpression t(Source{}, &f32, expr);
EXPECT_FALSE(t.IsValid());
}
TEST_F(TypeConstructorExpressionTest, IsValid_InvalidValue) {
type::F32 f32;
ExpressionList expr;
expr.push_back(create<IdentifierExpression>(mod.RegisterSymbol(""), ""));
expr.push_back(
create<IdentifierExpression>(Source{}, mod.RegisterSymbol(""), ""));
TypeConstructorExpression t(&f32, expr);
TypeConstructorExpression t(Source{}, &f32, expr);
EXPECT_FALSE(t.IsValid());
}
@ -114,14 +115,14 @@ TEST_F(TypeConstructorExpressionTest, ToStr) {
type::F32 f32;
type::Vector vec(&f32, 3);
ExpressionList expr;
expr.push_back(
create<IdentifierExpression>(mod.RegisterSymbol("expr_1"), "expr_1"));
expr.push_back(
create<IdentifierExpression>(mod.RegisterSymbol("expr_2"), "expr_2"));
expr.push_back(
create<IdentifierExpression>(mod.RegisterSymbol("expr_3"), "expr_3"));
expr.push_back(create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("expr_1"), "expr_1"));
expr.push_back(create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("expr_2"), "expr_2"));
expr.push_back(create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("expr_3"), "expr_3"));
TypeConstructorExpression t(&vec, expr);
TypeConstructorExpression t(Source{}, &vec, expr);
std::ostringstream out;
t.to_str(out, 2);
EXPECT_EQ(demangle(out.str()), R"( TypeConstructor[not set]{

View File

@ -22,9 +22,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::UnaryOpExpression);
namespace tint {
namespace ast {
UnaryOpExpression::UnaryOpExpression(UnaryOp op, Expression* expr)
: Base(), op_(op), expr_(expr) {}
UnaryOpExpression::UnaryOpExpression(const Source& source,
UnaryOp op,
Expression* expr)

View File

@ -28,10 +28,6 @@ namespace ast {
/// A unary op expression
class UnaryOpExpression : public Castable<UnaryOpExpression, Expression> {
public:
/// Constructor
/// @param op the op
/// @param expr the expr
UnaryOpExpression(UnaryOp op, Expression* expr);
/// Constructor
/// @param source the unary op expression source
/// @param op the op

View File

@ -26,17 +26,17 @@ namespace {
using UnaryOpExpressionTest = TestHelper;
TEST_F(UnaryOpExpressionTest, Creation) {
auto* ident =
create<IdentifierExpression>(mod.RegisterSymbol("ident"), "ident");
auto* ident = create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("ident"), "ident");
UnaryOpExpression u(UnaryOp::kNot, ident);
UnaryOpExpression u(Source{}, UnaryOp::kNot, ident);
EXPECT_EQ(u.op(), UnaryOp::kNot);
EXPECT_EQ(u.expr(), ident);
}
TEST_F(UnaryOpExpressionTest, Creation_WithSource) {
auto* ident =
create<IdentifierExpression>(mod.RegisterSymbol("ident"), "ident");
auto* ident = create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("ident"), "ident");
UnaryOpExpression u(Source{Source::Location{20, 2}}, UnaryOp::kNot, ident);
auto src = u.source();
EXPECT_EQ(src.range.begin.line, 20u);
@ -44,34 +44,35 @@ TEST_F(UnaryOpExpressionTest, Creation_WithSource) {
}
TEST_F(UnaryOpExpressionTest, IsUnaryOp) {
auto* ident =
create<IdentifierExpression>(mod.RegisterSymbol("ident"), "ident");
UnaryOpExpression u(UnaryOp::kNot, ident);
auto* ident = create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("ident"), "ident");
UnaryOpExpression u(Source{}, UnaryOp::kNot, ident);
EXPECT_TRUE(u.Is<UnaryOpExpression>());
}
TEST_F(UnaryOpExpressionTest, IsValid) {
auto* ident =
create<IdentifierExpression>(mod.RegisterSymbol("ident"), "ident");
UnaryOpExpression u(UnaryOp::kNot, ident);
auto* ident = create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("ident"), "ident");
UnaryOpExpression u(Source{}, UnaryOp::kNot, ident);
EXPECT_TRUE(u.IsValid());
}
TEST_F(UnaryOpExpressionTest, IsValid_NullExpression) {
UnaryOpExpression u(UnaryOp::kNot, nullptr);
UnaryOpExpression u(Source{}, UnaryOp::kNot, nullptr);
EXPECT_FALSE(u.IsValid());
}
TEST_F(UnaryOpExpressionTest, IsValid_InvalidExpression) {
auto* ident = create<IdentifierExpression>(mod.RegisterSymbol(""), "");
UnaryOpExpression u(UnaryOp::kNot, ident);
auto* ident =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol(""), "");
UnaryOpExpression u(Source{}, UnaryOp::kNot, ident);
EXPECT_FALSE(u.IsValid());
}
TEST_F(UnaryOpExpressionTest, ToStr) {
auto* ident =
create<IdentifierExpression>(mod.RegisterSymbol("ident"), "ident");
UnaryOpExpression u(UnaryOp::kNot, ident);
auto* ident = create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("ident"), "ident");
UnaryOpExpression u(Source{}, UnaryOp::kNot, ident);
std::ostringstream out;
u.to_str(out, 2);
EXPECT_EQ(demangle(out.str()), R"( UnaryOp[not set]{

View File

@ -84,7 +84,8 @@ TEST_F(VariableTest, IsValid_WithConstructor) {
StorageClass::kNone,
&t,
false,
create<IdentifierExpression>(mod.RegisterSymbol("ident"), "ident"),
create<IdentifierExpression>(Source{}, mod.RegisterSymbol("ident"),
"ident"),
ast::VariableDecorationList{}};
EXPECT_TRUE(v.IsValid());
}
@ -115,7 +116,7 @@ TEST_F(VariableTest, IsValid_InvalidConstructor) {
StorageClass::kNone,
&t,
false,
create<IdentifierExpression>(mod.RegisterSymbol(""), ""),
create<IdentifierExpression>(Source{}, mod.RegisterSymbol(""), ""),
ast::VariableDecorationList{}};
EXPECT_FALSE(v.IsValid());
}
@ -162,13 +163,14 @@ TEST_F(VariableTest, ConstantId) {
TEST_F(VariableTest, Decorated_to_str) {
type::F32 t;
auto* var = create<Variable>(
Source{}, "my_var", StorageClass::kFunction, &t, false,
create<IdentifierExpression>(mod.RegisterSymbol("expr"), "expr"),
VariableDecorationList{
create<BindingDecoration>(2, Source{}),
create<SetDecoration>(1, Source{}),
});
auto* var =
create<Variable>(Source{}, "my_var", StorageClass::kFunction, &t, false,
create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("expr"), "expr"),
VariableDecorationList{
create<BindingDecoration>(2, Source{}),
create<SetDecoration>(1, Source{}),
});
std::ostringstream out;
var->to_str(out, 2);

View File

@ -99,9 +99,9 @@ class InspectorHelper {
ast::FunctionDecorationList decorations = {}) {
auto* body = create<ast::BlockStatement>();
auto* ident_expr = create<ast::IdentifierExpression>(
mod()->RegisterSymbol(callee), callee);
auto* call_expr =
create<ast::CallExpression>(ident_expr, ast::ExpressionList());
Source{}, mod()->RegisterSymbol(callee), callee);
auto* call_expr = create<ast::CallExpression>(Source{}, ident_expr,
ast::ExpressionList());
body->append(create<ast::CallStatement>(call_expr));
body->append(create<ast::ReturnStatement>(Source{}));
return create<ast::Function>(Source{}, mod()->RegisterSymbol(caller),
@ -153,8 +153,10 @@ class InspectorHelper {
std::string in, out;
std::tie(in, out) = inout;
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(mod()->RegisterSymbol(out), out),
create<ast::IdentifierExpression>(mod()->RegisterSymbol(in), in)));
create<ast::IdentifierExpression>(Source{},
mod()->RegisterSymbol(out), out),
create<ast::IdentifierExpression>(Source{}, mod()->RegisterSymbol(in),
in)));
}
body->append(create<ast::ReturnStatement>(Source{}));
return create<ast::Function>(Source{}, mod()->RegisterSymbol(name), name,
@ -180,13 +182,15 @@ class InspectorHelper {
std::string in, out;
std::tie(in, out) = inout;
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(mod()->RegisterSymbol(out), out),
create<ast::IdentifierExpression>(mod()->RegisterSymbol(in), in)));
create<ast::IdentifierExpression>(Source{},
mod()->RegisterSymbol(out), out),
create<ast::IdentifierExpression>(Source{}, mod()->RegisterSymbol(in),
in)));
}
auto* ident_expr = create<ast::IdentifierExpression>(
mod()->RegisterSymbol(callee), callee);
auto* call_expr =
create<ast::CallExpression>(ident_expr, ast::ExpressionList());
Source{}, mod()->RegisterSymbol(callee), callee);
auto* call_expr = create<ast::CallExpression>(Source{}, ident_expr,
ast::ExpressionList());
body->append(create<ast::CallStatement>(call_expr));
body->append(create<ast::ReturnStatement>(Source{}));
return create<ast::Function>(Source{}, mod()->RegisterSymbol(caller),
@ -207,8 +211,8 @@ class InspectorHelper {
T* val) {
ast::Expression* constructor = nullptr;
if (val) {
constructor =
create<ast::ScalarConstructorExpression>(MakeLiteral(type, val));
constructor = create<ast::ScalarConstructorExpression>(
Source{}, MakeLiteral(type, val));
}
auto* var = create<ast::Variable>(
Source{}, // source
@ -445,13 +449,13 @@ class InspectorHelper {
std::string member_name = StructMemberName(member_idx, member_type);
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(
mod()->RegisterSymbol("local" + member_name),
Source{}, mod()->RegisterSymbol("local" + member_name),
"local" + member_name),
create<ast::MemberAccessorExpression>(
create<ast::MemberAccessorExpression>(Source{},
create<ast::IdentifierExpression>(
mod()->RegisterSymbol(struct_name), struct_name),
Source{}, mod()->RegisterSymbol(struct_name), struct_name),
create<ast::IdentifierExpression>(
mod()->RegisterSymbol(member_name), member_name))));
Source{}, mod()->RegisterSymbol(member_name), member_name))));
}
body->append(create<ast::ReturnStatement>(Source{}));
@ -588,19 +592,21 @@ class InspectorHelper {
ast::ExpressionList call_params;
call_params.push_back(create<ast::IdentifierExpression>(
mod()->RegisterSymbol(texture_name), texture_name));
Source{}, mod()->RegisterSymbol(texture_name), texture_name));
call_params.push_back(create<ast::IdentifierExpression>(
mod()->RegisterSymbol(sampler_name), sampler_name));
Source{}, mod()->RegisterSymbol(sampler_name), sampler_name));
call_params.push_back(create<ast::IdentifierExpression>(
mod()->RegisterSymbol(coords_name), coords_name));
Source{}, mod()->RegisterSymbol(coords_name), coords_name));
auto* call_expr = create<ast::CallExpression>(
Source{},
create<ast::IdentifierExpression>(
mod()->RegisterSymbol("textureSample"), "textureSample"),
Source{}, mod()->RegisterSymbol("textureSample"), "textureSample"),
call_params);
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(
mod()->RegisterSymbol("sampler_result"), "sampler_result"),
Source{}, mod()->RegisterSymbol("sampler_result"),
"sampler_result"),
call_expr));
body->append(create<ast::ReturnStatement>(Source{}));
@ -642,21 +648,23 @@ class InspectorHelper {
ast::ExpressionList call_params;
call_params.push_back(create<ast::IdentifierExpression>(
mod()->RegisterSymbol(texture_name), texture_name));
Source{}, mod()->RegisterSymbol(texture_name), texture_name));
call_params.push_back(create<ast::IdentifierExpression>(
mod()->RegisterSymbol(sampler_name), sampler_name));
Source{}, mod()->RegisterSymbol(sampler_name), sampler_name));
call_params.push_back(create<ast::IdentifierExpression>(
mod()->RegisterSymbol(coords_name), coords_name));
Source{}, mod()->RegisterSymbol(coords_name), coords_name));
call_params.push_back(create<ast::IdentifierExpression>(
mod()->RegisterSymbol(array_index), array_index));
Source{}, mod()->RegisterSymbol(array_index), array_index));
auto* call_expr = create<ast::CallExpression>(
Source{},
create<ast::IdentifierExpression>(
mod()->RegisterSymbol("textureSample"), "textureSample"),
Source{}, mod()->RegisterSymbol("textureSample"), "textureSample"),
call_params);
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(
mod()->RegisterSymbol("sampler_result"), "sampler_result"),
Source{}, mod()->RegisterSymbol("sampler_result"),
"sampler_result"),
call_expr));
body->append(create<ast::ReturnStatement>(Source{}));
@ -699,22 +707,24 @@ class InspectorHelper {
ast::ExpressionList call_params;
call_params.push_back(create<ast::IdentifierExpression>(
mod()->RegisterSymbol(texture_name), texture_name));
Source{}, mod()->RegisterSymbol(texture_name), texture_name));
call_params.push_back(create<ast::IdentifierExpression>(
mod()->RegisterSymbol(sampler_name), sampler_name));
Source{}, mod()->RegisterSymbol(sampler_name), sampler_name));
call_params.push_back(create<ast::IdentifierExpression>(
mod()->RegisterSymbol(coords_name), coords_name));
Source{}, mod()->RegisterSymbol(coords_name), coords_name));
call_params.push_back(create<ast::IdentifierExpression>(
mod()->RegisterSymbol(depth_name), depth_name));
Source{}, mod()->RegisterSymbol(depth_name), depth_name));
auto* call_expr = create<ast::CallExpression>(
Source{},
create<ast::IdentifierExpression>(
mod()->RegisterSymbol("textureSampleCompare"),
Source{}, mod()->RegisterSymbol("textureSampleCompare"),
"textureSampleCompare"),
call_params);
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(
mod()->RegisterSymbol("sampler_result"), "sampler_result"),
Source{}, mod()->RegisterSymbol("sampler_result"),
"sampler_result"),
call_expr));
body->append(create<ast::ReturnStatement>(Source{}));
@ -1538,9 +1548,9 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, MultipleUniformBuffers) {
auto AddFuncCall = [&](ast::BlockStatement* body, const std::string& callee) {
auto* ident_expr = create<ast::IdentifierExpression>(
mod()->RegisterSymbol(callee), callee);
auto* call_expr =
create<ast::CallExpression>(ident_expr, ast::ExpressionList());
Source{}, mod()->RegisterSymbol(callee), callee);
auto* call_expr = create<ast::CallExpression>(Source{}, ident_expr,
ast::ExpressionList());
body->append(create<ast::CallStatement>(call_expr));
};
auto* body = create<ast::BlockStatement>();
@ -1686,9 +1696,9 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, MultipleStorageBuffers) {
auto AddFuncCall = [&](ast::BlockStatement* body, const std::string& callee) {
auto* ident_expr = create<ast::IdentifierExpression>(
mod()->RegisterSymbol(callee), callee);
auto* call_expr =
create<ast::CallExpression>(ident_expr, ast::ExpressionList());
Source{}, mod()->RegisterSymbol(callee), callee);
auto* call_expr = create<ast::CallExpression>(Source{}, ident_expr,
ast::ExpressionList());
body->append(create<ast::CallStatement>(call_expr));
};
auto* body = create<ast::BlockStatement>();
@ -1861,9 +1871,9 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest,
auto AddFuncCall = [&](ast::BlockStatement* body, const std::string& callee) {
auto* ident_expr = create<ast::IdentifierExpression>(
mod()->RegisterSymbol(callee), callee);
auto* call_expr =
create<ast::CallExpression>(ident_expr, ast::ExpressionList());
Source{}, mod()->RegisterSymbol(callee), callee);
auto* call_expr = create<ast::CallExpression>(Source{}, ident_expr,
ast::ExpressionList());
body->append(create<ast::CallStatement>(call_expr));
};
auto* body = create<ast::BlockStatement>();

View File

@ -684,7 +684,7 @@ void FunctionEmitter::PushGuard(const std::string& guard_name,
const auto& top = statements_stack_.back();
auto* cond = create<ast::IdentifierExpression>(
ast_module_.RegisterSymbol(guard_name), guard_name);
Source{}, ast_module_.RegisterSymbol(guard_name), guard_name);
auto* body = create<ast::BlockStatement>();
AddStatement(
create<ast::IfStatement>(Source{}, cond, body, ast::ElseStatementList{}));
@ -1881,8 +1881,8 @@ TypedExpression FunctionEmitter::MakeExpression(uint32_t id) {
auto name = namer_.Name(id);
return TypedExpression{
parser_impl_.ConvertType(def_use_mgr_->GetDef(id)->type_id()),
create<ast::IdentifierExpression>(ast_module_.RegisterSymbol(name),
name)};
create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol(name), name)};
}
if (singly_used_values_.count(id)) {
auto expr = std::move(singly_used_values_[id]);
@ -1902,9 +1902,10 @@ TypedExpression FunctionEmitter::MakeExpression(uint32_t id) {
case SpvOpVariable: {
// This occurs for module-scope variables.
auto name = namer_.Name(inst->result_id());
return TypedExpression{parser_impl_.ConvertType(inst->type_id()),
create<ast::IdentifierExpression>(
ast_module_.RegisterSymbol(name), name)};
return TypedExpression{
parser_impl_.ConvertType(inst->type_id()),
create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol(name), name)};
}
default:
break;
@ -2571,7 +2572,7 @@ ast::Statement* FunctionEmitter::MakeBranchDetailed(
// Signal an exit from the branch.
return create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(
ast_module_.RegisterSymbol(flow_guard), flow_guard),
Source{}, ast_module_.RegisterSymbol(flow_guard), flow_guard),
MakeFalse(Source{}));
}
@ -2727,7 +2728,7 @@ bool FunctionEmitter::EmitStatementsInBasicBlock(const BlockInfo& block_info,
auto expr = MakeExpression(assignment.value);
AddStatement(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(
ast_module_.RegisterSymbol(var_name), var_name),
Source{}, ast_module_.RegisterSymbol(var_name), var_name),
expr.expr));
}
}
@ -2763,8 +2764,8 @@ bool FunctionEmitter::EmitConstDefOrWriteToHoistedVar(
auto name = namer_.Name(result_id);
// Emit an assignment of the expression to the hoisted variable.
AddStatement(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(ast_module_.RegisterSymbol(name),
namer_.Name(result_id)),
create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol(name), namer_.Name(result_id)),
ast_expr.expr));
return true;
}
@ -2854,10 +2855,11 @@ bool FunctionEmitter::EmitStatement(const spvtools::opt::Instruction& inst) {
}
case SpvOpPhi: {
// Emit a read from the associated state variable.
TypedExpression expr{parser_impl_.ConvertType(inst.type_id()),
create<ast::IdentifierExpression>(
ast_module_.RegisterSymbol(def_info->phi_var),
def_info->phi_var)};
TypedExpression expr{
parser_impl_.ConvertType(inst.type_id()),
create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol(def_info->phi_var),
def_info->phi_var)};
return EmitConstDefOrWriteToHoistedVar(inst, expr);
}
case SpvOpFunctionCall:
@ -2891,8 +2893,8 @@ TypedExpression FunctionEmitter::MaybeEmitCombinatorialValue(
if (binary_op != ast::BinaryOp::kNone) {
auto arg0 = MakeOperand(inst, 0);
auto arg1 = MakeOperand(inst, 1);
auto* binary_expr =
create<ast::BinaryExpression>(binary_op, arg0.expr, arg1.expr);
auto* binary_expr = create<ast::BinaryExpression>(Source{}, binary_op,
arg0.expr, arg1.expr);
TypedExpression result{ast_type, binary_expr};
return parser_impl_.RectifyForcedResultType(result, inst, arg0.type);
}
@ -2900,7 +2902,8 @@ TypedExpression FunctionEmitter::MaybeEmitCombinatorialValue(
auto unary_op = ast::UnaryOp::kNegation;
if (GetUnaryOp(opcode, &unary_op)) {
auto arg0 = MakeOperand(inst, 0);
auto* unary_expr = create<ast::UnaryOpExpression>(unary_op, arg0.expr);
auto* unary_expr =
create<ast::UnaryOpExpression>(Source{}, unary_op, arg0.expr);
TypedExpression result{ast_type, unary_expr};
return parser_impl_.RectifyForcedResultType(result, inst, arg0.type);
}
@ -2909,11 +2912,13 @@ TypedExpression FunctionEmitter::MaybeEmitCombinatorialValue(
if (unary_builtin_name != nullptr) {
ast::ExpressionList params;
params.emplace_back(MakeOperand(inst, 0).expr);
return {ast_type, create<ast::CallExpression>(
create<ast::IdentifierExpression>(
ast_module_.RegisterSymbol(unary_builtin_name),
unary_builtin_name),
std::move(params))};
return {ast_type,
create<ast::CallExpression>(
Source{},
create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol(unary_builtin_name),
unary_builtin_name),
std::move(params))};
}
const auto intrinsic = GetIntrinsic(opcode);
@ -2927,17 +2932,17 @@ TypedExpression FunctionEmitter::MaybeEmitCombinatorialValue(
if (opcode == SpvOpBitcast) {
return {ast_type, create<ast::BitcastExpression>(
ast_type, MakeOperand(inst, 0).expr)};
Source{}, ast_type, MakeOperand(inst, 0).expr)};
}
auto negated_op = NegatedFloatCompare(opcode);
if (negated_op != ast::BinaryOp::kNone) {
auto arg0 = MakeOperand(inst, 0);
auto arg1 = MakeOperand(inst, 1);
auto* binary_expr =
create<ast::BinaryExpression>(negated_op, arg0.expr, arg1.expr);
auto* negated_expr =
create<ast::UnaryOpExpression>(ast::UnaryOp::kNot, binary_expr);
auto* binary_expr = create<ast::BinaryExpression>(Source{}, negated_op,
arg0.expr, arg1.expr);
auto* negated_expr = create<ast::UnaryOpExpression>(
Source{}, ast::UnaryOp::kNot, binary_expr);
return {ast_type, negated_expr};
}
@ -2956,7 +2961,7 @@ TypedExpression FunctionEmitter::MaybeEmitCombinatorialValue(
operands.emplace_back(MakeOperand(inst, iarg).expr);
}
return {ast_type, create<ast::TypeConstructorExpression>(
ast_type, std::move(operands))};
Source{}, ast_type, std::move(operands))};
}
if (opcode == SpvOpCompositeExtract) {
@ -3013,8 +3018,8 @@ TypedExpression FunctionEmitter::EmitGlslStd450ExtInst(
return {};
}
auto* func =
create<ast::IdentifierExpression>(ast_module_.RegisterSymbol(name), name);
auto* func = create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol(name), name);
ast::ExpressionList operands;
ast::type::Type* first_operand_type = nullptr;
// All parameters to GLSL.std.450 extended instructions are IDs.
@ -3026,7 +3031,7 @@ TypedExpression FunctionEmitter::EmitGlslStd450ExtInst(
operands.emplace_back(operand.expr);
}
auto* ast_type = parser_impl_.ConvertType(inst.type_id());
auto* call = create<ast::CallExpression>(func, std::move(operands));
auto* call = create<ast::CallExpression>(Source{}, func, std::move(operands));
TypedExpression call_expr{ast_type, call};
return parser_impl_.RectifyForcedResultType(call_expr, inst,
first_operand_type);
@ -3040,20 +3045,20 @@ ast::IdentifierExpression* FunctionEmitter::Swizzle(uint32_t i) {
}
const char* names[] = {"x", "y", "z", "w"};
return create<ast::IdentifierExpression>(
ast_module_.RegisterSymbol(names[i & 3]), names[i & 3]);
Source{}, ast_module_.RegisterSymbol(names[i & 3]), names[i & 3]);
}
ast::IdentifierExpression* FunctionEmitter::PrefixSwizzle(uint32_t n) {
switch (n) {
case 1:
return create<ast::IdentifierExpression>(ast_module_.RegisterSymbol("x"),
"x");
return create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol("x"), "x");
case 2:
return create<ast::IdentifierExpression>(ast_module_.RegisterSymbol("xy"),
"xy");
return create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol("xy"), "xy");
case 3:
return create<ast::IdentifierExpression>(
ast_module_.RegisterSymbol("xyz"), "xyz");
Source{}, ast_module_.RegisterSymbol("xyz"), "xyz");
default:
break;
}
@ -3125,7 +3130,7 @@ TypedExpression FunctionEmitter::MakeAccessChain(
auto name = namer_.Name(base_id);
current_expr.expr = create<ast::IdentifierExpression>(
ast_module_.RegisterSymbol(name), name);
Source{}, ast_module_.RegisterSymbol(name), name);
current_expr.type = parser_impl_.ConvertType(ptr_ty_id);
}
}
@ -3174,11 +3179,11 @@ TypedExpression FunctionEmitter::MakeAccessChain(
<< " is too big. Max handled index is " << kMaxVectorLen - 1;
}
next_expr = create<ast::MemberAccessorExpression>(
current_expr.expr, Swizzle(uint32_t(index_const_val)));
Source{}, current_expr.expr, Swizzle(uint32_t(index_const_val)));
} else {
// Non-constant index. Use array syntax
next_expr = create<ast::ArrayAccessorExpression>(
current_expr.expr, MakeOperand(inst, index).expr);
Source{}, current_expr.expr, MakeOperand(inst, index).expr);
}
// All vector components are the same type.
pointee_type_id = pointee_type_inst->GetSingleWordInOperand(0);
@ -3186,18 +3191,18 @@ TypedExpression FunctionEmitter::MakeAccessChain(
case SpvOpTypeMatrix:
// Use array syntax.
next_expr = create<ast::ArrayAccessorExpression>(
current_expr.expr, MakeOperand(inst, index).expr);
Source{}, current_expr.expr, MakeOperand(inst, index).expr);
// All matrix components are the same type.
pointee_type_id = pointee_type_inst->GetSingleWordInOperand(0);
break;
case SpvOpTypeArray:
next_expr = create<ast::ArrayAccessorExpression>(
current_expr.expr, MakeOperand(inst, index).expr);
Source{}, current_expr.expr, MakeOperand(inst, index).expr);
pointee_type_id = pointee_type_inst->GetSingleWordInOperand(0);
break;
case SpvOpTypeRuntimeArray:
next_expr = create<ast::ArrayAccessorExpression>(
current_expr.expr, MakeOperand(inst, index).expr);
Source{}, current_expr.expr, MakeOperand(inst, index).expr);
pointee_type_id = pointee_type_inst->GetSingleWordInOperand(0);
break;
case SpvOpTypeStruct: {
@ -3218,10 +3223,10 @@ TypedExpression FunctionEmitter::MakeAccessChain(
auto name =
namer_.GetMemberName(pointee_type_id, uint32_t(index_const_val));
auto* member_access = create<ast::IdentifierExpression>(
ast_module_.RegisterSymbol(name), name);
Source{}, ast_module_.RegisterSymbol(name), name);
next_expr = create<ast::MemberAccessorExpression>(current_expr.expr,
member_access);
next_expr = create<ast::MemberAccessorExpression>(
Source{}, current_expr.expr, member_access);
pointee_type_id = pointee_type_inst->GetSingleWordInOperand(
static_cast<uint32_t>(index_const_val));
break;
@ -3251,12 +3256,13 @@ TypedExpression FunctionEmitter::MakeCompositeExtract(
// this as ever-deeper nested indexing expressions. Start off with an
// expression for the composite, and then bury that inside nested indexing
// expressions.
auto source = GetSourceForInst(inst);
TypedExpression current_expr(MakeOperand(inst, 0));
auto make_index = [this](uint32_t literal) {
auto make_index = [this, source](uint32_t literal) {
auto* type = create<ast::type::U32>();
return create<ast::ScalarConstructorExpression>(
create<ast::UintLiteral>(Source{}, type, literal));
source, create<ast::UintLiteral>(source, type, literal));
};
const auto composite = inst.GetSingleWordInOperand(0);
@ -3291,8 +3297,8 @@ TypedExpression FunctionEmitter::MakeCompositeExtract(
Fail() << "internal error: swizzle index " << index_val
<< " is too big. Max handled index is " << kMaxVectorLen - 1;
}
next_expr = create<ast::MemberAccessorExpression>(current_expr.expr,
Swizzle(index_val));
next_expr = create<ast::MemberAccessorExpression>(
Source{}, current_expr.expr, Swizzle(index_val));
// All vector components are the same type.
current_type_id = current_type_inst->GetSingleWordInOperand(0);
break;
@ -3311,8 +3317,8 @@ TypedExpression FunctionEmitter::MakeCompositeExtract(
<< " is too big. Max handled index is " << kMaxVectorLen - 1;
}
// Use array syntax.
next_expr = create<ast::ArrayAccessorExpression>(current_expr.expr,
make_index(index_val));
next_expr = create<ast::ArrayAccessorExpression>(
Source{}, current_expr.expr, make_index(index_val));
// All matrix components are the same type.
current_type_id = current_type_inst->GetSingleWordInOperand(0);
break;
@ -3321,8 +3327,8 @@ TypedExpression FunctionEmitter::MakeCompositeExtract(
// The array size could be a spec constant, and so it's not always
// statically checkable. Instead, rely on a runtime index clamp
// or runtime check to keep this safe.
next_expr = create<ast::ArrayAccessorExpression>(current_expr.expr,
make_index(index_val));
next_expr = create<ast::ArrayAccessorExpression>(
Source{}, current_expr.expr, make_index(index_val));
current_type_id = current_type_inst->GetSingleWordInOperand(0);
break;
case SpvOpTypeRuntimeArray:
@ -3338,10 +3344,10 @@ TypedExpression FunctionEmitter::MakeCompositeExtract(
}
auto name = namer_.GetMemberName(current_type_id, uint32_t(index_val));
auto* member_access = create<ast::IdentifierExpression>(
ast_module_.RegisterSymbol(name), name);
Source{}, ast_module_.RegisterSymbol(name), name);
next_expr = create<ast::MemberAccessorExpression>(current_expr.expr,
member_access);
next_expr = create<ast::MemberAccessorExpression>(
Source{}, current_expr.expr, member_access);
current_type_id = current_type_inst->GetSingleWordInOperand(index_val);
break;
}
@ -3358,13 +3364,13 @@ TypedExpression FunctionEmitter::MakeCompositeExtract(
ast::Expression* FunctionEmitter::MakeTrue(const Source& source) const {
return create<ast::ScalarConstructorExpression>(
create<ast::BoolLiteral>(source, parser_impl_.Bool(), true));
source, create<ast::BoolLiteral>(source, parser_impl_.Bool(), true));
}
ast::Expression* FunctionEmitter::MakeFalse(const Source& source) const {
ast::type::Bool bool_type;
return create<ast::ScalarConstructorExpression>(
create<ast::BoolLiteral>(source, parser_impl_.Bool(), false));
source, create<ast::BoolLiteral>(source, parser_impl_.Bool(), false));
}
TypedExpression FunctionEmitter::MakeVectorShuffle(
@ -3382,6 +3388,7 @@ TypedExpression FunctionEmitter::MakeVectorShuffle(
// Generate an ast::TypeConstructor expression.
// Assume the literal indices are valid, and there is a valid number of them.
auto source = GetSourceForInst(inst);
ast::type::Vector* result_type =
parser_impl_.ConvertType(inst.type_id())->As<ast::type::Vector>();
ast::ExpressionList values;
@ -3389,12 +3396,12 @@ TypedExpression FunctionEmitter::MakeVectorShuffle(
const auto index = inst.GetSingleWordInOperand(i);
if (index < vec0_len) {
values.emplace_back(create<ast::MemberAccessorExpression>(
MakeExpression(vec0_id).expr, Swizzle(index)));
source, MakeExpression(vec0_id).expr, Swizzle(index)));
} else if (index < vec0_len + vec1_len) {
const auto sub_index = index - vec0_len;
assert(sub_index < kMaxVectorLen);
values.emplace_back(create<ast::MemberAccessorExpression>(
MakeExpression(vec1_id).expr, Swizzle(sub_index)));
source, MakeExpression(vec1_id).expr, Swizzle(sub_index)));
} else if (index == 0xFFFFFFFF) {
// By rule, this maps to OpUndef. Instead, make it zero.
values.emplace_back(parser_impl_.MakeNullValue(result_type->type()));
@ -3405,7 +3412,7 @@ TypedExpression FunctionEmitter::MakeVectorShuffle(
}
}
return {result_type,
create<ast::TypeConstructorExpression>(result_type, values)};
create<ast::TypeConstructorExpression>(source, result_type, values)};
}
bool FunctionEmitter::RegisterLocallyDefinedValues() {
@ -3706,27 +3713,29 @@ TypedExpression FunctionEmitter::MakeNumericConversion(
ast::ExpressionList params;
params.push_back(arg_expr.expr);
TypedExpression result{expr_type, create<ast::TypeConstructorExpression>(
expr_type, std::move(params))};
TypedExpression result{
expr_type, create<ast::TypeConstructorExpression>(Source{}, expr_type,
std::move(params))};
if (requested_type == expr_type) {
return result;
}
return {requested_type,
create<ast::BitcastExpression>(requested_type, result.expr)};
return {requested_type, create<ast::BitcastExpression>(
Source{}, requested_type, result.expr)};
}
bool FunctionEmitter::EmitFunctionCall(const spvtools::opt::Instruction& inst) {
// We ignore function attributes such as Inline, DontInline, Pure, Const.
auto name = namer_.Name(inst.GetSingleWordInOperand(0));
auto* function =
create<ast::IdentifierExpression>(ast_module_.RegisterSymbol(name), name);
auto* function = create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol(name), name);
ast::ExpressionList params;
for (uint32_t iarg = 1; iarg < inst.NumInOperands(); ++iarg) {
params.emplace_back(MakeOperand(inst, iarg).expr);
}
auto* call_expr = create<ast::CallExpression>(function, std::move(params));
auto* call_expr =
create<ast::CallExpression>(Source{}, function, std::move(params));
auto* result_type = parser_impl_.ConvertType(inst.type_id());
if (!result_type) {
return Fail() << "internal error: no mapped type result of call: "
@ -3746,8 +3755,8 @@ TypedExpression FunctionEmitter::MakeIntrinsicCall(
std::ostringstream ss;
ss << intrinsic;
auto name = ss.str();
auto* ident =
create<ast::IdentifierExpression>(ast_module_.RegisterSymbol(name), name);
auto* ident = create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol(name), name);
ident->set_intrinsic(intrinsic);
ast::ExpressionList params;
@ -3759,7 +3768,8 @@ TypedExpression FunctionEmitter::MakeIntrinsicCall(
}
params.emplace_back(operand.expr);
}
auto* call_expr = create<ast::CallExpression>(ident, std::move(params));
auto* call_expr =
create<ast::CallExpression>(Source{}, ident, std::move(params));
auto* result_type = parser_impl_.ConvertType(inst.type_id());
if (!result_type) {
Fail() << "internal error: no mapped type result of call: "
@ -3790,9 +3800,9 @@ TypedExpression FunctionEmitter::MakeSimpleSelect(
// The condition goes last.
params.push_back(condition.expr);
return {operand1.type,
create<ast::CallExpression>(
create<ast::CallExpression>(Source{},
create<ast::IdentifierExpression>(
ast_module_.RegisterSymbol("select"), "select"),
Source{}, ast_module_.RegisterSymbol("select"), "select"),
std::move(params))};
}
return {};
@ -3818,7 +3828,7 @@ bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) {
}
auto name = namer_.Name(image->result_id());
params.push_back(create<ast::IdentifierExpression>(
ast_module_.RegisterSymbol(name), name));
Source{}, ast_module_.RegisterSymbol(name), name));
if (IsSampledImageAccess(inst.opcode())) {
// Form the sampler operand.
@ -3830,7 +3840,7 @@ bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) {
}
auto param_name = namer_.Name(sampler->result_id());
params.push_back(create<ast::IdentifierExpression>(
ast_module_.RegisterSymbol(param_name), param_name));
Source{}, ast_module_.RegisterSymbol(param_name), param_name));
}
ast::type::Pointer* texture_ptr_type =
@ -3937,7 +3947,7 @@ bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) {
if (texture_type->Is<ast::type::DepthTexture>()) {
// Convert it to a signed integer type.
lod_operand = create<ast::TypeConstructorExpression>(
create<ast::type::I32>(), ast::ExpressionList{lod_operand});
Source{}, create<ast::type::I32>(), ast::ExpressionList{lod_operand});
}
params.push_back(lod_operand);
image_operands_mask ^= SpvImageOperandsLodMask;
@ -3970,8 +3980,9 @@ bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) {
}
auto* ident = create<ast::IdentifierExpression>(
ast_module_.RegisterSymbol(builtin_name), builtin_name);
auto* call_expr = create<ast::CallExpression>(ident, std::move(params));
Source{}, ast_module_.RegisterSymbol(builtin_name), builtin_name);
auto* call_expr =
create<ast::CallExpression>(Source{}, ident, std::move(params));
if (inst.type_id() != 0) {
// It returns a value.
@ -3996,7 +4007,7 @@ bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) {
if (expected_component_type != result_component_type) {
// This occurs if one is signed integer and the other is unsigned integer,
// or vice versa. Perform a bitcast.
value = create<ast::BitcastExpression>(result_type, call_expr);
value = create<ast::BitcastExpression>(Source{}, result_type, call_expr);
}
EmitConstDefOrWriteToHoistedVar(inst, {result_type, value});
@ -4112,14 +4123,14 @@ ast::ExpressionList FunctionEmitter::MakeCoordinateOperandsForImageAccess(
// array component. Use a vector swizzle to get the first `num_axes`
// components.
result.push_back(create<ast::MemberAccessorExpression>(
raw_coords.expr, PrefixSwizzle(num_axes)));
Source{}, raw_coords.expr, PrefixSwizzle(num_axes)));
// Now get the array index.
ast::Expression* array_index = create<ast::MemberAccessorExpression>(
raw_coords.expr, Swizzle(num_axes));
Source{}, raw_coords.expr, Swizzle(num_axes));
// Convert it to a signed integer type.
result.push_back(create<ast::TypeConstructorExpression>(
create<ast::type::I32>(), ast::ExpressionList{array_index}));
Source{}, create<ast::type::I32>(), ast::ExpressionList{array_index}));
} else {
if (num_coords_supplied == num_coords_required) {
// Pass the value through.
@ -4128,7 +4139,7 @@ ast::ExpressionList FunctionEmitter::MakeCoordinateOperandsForImageAccess(
// There are more coordinates supplied than needed. So the source type is
// a vector. Use a vector swizzle to get the first `num_axes` components.
result.push_back(create<ast::MemberAccessorExpression>(
raw_coords.expr, PrefixSwizzle(num_axes)));
Source{}, raw_coords.expr, PrefixSwizzle(num_axes)));
}
}
return result;
@ -4173,7 +4184,7 @@ ast::Expression* FunctionEmitter::ConvertTexelForStorage(
// higher-numbered components.
auto* texel_prefix = (src_count == dest_count)
? texel.expr
: create<ast::MemberAccessorExpression>(
: create<ast::MemberAccessorExpression>(Source{},
texel.expr, PrefixSwizzle(dest_count));
if (!(dest_type->is_float_scalar_or_vector() ||
@ -4216,7 +4227,7 @@ ast::Expression* FunctionEmitter::ConvertTexelForStorage(
return texel_prefix;
}
// We must do a bitcast conversion.
return create<ast::BitcastExpression>(dest_type, texel_prefix);
return create<ast::BitcastExpression>(Source{}, dest_type, texel_prefix);
}
TypedExpression FunctionEmitter::ToI32(TypedExpression value) {
@ -4224,7 +4235,7 @@ TypedExpression FunctionEmitter::ToI32(TypedExpression value) {
return value;
}
return {i32_, create<ast::TypeConstructorExpression>(
i32_, ast::ExpressionList{value.expr})};
Source{}, i32_, ast::ExpressionList{value.expr})};
}
FunctionEmitter::FunctionDeclaration::FunctionDeclaration() = default;

View File

@ -1031,27 +1031,31 @@ bool ParserImpl::EmitScalarSpecConstants() {
case SpvOpSpecConstantTrue:
case SpvOpSpecConstantFalse: {
ast_type = ConvertType(inst.type_id());
ast_expr =
create<ast::ScalarConstructorExpression>(create<ast::BoolLiteral>(
Source{}, ast_type, inst.opcode() == SpvOpSpecConstantTrue));
ast_expr = create<ast::ScalarConstructorExpression>(
Source{},
create<ast::BoolLiteral>(Source{}, ast_type,
inst.opcode() == SpvOpSpecConstantTrue));
break;
}
case SpvOpSpecConstant: {
ast_type = ConvertType(inst.type_id());
const uint32_t literal_value = inst.GetSingleWordInOperand(0);
if (ast_type->Is<ast::type::I32>()) {
ast_expr =
create<ast::ScalarConstructorExpression>(create<ast::SintLiteral>(
Source{}, ast_type, static_cast<int32_t>(literal_value)));
ast_expr = create<ast::ScalarConstructorExpression>(
Source{},
create<ast::SintLiteral>(Source{}, ast_type,
static_cast<int32_t>(literal_value)));
} else if (ast_type->Is<ast::type::U32>()) {
ast_expr =
create<ast::ScalarConstructorExpression>(create<ast::UintLiteral>(
Source{}, ast_type, static_cast<uint32_t>(literal_value)));
ast_expr = create<ast::ScalarConstructorExpression>(
Source{},
create<ast::UintLiteral>(Source{}, ast_type,
static_cast<uint32_t>(literal_value)));
} else if (ast_type->Is<ast::type::F32>()) {
float float_value;
// Copy the bits so we can read them as a float.
std::memcpy(&float_value, &literal_value, sizeof(float_value));
ast_expr = create<ast::ScalarConstructorExpression>(
Source{},
create<ast::FloatLiteral>(Source{}, ast_type, float_value));
} else {
return Fail() << " invalid result type for OpSpecConstant "
@ -1323,25 +1327,29 @@ TypedExpression ParserImpl::MakeConstantExpression(uint32_t id) {
// See https://bugs.chromium.org/p/tint/issues/detail?id=34
if (ast_type->Is<ast::type::U32>()) {
return {ast_type,
create<ast::ScalarConstructorExpression>(create<ast::UintLiteral>(
source, ast_type, spirv_const->GetU32()))};
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::UintLiteral>(source, ast_type,
spirv_const->GetU32()))};
}
if (ast_type->Is<ast::type::I32>()) {
return {ast_type,
create<ast::ScalarConstructorExpression>(create<ast::SintLiteral>(
source, ast_type, spirv_const->GetS32()))};
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(source, ast_type,
spirv_const->GetS32()))};
}
if (ast_type->Is<ast::type::F32>()) {
return {ast_type,
create<ast::ScalarConstructorExpression>(create<ast::FloatLiteral>(
source, ast_type, spirv_const->GetFloat()))};
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(source, ast_type,
spirv_const->GetFloat()))};
}
if (ast_type->Is<ast::type::Bool>()) {
const bool value = spirv_const->AsNullConstant()
? false
: spirv_const->AsBoolConstant()->value();
return {ast_type, create<ast::ScalarConstructorExpression>(
create<ast::BoolLiteral>(source, ast_type, value))};
return {ast_type,
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::BoolLiteral>(source, ast_type, value))};
}
auto* spirv_composite_const = spirv_const->AsCompositeConstant();
if (spirv_composite_const != nullptr) {
@ -1367,7 +1375,7 @@ TypedExpression ParserImpl::MakeConstantExpression(uint32_t id) {
ast_components.emplace_back(ast_component.expr);
}
return {original_ast_type,
create<ast::TypeConstructorExpression>(original_ast_type,
create<ast::TypeConstructorExpression>(Source{}, original_ast_type,
std::move(ast_components))};
}
auto* spirv_null_const = spirv_const->AsNullConstant();
@ -1395,26 +1403,26 @@ ast::Expression* ParserImpl::MakeNullValue(ast::type::Type* type) {
if (type->Is<ast::type::Bool>()) {
return create<ast::ScalarConstructorExpression>(
create<ast::BoolLiteral>(Source{}, type, false));
Source{}, create<ast::BoolLiteral>(Source{}, type, false));
}
if (type->Is<ast::type::U32>()) {
return create<ast::ScalarConstructorExpression>(
create<ast::UintLiteral>(Source{}, type, 0u));
Source{}, create<ast::UintLiteral>(Source{}, type, 0u));
}
if (type->Is<ast::type::I32>()) {
return create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, type, 0));
Source{}, create<ast::SintLiteral>(Source{}, type, 0));
}
if (type->Is<ast::type::F32>()) {
return create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, type, 0.0f));
Source{}, create<ast::FloatLiteral>(Source{}, type, 0.0f));
}
if (const auto* vec_ty = type->As<ast::type::Vector>()) {
ast::ExpressionList ast_components;
for (size_t i = 0; i < vec_ty->size(); ++i) {
ast_components.emplace_back(MakeNullValue(vec_ty->type()));
}
return create<ast::TypeConstructorExpression>(type,
return create<ast::TypeConstructorExpression>(Source{}, type,
std::move(ast_components));
}
if (const auto* mat_ty = type->As<ast::type::Matrix>()) {
@ -1425,7 +1433,7 @@ ast::Expression* ParserImpl::MakeNullValue(ast::type::Type* type) {
for (size_t i = 0; i < mat_ty->columns(); ++i) {
ast_components.emplace_back(MakeNullValue(column_ty));
}
return create<ast::TypeConstructorExpression>(type,
return create<ast::TypeConstructorExpression>(Source{}, type,
std::move(ast_components));
}
if (auto* arr_ty = type->As<ast::type::Array>()) {
@ -1433,7 +1441,7 @@ ast::Expression* ParserImpl::MakeNullValue(ast::type::Type* type) {
for (size_t i = 0; i < arr_ty->size(); ++i) {
ast_components.emplace_back(MakeNullValue(arr_ty->type()));
}
return create<ast::TypeConstructorExpression>(original_type,
return create<ast::TypeConstructorExpression>(Source{}, original_type,
std::move(ast_components));
}
if (auto* struct_ty = type->As<ast::type::Struct>()) {
@ -1441,7 +1449,7 @@ ast::Expression* ParserImpl::MakeNullValue(ast::type::Type* type) {
for (auto* member : struct_ty->impl()->members()) {
ast_components.emplace_back(MakeNullValue(member->type()));
}
return create<ast::TypeConstructorExpression>(original_type,
return create<ast::TypeConstructorExpression>(Source{}, original_type,
std::move(ast_components));
}
Fail() << "can't make null value for type: " << type->type_name();
@ -1481,13 +1489,14 @@ TypedExpression ParserImpl::RectifyOperandSignedness(
if (unsigned_ty != nullptr) {
// Conversion is required.
return {unsigned_ty,
create<ast::BitcastExpression>(unsigned_ty, expr.expr)};
create<ast::BitcastExpression>(Source{}, unsigned_ty, expr.expr)};
}
} else if (requires_signed) {
auto* signed_ty = signed_type_for_[type];
if (signed_ty != nullptr) {
// Conversion is required.
return {signed_ty, create<ast::BitcastExpression>(signed_ty, expr.expr)};
return {signed_ty,
create<ast::BitcastExpression>(Source{}, signed_ty, expr.expr)};
}
}
// We should not reach here.
@ -1555,7 +1564,8 @@ TypedExpression ParserImpl::RectifyForcedResultType(
if ((forced_result_ty == nullptr) || (forced_result_ty == expr.type)) {
return expr;
}
return {expr.type, create<ast::BitcastExpression>(expr.type, expr.expr)};
return {expr.type,
create<ast::BitcastExpression>(Source{}, expr.type, expr.expr)};
}
bool ParserImpl::EmitFunctions() {

View File

@ -2028,7 +2028,8 @@ Maybe<ast::CallStatement*> ParserImpl::func_call_stmt() {
return create<ast::CallStatement>(create<ast::CallExpression>(
source,
create<ast::IdentifierExpression>(module_.RegisterSymbol(name), name),
create<ast::IdentifierExpression>(Source{}, module_.RegisterSymbol(name),
name),
std::move(params)));
}

View File

@ -131,22 +131,23 @@ ast::ArrayAccessorExpression* BoundArrayAccessors::Transform(
cast_expr.push_back(ctx->Clone(expr->idx_expr()));
ast::ExpressionList params;
params.push_back(
ctx->mod->create<ast::TypeConstructorExpression>(u32, cast_expr));
params.push_back(ctx->mod->create<ast::TypeConstructorExpression>(
Source{}, u32, cast_expr));
params.push_back(ctx->mod->create<ast::ScalarConstructorExpression>(
ctx->mod->create<ast::UintLiteral>(Source{}, u32, size - 1)));
Source{}, ctx->mod->create<ast::UintLiteral>(Source{}, u32, size - 1)));
auto* call_expr = ctx->mod->create<ast::CallExpression>(
Source{},
ctx->mod->create<ast::IdentifierExpression>(
ctx->mod->RegisterSymbol("min"), "min"),
Source{}, ctx->mod->RegisterSymbol("min"), "min"),
std::move(params));
call_expr->set_result_type(u32);
idx_expr = call_expr;
}
auto* arr = ctx->Clone(expr->array());
return ctx->mod->create<ast::ArrayAccessorExpression>(arr, idx_expr);
return ctx->mod->create<ast::ArrayAccessorExpression>(
ctx->Clone(expr->source()), ctx->Clone(expr->array()), idx_expr);
}
} // namespace transform

View File

@ -65,7 +65,7 @@ Transform::Output EmitVertexPointSize::Run(ast::Module* in) {
mod->AddGlobalVariable(pointsize_var);
// Build the AST expression & statement for assigning pointsize one.
auto* one = mod->create<ast::ScalarConstructorExpression>(
auto* one = mod->create<ast::ScalarConstructorExpression>(Source{},
mod->create<ast::FloatLiteral>(Source{}, f32, 1.0f));
auto* pointsize_ident = mod->create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol(kPointSizeVar), kPointSizeVar);

View File

@ -252,15 +252,16 @@ ast::VariableDeclStatement* FirstIndexOffset::CreateFirstIndexOffset(
ast::Variable* buffer_var,
ast::Module* mod) {
auto* buffer = mod->create<ast::IdentifierExpression>(
mod->RegisterSymbol(buffer_var->name()), buffer_var->name());
Source{}, mod->RegisterSymbol(buffer_var->name()), buffer_var->name());
auto* constructor = mod->create<ast::BinaryExpression>(
ast::BinaryOp::kAdd,
Source{}, ast::BinaryOp::kAdd,
mod->create<ast::IdentifierExpression>(
mod->RegisterSymbol(kIndexOffsetPrefix + original_name),
Source{}, mod->RegisterSymbol(kIndexOffsetPrefix + original_name),
kIndexOffsetPrefix + original_name),
mod->create<ast::MemberAccessorExpression>(
buffer, mod->create<ast::IdentifierExpression>(
mod->RegisterSymbol(field_name), field_name)));
Source{}, buffer,
mod->create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol(field_name), field_name)));
auto* var =
mod->create<ast::Variable>(Source{}, // source
original_name, // name

View File

@ -74,8 +74,9 @@ TEST_F(FirstIndexOffsetTest, Error_AlreadyTransformed) {
void Build() override {
AddBuiltinInput("vert_idx", ast::Builtin::kVertexIdx);
AddFunction("test")->body()->append(create<ast::ReturnStatement>(
Source{}, create<ast::IdentifierExpression>(
mod->RegisterSymbol("vert_idx"), "vert_idx")));
Source{},
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("vert_idx"), "vert_idx")));
}
};
@ -116,8 +117,9 @@ TEST_F(FirstIndexOffsetTest, BasicModuleVertexIndex) {
void Build() override {
AddBuiltinInput("vert_idx", ast::Builtin::kVertexIdx);
AddFunction("test")->body()->append(create<ast::ReturnStatement>(
Source{}, create<ast::IdentifierExpression>(
mod->RegisterSymbol("vert_idx"), "vert_idx")));
Source{},
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("vert_idx"), "vert_idx")));
}
};
@ -193,8 +195,9 @@ TEST_F(FirstIndexOffsetTest, BasicModuleInstanceIndex) {
void Build() override {
AddBuiltinInput("inst_idx", ast::Builtin::kInstanceIdx);
AddFunction("test")->body()->append(create<ast::ReturnStatement>(
Source{}, create<ast::IdentifierExpression>(
mod->RegisterSymbol("inst_idx"), "inst_idx")));
Source{},
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("inst_idx"), "inst_idx")));
}
};
@ -347,13 +350,15 @@ TEST_F(FirstIndexOffsetTest, NestedCalls) {
AddBuiltinInput("vert_idx", ast::Builtin::kVertexIdx);
ast::Function* func1 = AddFunction("func1");
func1->body()->append(create<ast::ReturnStatement>(
Source{}, create<ast::IdentifierExpression>(
mod->RegisterSymbol("vert_idx"), "vert_idx")));
Source{},
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("vert_idx"), "vert_idx")));
ast::Function* func2 = AddFunction("func2");
func2->body()->append(create<ast::ReturnStatement>(
Source{}, create<ast::CallExpression>(
Source{},
create<ast::IdentifierExpression>(
mod->RegisterSymbol("func1"), "func1"),
Source{}, mod->RegisterSymbol("func1"), "func1"),
ast::ExpressionList{})));
}
};

View File

@ -326,13 +326,13 @@ void VertexPulling::State::AddVertexPullingPreamble(
: instance_index_name;
// Identifier to index by
auto* index_identifier = mod->create<ast::IdentifierExpression>(
mod->RegisterSymbol(name), name);
Source{}, mod->RegisterSymbol(name), name);
// An expression for the start of the read in the buffer in bytes
auto* pos_value = mod->create<ast::BinaryExpression>(
ast::BinaryOp::kAdd,
Source{}, ast::BinaryOp::kAdd,
mod->create<ast::BinaryExpression>(
ast::BinaryOp::kMultiply, index_identifier,
Source{}, ast::BinaryOp::kMultiply, index_identifier,
GenUint(static_cast<uint32_t>(buffer_layout.array_stride))),
GenUint(static_cast<uint32_t>(attribute_desc.offset)));
@ -342,8 +342,8 @@ void VertexPulling::State::AddVertexPullingPreamble(
block->append(set_pos_expr);
block->append(mod->create<ast::AssignmentStatement>(
mod->create<ast::IdentifierExpression>(mod->RegisterSymbol(v->name()),
v->name()),
mod->create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol(v->name()), v->name()),
AccessByFormat(i, attribute_desc.format)));
}
}
@ -353,12 +353,12 @@ void VertexPulling::State::AddVertexPullingPreamble(
ast::Expression* VertexPulling::State::GenUint(uint32_t value) {
return mod->create<ast::ScalarConstructorExpression>(
mod->create<ast::UintLiteral>(Source{}, GetU32Type(), value));
Source{}, mod->create<ast::UintLiteral>(Source{}, GetU32Type(), value));
}
ast::Expression* VertexPulling::State::CreatePullingPositionIdent() {
return mod->create<ast::IdentifierExpression>(
mod->RegisterSymbol(kPullingPosVarName), kPullingPosVarName);
Source{}, mod->RegisterSymbol(kPullingPosVarName), kPullingPosVarName);
}
ast::Expression* VertexPulling::State::AccessByFormat(uint32_t buffer,
@ -397,26 +397,29 @@ ast::Expression* VertexPulling::State::AccessU32(uint32_t buffer,
// base case.
auto vbuf_name = GetVertexBufferName(buffer);
return mod->create<ast::ArrayAccessorExpression>(
Source{},
mod->create<ast::MemberAccessorExpression>(
mod->create<ast::IdentifierExpression>(mod->RegisterSymbol(vbuf_name),
vbuf_name),
Source{},
mod->create<ast::IdentifierExpression>(
mod->RegisterSymbol(kStructBufferName), kStructBufferName)),
mod->create<ast::BinaryExpression>(ast::BinaryOp::kDivide, pos,
Source{}, mod->RegisterSymbol(vbuf_name), vbuf_name),
mod->create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol(kStructBufferName),
kStructBufferName)),
mod->create<ast::BinaryExpression>(Source{}, ast::BinaryOp::kDivide, pos,
GenUint(4)));
}
ast::Expression* VertexPulling::State::AccessI32(uint32_t buffer,
ast::Expression* pos) {
// as<T> reinterprets bits
return mod->create<ast::BitcastExpression>(GetI32Type(),
return mod->create<ast::BitcastExpression>(Source{}, GetI32Type(),
AccessU32(buffer, pos));
}
ast::Expression* VertexPulling::State::AccessF32(uint32_t buffer,
ast::Expression* pos) {
// as<T> reinterprets bits
return mod->create<ast::BitcastExpression>(GetF32Type(),
return mod->create<ast::BitcastExpression>(Source{}, GetF32Type(),
AccessU32(buffer, pos));
}
@ -448,13 +451,14 @@ ast::Expression* VertexPulling::State::AccessVec(uint32_t buffer,
for (uint32_t i = 0; i < count; ++i) {
// Offset read position by element_stride for each component
auto* cur_pos = mod->create<ast::BinaryExpression>(
ast::BinaryOp::kAdd, CreatePullingPositionIdent(),
Source{}, ast::BinaryOp::kAdd, CreatePullingPositionIdent(),
GenUint(element_stride * i));
expr_list.push_back(AccessPrimitive(buffer, cur_pos, base_format));
}
return mod->create<ast::TypeConstructorExpression>(
mod->create<ast::type::Vector>(base_type, count), std::move(expr_list));
Source{}, mod->create<ast::type::Vector>(base_type, count),
std::move(expr_list));
}
ast::type::Type* VertexPulling::State::GetU32Type() {

File diff suppressed because it is too large Load Diff

View File

@ -50,6 +50,7 @@ TEST_F(ValidateControlBlockTest, SwitchSelectorExpressionNoneIntegerType_Fail) {
&f32, // type
false, // is_const
create<ast::ScalarConstructorExpression>(
Source{},
create<ast::SintLiteral>(Source{}, &f32, 3.14f)), // constructor
ast::VariableDecorationList{}); // decorations
@ -84,11 +85,12 @@ TEST_F(ValidateControlBlockTest, SwitchWithoutDefault_Fail) {
&i32, // type
false, // is_const
create<ast::ScalarConstructorExpression>(
Source{},
create<ast::SintLiteral>(Source{}, &i32, 2)), // constructor
ast::VariableDecorationList{}); // decorations
auto* cond =
create<ast::IdentifierExpression>(mod()->RegisterSymbol("a"), "a");
auto* cond = create<ast::IdentifierExpression>(
Source{}, mod()->RegisterSymbol("a"), "a");
ast::CaseSelectorList csl;
csl.push_back(create<ast::SintLiteral>(Source{}, &i32, 1));
ast::CaseStatementList body;
@ -122,12 +124,13 @@ TEST_F(ValidateControlBlockTest, SwitchWithTwoDefault_Fail) {
&i32, // type
false, // is_const
create<ast::ScalarConstructorExpression>(
Source{},
create<ast::SintLiteral>(Source{}, &i32, 2)), // constructor
ast::VariableDecorationList{}); // decorations
ast::CaseStatementList switch_body;
auto* cond =
create<ast::IdentifierExpression>(mod()->RegisterSymbol("a"), "a");
auto* cond = create<ast::IdentifierExpression>(
Source{}, mod()->RegisterSymbol("a"), "a");
ast::CaseSelectorList default_csl_1;
auto* block_default_1 = create<ast::BlockStatement>();
@ -172,12 +175,13 @@ TEST_F(ValidateControlBlockTest,
&i32, // type
false, // is_const
create<ast::ScalarConstructorExpression>(
Source{},
create<ast::SintLiteral>(Source{}, &i32, 2)), // constructor
ast::VariableDecorationList{}); // decorations
ast::CaseStatementList switch_body;
auto* cond =
create<ast::IdentifierExpression>(mod()->RegisterSymbol("a"), "a");
auto* cond = create<ast::IdentifierExpression>(
Source{}, mod()->RegisterSymbol("a"), "a");
ast::CaseSelectorList csl;
csl.push_back(create<ast::UintLiteral>(Source{}, &u32, 1));
@ -215,12 +219,13 @@ TEST_F(ValidateControlBlockTest,
&u32, // type
false, // is_const
create<ast::ScalarConstructorExpression>(
Source{},
create<ast::UintLiteral>(Source{}, &u32, 2)), // constructor
ast::VariableDecorationList{}); // decorations
ast::CaseStatementList switch_body;
auto* cond =
create<ast::IdentifierExpression>(mod()->RegisterSymbol("a"), "a");
auto* cond = create<ast::IdentifierExpression>(
Source{}, mod()->RegisterSymbol("a"), "a");
ast::CaseSelectorList csl;
csl.push_back(create<ast::SintLiteral>(Source{}, &i32, -1));
@ -257,12 +262,13 @@ TEST_F(ValidateControlBlockTest, NonUniqueCaseSelectorValueUint_Fail) {
&u32, // type
false, // is_const
create<ast::ScalarConstructorExpression>(
Source{},
create<ast::UintLiteral>(Source{}, &u32, 3)), // constructor
ast::VariableDecorationList{}); // decorations
ast::CaseStatementList switch_body;
auto* cond =
create<ast::IdentifierExpression>(mod()->RegisterSymbol("a"), "a");
auto* cond = create<ast::IdentifierExpression>(
Source{}, mod()->RegisterSymbol("a"), "a");
ast::CaseSelectorList csl_1;
csl_1.push_back(create<ast::UintLiteral>(Source{}, &u32, 0));
@ -305,12 +311,13 @@ TEST_F(ValidateControlBlockTest, NonUniqueCaseSelectorValueSint_Fail) {
&i32, // type
false, // is_const
create<ast::ScalarConstructorExpression>(
Source{},
create<ast::SintLiteral>(Source{}, &i32, 2)), // constructor
ast::VariableDecorationList{}); // decorations
ast::CaseStatementList switch_body;
auto* cond =
create<ast::IdentifierExpression>(mod()->RegisterSymbol("a"), "a");
auto* cond = create<ast::IdentifierExpression>(
Source{}, mod()->RegisterSymbol("a"), "a");
ast::CaseSelectorList csl_1;
csl_1.push_back(create<ast::SintLiteral>(Source{}, &i32, 10));
@ -353,11 +360,12 @@ TEST_F(ValidateControlBlockTest, LastClauseLastStatementIsFallthrough_Fail) {
&i32, // type
false, // is_const
create<ast::ScalarConstructorExpression>(
Source{},
create<ast::SintLiteral>(Source{}, &i32, 2)), // constructor
ast::VariableDecorationList{}); // decorations
auto* cond =
create<ast::IdentifierExpression>(mod()->RegisterSymbol("a"), "a");
auto* cond = create<ast::IdentifierExpression>(
Source{}, mod()->RegisterSymbol("a"), "a");
ast::CaseSelectorList default_csl;
auto* block_default = create<ast::BlockStatement>();
block_default->append(
@ -390,11 +398,12 @@ TEST_F(ValidateControlBlockTest, SwitchCase_Pass) {
&i32, // type
false, // is_const
create<ast::ScalarConstructorExpression>(
Source{},
create<ast::SintLiteral>(Source{}, &i32, 2)), // constructor
ast::VariableDecorationList{}); // decorations
auto* cond =
create<ast::IdentifierExpression>(mod()->RegisterSymbol("a"), "a");
auto* cond = create<ast::IdentifierExpression>(
Source{}, mod()->RegisterSymbol("a"), "a");
ast::CaseSelectorList default_csl;
auto* block_default = create<ast::BlockStatement>();
ast::CaseStatementList body;
@ -430,11 +439,12 @@ TEST_F(ValidateControlBlockTest, SwitchCaseAlias_Pass) {
&my_int, // type
false, // is_const
create<ast::ScalarConstructorExpression>(
Source{},
create<ast::SintLiteral>(Source{}, &u32, 2)), // constructor
ast::VariableDecorationList{}); // decorations
auto* cond =
create<ast::IdentifierExpression>(mod()->RegisterSymbol("a"), "a");
auto* cond = create<ast::IdentifierExpression>(
Source{}, mod()->RegisterSymbol("a"), "a");
ast::CaseSelectorList default_csl;
auto* block_default = create<ast::BlockStatement>();
ast::CaseStatementList body;

View File

@ -46,6 +46,7 @@ TEST_F(ValidateFunctionTest, VoidFunctionEndWithoutReturnStatement_Pass) {
&i32, // type
false, // is_const
create<ast::ScalarConstructorExpression>(
Source{},
create<ast::SintLiteral>(Source{}, &i32, 2)), // constructor
ast::VariableDecorationList{}); // decorations
@ -94,6 +95,7 @@ TEST_F(ValidateFunctionTest, FunctionEndWithoutReturnStatement_Fail) {
&i32, // type
false, // is_const
create<ast::ScalarConstructorExpression>(
Source{},
create<ast::SintLiteral>(Source{}, &i32, 2)), // constructor
ast::VariableDecorationList{}); // decorations
@ -155,7 +157,7 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementType_fail) {
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
auto* return_expr = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 2));
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
body->append(create<ast::ReturnStatement>(Source{Source::Location{12, 34}},
return_expr));
@ -179,7 +181,7 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementTypeF32_fail) {
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
auto* return_expr = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 2));
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
body->append(create<ast::ReturnStatement>(Source{Source::Location{12, 34}},
return_expr));
@ -205,7 +207,7 @@ TEST_F(ValidateFunctionTest, FunctionNamesMustBeUnique_fail) {
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
auto* return_expr = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 2));
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
body->append(create<ast::ReturnStatement>(Source{}, return_expr));
auto* func =
@ -215,7 +217,7 @@ TEST_F(ValidateFunctionTest, FunctionNamesMustBeUnique_fail) {
ast::VariableList params_copy;
auto* body_copy = create<ast::BlockStatement>();
auto* return_expr_copy = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 2));
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
body_copy->append(create<ast::ReturnStatement>(Source{}, return_expr_copy));
auto* func_copy = create<ast::Function>(
@ -237,7 +239,8 @@ TEST_F(ValidateFunctionTest, RecursionIsNotAllowed_Fail) {
ast::ExpressionList call_params;
auto* call_expr = create<ast::CallExpression>(
Source{Source::Location{12, 34}},
create<ast::IdentifierExpression>(mod()->RegisterSymbol("func"), "func"),
create<ast::IdentifierExpression>(Source{}, mod()->RegisterSymbol("func"),
"func"),
call_params);
ast::VariableList params0;
auto* body0 = create<ast::BlockStatement>();
@ -259,7 +262,8 @@ TEST_F(ValidateFunctionTest, RecursionIsNotAllowedExpr_Fail) {
ast::ExpressionList call_params;
auto* call_expr = create<ast::CallExpression>(
Source{Source::Location{12, 34}},
create<ast::IdentifierExpression>(mod()->RegisterSymbol("func"), "func"),
create<ast::IdentifierExpression>(Source{}, mod()->RegisterSymbol("func"),
"func"),
call_params);
auto* var =
create<ast::Variable>(Source{}, // source
@ -274,7 +278,7 @@ TEST_F(ValidateFunctionTest, RecursionIsNotAllowedExpr_Fail) {
auto* body0 = create<ast::BlockStatement>();
body0->append(create<ast::VariableDeclStatement>(var));
auto* return_expr = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 2));
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
body0->append(create<ast::ReturnStatement>(Source{}, return_expr));
auto* func0 = create<ast::Function>(Source{}, mod()->RegisterSymbol("func"),
@ -293,7 +297,7 @@ TEST_F(ValidateFunctionTest, Function_WithPipelineStage_NotVoid_Fail) {
ast::type::I32 i32;
ast::VariableList params;
auto* return_expr = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 0));
Source{}, create<ast::SintLiteral>(Source{}, &i32, 0));
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>(Source{}, return_expr));

View File

@ -65,9 +65,9 @@ TEST_F(ValidatorTest, DISABLED_AssignToScalar_Fail) {
ast::type::I32 i32;
auto* lhs = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 1));
auto* rhs = create<ast::IdentifierExpression>(mod()->RegisterSymbol("my_var"),
"my_var");
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1));
auto* rhs = create<ast::IdentifierExpression>(
Source{}, mod()->RegisterSymbol("my_var"), "my_var");
ast::AssignmentStatement assign(Source{Source::Location{12, 34}}, lhs, rhs);
// TODO(sarahM0): Invalidate assignment to scalar.
@ -83,7 +83,7 @@ TEST_F(ValidatorTest, UsingUndefinedVariable_Fail) {
auto* lhs = create<ast::IdentifierExpression>(
Source{Source::Location{12, 34}}, mod()->RegisterSymbol("b"), "b");
auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 2));
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
auto* assign = create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, lhs, rhs);
@ -101,7 +101,7 @@ TEST_F(ValidatorTest, UsingUndefinedVariableInBlockStatement_Fail) {
auto* lhs = create<ast::IdentifierExpression>(
Source{Source::Location{12, 34}}, mod()->RegisterSymbol("b"), "b");
auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 2));
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>(
@ -123,13 +123,14 @@ TEST_F(ValidatorTest, AssignCompatibleTypes_Pass) {
&i32, // type
false, // is_const
create<ast::ScalarConstructorExpression>(
Source{},
create<ast::SintLiteral>(Source{}, &i32, 2)), // constructor
ast::VariableDecorationList{}); // decorations
auto* lhs =
create<ast::IdentifierExpression>(mod()->RegisterSymbol("a"), "a");
auto* lhs = create<ast::IdentifierExpression>(
Source{}, mod()->RegisterSymbol("a"), "a");
auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 2));
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
ast::AssignmentStatement assign(Source{Source::Location{12, 34}}, lhs, rhs);
td()->RegisterVariableForTesting(var);
@ -154,13 +155,14 @@ TEST_F(ValidatorTest, AssignIncompatibleTypes_Fail) {
&i32, // type
false, // is_const
create<ast::ScalarConstructorExpression>(
Source{},
create<ast::SintLiteral>(Source{}, &i32, 2)), // constructor
ast::VariableDecorationList{}); // decorations
auto* lhs =
create<ast::IdentifierExpression>(mod()->RegisterSymbol("a"), "a");
auto* lhs = create<ast::IdentifierExpression>(
Source{}, mod()->RegisterSymbol("a"), "a");
auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 2.3f));
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.3f));
ast::AssignmentStatement assign(Source{Source::Location{12, 34}}, lhs, rhs);
td()->RegisterVariableForTesting(var);
@ -188,13 +190,14 @@ TEST_F(ValidatorTest, AssignCompatibleTypesInBlockStatement_Pass) {
&i32, // type
false, // is_const
create<ast::ScalarConstructorExpression>(
Source{},
create<ast::SintLiteral>(Source{}, &i32, 2)), // constructor
ast::VariableDecorationList{}); // decorations
auto* lhs =
create<ast::IdentifierExpression>(mod()->RegisterSymbol("a"), "a");
auto* lhs = create<ast::IdentifierExpression>(
Source{}, mod()->RegisterSymbol("a"), "a");
auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 2));
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var));
@ -223,12 +226,13 @@ TEST_F(ValidatorTest, AssignIncompatibleTypesInBlockStatement_Fail) {
&i32, // type
false, // is_const
create<ast::ScalarConstructorExpression>(
Source{},
create<ast::SintLiteral>(Source{}, &i32, 2)), // constructor
ast::VariableDecorationList{}); // decorations
auto* lhs =
create<ast::IdentifierExpression>(mod()->RegisterSymbol("a"), "a");
auto* lhs = create<ast::IdentifierExpression>(
Source{}, mod()->RegisterSymbol("a"), "a");
auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 2.3f));
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.3f));
ast::BlockStatement block;
block.append(create<ast::VariableDeclStatement>(var));
@ -324,6 +328,7 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Fail) {
&f32, // type
false, // is_const
create<ast::ScalarConstructorExpression>(
Source{},
create<ast::FloatLiteral>(Source{}, &f32, 2.1)), // constructor
ast::VariableDecorationList{})); // decorations
@ -331,7 +336,7 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Fail) {
Source{Source::Location{12, 34}}, mod()->RegisterSymbol("not_global_var"),
"not_global_var");
auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 3.14f));
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 3.14f));
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
@ -363,13 +368,14 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Pass) {
&f32, // type
false, // is_const
create<ast::ScalarConstructorExpression>(
Source{},
create<ast::FloatLiteral>(Source{}, &f32, 2.1)), // constructor
ast::VariableDecorationList{})); // decorations
auto* lhs = create<ast::IdentifierExpression>(
mod()->RegisterSymbol("global_var"), "global_var");
Source{}, mod()->RegisterSymbol("global_var"), "global_var");
auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 3.14f));
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 3.14f));
ast::VariableList params;
@ -402,19 +408,20 @@ TEST_F(ValidatorTest, UsingUndefinedVariableInnerScope_Fail) {
&f32, // type
false, // is_const
create<ast::ScalarConstructorExpression>(
Source{},
create<ast::FloatLiteral>(Source{}, &f32, 2.0)), // constructor
ast::VariableDecorationList{}); // decorations
ast::type::Bool bool_type;
auto* cond = create<ast::ScalarConstructorExpression>(
create<ast::BoolLiteral>(Source{}, &bool_type, true));
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var));
auto* lhs = create<ast::IdentifierExpression>(
Source{Source::Location{12, 34}}, mod()->RegisterSymbol("a"), "a");
auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 3.14f));
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 3.14f));
auto* outer_body = create<ast::BlockStatement>();
outer_body->append(
@ -442,17 +449,18 @@ TEST_F(ValidatorTest, UsingUndefinedVariableOuterScope_Pass) {
&f32, // type
false, // is_const
create<ast::ScalarConstructorExpression>(
Source{},
create<ast::FloatLiteral>(Source{}, &f32, 2.0)), // constructor
ast::VariableDecorationList{}); // decorations
auto* lhs = create<ast::IdentifierExpression>(
Source{Source::Location{12, 34}}, mod()->RegisterSymbol("a"), "a");
auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 3.14f));
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 3.14f));
ast::type::Bool bool_type;
auto* cond = create<ast::ScalarConstructorExpression>(
create<ast::BoolLiteral>(Source{}, &bool_type, true));
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, lhs, rhs));
@ -479,6 +487,7 @@ TEST_F(ValidatorTest, GlobalVariableUnique_Pass) {
&f32, // type
false, // is_const
create<ast::ScalarConstructorExpression>(
Source{},
create<ast::FloatLiteral>(Source{}, &f32, 0.1)), // constructor
ast::VariableDecorationList{}); // decorations
mod()->AddGlobalVariable(var0);
@ -490,6 +499,7 @@ TEST_F(ValidatorTest, GlobalVariableUnique_Pass) {
&f32, // type
false, // is_const
create<ast::ScalarConstructorExpression>(
Source{},
create<ast::SintLiteral>(Source{}, &i32, 0)), // constructor
ast::VariableDecorationList{}); // decorations
mod()->AddGlobalVariable(var1);
@ -510,6 +520,7 @@ TEST_F(ValidatorTest, GlobalVariableNotUnique_Fail) {
&f32, // type
false, // is_const
create<ast::ScalarConstructorExpression>(
Source{},
create<ast::FloatLiteral>(Source{}, &f32, 0.1)), // constructor
ast::VariableDecorationList{}); // decorations
mod()->AddGlobalVariable(var0);
@ -521,6 +532,7 @@ TEST_F(ValidatorTest, GlobalVariableNotUnique_Fail) {
&f32, // type
false, // is_const
create<ast::ScalarConstructorExpression>(
Source{},
create<ast::SintLiteral>(Source{}, &i32, 0)), // constructor
ast::VariableDecorationList{}); // decorations
mod()->AddGlobalVariable(var1);
@ -543,13 +555,14 @@ TEST_F(ValidatorTest, AssignToConstant_Fail) {
&i32, // type
true, // is_const
create<ast::ScalarConstructorExpression>(
Source{},
create<ast::SintLiteral>(Source{}, &i32, 2)), // constructor
ast::VariableDecorationList{}); // decorations
auto* lhs =
create<ast::IdentifierExpression>(mod()->RegisterSymbol("a"), "a");
auto* lhs = create<ast::IdentifierExpression>(
Source{}, mod()->RegisterSymbol("a"), "a");
auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 2));
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var));
@ -580,6 +593,7 @@ TEST_F(ValidatorTest, GlobalVariableFunctionVariableNotUnique_Fail) {
&f32, // type
false, // is_const
create<ast::ScalarConstructorExpression>(
Source{},
create<ast::FloatLiteral>(Source{}, &f32, 2.1)), // constructor
ast::VariableDecorationList{}); // decorations
mod()->AddGlobalVariable(global_var);
@ -591,6 +605,7 @@ TEST_F(ValidatorTest, GlobalVariableFunctionVariableNotUnique_Fail) {
&f32, // type
false, // is_const
create<ast::ScalarConstructorExpression>(
Source{},
create<ast::FloatLiteral>(Source{}, &f32, 2.0)), // constructor
ast::VariableDecorationList{}); // decorations
ast::VariableList params;
@ -624,6 +639,7 @@ TEST_F(ValidatorTest, RedeclaredIndentifier_Fail) {
&i32, // type
false, // is_const
create<ast::ScalarConstructorExpression>(
Source{},
create<ast::SintLiteral>(Source{}, &i32, 2)), // constructor
ast::VariableDecorationList{}); // decorations
@ -634,6 +650,7 @@ TEST_F(ValidatorTest, RedeclaredIndentifier_Fail) {
&f32, // type
false, // is_const
create<ast::ScalarConstructorExpression>(
Source{},
create<ast::FloatLiteral>(Source{}, &f32, 0.1)), // constructor
ast::VariableDecorationList{}); // decorations
@ -667,12 +684,13 @@ TEST_F(ValidatorTest, RedeclaredIdentifierInnerScope_Pass) {
&f32, // type
false, // is_const
create<ast::ScalarConstructorExpression>(
Source{},
create<ast::FloatLiteral>(Source{}, &f32, 2.0)), // constructor
ast::VariableDecorationList{}); // decorations
ast::type::Bool bool_type;
auto* cond = create<ast::ScalarConstructorExpression>(
create<ast::BoolLiteral>(Source{}, &bool_type, true));
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var));
@ -683,6 +701,7 @@ TEST_F(ValidatorTest, RedeclaredIdentifierInnerScope_Pass) {
&f32, // type
false, // is_const
create<ast::ScalarConstructorExpression>(
Source{},
create<ast::FloatLiteral>(Source{}, &f32, 3.14)), // constructor
ast::VariableDecorationList{}); // decorations
@ -711,6 +730,7 @@ TEST_F(ValidatorTest, DISABLED_RedeclaredIdentifierInnerScope_False) {
&f32, // type
false, // is_const
create<ast::ScalarConstructorExpression>(
Source{},
create<ast::FloatLiteral>(Source{}, &f32, 3.14)), // constructor
ast::VariableDecorationList{}); // decorations
@ -721,12 +741,13 @@ TEST_F(ValidatorTest, DISABLED_RedeclaredIdentifierInnerScope_False) {
&f32, // type
false, // is_const
create<ast::ScalarConstructorExpression>(
Source{},
create<ast::FloatLiteral>(Source{}, &f32, 2.0)), // constructor
ast::VariableDecorationList{}); // decorations
ast::type::Bool bool_type;
auto* cond = create<ast::ScalarConstructorExpression>(
create<ast::BoolLiteral>(Source{}, &bool_type, true));
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(
Source{Source::Location{12, 34}}, var));
@ -753,6 +774,7 @@ TEST_F(ValidatorTest, RedeclaredIdentifierDifferentFunctions_Pass) {
&f32, // type
false, // is_const
create<ast::ScalarConstructorExpression>(
Source{},
create<ast::FloatLiteral>(Source{}, &f32, 2.0)), // constructor
ast::VariableDecorationList{}); // decorations
@ -763,6 +785,7 @@ TEST_F(ValidatorTest, RedeclaredIdentifierDifferentFunctions_Pass) {
&void_type, // type
false, // is_const
create<ast::ScalarConstructorExpression>(
Source{},
create<ast::FloatLiteral>(Source{}, &f32, 1.0)), // constructor
ast::VariableDecorationList{}); // decorations
@ -810,10 +833,10 @@ TEST_F(ValidatorTest, VariableDeclNoConstructor_Pass) {
ast::VariableDecorationList{}); // decorations
td()->RegisterVariableForTesting(var);
auto* lhs =
create<ast::IdentifierExpression>(mod()->RegisterSymbol("a"), "a");
auto* lhs = create<ast::IdentifierExpression>(
Source{}, mod()->RegisterSymbol("a"), "a");
auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 2));
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var));

View File

@ -55,7 +55,7 @@ bool AppendVector(
}
// Cast scalar to the vector element type
ast::TypeConstructorExpression scalar_cast(packed_el_ty, {scalar});
ast::TypeConstructorExpression scalar_cast(Source{}, packed_el_ty, {scalar});
scalar_cast.set_result_type(packed_el_ty);
ast::type::Vector packed_ty(packed_el_ty, packed_size);
@ -74,7 +74,8 @@ bool AppendVector(
packed.emplace_back(scalar);
}
ast::TypeConstructorExpression constructor{&packed_ty, std::move(packed)};
ast::TypeConstructorExpression constructor{Source{}, &packed_ty,
std::move(packed)};
constructor.set_result_type(&packed_ty);
return callback(&constructor);

View File

@ -780,7 +780,7 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& pre,
auto emit_vector_appended_with_i32_zero = [&](tint::ast::Expression* vector) {
auto* i32 = module_->create<ast::type::I32>();
ast::SintLiteral zero_lit(Source{}, i32, 0);
ast::ScalarConstructorExpression zero(&zero_lit);
ast::ScalarConstructorExpression zero(Source{}, &zero_lit);
zero.set_result_type(i32);
return AppendVector(vector, &zero,
[&](ast::TypeConstructorExpression* packed) {

View File

@ -32,23 +32,23 @@ using HlslGeneratorImplTest_Expression = TestHelper;
TEST_F(HlslGeneratorImplTest_Expression, EmitExpression_ArrayAccessor) {
ast::type::I32 i32;
auto* lit = create<ast::SintLiteral>(Source{}, &i32, 5);
auto* idx = create<ast::ScalarConstructorExpression>(lit);
auto* ary =
create<ast::IdentifierExpression>(mod.RegisterSymbol("ary"), "ary");
auto* idx = create<ast::ScalarConstructorExpression>(Source{}, lit);
auto* ary = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("ary"), "ary");
ast::ArrayAccessorExpression expr(ary, idx);
ast::ArrayAccessorExpression expr(Source{}, ary, idx);
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(), "ary[5]");
}
TEST_F(HlslGeneratorImplTest_Expression, EmitArrayAccessor) {
auto* ary =
create<ast::IdentifierExpression>(mod.RegisterSymbol("ary"), "ary");
auto* idx =
create<ast::IdentifierExpression>(mod.RegisterSymbol("idx"), "idx");
auto* ary = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("ary"), "ary");
auto* idx = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("idx"), "idx");
ast::ArrayAccessorExpression expr(ary, idx);
ast::ArrayAccessorExpression expr(Source{}, ary, idx);
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(), "ary[idx]");

View File

@ -28,10 +28,10 @@ namespace {
using HlslGeneratorImplTest_Assign = TestHelper;
TEST_F(HlslGeneratorImplTest_Assign, Emit_Assign) {
auto* lhs =
create<ast::IdentifierExpression>(mod.RegisterSymbol("lhs"), "lhs");
auto* rhs =
create<ast::IdentifierExpression>(mod.RegisterSymbol("rhs"), "rhs");
auto* lhs = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("lhs"), "lhs");
auto* rhs = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("rhs"), "rhs");
ast::AssignmentStatement assign(lhs, rhs);
gen.increment_indent();

View File

@ -79,15 +79,15 @@ TEST_P(HlslBinaryTest, Emit_f32) {
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
auto* left =
create<ast::IdentifierExpression>(mod.RegisterSymbol("left"), "left");
auto* right =
create<ast::IdentifierExpression>(mod.RegisterSymbol("right"), "right");
auto* left = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("left"), "left");
auto* right = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("right"), "right");
td.RegisterVariableForTesting(left_var);
td.RegisterVariableForTesting(right_var);
ast::BinaryExpression expr(params.op, left, right);
ast::BinaryExpression expr(Source{}, params.op, left, right);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
@ -115,15 +115,15 @@ TEST_P(HlslBinaryTest, Emit_u32) {
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
auto* left =
create<ast::IdentifierExpression>(mod.RegisterSymbol("left"), "left");
auto* right =
create<ast::IdentifierExpression>(mod.RegisterSymbol("right"), "right");
auto* left = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("left"), "left");
auto* right = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("right"), "right");
td.RegisterVariableForTesting(left_var);
td.RegisterVariableForTesting(right_var);
ast::BinaryExpression expr(params.op, left, right);
ast::BinaryExpression expr(Source{}, params.op, left, right);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
@ -151,15 +151,15 @@ TEST_P(HlslBinaryTest, Emit_i32) {
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
auto* left =
create<ast::IdentifierExpression>(mod.RegisterSymbol("left"), "left");
auto* right =
create<ast::IdentifierExpression>(mod.RegisterSymbol("right"), "right");
auto* left = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("left"), "left");
auto* right = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("right"), "right");
td.RegisterVariableForTesting(left_var);
td.RegisterVariableForTesting(right_var);
ast::BinaryExpression expr(params.op, left, right);
ast::BinaryExpression expr(Source{}, params.op, left, right);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
@ -191,19 +191,20 @@ TEST_F(HlslGeneratorImplTest_Binary, Multiply_VectorScalar) {
ast::type::Vector vec3(&f32, 3);
auto* lhs = create<ast::TypeConstructorExpression>(
&vec3, ast::ExpressionList{
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 1.f)),
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 1.f)),
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 1.f)),
});
Source{}, &vec3,
ast::ExpressionList{
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)),
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)),
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)),
});
auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 1.f));
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f));
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, lhs, rhs);
ast::BinaryExpression expr(Source{}, ast::BinaryOp::kMultiply, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
EXPECT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
@ -217,18 +218,18 @@ TEST_F(HlslGeneratorImplTest_Binary, Multiply_ScalarVector) {
ast::type::Vector vec3(&f32, 3);
auto* lhs = create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 1.f));
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f));
ast::ExpressionList vals;
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 1.f)));
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)));
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 1.f)));
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)));
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 1.f)));
auto* rhs = create<ast::TypeConstructorExpression>(&vec3, vals);
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)));
auto* rhs = create<ast::TypeConstructorExpression>(Source{}, &vec3, vals);
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, lhs, rhs);
ast::BinaryExpression expr(Source{}, ast::BinaryOp::kMultiply, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
EXPECT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
@ -249,14 +250,14 @@ TEST_F(HlslGeneratorImplTest_Binary, Multiply_MatrixScalar) {
false, // is_const
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
auto* lhs =
create<ast::IdentifierExpression>(mod.RegisterSymbol("mat"), "mat");
auto* lhs = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("mat"), "mat");
auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 1.f));
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f));
td.RegisterVariableForTesting(var);
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, lhs, rhs);
ast::BinaryExpression expr(Source{}, ast::BinaryOp::kMultiply, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
EXPECT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
@ -276,13 +277,13 @@ TEST_F(HlslGeneratorImplTest_Binary, Multiply_ScalarMatrix) {
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
auto* lhs = create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 1.f));
auto* rhs =
create<ast::IdentifierExpression>(mod.RegisterSymbol("mat"), "mat");
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f));
auto* rhs = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("mat"), "mat");
td.RegisterVariableForTesting(var);
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, lhs, rhs);
ast::BinaryExpression expr(Source{}, ast::BinaryOp::kMultiply, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
EXPECT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
@ -302,21 +303,21 @@ TEST_F(HlslGeneratorImplTest_Binary, Multiply_MatrixVector) {
false, // is_const
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
auto* lhs =
create<ast::IdentifierExpression>(mod.RegisterSymbol("mat"), "mat");
auto* lhs = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("mat"), "mat");
ast::ExpressionList vals;
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 1.f)));
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)));
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 1.f)));
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)));
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 1.f)));
auto* rhs = create<ast::TypeConstructorExpression>(&vec3, vals);
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)));
auto* rhs = create<ast::TypeConstructorExpression>(Source{}, &vec3, vals);
td.RegisterVariableForTesting(var);
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, lhs, rhs);
ast::BinaryExpression expr(Source{}, ast::BinaryOp::kMultiply, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
EXPECT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
@ -339,19 +340,19 @@ TEST_F(HlslGeneratorImplTest_Binary, Multiply_VectorMatrix) {
ast::ExpressionList vals;
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 1.f)));
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)));
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 1.f)));
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)));
vals.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 1.f)));
auto* lhs = create<ast::TypeConstructorExpression>(&vec3, vals);
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)));
auto* lhs = create<ast::TypeConstructorExpression>(Source{}, &vec3, vals);
auto* rhs =
create<ast::IdentifierExpression>(mod.RegisterSymbol("mat"), "mat");
auto* rhs = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("mat"), "mat");
td.RegisterVariableForTesting(var);
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, lhs, rhs);
ast::BinaryExpression expr(Source{}, ast::BinaryOp::kMultiply, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
EXPECT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
@ -371,14 +372,14 @@ TEST_F(HlslGeneratorImplTest_Binary, Multiply_MatrixMatrix) {
false, // is_const
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
auto* lhs =
create<ast::IdentifierExpression>(mod.RegisterSymbol("mat"), "mat");
auto* rhs =
create<ast::IdentifierExpression>(mod.RegisterSymbol("mat"), "mat");
auto* lhs = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("mat"), "mat");
auto* rhs = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("mat"), "mat");
td.RegisterVariableForTesting(var);
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, lhs, rhs);
ast::BinaryExpression expr(Source{}, ast::BinaryOp::kMultiply, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
EXPECT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
@ -386,12 +387,12 @@ TEST_F(HlslGeneratorImplTest_Binary, Multiply_MatrixMatrix) {
}
TEST_F(HlslGeneratorImplTest_Binary, Logical_And) {
auto* left =
create<ast::IdentifierExpression>(mod.RegisterSymbol("left"), "left");
auto* right =
create<ast::IdentifierExpression>(mod.RegisterSymbol("right"), "right");
auto* left = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("left"), "left");
auto* right = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("right"), "right");
ast::BinaryExpression expr(ast::BinaryOp::kLogicalAnd, left, right);
ast::BinaryExpression expr(Source{}, ast::BinaryOp::kLogicalAnd, left, right);
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(), "(_tint_tmp)");
@ -404,15 +405,19 @@ if (_tint_tmp) {
TEST_F(HlslGeneratorImplTest_Binary, Logical_Multi) {
// (a && b) || (c || d)
auto* a = create<ast::IdentifierExpression>(mod.RegisterSymbol("a"), "a");
auto* b = create<ast::IdentifierExpression>(mod.RegisterSymbol("b"), "b");
auto* c = create<ast::IdentifierExpression>(mod.RegisterSymbol("c"), "c");
auto* d = create<ast::IdentifierExpression>(mod.RegisterSymbol("d"), "d");
auto* a =
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("a"), "a");
auto* b =
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("b"), "b");
auto* c =
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("c"), "c");
auto* d =
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("d"), "d");
ast::BinaryExpression expr(
ast::BinaryOp::kLogicalOr,
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, a, b),
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr, c, d));
Source{}, ast::BinaryOp::kLogicalOr,
create<ast::BinaryExpression>(Source{}, ast::BinaryOp::kLogicalAnd, a, b),
create<ast::BinaryExpression>(Source{}, ast::BinaryOp::kLogicalOr, c, d));
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(), "(_tint_tmp_0)");
@ -432,12 +437,12 @@ if (!_tint_tmp_0) {
}
TEST_F(HlslGeneratorImplTest_Binary, Logical_Or) {
auto* left =
create<ast::IdentifierExpression>(mod.RegisterSymbol("left"), "left");
auto* right =
create<ast::IdentifierExpression>(mod.RegisterSymbol("right"), "right");
auto* left = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("left"), "left");
auto* right = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("right"), "right");
ast::BinaryExpression expr(ast::BinaryOp::kLogicalOr, left, right);
ast::BinaryExpression expr(Source{}, ast::BinaryOp::kLogicalOr, left, right);
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(), "(_tint_tmp)");
@ -462,36 +467,39 @@ TEST_F(HlslGeneratorImplTest_Binary, If_WithLogical) {
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>(
Source{}, create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 3))));
Source{}, create<ast::SintLiteral>(Source{}, &i32, 3))));
auto* else_stmt = create<ast::ElseStatement>(body);
body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>(
Source{}, create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 2))));
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2))));
auto* else_if_stmt = create<ast::ElseStatement>(
create<ast::BinaryExpression>(
ast::BinaryOp::kLogicalOr,
create<ast::IdentifierExpression>(mod.RegisterSymbol("b"), "b"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("c"), "c")),
Source{}, ast::BinaryOp::kLogicalOr,
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("b"),
"b"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("c"),
"c")),
body);
body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>(
Source{}, create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 1))));
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1))));
ast::IfStatement expr(
Source{},
create<ast::BinaryExpression>(
ast::BinaryOp::kLogicalAnd,
create<ast::IdentifierExpression>(mod.RegisterSymbol("a"), "a"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("b"), "b")),
body,
{
else_if_stmt,
else_stmt,
});
ast::IfStatement expr(Source{},
create<ast::BinaryExpression>(
Source{}, ast::BinaryOp::kLogicalAnd,
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("a"), "a"),
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("b"), "b")),
body,
{
else_if_stmt,
else_stmt,
});
ASSERT_TRUE(gen.EmitStatement(out, &expr)) << gen.error();
EXPECT_EQ(result(), R"(bool _tint_tmp = a;
@ -516,15 +524,19 @@ if ((_tint_tmp)) {
TEST_F(HlslGeneratorImplTest_Binary, Return_WithLogical) {
// return (a && b) || c;
auto* a = create<ast::IdentifierExpression>(mod.RegisterSymbol("a"), "a");
auto* b = create<ast::IdentifierExpression>(mod.RegisterSymbol("b"), "b");
auto* c = create<ast::IdentifierExpression>(mod.RegisterSymbol("c"), "c");
auto* a =
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("a"), "a");
auto* b =
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("b"), "b");
auto* c =
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("c"), "c");
ast::ReturnStatement expr(
Source{},
create<ast::BinaryExpression>(
ast::BinaryOp::kLogicalOr,
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, a, b), c));
ast::ReturnStatement expr(Source{},
create<ast::BinaryExpression>(
Source{}, ast::BinaryOp::kLogicalOr,
create<ast::BinaryExpression>(
Source{}, ast::BinaryOp::kLogicalAnd, a, b),
c));
ASSERT_TRUE(gen.EmitStatement(out, &expr)) << gen.error();
EXPECT_EQ(result(), R"(bool _tint_tmp = a;
@ -541,16 +553,21 @@ return (_tint_tmp_0);
TEST_F(HlslGeneratorImplTest_Binary, Assign_WithLogical) {
// a = (b || c) && d;
auto* a = create<ast::IdentifierExpression>(mod.RegisterSymbol("a"), "a");
auto* b = create<ast::IdentifierExpression>(mod.RegisterSymbol("b"), "b");
auto* c = create<ast::IdentifierExpression>(mod.RegisterSymbol("c"), "c");
auto* d = create<ast::IdentifierExpression>(mod.RegisterSymbol("d"), "d");
auto* a =
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("a"), "a");
auto* b =
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("b"), "b");
auto* c =
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("c"), "c");
auto* d =
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("d"), "d");
ast::AssignmentStatement expr(
a,
create<ast::BinaryExpression>(
ast::BinaryOp::kLogicalAnd,
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr, b, c), d));
a, create<ast::BinaryExpression>(
Source{}, ast::BinaryOp::kLogicalAnd,
create<ast::BinaryExpression>(Source{}, ast::BinaryOp::kLogicalOr,
b, c),
d));
ASSERT_TRUE(gen.EmitStatement(out, &expr)) << gen.error();
EXPECT_EQ(result(), R"(bool _tint_tmp = b;
@ -569,21 +586,25 @@ TEST_F(HlslGeneratorImplTest_Binary, Decl_WithLogical) {
// var a : bool = (b && c) || d;
ast::type::Bool bool_type;
auto* b = create<ast::IdentifierExpression>(mod.RegisterSymbol("b"), "b");
auto* c = create<ast::IdentifierExpression>(mod.RegisterSymbol("c"), "c");
auto* d = create<ast::IdentifierExpression>(mod.RegisterSymbol("d"), "d");
auto* b =
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("b"), "b");
auto* c =
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("c"), "c");
auto* d =
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("d"), "d");
auto* var = create<ast::Variable>(
Source{}, // source
"a", // name
ast::StorageClass::kFunction, // storage_class
&bool_type, // type
false, // is_const
create<ast::BinaryExpression>(
ast::BinaryOp::kLogicalOr,
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, b, c),
d), // constructor
ast::VariableDecorationList{}); // decorations
auto* var =
create<ast::Variable>(Source{}, // source
"a", // name
ast::StorageClass::kFunction, // storage_class
&bool_type, // type
false, // is_const
create<ast::BinaryExpression>(
Source{}, ast::BinaryOp::kLogicalOr,
create<ast::BinaryExpression>(
Source{}, ast::BinaryOp::kLogicalAnd, b, c),
d), // constructor
ast::VariableDecorationList{}); // decorations
ast::VariableDeclStatement expr(var);
@ -604,14 +625,19 @@ TEST_F(HlslGeneratorImplTest_Binary, Bitcast_WithLogical) {
// as<i32>(a && (b || c))
ast::type::I32 i32;
auto* a = create<ast::IdentifierExpression>(mod.RegisterSymbol("a"), "a");
auto* b = create<ast::IdentifierExpression>(mod.RegisterSymbol("b"), "b");
auto* c = create<ast::IdentifierExpression>(mod.RegisterSymbol("c"), "c");
auto* a =
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("a"), "a");
auto* b =
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("b"), "b");
auto* c =
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("c"), "c");
ast::BitcastExpression expr(&i32, create<ast::BinaryExpression>(
ast::BinaryOp::kLogicalAnd, a,
create<ast::BinaryExpression>(
ast::BinaryOp::kLogicalOr, b, c)));
ast::BitcastExpression expr(
Source{}, &i32,
create<ast::BinaryExpression>(
Source{}, ast::BinaryOp::kLogicalAnd, a,
create<ast::BinaryExpression>(Source{}, ast::BinaryOp::kLogicalOr, b,
c)));
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
EXPECT_EQ(pre_result(), R"(bool _tint_tmp = a;
@ -638,26 +664,34 @@ TEST_F(HlslGeneratorImplTest_Binary, Call_WithLogical) {
ast::ExpressionList params;
params.push_back(create<ast::BinaryExpression>(
ast::BinaryOp::kLogicalAnd,
create<ast::IdentifierExpression>(mod.RegisterSymbol("a"), "a"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("b"), "b")));
Source{}, ast::BinaryOp::kLogicalAnd,
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("a"), "a"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("b"),
"b")));
params.push_back(create<ast::BinaryExpression>(
ast::BinaryOp::kLogicalOr,
create<ast::IdentifierExpression>(mod.RegisterSymbol("c"), "c"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("d"), "d")));
Source{}, ast::BinaryOp::kLogicalOr,
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("c"), "c"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("d"),
"d")));
params.push_back(create<ast::BinaryExpression>(
ast::BinaryOp::kLogicalAnd,
Source{}, ast::BinaryOp::kLogicalAnd,
create<ast::BinaryExpression>(
ast::BinaryOp::kLogicalOr,
create<ast::IdentifierExpression>(mod.RegisterSymbol("a"), "a"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("c"), "c")),
Source{}, ast::BinaryOp::kLogicalOr,
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("a"),
"a"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("c"),
"c")),
create<ast::BinaryExpression>(
ast::BinaryOp::kLogicalOr,
create<ast::IdentifierExpression>(mod.RegisterSymbol("b"), "b"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("d"), "d"))));
Source{}, ast::BinaryOp::kLogicalOr,
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("b"),
"b"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("d"),
"d"))));
ast::CallStatement expr(create<ast::CallExpression>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo"),
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo"),
params));
ASSERT_TRUE(gen.EmitStatement(out, &expr)) << gen.error();

View File

@ -31,8 +31,9 @@ using HlslGeneratorImplTest_Bitcast = TestHelper;
TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Float) {
ast::type::F32 f32;
auto* id = create<ast::IdentifierExpression>(mod.RegisterSymbol("id"), "id");
ast::BitcastExpression bitcast(&f32, id);
auto* id = create<ast::IdentifierExpression>(Source{},
mod.RegisterSymbol("id"), "id");
ast::BitcastExpression bitcast(Source{}, &f32, id);
ASSERT_TRUE(gen.EmitExpression(pre, out, &bitcast)) << gen.error();
EXPECT_EQ(result(), "asfloat(id)");
@ -40,8 +41,9 @@ TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Float) {
TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Int) {
ast::type::I32 i32;
auto* id = create<ast::IdentifierExpression>(mod.RegisterSymbol("id"), "id");
ast::BitcastExpression bitcast(&i32, id);
auto* id = create<ast::IdentifierExpression>(Source{},
mod.RegisterSymbol("id"), "id");
ast::BitcastExpression bitcast(Source{}, &i32, id);
ASSERT_TRUE(gen.EmitExpression(pre, out, &bitcast)) << gen.error();
EXPECT_EQ(result(), "asint(id)");
@ -49,8 +51,9 @@ TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Int) {
TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Uint) {
ast::type::U32 u32;
auto* id = create<ast::IdentifierExpression>(mod.RegisterSymbol("id"), "id");
ast::BitcastExpression bitcast(&u32, id);
auto* id = create<ast::IdentifierExpression>(Source{},
mod.RegisterSymbol("id"), "id");
ast::BitcastExpression bitcast(Source{}, &u32, id);
ASSERT_TRUE(gen.EmitExpression(pre, out, &bitcast)) << gen.error();
EXPECT_EQ(result(), "asuint(id)");

View File

@ -32,9 +32,9 @@ using HlslGeneratorImplTest_Call = TestHelper;
TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithoutParams) {
ast::type::Void void_type;
auto* id = create<ast::IdentifierExpression>(mod.RegisterSymbol("my_func"),
"my_func");
ast::CallExpression call(id, {});
auto* id = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("my_func"), "my_func");
ast::CallExpression call(Source{}, id, {});
auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("my_func"), "my_func", ast::VariableList{},
@ -48,14 +48,14 @@ TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithoutParams) {
TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithParams) {
ast::type::Void void_type;
auto* id = create<ast::IdentifierExpression>(mod.RegisterSymbol("my_func"),
"my_func");
auto* id = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("my_func"), "my_func");
ast::ExpressionList params;
params.push_back(create<ast::IdentifierExpression>(
mod.RegisterSymbol("param1"), "param1"));
Source{}, mod.RegisterSymbol("param1"), "param1"));
params.push_back(create<ast::IdentifierExpression>(
mod.RegisterSymbol("param2"), "param2"));
ast::CallExpression call(id, params);
Source{}, mod.RegisterSymbol("param2"), "param2"));
ast::CallExpression call(Source{}, id, params);
auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("my_func"), "my_func", ast::VariableList{},
@ -69,14 +69,14 @@ TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithParams) {
TEST_F(HlslGeneratorImplTest_Call, EmitStatement_Call) {
ast::type::Void void_type;
auto* id = create<ast::IdentifierExpression>(mod.RegisterSymbol("my_func"),
"my_func");
auto* id = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("my_func"), "my_func");
ast::ExpressionList params;
params.push_back(create<ast::IdentifierExpression>(
mod.RegisterSymbol("param1"), "param1"));
Source{}, mod.RegisterSymbol("param1"), "param1"));
params.push_back(create<ast::IdentifierExpression>(
mod.RegisterSymbol("param2"), "param2"));
ast::CallStatement call(create<ast::CallExpression>(id, params));
Source{}, mod.RegisterSymbol("param2"), "param2"));
ast::CallStatement call(create<ast::CallExpression>(Source{}, id, params));
auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("my_func"), "my_func", ast::VariableList{},

View File

@ -32,10 +32,10 @@ TEST_F(HlslGeneratorImplTest_Cast, EmitExpression_Cast_Scalar) {
ast::type::F32 f32;
ast::ExpressionList params;
params.push_back(
create<ast::IdentifierExpression>(mod.RegisterSymbol("id"), "id"));
params.push_back(create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("id"), "id"));
ast::TypeConstructorExpression cast(&f32, params);
ast::TypeConstructorExpression cast(Source{}, &f32, params);
ASSERT_TRUE(gen.EmitExpression(pre, out, &cast)) << gen.error();
EXPECT_EQ(result(), "float(id)");
@ -46,10 +46,10 @@ TEST_F(HlslGeneratorImplTest_Cast, EmitExpression_Cast_Vector) {
ast::type::Vector vec3(&f32, 3);
ast::ExpressionList params;
params.push_back(
create<ast::IdentifierExpression>(mod.RegisterSymbol("id"), "id"));
params.push_back(create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("id"), "id"));
ast::TypeConstructorExpression cast(&vec3, params);
ast::TypeConstructorExpression cast(Source{}, &vec3, params);
ASSERT_TRUE(gen.EmitExpression(pre, out, &cast)) << gen.error();
EXPECT_EQ(result(), "float3(id)");

View File

@ -38,7 +38,7 @@ using HlslGeneratorImplTest_Constructor = TestHelper;
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Bool) {
ast::type::Bool bool_type;
auto* lit = create<ast::BoolLiteral>(Source{}, &bool_type, false);
ast::ScalarConstructorExpression expr(lit);
ast::ScalarConstructorExpression expr(Source{}, lit);
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(), "false");
@ -47,7 +47,7 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Bool) {
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Int) {
ast::type::I32 i32;
auto* lit = create<ast::SintLiteral>(Source{}, &i32, -12345);
ast::ScalarConstructorExpression expr(lit);
ast::ScalarConstructorExpression expr(Source{}, lit);
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(), "-12345");
@ -56,7 +56,7 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Int) {
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_UInt) {
ast::type::U32 u32;
auto* lit = create<ast::UintLiteral>(Source{}, &u32, 56779);
ast::ScalarConstructorExpression expr(lit);
ast::ScalarConstructorExpression expr(Source{}, lit);
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(), "56779u");
@ -67,7 +67,7 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Float) {
// Use a number close to 1<<30 but whose decimal representation ends in 0.
auto* lit = create<ast::FloatLiteral>(Source{}, &f32,
static_cast<float>((1 << 30) - 4));
ast::ScalarConstructorExpression expr(lit);
ast::ScalarConstructorExpression expr(Source{}, lit);
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(), "1073741824.0f");
@ -78,9 +78,9 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Float) {
auto* lit = create<ast::FloatLiteral>(Source{}, &f32, -1.2e-5);
ast::ExpressionList values;
values.push_back(create<ast::ScalarConstructorExpression>(lit));
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit));
ast::TypeConstructorExpression expr(&f32, values);
ast::TypeConstructorExpression expr(Source{}, &f32, values);
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(), "float(-0.000012f)");
@ -91,9 +91,9 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Bool) {
auto* lit = create<ast::BoolLiteral>(Source{}, &b, true);
ast::ExpressionList values;
values.push_back(create<ast::ScalarConstructorExpression>(lit));
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit));
ast::TypeConstructorExpression expr(&b, values);
ast::TypeConstructorExpression expr(Source{}, &b, values);
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(), "bool(true)");
@ -104,9 +104,9 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Int) {
auto* lit = create<ast::SintLiteral>(Source{}, &i32, -12345);
ast::ExpressionList values;
values.push_back(create<ast::ScalarConstructorExpression>(lit));
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit));
ast::TypeConstructorExpression expr(&i32, values);
ast::TypeConstructorExpression expr(Source{}, &i32, values);
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(), "int(-12345)");
@ -117,9 +117,9 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Uint) {
auto* lit = create<ast::UintLiteral>(Source{}, &u32, 12345);
ast::ExpressionList values;
values.push_back(create<ast::ScalarConstructorExpression>(lit));
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit));
ast::TypeConstructorExpression expr(&u32, values);
ast::TypeConstructorExpression expr(Source{}, &u32, values);
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(), "uint(12345u)");
@ -133,11 +133,11 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Vec) {
auto* lit2 = create<ast::FloatLiteral>(Source{}, &f32, 2.f);
auto* lit3 = create<ast::FloatLiteral>(Source{}, &f32, 3.f);
ast::ExpressionList values;
values.push_back(create<ast::ScalarConstructorExpression>(lit1));
values.push_back(create<ast::ScalarConstructorExpression>(lit2));
values.push_back(create<ast::ScalarConstructorExpression>(lit3));
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit1));
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit2));
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit3));
ast::TypeConstructorExpression expr(&vec, values);
ast::TypeConstructorExpression expr(Source{}, &vec, values);
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(), "float3(1.0f, 2.0f, 3.0f)");
@ -148,7 +148,7 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Vec_Empty) {
ast::type::Vector vec(&f32, 3);
ast::ExpressionList values;
ast::TypeConstructorExpression expr(&vec, values);
ast::TypeConstructorExpression expr(Source{}, &vec, values);
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(), "float3(0.0f)");
@ -173,14 +173,15 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Mat) {
static_cast<float>(3 + (i * 2)));
ast::ExpressionList values;
values.push_back(create<ast::ScalarConstructorExpression>(lit1));
values.push_back(create<ast::ScalarConstructorExpression>(lit2));
values.push_back(create<ast::ScalarConstructorExpression>(lit3));
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit1));
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit2));
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit3));
mat_values.push_back(create<ast::TypeConstructorExpression>(&vec, values));
mat_values.push_back(
create<ast::TypeConstructorExpression>(Source{}, &vec, values));
}
ast::TypeConstructorExpression expr(&mat, mat_values);
ast::TypeConstructorExpression expr(Source{}, &mat, mat_values);
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error();
@ -206,14 +207,15 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Array) {
static_cast<float>(3 + (i * 3)));
ast::ExpressionList values;
values.push_back(create<ast::ScalarConstructorExpression>(lit1));
values.push_back(create<ast::ScalarConstructorExpression>(lit2));
values.push_back(create<ast::ScalarConstructorExpression>(lit3));
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit1));
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit2));
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit3));
ary_values.push_back(create<ast::TypeConstructorExpression>(&vec, values));
ary_values.push_back(
create<ast::TypeConstructorExpression>(Source{}, &vec, values));
}
ast::TypeConstructorExpression expr(&ary, ary_values);
ast::TypeConstructorExpression expr(Source{}, &ary, ary_values);
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(),

View File

@ -84,11 +84,15 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo")));
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo")));
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar")));
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar")));
auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("vtx_main"), "vtx_main", params, &f32, body,
@ -157,11 +161,15 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo")));
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo")));
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar")));
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar")));
auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("vtx_main"), "vtx_main", params, &f32, body,
@ -230,11 +238,15 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo")));
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo")));
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar")));
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar")));
auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body,
@ -302,11 +314,15 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo")));
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo")));
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar")));
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar")));
auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body,
@ -371,11 +387,15 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo")));
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo")));
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar")));
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar")));
auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body,
@ -435,11 +455,15 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo")));
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo")));
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar")));
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar")));
auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body,
@ -506,11 +530,14 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("depth"), "depth"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("depth"),
"depth"),
create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("coord"),
"coord"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("x"), "x"))));
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("coord"), "coord"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("x"),
"x"))));
auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("main"), "main", params, &void_type, body,

View File

@ -171,8 +171,10 @@ TEST_F(HlslGeneratorImplTest_Function,
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo")));
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo")));
body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params,
@ -241,11 +243,14 @@ TEST_F(HlslGeneratorImplTest_Function,
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("depth"), "depth"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("depth"),
"depth"),
create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("coord"),
"coord"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("x"), "x"))));
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("coord"), "coord"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("x"),
"x"))));
body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params,
@ -305,9 +310,10 @@ TEST_F(HlslGeneratorImplTest_Function,
&f32, // type
false, // is_const
create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("coord"),
"coord"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("x"),
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("coord"), "coord"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("x"),
"x")), // constructor
ast::VariableDecorationList{}); // decorations
@ -377,12 +383,14 @@ TEST_F(HlslGeneratorImplTest_Function,
&f32, // type
false, // is_const
create<ast::MemberAccessorExpression>(
Source{},
create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("uniforms"),
"uniforms"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("coord"),
"coord")),
create<ast::IdentifierExpression>(mod.RegisterSymbol("x"),
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("uniforms"), "uniforms"),
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("coord"), "coord")),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("x"),
"x")), // constructor
ast::VariableDecorationList{}); // decorations
@ -458,9 +466,10 @@ TEST_F(HlslGeneratorImplTest_Function,
&f32, // type
false, // is_const
create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("coord"),
"coord"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("b"),
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("coord"), "coord"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("b"),
"b")), // constructor
ast::VariableDecorationList{}); // decorations
@ -532,9 +541,10 @@ TEST_F(HlslGeneratorImplTest_Function,
&f32, // type
false, // is_const
create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("coord"),
"coord"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("b"),
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("coord"), "coord"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("b"),
"b")), // constructor
ast::VariableDecorationList{}); // decorations
@ -601,12 +611,15 @@ TEST_F(HlslGeneratorImplTest_Function,
ast::VariableList params;
auto* assign = create<ast::AssignmentStatement>(
Source{},
create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("coord"),
"coord"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("b"), "b")),
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("coord"), "coord"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("b"),
"b")),
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 2.0f)));
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.0f)));
auto* body = create<ast::BlockStatement>();
body->append(assign);
@ -694,14 +707,18 @@ TEST_F(
auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo")));
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo")));
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("val"), "val"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("param"), "param")));
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("val"),
"val"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("param"),
"param")));
body->append(create<ast::ReturnStatement>(
Source{},
create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo")));
Source{}, create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("foo"), "foo")));
auto* sub_func = create<ast::Function>(
Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body,
ast::FunctionDecorationList{});
@ -710,14 +727,16 @@ TEST_F(
ast::ExpressionList expr;
expr.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar"),
create<ast::CallExpression>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("sub_func"),
"sub_func"),
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("sub_func"), "sub_func"),
expr)));
body->append(create<ast::ReturnStatement>(Source{}));
auto* func_1 = create<ast::Function>(
@ -788,8 +807,8 @@ TEST_F(HlslGeneratorImplTest_Function,
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>(
Source{},
create<ast::IdentifierExpression>(mod.RegisterSymbol("param"), "param")));
Source{}, create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("param"), "param")));
auto* sub_func = create<ast::Function>(
Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body,
ast::FunctionDecorationList{});
@ -798,14 +817,16 @@ TEST_F(HlslGeneratorImplTest_Function,
ast::ExpressionList expr;
expr.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("depth"), "depth"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("depth"),
"depth"),
create<ast::CallExpression>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("sub_func"),
"sub_func"),
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("sub_func"), "sub_func"),
expr)));
body->append(create<ast::ReturnStatement>(Source{}));
auto* func_1 = create<ast::Function>(
@ -884,14 +905,17 @@ TEST_F(
auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("depth"), "depth"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("depth"),
"depth"),
create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("coord"),
"coord"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("x"), "x"))));
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("coord"), "coord"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("x"),
"x"))));
body->append(create<ast::ReturnStatement>(
Source{},
create<ast::IdentifierExpression>(mod.RegisterSymbol("param"), "param")));
Source{}, create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("param"), "param")));
auto* sub_func = create<ast::Function>(
Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body,
ast::FunctionDecorationList{});
@ -900,14 +924,16 @@ TEST_F(
ast::ExpressionList expr;
expr.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("depth"), "depth"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("depth"),
"depth"),
create<ast::CallExpression>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("sub_func"),
"sub_func"),
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("sub_func"), "sub_func"),
expr)));
body->append(create<ast::ReturnStatement>(Source{}));
auto* func_1 = create<ast::Function>(
@ -977,11 +1003,12 @@ TEST_F(HlslGeneratorImplTest_Function,
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>(
Source{},
create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("coord"),
"coord"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("x"), "x"))));
Source{}, create<ast::MemberAccessorExpression>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("coord"), "coord"),
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("x"), "x"))));
auto* sub_func = create<ast::Function>(
Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body,
ast::FunctionDecorationList{});
@ -990,19 +1017,20 @@ TEST_F(HlslGeneratorImplTest_Function,
ast::ExpressionList expr;
expr.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
auto* var =
create<ast::Variable>(Source{}, // source
"v", // name
ast::StorageClass::kFunction, // storage_class
&f32, // type
false, // is_const
create<ast::CallExpression>(
create<ast::IdentifierExpression>(
mod.RegisterSymbol("sub_func"), "sub_func"),
expr), // constructor
ast::VariableDecorationList{}); // decorations
auto* var = create<ast::Variable>(
Source{}, // source
"v", // name
ast::StorageClass::kFunction, // storage_class
&f32, // type
false, // is_const
create<ast::CallExpression>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("sub_func"), "sub_func"),
expr), // constructor
ast::VariableDecorationList{}); // decorations
body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var));
@ -1069,11 +1097,12 @@ TEST_F(HlslGeneratorImplTest_Function,
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>(
Source{},
create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("coord"),
"coord"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("x"), "x"))));
Source{}, create<ast::MemberAccessorExpression>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("coord"), "coord"),
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("x"), "x"))));
auto* sub_func = create<ast::Function>(
Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body,
ast::FunctionDecorationList{});
@ -1082,19 +1111,20 @@ TEST_F(HlslGeneratorImplTest_Function,
ast::ExpressionList expr;
expr.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
auto* var =
create<ast::Variable>(Source{}, // source
"v", // name
ast::StorageClass::kFunction, // storage_class
&f32, // type
false, // is_const
create<ast::CallExpression>(
create<ast::IdentifierExpression>(
mod.RegisterSymbol("sub_func"), "sub_func"),
expr), // constructor
ast::VariableDecorationList{}); // decorations
auto* var = create<ast::Variable>(
Source{}, // source
"v", // name
ast::StorageClass::kFunction, // storage_class
&f32, // type
false, // is_const
create<ast::CallExpression>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("sub_func"), "sub_func"),
expr), // constructor
ast::VariableDecorationList{}); // decorations
body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var));
@ -1148,9 +1178,10 @@ TEST_F(HlslGeneratorImplTest_Function,
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar"),
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 1.0f))));
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f))));
auto* list = create<ast::BlockStatement>();
list->append(create<ast::ReturnStatement>(Source{}));
@ -1158,11 +1189,11 @@ TEST_F(HlslGeneratorImplTest_Function,
body->append(create<ast::IfStatement>(
Source{},
create<ast::BinaryExpression>(
ast::BinaryOp::kEqual,
Source{}, ast::BinaryOp::kEqual,
create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 1)),
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1)),
create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 1))),
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1))),
list, ast::ElseStatementList{}));
body->append(create<ast::ReturnStatement>(Source{}));
@ -1356,9 +1387,10 @@ TEST_F(HlslGeneratorImplTest_Function,
&f32, // type
false, // is_const
create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("data"),
"data"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("d"),
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("data"), "data"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("d"),
"d")), // constructor
ast::VariableDecorationList{}); // decorations
@ -1384,9 +1416,10 @@ TEST_F(HlslGeneratorImplTest_Function,
&f32, // type
false, // is_const
create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("data"),
"data"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("d"),
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("data"), "data"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("d"),
"d")), // constructor
ast::VariableDecorationList{}); // decorations

View File

@ -24,14 +24,15 @@ namespace {
using HlslGeneratorImplTest_Identifier = TestHelper;
TEST_F(HlslGeneratorImplTest_Identifier, EmitIdentifierExpression) {
ast::IdentifierExpression i(mod.RegisterSymbol("foo"), "foo");
ast::IdentifierExpression i(Source{}, mod.RegisterSymbol("foo"), "foo");
ASSERT_TRUE(gen.EmitExpression(pre, out, &i)) << gen.error();
EXPECT_EQ(result(), "foo");
}
TEST_F(HlslGeneratorImplTest_Identifier,
EmitIdentifierExpression_Single_WithCollision) {
ast::IdentifierExpression i(mod.RegisterSymbol("virtual"), "virtual");
ast::IdentifierExpression i(Source{}, mod.RegisterSymbol("virtual"),
"virtual");
ASSERT_TRUE(gen.EmitExpression(pre, out, &i)) << gen.error();
EXPECT_EQ(result(), "virtual_tint_0");
}

View File

@ -27,8 +27,8 @@ namespace {
using HlslGeneratorImplTest_If = TestHelper;
TEST_F(HlslGeneratorImplTest_If, Emit_If) {
auto* cond =
create<ast::IdentifierExpression>(mod.RegisterSymbol("cond"), "cond");
auto* cond = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("cond"), "cond");
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>(Source{}));
@ -44,12 +44,12 @@ TEST_F(HlslGeneratorImplTest_If, Emit_If) {
TEST_F(HlslGeneratorImplTest_If, Emit_IfWithElseIf) {
auto* else_cond = create<ast::IdentifierExpression>(
mod.RegisterSymbol("else_cond"), "else_cond");
Source{}, mod.RegisterSymbol("else_cond"), "else_cond");
auto* else_body = create<ast::BlockStatement>();
else_body->append(create<ast::ReturnStatement>(Source{}));
auto* cond =
create<ast::IdentifierExpression>(mod.RegisterSymbol("cond"), "cond");
auto* cond = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("cond"), "cond");
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>(Source{}));
@ -73,8 +73,8 @@ TEST_F(HlslGeneratorImplTest_If, Emit_IfWithElse) {
auto* else_body = create<ast::BlockStatement>();
else_body->append(create<ast::ReturnStatement>(Source{}));
auto* cond =
create<ast::IdentifierExpression>(mod.RegisterSymbol("cond"), "cond");
auto* cond = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("cond"), "cond");
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>(Source{}));
@ -94,7 +94,7 @@ TEST_F(HlslGeneratorImplTest_If, Emit_IfWithElse) {
TEST_F(HlslGeneratorImplTest_If, Emit_IfWithMultiple) {
auto* else_cond = create<ast::IdentifierExpression>(
mod.RegisterSymbol("else_cond"), "else_cond");
Source{}, mod.RegisterSymbol("else_cond"), "else_cond");
auto* else_body = create<ast::BlockStatement>();
else_body->append(create<ast::ReturnStatement>(Source{}));
@ -102,8 +102,8 @@ TEST_F(HlslGeneratorImplTest_If, Emit_IfWithMultiple) {
auto* else_body_2 = create<ast::BlockStatement>();
else_body_2->append(create<ast::ReturnStatement>(Source{}));
auto* cond =
create<ast::IdentifierExpression>(mod.RegisterSymbol("cond"), "cond");
auto* cond = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("cond"), "cond");
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>(Source{}));

View File

@ -54,11 +54,11 @@ TEST_P(HlslImportData_SingleParamTest, FloatScalar) {
ast::ExpressionList params;
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 1.f)));
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)));
auto* ident = create<ast::IdentifierExpression>(
mod.RegisterSymbol(param.name), param.name);
ast::CallExpression expr(ident, params);
Source{}, mod.RegisterSymbol(param.name), param.name);
ast::CallExpression expr(Source{}, ident, params);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ASSERT_TRUE(gen.EmitCall(pre, out, &expr)) << gen.error();
@ -100,11 +100,13 @@ TEST_P(HlslImportData_SingleIntParamTest, IntScalar) {
ast::ExpressionList params;
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 1)));
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1)));
ast::CallExpression expr(create<ast::IdentifierExpression>(
mod.RegisterSymbol(param.name), param.name),
params);
ast::CallExpression expr(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol(param.name), param.name),
params);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ASSERT_TRUE(gen.EmitCall(pre, out, &expr)) << gen.error();
@ -122,13 +124,15 @@ TEST_P(HlslImportData_DualParamTest, FloatScalar) {
ast::ExpressionList params;
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 1.f)));
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)));
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 2.f)));
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.f)));
ast::CallExpression expr(create<ast::IdentifierExpression>(
mod.RegisterSymbol(param.name), param.name),
params);
ast::CallExpression expr(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol(param.name), param.name),
params);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ASSERT_TRUE(gen.EmitCall(pre, out, &expr)) << gen.error();
@ -153,28 +157,32 @@ TEST_P(HlslImportData_DualParam_VectorTest, FloatVector) {
ast::ExpressionList params;
params.push_back(create<ast::TypeConstructorExpression>(
&vec, ast::ExpressionList{
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 1.f)),
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 2.f)),
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 3.f)),
}));
Source{}, &vec,
ast::ExpressionList{
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)),
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.f)),
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 3.f)),
}));
params.push_back(create<ast::TypeConstructorExpression>(
&vec, ast::ExpressionList{
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 4.f)),
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 5.f)),
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 6.f)),
}));
Source{}, &vec,
ast::ExpressionList{
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 4.f)),
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 5.f)),
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 6.f)),
}));
ast::CallExpression expr(create<ast::IdentifierExpression>(
mod.RegisterSymbol(param.name), param.name),
params);
ast::CallExpression expr(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol(param.name), param.name),
params);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ASSERT_TRUE(gen.EmitCall(pre, out, &expr)) << gen.error();
@ -194,13 +202,15 @@ TEST_P(HlslImportData_DualParam_Int_Test, IntScalar) {
ast::ExpressionList params;
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 1)));
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1)));
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 2)));
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2)));
ast::CallExpression expr(create<ast::IdentifierExpression>(
mod.RegisterSymbol(param.name), param.name),
params);
ast::CallExpression expr(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol(param.name), param.name),
params);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ASSERT_TRUE(gen.EmitCall(pre, out, &expr)) << gen.error();
@ -219,15 +229,17 @@ TEST_P(HlslImportData_TripleParamTest, FloatScalar) {
ast::ExpressionList params;
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 1.f)));
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)));
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 2.f)));
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.f)));
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 3.f)));
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 3.f)));
ast::CallExpression expr(create<ast::IdentifierExpression>(
mod.RegisterSymbol(param.name), param.name),
params);
ast::CallExpression expr(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol(param.name), param.name),
params);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ASSERT_TRUE(gen.EmitCall(pre, out, &expr)) << gen.error();
@ -253,15 +265,17 @@ TEST_P(HlslImportData_TripleParam_Int_Test, IntScalar) {
ast::ExpressionList params;
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 1)));
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1)));
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 2)));
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2)));
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 3)));
Source{}, create<ast::SintLiteral>(Source{}, &i32, 3)));
ast::CallExpression expr(create<ast::IdentifierExpression>(
mod.RegisterSymbol(param.name), param.name),
params);
ast::CallExpression expr(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol(param.name), param.name),
params);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ASSERT_TRUE(gen.EmitCall(pre, out, &expr)) << gen.error();
@ -285,12 +299,13 @@ TEST_F(HlslGeneratorImplTest_Import, HlslImportData_Determinant) {
ast::VariableDecorationList{}); // decorations
ast::ExpressionList params;
params.push_back(
create<ast::IdentifierExpression>(mod.RegisterSymbol("var"), "var"));
params.push_back(create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("var"), "var"));
ast::CallExpression expr(
create<ast::IdentifierExpression>(mod.RegisterSymbol("determinant"),
"determinant"),
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("determinant"), "determinant"),
params);
mod.AddGlobalVariable(var);

View File

@ -93,14 +93,15 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, DISABLED_Intrinsic_OuterProduct) {
ast::VariableDecorationList{}); // decorations
ast::ExpressionList params;
params.push_back(
create<ast::IdentifierExpression>(mod.RegisterSymbol("a"), "a"));
params.push_back(
create<ast::IdentifierExpression>(mod.RegisterSymbol("b"), "b"));
params.push_back(create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("a"), "a"));
params.push_back(create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("b"), "b"));
ast::CallExpression call(
create<ast::IdentifierExpression>(mod.RegisterSymbol("outer_product"),
"outer_product"),
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("outer_product"), "outer_product"),
params);
td.RegisterVariableForTesting(a);
@ -127,13 +128,14 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, Intrinsic_Call) {
ast::ExpressionList params;
params.push_back(create<ast::IdentifierExpression>(
mod.RegisterSymbol("param1"), "param1"));
Source{}, mod.RegisterSymbol("param1"), "param1"));
params.push_back(create<ast::IdentifierExpression>(
mod.RegisterSymbol("param2"), "param2"));
Source{}, mod.RegisterSymbol("param2"), "param2"));
ast::CallExpression call(
create<ast::IdentifierExpression>(mod.RegisterSymbol("dot"), "dot"),
params);
ast::CallExpression call(Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("dot"), "dot"),
params);
ast::Variable v1(Source{}, "param1", ast::StorageClass::kFunction, &vec,
false, nullptr, ast::VariableDecorationList{});

View File

@ -272,7 +272,7 @@ TEST_P(HlslGeneratorIntrinsicTextureTest, Call) {
param.buildTextureVariable(this);
param.buildSamplerVariable(this);
ast::CallExpression call{Expr(param.function), param.args(this)};
ast::CallExpression call{Source{}, Expr(param.function), param.args(this)};
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(td.DetermineResultType(&call)) << td.error();

View File

@ -86,10 +86,10 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopNestedWithContinuing) {
body = create<ast::BlockStatement>();
body->append(inner);
auto* lhs =
create<ast::IdentifierExpression>(mod.RegisterSymbol("lhs"), "lhs");
auto* rhs =
create<ast::IdentifierExpression>(mod.RegisterSymbol("rhs"), "rhs");
auto* lhs = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("lhs"), "lhs");
auto* rhs = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("rhs"), "rhs");
continuing = create<ast::BlockStatement>();
continuing->append(create<ast::AssignmentStatement>(lhs, rhs));
@ -153,6 +153,7 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopWithVarUsedInContinuing) {
&f32, // type
false, // is_const
create<ast::ScalarConstructorExpression>(
Source{},
create<ast::FloatLiteral>(Source{}, &f32, 2.4)), // constructor
ast::VariableDecorationList{}); // decorations
@ -167,10 +168,10 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopWithVarUsedInContinuing) {
nullptr, // constructor
ast::VariableDecorationList{}))); // decorations
auto* lhs =
create<ast::IdentifierExpression>(mod.RegisterSymbol("lhs"), "lhs");
auto* rhs =
create<ast::IdentifierExpression>(mod.RegisterSymbol("rhs"), "rhs");
auto* lhs = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("lhs"), "lhs");
auto* rhs = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("rhs"), "rhs");
auto* continuing = create<ast::BlockStatement>();
continuing->append(create<ast::AssignmentStatement>(lhs, rhs));

View File

@ -66,12 +66,12 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, EmitExpression_MemberAccessor) {
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
auto* str =
create<ast::IdentifierExpression>(mod.RegisterSymbol("str"), "str");
auto* mem =
create<ast::IdentifierExpression>(mod.RegisterSymbol("mem"), "mem");
auto* str = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("str"), "str");
auto* mem = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("mem"), "mem");
ast::MemberAccessorExpression expr(str, mem);
ast::MemberAccessorExpression expr(Source{}, str, mem);
td.RegisterVariableForTesting(str_var);
gen.register_global(str_var);
@ -118,8 +118,11 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::VariableDecorationList{}); // decorations
ast::MemberAccessorExpression expr(
create<ast::IdentifierExpression>(mod.RegisterSymbol("data"), "data"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("b"), "b"));
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("data"),
"data"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("b"),
"b"));
td.RegisterVariableForTesting(coord_var);
gen.register_global(coord_var);
@ -168,8 +171,11 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::VariableDecorationList{}); // decorations
ast::MemberAccessorExpression expr(
create<ast::IdentifierExpression>(mod.RegisterSymbol("data"), "data"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("a"), "a"));
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("data"),
"data"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("a"),
"a"));
td.RegisterVariableForTesting(coord_var);
gen.register_global(coord_var);
@ -230,9 +236,13 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::VariableDecorationList{}); // decorations
auto* lhs = create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("data"), "data"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("a"), "a"));
auto* rhs = create<ast::IdentifierExpression>(mod.RegisterSymbol("b"), "b");
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("data"),
"data"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("a"),
"a"));
auto* rhs =
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("b"), "b");
ast::AssignmentStatement assign(lhs, rhs);
@ -293,10 +303,13 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::VariableDecorationList{}); // decorations
auto* lhs = create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("data"), "data"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("a"), "a"));
auto* rhs =
create<ast::TypeConstructorExpression>(&mat, ast::ExpressionList{});
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("data"),
"data"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("a"),
"a"));
auto* rhs = create<ast::TypeConstructorExpression>(Source{}, &mat,
ast::ExpressionList{});
ast::AssignmentStatement assign(lhs, rhs);
@ -354,8 +367,11 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::VariableDecorationList{}); // decorations
ast::MemberAccessorExpression expr(
create<ast::IdentifierExpression>(mod.RegisterSymbol("data"), "data"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("a"), "a"));
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("data"),
"data"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("a"),
"a"));
td.RegisterVariableForTesting(coord_var);
gen.register_global(coord_var);
@ -411,8 +427,11 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::VariableDecorationList{}); // decorations
ast::MemberAccessorExpression expr(
create<ast::IdentifierExpression>(mod.RegisterSymbol("data"), "data"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("a"), "a"));
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("data"),
"data"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("a"),
"a"));
td.RegisterVariableForTesting(coord_var);
gen.register_global(coord_var);
@ -460,8 +479,11 @@ TEST_F(
ast::VariableDecorationList{}); // decorations
ast::MemberAccessorExpression expr(
create<ast::IdentifierExpression>(mod.RegisterSymbol("data"), "data"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("a"), "a"));
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("data"),
"data"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("a"),
"a"));
td.RegisterVariableForTesting(coord_var);
gen.register_global(coord_var);
@ -513,15 +535,19 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::VariableDecorationList{}); // decorations
ast::ArrayAccessorExpression expr(
Source{},
create<ast::ArrayAccessorExpression>(
Source{},
create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("data"),
"data"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("a"), "a")),
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("data"), "data"),
create<ast::IdentifierExpression>(Source{},
mod.RegisterSymbol("a"), "a")),
create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 2))),
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2))),
create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 1)));
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1)));
td.RegisterVariableForTesting(coord_var);
gen.register_global(coord_var);
@ -569,11 +595,15 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::VariableDecorationList{}); // decorations
ast::ArrayAccessorExpression expr(
Source{},
create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("data"), "data"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("a"), "a")),
Source{},
create<ast::IdentifierExpression>(Source{},
mod.RegisterSymbol("data"), "data"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("a"),
"a")),
create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 2)));
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2)));
td.RegisterVariableForTesting(coord_var);
gen.register_global(coord_var);
@ -621,19 +651,23 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::VariableDecorationList{}); // decorations
ast::ArrayAccessorExpression expr(
Source{},
create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("data"), "data"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("a"), "a")),
Source{},
create<ast::IdentifierExpression>(Source{},
mod.RegisterSymbol("data"), "data"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("a"),
"a")),
create<ast::BinaryExpression>(
ast::BinaryOp::kSubtract,
Source{}, ast::BinaryOp::kSubtract,
create<ast::BinaryExpression>(
ast::BinaryOp::kAdd,
Source{}, ast::BinaryOp::kAdd,
create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 2)),
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2)),
create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 4))),
Source{}, create<ast::SintLiteral>(Source{}, &i32, 4))),
create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 3))));
Source{}, create<ast::SintLiteral>(Source{}, &i32, 3))));
td.RegisterVariableForTesting(coord_var);
gen.register_global(coord_var);
@ -689,10 +723,13 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ASSERT_TRUE(td.Determine()) << td.error();
auto* lhs = create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("data"), "data"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("b"), "b"));
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("data"),
"data"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("b"),
"b"));
auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 2.0f));
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.0f));
ast::AssignmentStatement assign(lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&assign));
@ -743,13 +780,17 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ASSERT_TRUE(td.Determine()) << td.error();
auto* lhs = create<ast::ArrayAccessorExpression>(
Source{},
create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("data"), "data"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("a"), "a")),
Source{},
create<ast::IdentifierExpression>(Source{},
mod.RegisterSymbol("data"), "data"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("a"),
"a")),
create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 2)));
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2)));
auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 2));
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
ast::AssignmentStatement assign(lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&assign)) << td.error();
@ -801,10 +842,13 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ASSERT_TRUE(td.Determine()) << td.error();
auto* lhs = create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("data"), "data"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("a"), "a"));
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("data"),
"data"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("a"),
"a"));
auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 2));
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2));
ast::AssignmentStatement assign(lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&assign));
@ -858,8 +902,11 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ASSERT_TRUE(td.Determine()) << td.error();
ast::MemberAccessorExpression expr(
create<ast::IdentifierExpression>(mod.RegisterSymbol("data"), "data"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("b"), "b"));
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("data"),
"data"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("b"),
"b"));
ASSERT_TRUE(td.DetermineResultType(&expr));
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
@ -914,14 +961,17 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto* lit2 = create<ast::FloatLiteral>(Source{}, &f32, 2.f);
auto* lit3 = create<ast::FloatLiteral>(Source{}, &f32, 3.f);
ast::ExpressionList values;
values.push_back(create<ast::ScalarConstructorExpression>(lit1));
values.push_back(create<ast::ScalarConstructorExpression>(lit2));
values.push_back(create<ast::ScalarConstructorExpression>(lit3));
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit1));
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit2));
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit3));
auto* lhs = create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("data"), "data"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("b"), "b"));
auto* rhs = create<ast::TypeConstructorExpression>(&fvec3, values);
Source{},
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("data"),
"data"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("b"),
"b"));
auto* rhs = create<ast::TypeConstructorExpression>(Source{}, &fvec3, values);
ast::AssignmentStatement assign(lhs, rhs);
@ -995,14 +1045,19 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ASSERT_TRUE(td.Determine()) << td.error();
ast::MemberAccessorExpression expr(
Source{},
create<ast::ArrayAccessorExpression>(
Source{},
create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("data"),
"data"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("c"), "c")),
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("data"), "data"),
create<ast::IdentifierExpression>(Source{},
mod.RegisterSymbol("c"), "c")),
create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 2))),
create<ast::IdentifierExpression>(mod.RegisterSymbol("b"), "b"));
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2))),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("b"),
"b"));
ASSERT_TRUE(td.DetermineResultType(&expr));
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
@ -1073,17 +1128,23 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ASSERT_TRUE(td.Determine()) << td.error();
ast::MemberAccessorExpression expr(
Source{},
create<ast::MemberAccessorExpression>(
Source{},
create<ast::ArrayAccessorExpression>(
Source{},
create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("data"),
"data"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("c"),
"c")),
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("data"), "data"),
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("c"), "c")),
create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 2))),
create<ast::IdentifierExpression>(mod.RegisterSymbol("b"), "b")),
create<ast::IdentifierExpression>(mod.RegisterSymbol("xy"), "xy"));
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2))),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("b"),
"b")),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("xy"),
"xy"));
ASSERT_TRUE(td.DetermineResultType(&expr));
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
@ -1153,17 +1214,23 @@ TEST_F(
ASSERT_TRUE(td.Determine()) << td.error();
ast::MemberAccessorExpression expr(
Source{},
create<ast::MemberAccessorExpression>(
Source{},
create<ast::ArrayAccessorExpression>(
Source{},
create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("data"),
"data"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("c"),
"c")),
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("data"), "data"),
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("c"), "c")),
create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 2))),
create<ast::IdentifierExpression>(mod.RegisterSymbol("b"), "b")),
create<ast::IdentifierExpression>(mod.RegisterSymbol("g"), "g"));
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2))),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("b"),
"b")),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("g"),
"g"));
ASSERT_TRUE(td.DetermineResultType(&expr));
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
@ -1232,18 +1299,23 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ASSERT_TRUE(td.Determine()) << td.error();
ast::ArrayAccessorExpression expr(
Source{},
create<ast::MemberAccessorExpression>(
Source{},
create<ast::ArrayAccessorExpression>(
Source{},
create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("data"),
"data"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("c"),
"c")),
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("data"), "data"),
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("c"), "c")),
create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 2))),
create<ast::IdentifierExpression>(mod.RegisterSymbol("b"), "b")),
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2))),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("b"),
"b")),
create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 1)));
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1)));
ASSERT_TRUE(td.DetermineResultType(&expr));
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
@ -1312,24 +1384,29 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ASSERT_TRUE(td.Determine()) << td.error();
auto* lhs = create<ast::MemberAccessorExpression>(
Source{},
create<ast::ArrayAccessorExpression>(
Source{},
create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("data"),
"data"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("c"), "c")),
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("data"), "data"),
create<ast::IdentifierExpression>(Source{},
mod.RegisterSymbol("c"), "c")),
create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 2))),
create<ast::IdentifierExpression>(mod.RegisterSymbol("b"), "b"));
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2))),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("b"),
"b"));
auto* lit1 = create<ast::FloatLiteral>(Source{}, &f32, 1.f);
auto* lit2 = create<ast::FloatLiteral>(Source{}, &f32, 2.f);
auto* lit3 = create<ast::FloatLiteral>(Source{}, &f32, 3.f);
ast::ExpressionList values;
values.push_back(create<ast::ScalarConstructorExpression>(lit1));
values.push_back(create<ast::ScalarConstructorExpression>(lit2));
values.push_back(create<ast::ScalarConstructorExpression>(lit3));
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit1));
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit2));
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit3));
auto* rhs = create<ast::TypeConstructorExpression>(&fvec3, values);
auto* rhs = create<ast::TypeConstructorExpression>(Source{}, &fvec3, values);
ast::AssignmentStatement assign(lhs, rhs);
@ -1402,20 +1479,26 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ASSERT_TRUE(td.Determine()) << td.error();
auto* lhs = create<ast::MemberAccessorExpression>(
Source{},
create<ast::MemberAccessorExpression>(
Source{},
create<ast::ArrayAccessorExpression>(
Source{},
create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("data"),
"data"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("c"),
"c")),
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("data"), "data"),
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("c"), "c")),
create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 2))),
create<ast::IdentifierExpression>(mod.RegisterSymbol("b"), "b")),
create<ast::IdentifierExpression>(mod.RegisterSymbol("y"), "y"));
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2))),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("b"),
"b")),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("y"),
"y"));
auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &i32, 1.f));
Source{}, create<ast::FloatLiteral>(Source{}, &i32, 1.f));
ast::AssignmentStatement assign(lhs, rhs);

View File

@ -38,20 +38,21 @@ TEST_F(HlslGeneratorImplTest_ModuleConstant, Emit_ModuleConstant) {
ast::ExpressionList exprs;
exprs.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
exprs.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 2.0f)));
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.0f)));
exprs.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 3.0f)));
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 3.0f)));
auto* var = create<ast::Variable>(
Source{}, // source
"pos", // name
ast::StorageClass::kNone, // storage_class
&ary, // type
true, // is_const
create<ast::TypeConstructorExpression>(&ary, exprs), // constructor
ast::VariableDecorationList{}); // decorations
auto* var =
create<ast::Variable>(Source{}, // source
"pos", // name
ast::StorageClass::kNone, // storage_class
&ary, // type
true, // is_const
create<ast::TypeConstructorExpression>(
Source{}, &ary, exprs), // constructor
ast::VariableDecorationList{}); // decorations
ASSERT_TRUE(gen.EmitProgramConstVariable(out, var)) << gen.error();
EXPECT_EQ(result(), "static const float pos[3] = {1.0f, 2.0f, 3.0f};\n");
@ -67,6 +68,7 @@ TEST_F(HlslGeneratorImplTest_ModuleConstant, Emit_SpecConstant) {
&f32, // type
true, // is_const
create<ast::ScalarConstructorExpression>(
Source{},
create<ast::FloatLiteral>(Source{}, &f32, 3.0f)), // constructor
ast::VariableDecorationList{
// decorations

View File

@ -36,8 +36,8 @@ TEST_F(HlslGeneratorImplTest_Return, Emit_Return) {
}
TEST_F(HlslGeneratorImplTest_Return, Emit_ReturnWithValue) {
auto* expr =
create<ast::IdentifierExpression>(mod.RegisterSymbol("expr"), "expr");
auto* expr = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("expr"), "expr");
ast::ReturnStatement r(Source{}, expr);
gen.increment_indent();

View File

@ -48,8 +48,8 @@ TEST_F(HlslGeneratorImplTest_Switch, Emit_Switch) {
body.push_back(case_stmt);
body.push_back(def);
auto* cond =
create<ast::IdentifierExpression>(mod.RegisterSymbol("cond"), "cond");
auto* cond = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("cond"), "cond");
ast::SwitchStatement s(cond, body);
gen.increment_indent();

View File

@ -56,7 +56,7 @@ TEST_F(HlslGeneratorImplTest, InputStructName_ConflictWithExisting) {
TEST_F(HlslGeneratorImplTest, NameConflictWith_InputStructName) {
ASSERT_EQ(gen.generate_name("func_main_in"), "func_main_in");
ast::IdentifierExpression ident(mod.RegisterSymbol("func_main_in"),
ast::IdentifierExpression ident(Source{}, mod.RegisterSymbol("func_main_in"),
"func_main_in");
ASSERT_TRUE(gen.EmitIdentifier(pre, out, &ident));
EXPECT_EQ(result(), "func_main_in_0");

View File

@ -37,9 +37,9 @@ using HlslUnaryOpTest = TestParamHelper<UnaryOpData>;
TEST_P(HlslUnaryOpTest, Emit) {
auto params = GetParam();
auto* expr =
create<ast::IdentifierExpression>(mod.RegisterSymbol("expr"), "expr");
ast::UnaryOpExpression op(params.op, expr);
auto* expr = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("expr"), "expr");
ast::UnaryOpExpression op(Source{}, params.op, expr);
ASSERT_TRUE(gen.EmitExpression(pre, out, &op)) << gen.error();
EXPECT_EQ(result(), std::string(params.name) + "(expr)");

View File

@ -128,7 +128,7 @@ TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Private) {
TEST_F(HlslGeneratorImplTest_VariableDecl,
Emit_VariableDeclStatement_Initializer_Private) {
auto* ident = create<ast::IdentifierExpression>(
mod.RegisterSymbol("initializer"), "initializer");
Source{}, mod.RegisterSymbol("initializer"), "initializer");
ast::type::F32 f32;
auto* var =
@ -152,7 +152,8 @@ TEST_F(HlslGeneratorImplTest_VariableDecl,
ast::type::Vector vec(&f32, 3);
ast::ExpressionList values;
auto* zero_vec = create<ast::TypeConstructorExpression>(&vec, values);
auto* zero_vec =
create<ast::TypeConstructorExpression>(Source{}, &vec, values);
auto* var =
create<ast::Variable>(Source{}, // source
@ -175,7 +176,8 @@ TEST_F(HlslGeneratorImplTest_VariableDecl,
ast::type::Matrix mat(&f32, 3, 2);
ast::ExpressionList values;
auto* zero_mat = create<ast::TypeConstructorExpression>(&mat, values);
auto* zero_mat =
create<ast::TypeConstructorExpression>(Source{}, &mat, values);
auto* var =
create<ast::Variable>(Source{}, // source

View File

@ -34,23 +34,23 @@ using MslGeneratorImplTest = TestHelper;
TEST_F(MslGeneratorImplTest, EmitExpression_ArrayAccessor) {
ast::type::I32 i32;
auto* lit = create<ast::SintLiteral>(Source{}, &i32, 5);
auto* idx = create<ast::ScalarConstructorExpression>(lit);
auto* ary =
create<ast::IdentifierExpression>(mod.RegisterSymbol("ary"), "ary");
auto* idx = create<ast::ScalarConstructorExpression>(Source{}, lit);
auto* ary = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("ary"), "ary");
ast::ArrayAccessorExpression expr(ary, idx);
ast::ArrayAccessorExpression expr(Source{}, ary, idx);
ASSERT_TRUE(gen.EmitExpression(&expr)) << gen.error();
EXPECT_EQ(gen.result(), "ary[5]");
}
TEST_F(MslGeneratorImplTest, EmitArrayAccessor) {
auto* ary =
create<ast::IdentifierExpression>(mod.RegisterSymbol("ary"), "ary");
auto* idx =
create<ast::IdentifierExpression>(mod.RegisterSymbol("idx"), "idx");
auto* ary = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("ary"), "ary");
auto* idx = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("idx"), "idx");
ast::ArrayAccessorExpression expr(ary, idx);
ast::ArrayAccessorExpression expr(Source{}, ary, idx);
ASSERT_TRUE(gen.EmitArrayAccessor(&expr)) << gen.error();
EXPECT_EQ(gen.result(), "ary[idx]");

View File

@ -30,10 +30,10 @@ namespace {
using MslGeneratorImplTest = TestHelper;
TEST_F(MslGeneratorImplTest, Emit_Assign) {
auto* lhs =
create<ast::IdentifierExpression>(mod.RegisterSymbol("lhs"), "lhs");
auto* rhs =
create<ast::IdentifierExpression>(mod.RegisterSymbol("rhs"), "rhs");
auto* lhs = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("lhs"), "lhs");
auto* rhs = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("rhs"), "rhs");
ast::AssignmentStatement assign(lhs, rhs);
gen.increment_indent();

View File

@ -38,12 +38,12 @@ using MslBinaryTest = TestParamHelper<BinaryData>;
TEST_P(MslBinaryTest, Emit) {
auto params = GetParam();
auto* left =
create<ast::IdentifierExpression>(mod.RegisterSymbol("left"), "left");
auto* right =
create<ast::IdentifierExpression>(mod.RegisterSymbol("right"), "right");
auto* left = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("left"), "left");
auto* right = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("right"), "right");
ast::BinaryExpression expr(params.op, left, right);
ast::BinaryExpression expr(Source{}, params.op, left, right);
ASSERT_TRUE(gen.EmitExpression(&expr)) << gen.error();
EXPECT_EQ(gen.result(), params.result);

View File

@ -31,8 +31,9 @@ using MslGeneratorImplTest = TestHelper;
TEST_F(MslGeneratorImplTest, EmitExpression_Bitcast) {
ast::type::F32 f32;
auto* id = create<ast::IdentifierExpression>(mod.RegisterSymbol("id"), "id");
ast::BitcastExpression bitcast(&f32, id);
auto* id = create<ast::IdentifierExpression>(Source{},
mod.RegisterSymbol("id"), "id");
ast::BitcastExpression bitcast(Source{}, &f32, id);
ASSERT_TRUE(gen.EmitExpression(&bitcast)) << gen.error();
EXPECT_EQ(gen.result(), "as_type<float>(id)");

View File

@ -34,9 +34,9 @@ using MslGeneratorImplTest = TestHelper;
TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithoutParams) {
ast::type::Void void_type;
auto* id = create<ast::IdentifierExpression>(mod.RegisterSymbol("my_func"),
"my_func");
ast::CallExpression call(id, {});
auto* id = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("my_func"), "my_func");
ast::CallExpression call(Source{}, id, {});
auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("my_func"), "my_func", ast::VariableList{},
@ -50,14 +50,14 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithoutParams) {
TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithParams) {
ast::type::Void void_type;
auto* id = create<ast::IdentifierExpression>(mod.RegisterSymbol("my_func"),
"my_func");
auto* id = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("my_func"), "my_func");
ast::ExpressionList params;
params.push_back(create<ast::IdentifierExpression>(
mod.RegisterSymbol("param1"), "param1"));
Source{}, mod.RegisterSymbol("param1"), "param1"));
params.push_back(create<ast::IdentifierExpression>(
mod.RegisterSymbol("param2"), "param2"));
ast::CallExpression call(id, params);
Source{}, mod.RegisterSymbol("param2"), "param2"));
ast::CallExpression call(Source{}, id, params);
auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("my_func"), "my_func", ast::VariableList{},
@ -71,14 +71,14 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithParams) {
TEST_F(MslGeneratorImplTest, EmitStatement_Call) {
ast::type::Void void_type;
auto* id = create<ast::IdentifierExpression>(mod.RegisterSymbol("my_func"),
"my_func");
auto* id = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("my_func"), "my_func");
ast::ExpressionList params;
params.push_back(create<ast::IdentifierExpression>(
mod.RegisterSymbol("param1"), "param1"));
Source{}, mod.RegisterSymbol("param1"), "param1"));
params.push_back(create<ast::IdentifierExpression>(
mod.RegisterSymbol("param2"), "param2"));
ast::CallStatement call(create<ast::CallExpression>(id, params));
Source{}, mod.RegisterSymbol("param2"), "param2"));
ast::CallStatement call(create<ast::CallExpression>(Source{}, id, params));
auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("my_func"), "my_func", ast::VariableList{},

View File

@ -34,10 +34,10 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Cast_Scalar) {
ast::type::F32 f32;
ast::ExpressionList params;
params.push_back(
create<ast::IdentifierExpression>(mod.RegisterSymbol("id"), "id"));
params.push_back(create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("id"), "id"));
ast::TypeConstructorExpression cast(&f32, params);
ast::TypeConstructorExpression cast(Source{}, &f32, params);
ASSERT_TRUE(gen.EmitExpression(&cast)) << gen.error();
EXPECT_EQ(gen.result(), "float(id)");
@ -48,10 +48,10 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Cast_Vector) {
ast::type::Vector vec3(&f32, 3);
ast::ExpressionList params;
params.push_back(
create<ast::IdentifierExpression>(mod.RegisterSymbol("id"), "id"));
params.push_back(create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("id"), "id"));
ast::TypeConstructorExpression cast(&vec3, params);
ast::TypeConstructorExpression cast(Source{}, &vec3, params);
ASSERT_TRUE(gen.EmitExpression(&cast)) << gen.error();
EXPECT_EQ(gen.result(), "float3(id)");

View File

@ -40,7 +40,7 @@ using MslGeneratorImplTest = TestHelper;
TEST_F(MslGeneratorImplTest, EmitConstructor_Bool) {
ast::type::Bool bool_type;
auto* lit = create<ast::BoolLiteral>(Source{}, &bool_type, false);
ast::ScalarConstructorExpression expr(lit);
ast::ScalarConstructorExpression expr(Source{}, lit);
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
EXPECT_EQ(gen.result(), "false");
@ -49,7 +49,7 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Bool) {
TEST_F(MslGeneratorImplTest, EmitConstructor_Int) {
ast::type::I32 i32;
auto* lit = create<ast::SintLiteral>(Source{}, &i32, -12345);
ast::ScalarConstructorExpression expr(lit);
ast::ScalarConstructorExpression expr(Source{}, lit);
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
EXPECT_EQ(gen.result(), "-12345");
@ -58,7 +58,7 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Int) {
TEST_F(MslGeneratorImplTest, EmitConstructor_UInt) {
ast::type::U32 u32;
auto* lit = create<ast::UintLiteral>(Source{}, &u32, 56779);
ast::ScalarConstructorExpression expr(lit);
ast::ScalarConstructorExpression expr(Source{}, lit);
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
EXPECT_EQ(gen.result(), "56779u");
@ -69,7 +69,7 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Float) {
// Use a number close to 1<<30 but whose decimal representation ends in 0.
auto* lit = create<ast::FloatLiteral>(Source{}, &f32,
static_cast<float>((1 << 30) - 4));
ast::ScalarConstructorExpression expr(lit);
ast::ScalarConstructorExpression expr(Source{}, lit);
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
EXPECT_EQ(gen.result(), "1073741824.0f");
@ -80,9 +80,9 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Float) {
auto* lit = create<ast::FloatLiteral>(Source{}, &f32, -1.2e-5);
ast::ExpressionList values;
values.push_back(create<ast::ScalarConstructorExpression>(lit));
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit));
ast::TypeConstructorExpression expr(&f32, values);
ast::TypeConstructorExpression expr(Source{}, &f32, values);
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
EXPECT_EQ(gen.result(), "float(-0.000012f)");
@ -93,9 +93,9 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Bool) {
auto* lit = create<ast::BoolLiteral>(Source{}, &b, true);
ast::ExpressionList values;
values.push_back(create<ast::ScalarConstructorExpression>(lit));
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit));
ast::TypeConstructorExpression expr(&b, values);
ast::TypeConstructorExpression expr(Source{}, &b, values);
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
EXPECT_EQ(gen.result(), "bool(true)");
@ -106,9 +106,9 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Int) {
auto* lit = create<ast::SintLiteral>(Source{}, &i32, -12345);
ast::ExpressionList values;
values.push_back(create<ast::ScalarConstructorExpression>(lit));
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit));
ast::TypeConstructorExpression expr(&i32, values);
ast::TypeConstructorExpression expr(Source{}, &i32, values);
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
EXPECT_EQ(gen.result(), "int(-12345)");
@ -119,9 +119,9 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Uint) {
auto* lit = create<ast::UintLiteral>(Source{}, &u32, 12345);
ast::ExpressionList values;
values.push_back(create<ast::ScalarConstructorExpression>(lit));
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit));
ast::TypeConstructorExpression expr(&u32, values);
ast::TypeConstructorExpression expr(Source{}, &u32, values);
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
EXPECT_EQ(gen.result(), "uint(12345u)");
@ -135,11 +135,11 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Vec) {
auto* lit2 = create<ast::FloatLiteral>(Source{}, &f32, 2.f);
auto* lit3 = create<ast::FloatLiteral>(Source{}, &f32, 3.f);
ast::ExpressionList values;
values.push_back(create<ast::ScalarConstructorExpression>(lit1));
values.push_back(create<ast::ScalarConstructorExpression>(lit2));
values.push_back(create<ast::ScalarConstructorExpression>(lit3));
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit1));
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit2));
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit3));
ast::TypeConstructorExpression expr(&vec, values);
ast::TypeConstructorExpression expr(Source{}, &vec, values);
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
EXPECT_EQ(gen.result(), "float3(1.0f, 2.0f, 3.0f)");
@ -150,7 +150,7 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Vec_Empty) {
ast::type::Vector vec(&f32, 3);
ast::ExpressionList values;
ast::TypeConstructorExpression expr(&vec, values);
ast::TypeConstructorExpression expr(Source{}, &vec, values);
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
EXPECT_EQ(gen.result(), "float3(0.0f)");
@ -175,14 +175,15 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Mat) {
static_cast<float>(3 + (i * 2)));
ast::ExpressionList values;
values.push_back(create<ast::ScalarConstructorExpression>(lit1));
values.push_back(create<ast::ScalarConstructorExpression>(lit2));
values.push_back(create<ast::ScalarConstructorExpression>(lit3));
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit1));
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit2));
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit3));
mat_values.push_back(create<ast::TypeConstructorExpression>(&vec, values));
mat_values.push_back(
create<ast::TypeConstructorExpression>(Source{}, &vec, values));
}
ast::TypeConstructorExpression expr(&mat, mat_values);
ast::TypeConstructorExpression expr(Source{}, &mat, mat_values);
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
// A matrix of type T with n columns and m rows can also be constructed from
@ -207,14 +208,15 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Array) {
static_cast<float>(3 + (i * 3)));
ast::ExpressionList values;
values.push_back(create<ast::ScalarConstructorExpression>(lit1));
values.push_back(create<ast::ScalarConstructorExpression>(lit2));
values.push_back(create<ast::ScalarConstructorExpression>(lit3));
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit1));
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit2));
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit3));
ary_values.push_back(create<ast::TypeConstructorExpression>(&vec, values));
ary_values.push_back(
create<ast::TypeConstructorExpression>(Source{}, &vec, values));
}
ast::TypeConstructorExpression expr(&ary, ary_values);
ast::TypeConstructorExpression expr(Source{}, &ary, ary_values);
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
EXPECT_EQ(gen.result(),
"{float3(1.0f, 2.0f, 3.0f), float3(4.0f, 5.0f, 6.0f), "

View File

@ -83,11 +83,15 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Input) {
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo")));
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo")));
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar")));
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar")));
auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("vtx_main"), "vtx_main", params, &f32, body,
@ -153,11 +157,15 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Output) {
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo")));
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo")));
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar")));
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar")));
auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("vtx_main"), "vtx_main", params, &f32, body,
@ -223,11 +231,15 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Input) {
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo")));
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo")));
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar")));
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar")));
auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body,
ast::FunctionDecorationList{
@ -292,11 +304,15 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Output) {
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo")));
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo")));
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar")));
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar")));
auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body,
@ -359,11 +375,15 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Input) {
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo")));
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo")));
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar")));
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar")));
auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body,
@ -421,11 +441,15 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Output) {
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo")));
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo")));
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar")));
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar")));
auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body,
@ -490,11 +514,14 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Builtins) {
auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("depth"), "depth"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("depth"),
"depth"),
create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("coord"),
"coord"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("x"), "x"))));
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("coord"), "coord"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("x"),
"x"))));
auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("main"), "main", params, &void_type, body,

View File

@ -179,8 +179,10 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_WithInOutVars) {
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo")));
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo")));
body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>(
@ -252,11 +254,14 @@ TEST_F(MslGeneratorImplTest,
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("depth"), "depth"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("depth"),
"depth"),
create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("coord"),
"coord"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("x"), "x"))));
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("coord"), "coord"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("x"),
"x"))));
body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>(
@ -316,9 +321,10 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_With_Uniform) {
&f32, // type
false, // is_const
create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("coord"),
"coord"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("x"),
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("coord"), "coord"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("x"),
"x")), // constructor
ast::VariableDecorationList{}); // decorations
@ -395,9 +401,10 @@ TEST_F(MslGeneratorImplTest,
&f32, // type
false, // is_const
create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("coord"),
"coord"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("b"),
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("coord"), "coord"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("b"),
"b")), // constructor
ast::VariableDecorationList{}); // decorations
@ -479,9 +486,10 @@ TEST_F(MslGeneratorImplTest,
&f32, // type
false, // is_const
create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("coord"),
"coord"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("b"),
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("coord"), "coord"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("b"),
"b")), // constructor
ast::VariableDecorationList{}); // decorations
@ -578,14 +586,18 @@ TEST_F(
auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo")));
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("foo"),
"foo")));
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("val"), "val"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("param"), "param")));
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("val"),
"val"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("param"),
"param")));
body->append(create<ast::ReturnStatement>(
Source{},
create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo")));
Source{}, create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("foo"), "foo")));
auto* sub_func = create<ast::Function>(
Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body,
ast::FunctionDecorationList{});
@ -594,14 +606,16 @@ TEST_F(
ast::ExpressionList expr;
expr.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar"),
create<ast::CallExpression>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("sub_func"),
"sub_func"),
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("sub_func"), "sub_func"),
expr)));
body->append(create<ast::ReturnStatement>(Source{}));
auto* func_1 = create<ast::Function>(
@ -675,8 +689,8 @@ TEST_F(MslGeneratorImplTest,
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>(
Source{},
create<ast::IdentifierExpression>(mod.RegisterSymbol("param"), "param")));
Source{}, create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("param"), "param")));
auto* sub_func = create<ast::Function>(
Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body,
ast::FunctionDecorationList{});
@ -685,14 +699,16 @@ TEST_F(MslGeneratorImplTest,
ast::ExpressionList expr;
expr.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("depth"), "depth"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("depth"),
"depth"),
create<ast::CallExpression>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("sub_func"),
"sub_func"),
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("sub_func"), "sub_func"),
expr)));
body->append(create<ast::ReturnStatement>(Source{}));
@ -775,14 +791,17 @@ TEST_F(
auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("depth"), "depth"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("depth"),
"depth"),
create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("coord"),
"coord"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("x"), "x"))));
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("coord"), "coord"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("x"),
"x"))));
body->append(create<ast::ReturnStatement>(
Source{},
create<ast::IdentifierExpression>(mod.RegisterSymbol("param"), "param")));
Source{}, create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("param"), "param")));
auto* sub_func = create<ast::Function>(
Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body,
ast::FunctionDecorationList{});
@ -791,14 +810,16 @@ TEST_F(
ast::ExpressionList expr;
expr.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("depth"), "depth"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("depth"),
"depth"),
create<ast::CallExpression>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("sub_func"),
"sub_func"),
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("sub_func"), "sub_func"),
expr)));
body->append(create<ast::ReturnStatement>(Source{}));
auto* func_1 = create<ast::Function>(
@ -866,11 +887,12 @@ TEST_F(MslGeneratorImplTest,
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>(
Source{},
create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("coord"),
"coord"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("x"), "x"))));
Source{}, create<ast::MemberAccessorExpression>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("coord"), "coord"),
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("x"), "x"))));
auto* sub_func = create<ast::Function>(
Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body,
ast::FunctionDecorationList{});
@ -879,19 +901,20 @@ TEST_F(MslGeneratorImplTest,
ast::ExpressionList expr;
expr.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
auto* var =
create<ast::Variable>(Source{}, // source
"v", // name
ast::StorageClass::kFunction, // storage_class
&f32, // type
false, // is_const
create<ast::CallExpression>(
create<ast::IdentifierExpression>(
mod.RegisterSymbol("sub_func"), "sub_func"),
expr), // constructor
ast::VariableDecorationList{}); // decorations
auto* var = create<ast::Variable>(
Source{}, // source
"v", // name
ast::StorageClass::kFunction, // storage_class
&f32, // type
false, // is_const
create<ast::CallExpression>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("sub_func"), "sub_func"),
expr), // constructor
ast::VariableDecorationList{}); // decorations
body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var));
@ -972,11 +995,12 @@ TEST_F(MslGeneratorImplTest,
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>(
Source{},
create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("coord"),
"coord"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("b"), "b"))));
Source{}, create<ast::MemberAccessorExpression>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("coord"), "coord"),
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("b"), "b"))));
auto* sub_func = create<ast::Function>(
Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body,
ast::FunctionDecorationList{});
@ -985,19 +1009,20 @@ TEST_F(MslGeneratorImplTest,
ast::ExpressionList expr;
expr.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
auto* var =
create<ast::Variable>(Source{}, // source
"v", // name
ast::StorageClass::kFunction, // storage_class
&f32, // type
false, // is_const
create<ast::CallExpression>(
create<ast::IdentifierExpression>(
mod.RegisterSymbol("sub_func"), "sub_func"),
expr), // constructor
ast::VariableDecorationList{}); // decorations
auto* var = create<ast::Variable>(
Source{}, // source
"v", // name
ast::StorageClass::kFunction, // storage_class
&f32, // type
false, // is_const
create<ast::CallExpression>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("sub_func"), "sub_func"),
expr), // constructor
ast::VariableDecorationList{}); // decorations
body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var));
@ -1084,11 +1109,12 @@ TEST_F(MslGeneratorImplTest,
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>(
Source{},
create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("coord"),
"coord"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("b"), "b"))));
Source{}, create<ast::MemberAccessorExpression>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("coord"), "coord"),
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("b"), "b"))));
auto* sub_func = create<ast::Function>(
Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body,
ast::FunctionDecorationList{});
@ -1097,19 +1123,20 @@ TEST_F(MslGeneratorImplTest,
ast::ExpressionList expr;
expr.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
auto* var =
create<ast::Variable>(Source{}, // source
"v", // name
ast::StorageClass::kFunction, // storage_class
&f32, // type
false, // is_const
create<ast::CallExpression>(
create<ast::IdentifierExpression>(
mod.RegisterSymbol("sub_func"), "sub_func"),
expr), // constructor
ast::VariableDecorationList{}); // decorations
auto* var = create<ast::Variable>(
Source{}, // source
"v", // name
ast::StorageClass::kFunction, // storage_class
&f32, // type
false, // is_const
create<ast::CallExpression>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("sub_func"), "sub_func"),
expr), // constructor
ast::VariableDecorationList{}); // decorations
body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var));
@ -1170,9 +1197,10 @@ TEST_F(MslGeneratorImplTest,
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("bar"),
"bar"),
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 1.0f))));
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f))));
auto* list = create<ast::BlockStatement>();
list->append(create<ast::ReturnStatement>(Source{}));
@ -1180,11 +1208,11 @@ TEST_F(MslGeneratorImplTest,
body->append(create<ast::IfStatement>(
Source{},
create<ast::BinaryExpression>(
ast::BinaryOp::kEqual,
Source{}, ast::BinaryOp::kEqual,
create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 1)),
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1)),
create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 1))),
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1))),
list, ast::ElseStatementList{}));
body->append(create<ast::ReturnStatement>(Source{}));
@ -1336,9 +1364,10 @@ TEST_F(MslGeneratorImplTest,
&f32, // type
false, // is_const
create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("data"),
"data"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("d"),
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("data"), "data"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("d"),
"d")), // constructor
ast::VariableDecorationList{}); // decorations
@ -1365,9 +1394,10 @@ TEST_F(MslGeneratorImplTest,
&f32, // type
false, // is_const
create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("data"),
"data"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("d"),
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("data"), "data"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("d"),
"d")), // constructor
ast::VariableDecorationList{}); // decorations

View File

@ -26,14 +26,15 @@ namespace {
using MslGeneratorImplTest = TestHelper;
TEST_F(MslGeneratorImplTest, EmitIdentifierExpression) {
ast::IdentifierExpression i(mod.RegisterSymbol("foo"), "foo");
ast::IdentifierExpression i(Source{}, mod.RegisterSymbol("foo"), "foo");
ASSERT_TRUE(gen.EmitExpression(&i)) << gen.error();
EXPECT_EQ(gen.result(), "foo");
}
TEST_F(MslGeneratorImplTest, EmitIdentifierExpression_Single_WithCollision) {
ast::IdentifierExpression i(mod.RegisterSymbol("virtual"), "virtual");
ast::IdentifierExpression i(Source{}, mod.RegisterSymbol("virtual"),
"virtual");
ASSERT_TRUE(gen.EmitExpression(&i)) << gen.error();
EXPECT_EQ(gen.result(), "virtual_tint_0");

View File

@ -29,8 +29,8 @@ namespace {
using MslGeneratorImplTest = TestHelper;
TEST_F(MslGeneratorImplTest, Emit_If) {
auto* cond =
create<ast::IdentifierExpression>(mod.RegisterSymbol("cond"), "cond");
auto* cond = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("cond"), "cond");
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>(Source{}));
@ -47,12 +47,12 @@ TEST_F(MslGeneratorImplTest, Emit_If) {
TEST_F(MslGeneratorImplTest, Emit_IfWithElseIf) {
auto* else_cond = create<ast::IdentifierExpression>(
mod.RegisterSymbol("else_cond"), "else_cond");
Source{}, mod.RegisterSymbol("else_cond"), "else_cond");
auto* else_body = create<ast::BlockStatement>();
else_body->append(create<ast::ReturnStatement>(Source{}));
auto* cond =
create<ast::IdentifierExpression>(mod.RegisterSymbol("cond"), "cond");
auto* cond = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("cond"), "cond");
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>(Source{}));
@ -74,8 +74,8 @@ TEST_F(MslGeneratorImplTest, Emit_IfWithElse) {
auto* else_body = create<ast::BlockStatement>();
else_body->append(create<ast::ReturnStatement>(Source{}));
auto* cond =
create<ast::IdentifierExpression>(mod.RegisterSymbol("cond"), "cond");
auto* cond = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("cond"), "cond");
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>(Source{}));
@ -95,7 +95,7 @@ TEST_F(MslGeneratorImplTest, Emit_IfWithElse) {
TEST_F(MslGeneratorImplTest, Emit_IfWithMultiple) {
auto* else_cond = create<ast::IdentifierExpression>(
mod.RegisterSymbol("else_cond"), "else_cond");
Source{}, mod.RegisterSymbol("else_cond"), "else_cond");
auto* else_body = create<ast::BlockStatement>();
else_body->append(create<ast::ReturnStatement>(Source{}));
@ -103,8 +103,8 @@ TEST_F(MslGeneratorImplTest, Emit_IfWithMultiple) {
auto* else_body_2 = create<ast::BlockStatement>();
else_body_2->append(create<ast::ReturnStatement>(Source{}));
auto* cond =
create<ast::IdentifierExpression>(mod.RegisterSymbol("cond"), "cond");
auto* cond = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("cond"), "cond");
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>(Source{}));

View File

@ -55,12 +55,12 @@ TEST_P(MslImportData_SingleParamTest, FloatScalar) {
ast::ExpressionList params;
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 1.f)));
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)));
auto* ident = create<ast::IdentifierExpression>(
mod.RegisterSymbol(param.name), param.name);
Source{}, mod.RegisterSymbol(param.name), param.name);
ast::CallExpression call(ident, params);
ast::CallExpression call(Source{}, ident, params);
// The call type determination will set the intrinsic data for the ident
ASSERT_TRUE(td.DetermineResultType(&call)) << td.error();
@ -99,11 +99,12 @@ TEST_F(MslGeneratorImplTest, MslImportData_SingleParamTest_IntScalar) {
ast::ExpressionList params;
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 1)));
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1)));
ast::CallExpression expr(
create<ast::IdentifierExpression>(mod.RegisterSymbol("abs"), "abs"),
params);
ast::CallExpression expr(Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("abs"), "abs"),
params);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -119,13 +120,15 @@ TEST_P(MslImportData_DualParamTest, FloatScalar) {
ast::ExpressionList params;
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 1.f)));
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)));
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 2.f)));
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.f)));
ast::CallExpression expr(create<ast::IdentifierExpression>(
mod.RegisterSymbol(param.name), param.name),
params);
ast::CallExpression expr(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol(param.name), param.name),
params);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ASSERT_TRUE(gen.EmitCall(&expr)) << gen.error();
@ -153,28 +156,32 @@ TEST_P(MslImportData_DualParam_VectorTest, FloatVector) {
ast::ExpressionList params;
params.push_back(create<ast::TypeConstructorExpression>(
&vec, ast::ExpressionList{
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 1.f)),
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 2.f)),
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 3.f)),
}));
Source{}, &vec,
ast::ExpressionList{
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)),
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.f)),
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 3.f)),
}));
params.push_back(create<ast::TypeConstructorExpression>(
&vec, ast::ExpressionList{
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 4.f)),
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 5.f)),
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 6.f)),
}));
Source{}, &vec,
ast::ExpressionList{
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 4.f)),
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 5.f)),
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 6.f)),
}));
ast::CallExpression expr(create<ast::IdentifierExpression>(
mod.RegisterSymbol(param.name), param.name),
params);
ast::CallExpression expr(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol(param.name), param.name),
params);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ASSERT_TRUE(gen.EmitCall(&expr)) << gen.error();
@ -194,13 +201,15 @@ TEST_P(MslImportData_DualParam_Int_Test, IntScalar) {
ast::ExpressionList params;
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 1)));
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1)));
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 2)));
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2)));
ast::CallExpression expr(create<ast::IdentifierExpression>(
mod.RegisterSymbol(param.name), param.name),
params);
ast::CallExpression expr(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol(param.name), param.name),
params);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ASSERT_TRUE(gen.EmitCall(&expr)) << gen.error();
@ -219,15 +228,17 @@ TEST_P(MslImportData_TripleParamTest, FloatScalar) {
ast::ExpressionList params;
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 1.f)));
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)));
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 2.f)));
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.f)));
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 3.f)));
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 3.f)));
ast::CallExpression expr(create<ast::IdentifierExpression>(
mod.RegisterSymbol(param.name), param.name),
params);
ast::CallExpression expr(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol(param.name), param.name),
params);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ASSERT_TRUE(gen.EmitCall(&expr)) << gen.error();
@ -251,15 +262,17 @@ TEST_P(MslImportData_TripleParam_Int_Test, IntScalar) {
ast::ExpressionList params;
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 1)));
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1)));
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 2)));
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2)));
params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 3)));
Source{}, create<ast::SintLiteral>(Source{}, &i32, 3)));
ast::CallExpression expr(create<ast::IdentifierExpression>(
mod.RegisterSymbol(param.name), param.name),
params);
ast::CallExpression expr(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol(param.name), param.name),
params);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ASSERT_TRUE(gen.EmitCall(&expr)) << gen.error();
@ -285,12 +298,13 @@ TEST_F(MslGeneratorImplTest, MslImportData_Determinant) {
ast::VariableDecorationList{}); // decorations
ast::ExpressionList params;
params.push_back(
create<ast::IdentifierExpression>(mod.RegisterSymbol("var"), "var"));
params.push_back(create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("var"), "var"));
ast::CallExpression expr(
create<ast::IdentifierExpression>(mod.RegisterSymbol("determinant"),
"determinant"),
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("determinant"), "determinant"),
params);
mod.AddGlobalVariable(var);

View File

@ -88,14 +88,15 @@ TEST_F(MslGeneratorImplTest, DISABLED_Intrinsic_OuterProduct) {
ast::VariableDecorationList{}); // decorations
ast::ExpressionList params;
params.push_back(
create<ast::IdentifierExpression>(mod.RegisterSymbol("a"), "a"));
params.push_back(
create<ast::IdentifierExpression>(mod.RegisterSymbol("b"), "b"));
params.push_back(create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("a"), "a"));
params.push_back(create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("b"), "b"));
ast::CallExpression call(
create<ast::IdentifierExpression>(mod.RegisterSymbol("outer_product"),
"outer_product"),
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("outer_product"), "outer_product"),
params);
td.RegisterVariableForTesting(a);
@ -122,13 +123,14 @@ TEST_F(MslGeneratorImplTest, Intrinsic_Call) {
ast::ExpressionList params;
params.push_back(create<ast::IdentifierExpression>(
mod.RegisterSymbol("param1"), "param1"));
Source{}, mod.RegisterSymbol("param1"), "param1"));
params.push_back(create<ast::IdentifierExpression>(
mod.RegisterSymbol("param2"), "param2"));
Source{}, mod.RegisterSymbol("param2"), "param2"));
ast::CallExpression call(
create<ast::IdentifierExpression>(mod.RegisterSymbol("dot"), "dot"),
params);
ast::CallExpression call(Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("dot"), "dot"),
params);
ast::Variable v1(Source{}, "param1", ast::StorageClass::kFunction, &vec,
false, nullptr, ast::VariableDecorationList{});

View File

@ -263,7 +263,7 @@ TEST_P(MslGeneratorIntrinsicTextureTest, Call) {
param.buildTextureVariable(this);
param.buildSamplerVariable(this);
ast::CallExpression call{Expr(param.function), param.args(this)};
ast::CallExpression call{Source{}, Expr(param.function), param.args(this)};
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(td.DetermineResultType(&call)) << td.error();

View File

@ -90,10 +90,10 @@ TEST_F(MslGeneratorImplTest, Emit_LoopNestedWithContinuing) {
body = create<ast::BlockStatement>();
body->append(inner);
auto* lhs =
create<ast::IdentifierExpression>(mod.RegisterSymbol("lhs"), "lhs");
auto* rhs =
create<ast::IdentifierExpression>(mod.RegisterSymbol("rhs"), "rhs");
auto* lhs = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("lhs"), "lhs");
auto* rhs = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("rhs"), "rhs");
continuing = create<ast::BlockStatement>();
continuing->append(create<ast::AssignmentStatement>(lhs, rhs));
@ -158,6 +158,7 @@ TEST_F(MslGeneratorImplTest, Emit_LoopWithVarUsedInContinuing) {
&f32, // type
false, // is_const
create<ast::ScalarConstructorExpression>(
Source{},
create<ast::FloatLiteral>(Source{}, &f32, 2.4)), // constructor
ast::VariableDecorationList{}); // decorations
@ -172,10 +173,10 @@ TEST_F(MslGeneratorImplTest, Emit_LoopWithVarUsedInContinuing) {
nullptr, // constructor
ast::VariableDecorationList{}))); // decorations
auto* lhs =
create<ast::IdentifierExpression>(mod.RegisterSymbol("lhs"), "lhs");
auto* rhs =
create<ast::IdentifierExpression>(mod.RegisterSymbol("rhs"), "rhs");
auto* lhs = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("lhs"), "lhs");
auto* rhs = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("rhs"), "rhs");
auto* continuing = create<ast::BlockStatement>();
continuing->append(create<ast::AssignmentStatement>(lhs, rhs));

View File

@ -29,12 +29,12 @@ namespace {
using MslGeneratorImplTest = TestHelper;
TEST_F(MslGeneratorImplTest, EmitExpression_MemberAccessor) {
auto* str =
create<ast::IdentifierExpression>(mod.RegisterSymbol("str"), "str");
auto* mem =
create<ast::IdentifierExpression>(mod.RegisterSymbol("mem"), "mem");
auto* str = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("str"), "str");
auto* mem = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("mem"), "mem");
ast::MemberAccessorExpression expr(str, mem);
ast::MemberAccessorExpression expr(Source{}, str, mem);
ASSERT_TRUE(gen.EmitExpression(&expr)) << gen.error();
EXPECT_EQ(gen.result(), "str.mem");

View File

@ -40,20 +40,21 @@ TEST_F(MslGeneratorImplTest, Emit_ModuleConstant) {
ast::ExpressionList exprs;
exprs.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
exprs.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 2.0f)));
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.0f)));
exprs.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 3.0f)));
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 3.0f)));
auto* var = create<ast::Variable>(
Source{}, // source
"pos", // name
ast::StorageClass::kNone, // storage_class
&ary, // type
true, // is_const
create<ast::TypeConstructorExpression>(&ary, exprs), // constructor
ast::VariableDecorationList{}); // decorations
auto* var =
create<ast::Variable>(Source{}, // source
"pos", // name
ast::StorageClass::kNone, // storage_class
&ary, // type
true, // is_const
create<ast::TypeConstructorExpression>(
Source{}, &ary, exprs), // constructor
ast::VariableDecorationList{}); // decorations
ASSERT_TRUE(gen.EmitProgramConstVariable(var)) << gen.error();
EXPECT_EQ(gen.result(), "constant float pos[3] = {1.0f, 2.0f, 3.0f};\n");
@ -69,6 +70,7 @@ TEST_F(MslGeneratorImplTest, Emit_SpecConstant) {
&f32, // type
true, // is_const
create<ast::ScalarConstructorExpression>(
Source{},
create<ast::FloatLiteral>(Source{}, &f32, 3.0f)), // constructor
ast::VariableDecorationList{
// decorations

View File

@ -39,8 +39,8 @@ TEST_F(MslGeneratorImplTest, Emit_Return) {
}
TEST_F(MslGeneratorImplTest, Emit_ReturnWithValue) {
auto* expr =
create<ast::IdentifierExpression>(mod.RegisterSymbol("expr"), "expr");
auto* expr = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("expr"), "expr");
ast::ReturnStatement r(Source{}, expr);
gen.increment_indent();

View File

@ -50,8 +50,8 @@ TEST_F(MslGeneratorImplTest, Emit_Switch) {
body.push_back(case_stmt);
body.push_back(def);
auto* cond =
create<ast::IdentifierExpression>(mod.RegisterSymbol("cond"), "cond");
auto* cond = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("cond"), "cond");
ast::SwitchStatement s(cond, body);
gen.increment_indent();

View File

@ -79,7 +79,7 @@ TEST_F(MslGeneratorImplTest, InputStructName_ConflictWithExisting) {
TEST_F(MslGeneratorImplTest, NameConflictWith_InputStructName) {
ASSERT_EQ(gen.generate_name("func_main_in"), "func_main_in");
ast::IdentifierExpression ident(mod.RegisterSymbol("func_main_in"),
ast::IdentifierExpression ident(Source{}, mod.RegisterSymbol("func_main_in"),
"func_main_in");
ASSERT_TRUE(gen.EmitIdentifier(&ident));
EXPECT_EQ(gen.result(), "func_main_in_0");

View File

@ -39,9 +39,9 @@ using MslUnaryOpTest = TestParamHelper<UnaryOpData>;
TEST_P(MslUnaryOpTest, Emit) {
auto params = GetParam();
auto* expr =
create<ast::IdentifierExpression>(mod.RegisterSymbol("expr"), "expr");
ast::UnaryOpExpression op(params.op, expr);
auto* expr = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("expr"), "expr");
ast::UnaryOpExpression op(Source{}, params.op, expr);
ASSERT_TRUE(gen.EmitExpression(&op)) << gen.error();
EXPECT_EQ(gen.result(), std::string(params.name) + "(expr)");

View File

@ -194,7 +194,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Private) {
TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Initializer_Private) {
auto* ident = create<ast::IdentifierExpression>(
mod.RegisterSymbol("initializer"), "initializer");
Source{}, mod.RegisterSymbol("initializer"), "initializer");
ast::type::F32 f32;
auto* var =
@ -218,7 +218,8 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Initializer_ZeroVec) {
ast::type::Vector vec(&f32, 3);
ast::ExpressionList values;
auto* zero_vec = create<ast::TypeConstructorExpression>(&vec, values);
auto* zero_vec =
create<ast::TypeConstructorExpression>(Source{}, &vec, values);
auto* var =
create<ast::Variable>(Source{}, // source

View File

@ -56,12 +56,12 @@ TEST_F(BuilderTest, ArrayAccessor) {
ast::Variable var(Source{}, "ary", ast::StorageClass::kFunction, &vec3, false,
nullptr, ast::VariableDecorationList{});
auto* ary =
create<ast::IdentifierExpression>(mod->RegisterSymbol("ary"), "ary");
auto* ary = create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("ary"), "ary");
auto* idx_expr = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 1));
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1));
ast::ArrayAccessorExpression expr(ary, idx_expr);
ast::ArrayAccessorExpression expr(Source{}, ary, idx_expr);
td.RegisterVariableForTesting(&var);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -101,12 +101,12 @@ TEST_F(BuilderTest, Accessor_Array_LoadIndex) {
ast::Variable idx(Source{}, "idx", ast::StorageClass::kFunction, &i32, false,
nullptr, ast::VariableDecorationList{});
auto* ary =
create<ast::IdentifierExpression>(mod->RegisterSymbol("ary"), "ary");
auto* idx_expr =
create<ast::IdentifierExpression>(mod->RegisterSymbol("idx"), "idx");
auto* ary = create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("ary"), "ary");
auto* idx_expr = create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("idx"), "idx");
ast::ArrayAccessorExpression expr(ary, idx_expr);
ast::ArrayAccessorExpression expr(Source{}, ary, idx_expr);
td.RegisterVariableForTesting(&var);
td.RegisterVariableForTesting(&idx);
@ -148,16 +148,17 @@ TEST_F(BuilderTest, ArrayAccessor_Dynamic) {
ast::Variable var(Source{}, "ary", ast::StorageClass::kFunction, &vec3, false,
nullptr, ast::VariableDecorationList{});
auto* ary =
create<ast::IdentifierExpression>(mod->RegisterSymbol("ary"), "ary");
auto* ary = create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("ary"), "ary");
ast::ArrayAccessorExpression expr(
ary, create<ast::BinaryExpression>(
ast::BinaryOp::kAdd,
create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 1)),
create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 2))));
Source{}, ary,
create<ast::BinaryExpression>(
Source{}, ast::BinaryOp::kAdd,
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1)),
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2))));
td.RegisterVariableForTesting(&var);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -198,12 +199,15 @@ TEST_F(BuilderTest, ArrayAccessor_MultiLevel) {
nullptr, ast::VariableDecorationList{});
ast::ArrayAccessorExpression expr(
Source{},
create<ast::ArrayAccessorExpression>(
create<ast::IdentifierExpression>(mod->RegisterSymbol("ary"), "ary"),
Source{},
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("ary"), "ary"),
create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 3))),
Source{}, create<ast::SintLiteral>(Source{}, &i32, 3))),
create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 2)));
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2)));
td.RegisterVariableForTesting(&var);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -246,11 +250,15 @@ TEST_F(BuilderTest, Accessor_ArrayWithSwizzle) {
nullptr, ast::VariableDecorationList{});
ast::MemberAccessorExpression expr(
Source{},
create<ast::ArrayAccessorExpression>(
create<ast::IdentifierExpression>(mod->RegisterSymbol("ary"), "ary"),
Source{},
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("ary"), "ary"),
create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 2))),
create<ast::IdentifierExpression>(mod->RegisterSymbol("xy"), "xy"));
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2))),
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("xy"),
"xy"));
td.RegisterVariableForTesting(&var);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -303,8 +311,11 @@ TEST_F(BuilderTest, MemberAccessor) {
false, nullptr, ast::VariableDecorationList{});
ast::MemberAccessorExpression expr(
create<ast::IdentifierExpression>(mod->RegisterSymbol("ident"), "ident"),
create<ast::IdentifierExpression>(mod->RegisterSymbol("b"), "b"));
Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("ident"),
"ident"),
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("b"),
"b"));
td.RegisterVariableForTesting(&var);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -359,12 +370,15 @@ TEST_F(BuilderTest, MemberAccessor_Nested) {
false, nullptr, ast::VariableDecorationList{});
ast::MemberAccessorExpression expr(
Source{},
create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>(mod->RegisterSymbol("ident"),
"ident"),
create<ast::IdentifierExpression>(mod->RegisterSymbol("inner"),
"inner")),
create<ast::IdentifierExpression>(mod->RegisterSymbol("a"), "a"));
Source{},
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("ident"), "ident"),
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("inner"), "inner")),
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("a"),
"a"));
td.RegisterVariableForTesting(&var);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -422,12 +436,15 @@ TEST_F(BuilderTest, MemberAccessor_Nested_WithAlias) {
false, nullptr, ast::VariableDecorationList{});
ast::MemberAccessorExpression expr(
Source{},
create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>(mod->RegisterSymbol("ident"),
"ident"),
create<ast::IdentifierExpression>(mod->RegisterSymbol("inner"),
"inner")),
create<ast::IdentifierExpression>(mod->RegisterSymbol("a"), "a"));
Source{},
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("ident"), "ident"),
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("inner"), "inner")),
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("a"),
"a"));
td.RegisterVariableForTesting(&var);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -484,15 +501,18 @@ TEST_F(BuilderTest, MemberAccessor_Nested_Assignment_LHS) {
false, nullptr, ast::VariableDecorationList{});
auto* lhs = create<ast::MemberAccessorExpression>(
Source{},
create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>(mod->RegisterSymbol("ident"),
"ident"),
create<ast::IdentifierExpression>(mod->RegisterSymbol("inner"),
"inner")),
create<ast::IdentifierExpression>(mod->RegisterSymbol("a"), "a"));
Source{},
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("ident"), "ident"),
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("inner"), "inner")),
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("a"),
"a"));
auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 2.f));
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.f));
ast::AssignmentStatement expr(lhs, rhs);
@ -554,16 +574,19 @@ TEST_F(BuilderTest, MemberAccessor_Nested_Assignment_RHS) {
ast::Variable store(Source{}, "store", ast::StorageClass::kFunction, &f32,
false, nullptr, ast::VariableDecorationList{});
auto* lhs =
create<ast::IdentifierExpression>(mod->RegisterSymbol("store"), "store");
auto* lhs = create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("store"), "store");
auto* rhs = create<ast::MemberAccessorExpression>(
Source{},
create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>(mod->RegisterSymbol("ident"),
"ident"),
create<ast::IdentifierExpression>(mod->RegisterSymbol("inner"),
"inner")),
create<ast::IdentifierExpression>(mod->RegisterSymbol("a"), "a"));
Source{},
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("ident"), "ident"),
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("inner"), "inner")),
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("a"),
"a"));
ast::AssignmentStatement expr(lhs, rhs);
@ -608,8 +631,11 @@ TEST_F(BuilderTest, MemberAccessor_Swizzle_Single) {
false, nullptr, ast::VariableDecorationList{});
ast::MemberAccessorExpression expr(
create<ast::IdentifierExpression>(mod->RegisterSymbol("ident"), "ident"),
create<ast::IdentifierExpression>(mod->RegisterSymbol("y"), "y"));
Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("ident"),
"ident"),
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("y"),
"y"));
td.RegisterVariableForTesting(&var);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -645,8 +671,11 @@ TEST_F(BuilderTest, MemberAccessor_Swizzle_MultipleNames) {
false, nullptr, ast::VariableDecorationList{});
ast::MemberAccessorExpression expr(
create<ast::IdentifierExpression>(mod->RegisterSymbol("ident"), "ident"),
create<ast::IdentifierExpression>(mod->RegisterSymbol("yx"), "yx"));
Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("ident"),
"ident"),
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("yx"),
"yx"));
td.RegisterVariableForTesting(&var);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -681,11 +710,15 @@ TEST_F(BuilderTest, MemberAccessor_Swizzle_of_Swizzle) {
false, nullptr, ast::VariableDecorationList{});
ast::MemberAccessorExpression expr(
Source{},
create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>(mod->RegisterSymbol("ident"),
"ident"),
create<ast::IdentifierExpression>(mod->RegisterSymbol("yxz"), "yxz")),
create<ast::IdentifierExpression>(mod->RegisterSymbol("xz"), "xz"));
Source{},
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("ident"), "ident"),
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("yxz"), "yxz")),
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("xz"),
"xz"));
td.RegisterVariableForTesting(&var);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -721,11 +754,15 @@ TEST_F(BuilderTest, MemberAccessor_Member_of_Swizzle) {
false, nullptr, ast::VariableDecorationList{});
ast::MemberAccessorExpression expr(
Source{},
create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>(mod->RegisterSymbol("ident"),
"ident"),
create<ast::IdentifierExpression>(mod->RegisterSymbol("yxz"), "yxz")),
create<ast::IdentifierExpression>(mod->RegisterSymbol("x"), "x"));
Source{},
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("ident"), "ident"),
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("yxz"), "yxz")),
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("x"),
"x"));
td.RegisterVariableForTesting(&var);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -761,12 +798,15 @@ TEST_F(BuilderTest, MemberAccessor_Array_of_Swizzle) {
false, nullptr, ast::VariableDecorationList{});
ast::ArrayAccessorExpression expr(
Source{},
create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>(mod->RegisterSymbol("ident"),
"ident"),
create<ast::IdentifierExpression>(mod->RegisterSymbol("yxz"), "yxz")),
Source{},
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("ident"), "ident"),
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("yxz"), "yxz")),
create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 1)));
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1)));
td.RegisterVariableForTesting(&var);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -832,23 +872,32 @@ TEST_F(BuilderTest, Accessor_Mixed_ArrayAndMember) {
&a_ary_type, false, nullptr, ast::VariableDecorationList{});
ast::MemberAccessorExpression expr(
Source{},
create<ast::MemberAccessorExpression>(
Source{},
create<ast::MemberAccessorExpression>(
Source{},
create<ast::ArrayAccessorExpression>(
Source{},
create<ast::MemberAccessorExpression>(
Source{},
create<ast::ArrayAccessorExpression>(
Source{},
create<ast::IdentifierExpression>(
mod->RegisterSymbol("index"), "index"),
Source{}, mod->RegisterSymbol("index"), "index"),
create<ast::ScalarConstructorExpression>(
Source{},
create<ast::SintLiteral>(Source{}, &i32, 0))),
create<ast::IdentifierExpression>(
mod->RegisterSymbol("foo"), "foo")),
Source{}, mod->RegisterSymbol("foo"), "foo")),
create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(Source{}, &i32, 2))),
create<ast::IdentifierExpression>(mod->RegisterSymbol("bar"),
"bar")),
create<ast::IdentifierExpression>(mod->RegisterSymbol("baz"), "baz")),
create<ast::IdentifierExpression>(mod->RegisterSymbol("yx"), "yx"));
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2))),
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("bar"), "bar")),
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("baz"), "baz")),
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("yx"),
"yx"));
td.RegisterVariableForTesting(&var);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -901,37 +950,43 @@ TEST_F(BuilderTest, Accessor_Array_Of_Vec) {
ast::ExpressionList ary_params;
ary_params.push_back(create<ast::TypeConstructorExpression>(
&vec, ast::ExpressionList{
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 0.0)),
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 0.5)),
}));
Source{}, &vec,
ast::ExpressionList{
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 0.0)),
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 0.5)),
}));
ary_params.push_back(create<ast::TypeConstructorExpression>(
&vec, ast::ExpressionList{
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, -0.5)),
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, -0.5)),
}));
Source{}, &vec,
ast::ExpressionList{
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, -0.5)),
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, -0.5)),
}));
ary_params.push_back(create<ast::TypeConstructorExpression>(
&vec, ast::ExpressionList{
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 0.5)),
create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, -0.5)),
}));
Source{}, &vec,
ast::ExpressionList{
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 0.5)),
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, -0.5)),
}));
ast::Variable var(Source{}, "pos", ast::StorageClass::kPrivate, &arr, true,
create<ast::TypeConstructorExpression>(&arr, ary_params),
ast::VariableDecorationList{});
ast::Variable var(
Source{}, "pos", ast::StorageClass::kPrivate, &arr, true,
create<ast::TypeConstructorExpression>(Source{}, &arr, ary_params),
ast::VariableDecorationList{});
ast::ArrayAccessorExpression expr(
create<ast::IdentifierExpression>(mod->RegisterSymbol("pos"), "pos"),
Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("pos"),
"pos"),
create<ast::ScalarConstructorExpression>(
create<ast::UintLiteral>(Source{}, &u32, 1)));
Source{}, create<ast::UintLiteral>(Source{}, &u32, 1)));
td.RegisterVariableForTesting(&var);
ASSERT_TRUE(td.DetermineResultType(var.constructor())) << td.error();
@ -977,19 +1032,21 @@ TEST_F(BuilderTest, Accessor_Const_Vec) {
ast::ExpressionList vec_params;
vec_params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 0.0)));
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 0.0)));
vec_params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(Source{}, &f32, 0.5)));
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 0.5)));
ast::Variable var(
Source{}, "pos", ast::StorageClass::kPrivate, &vec, true,
create<ast::TypeConstructorExpression>(&vec, std::move(vec_params)),
ast::VariableDecorationList{});
ast::Variable var(Source{}, "pos", ast::StorageClass::kPrivate, &vec, true,
create<ast::TypeConstructorExpression>(
Source{}, &vec, std::move(vec_params)),
ast::VariableDecorationList{});
ast::ArrayAccessorExpression expr(
create<ast::IdentifierExpression>(mod->RegisterSymbol("pos"), "pos"),
Source{},
create<ast::IdentifierExpression>(Source{}, mod->RegisterSymbol("pos"),
"pos"),
create<ast::ScalarConstructorExpression>(
create<ast::UintLiteral>(Source{}, &u32, 1)));
Source{}, create<ast::UintLiteral>(Source{}, &u32, 1)));
td.RegisterVariableForTesting(&var);
ASSERT_TRUE(td.DetermineResultType(var.constructor())) << td.error();

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