Unrevert "[ast] Remove unused constructors and setters".
Hopefully the trybot issue is now resolved. This reverts commit5792783e72
, unreverting commit4d28b27935
. Change-Id: I2855bf17c5025a3d349e7fce16fdca342517aad3 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34564 Reviewed-by: dan sinclair <dsinclair@chromium.org> Commit-Queue: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
89ea705766
commit
c15d0a73ee
|
@ -22,8 +22,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::ArrayAccessorExpression);
|
||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
ArrayAccessorExpression::ArrayAccessorExpression() : Base() {}
|
|
||||||
|
|
||||||
ArrayAccessorExpression::ArrayAccessorExpression(Expression* array,
|
ArrayAccessorExpression::ArrayAccessorExpression(Expression* array,
|
||||||
Expression* idx_expr)
|
Expression* idx_expr)
|
||||||
: Base(), array_(array), idx_expr_(idx_expr) {}
|
: Base(), array_(array), idx_expr_(idx_expr) {}
|
||||||
|
|
|
@ -28,8 +28,6 @@ namespace ast {
|
||||||
class ArrayAccessorExpression
|
class ArrayAccessorExpression
|
||||||
: public Castable<ArrayAccessorExpression, Expression> {
|
: public Castable<ArrayAccessorExpression, Expression> {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
|
||||||
ArrayAccessorExpression();
|
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// @param array the array
|
/// @param array the array
|
||||||
/// @param idx_expr the index expression
|
/// @param idx_expr the index expression
|
||||||
|
@ -45,9 +43,6 @@ class ArrayAccessorExpression
|
||||||
ArrayAccessorExpression(ArrayAccessorExpression&&);
|
ArrayAccessorExpression(ArrayAccessorExpression&&);
|
||||||
~ArrayAccessorExpression() override;
|
~ArrayAccessorExpression() override;
|
||||||
|
|
||||||
/// Sets the array
|
|
||||||
/// @param array the array
|
|
||||||
void set_array(Expression* array) { array_ = array; }
|
|
||||||
/// @returns the array
|
/// @returns the array
|
||||||
Expression* array() const { return array_; }
|
Expression* array() const { return array_; }
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,10 @@ TEST_F(ArrayAccessorExpressionTest, CreateWithSource) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ArrayAccessorExpressionTest, IsArrayAccessor) {
|
TEST_F(ArrayAccessorExpressionTest, IsArrayAccessor) {
|
||||||
ArrayAccessorExpression exp;
|
auto* ary = create<IdentifierExpression>("ary");
|
||||||
|
auto* idx = create<IdentifierExpression>("idx");
|
||||||
|
|
||||||
|
ArrayAccessorExpression exp(ary, idx);
|
||||||
EXPECT_TRUE(exp.Is<ArrayAccessorExpression>());
|
EXPECT_TRUE(exp.Is<ArrayAccessorExpression>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,16 +61,14 @@ TEST_F(ArrayAccessorExpressionTest, IsValid) {
|
||||||
TEST_F(ArrayAccessorExpressionTest, IsValid_MissingArray) {
|
TEST_F(ArrayAccessorExpressionTest, IsValid_MissingArray) {
|
||||||
auto* idx = create<IdentifierExpression>("idx");
|
auto* idx = create<IdentifierExpression>("idx");
|
||||||
|
|
||||||
ArrayAccessorExpression exp;
|
ArrayAccessorExpression exp(nullptr, idx);
|
||||||
exp.set_idx_expr(idx);
|
|
||||||
EXPECT_FALSE(exp.IsValid());
|
EXPECT_FALSE(exp.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ArrayAccessorExpressionTest, IsValid_MissingIndex) {
|
TEST_F(ArrayAccessorExpressionTest, IsValid_MissingIndex) {
|
||||||
auto* ary = create<IdentifierExpression>("ary");
|
auto* ary = create<IdentifierExpression>("ary");
|
||||||
|
|
||||||
ArrayAccessorExpression exp;
|
ArrayAccessorExpression exp(ary, nullptr);
|
||||||
exp.set_array(ary);
|
|
||||||
EXPECT_FALSE(exp.IsValid());
|
EXPECT_FALSE(exp.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,8 +22,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::AssignmentStatement);
|
||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
AssignmentStatement::AssignmentStatement() : Base() {}
|
|
||||||
|
|
||||||
AssignmentStatement::AssignmentStatement(Expression* lhs, Expression* rhs)
|
AssignmentStatement::AssignmentStatement(Expression* lhs, Expression* rhs)
|
||||||
: Base(), lhs_(lhs), rhs_(rhs) {}
|
: Base(), lhs_(lhs), rhs_(rhs) {}
|
||||||
|
|
||||||
|
|
|
@ -28,8 +28,6 @@ namespace ast {
|
||||||
/// An assignment statement
|
/// An assignment statement
|
||||||
class AssignmentStatement : public Castable<AssignmentStatement, Statement> {
|
class AssignmentStatement : public Castable<AssignmentStatement, Statement> {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
|
||||||
AssignmentStatement();
|
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// @param lhs the left side of the expression
|
/// @param lhs the left side of the expression
|
||||||
/// @param rhs the right side of the expression
|
/// @param rhs the right side of the expression
|
||||||
|
@ -43,15 +41,8 @@ class AssignmentStatement : public Castable<AssignmentStatement, Statement> {
|
||||||
AssignmentStatement(AssignmentStatement&&);
|
AssignmentStatement(AssignmentStatement&&);
|
||||||
~AssignmentStatement() override;
|
~AssignmentStatement() override;
|
||||||
|
|
||||||
/// Sets the left side of the statement
|
|
||||||
/// @param lhs the left side to set
|
|
||||||
void set_lhs(Expression* lhs) { lhs_ = lhs; }
|
|
||||||
/// @returns the left side expression
|
/// @returns the left side expression
|
||||||
Expression* lhs() const { return lhs_; }
|
Expression* lhs() const { return lhs_; }
|
||||||
|
|
||||||
/// Sets the right side of the statement
|
|
||||||
/// @param rhs the right side to set
|
|
||||||
void set_rhs(Expression* rhs) { rhs_ = rhs; }
|
|
||||||
/// @returns the right side expression
|
/// @returns the right side expression
|
||||||
Expression* rhs() const { return rhs_; }
|
Expression* rhs() const { return rhs_; }
|
||||||
|
|
||||||
|
|
|
@ -61,16 +61,14 @@ TEST_F(AssignmentStatementTest, IsValid) {
|
||||||
TEST_F(AssignmentStatementTest, IsValid_MissingLHS) {
|
TEST_F(AssignmentStatementTest, IsValid_MissingLHS) {
|
||||||
auto* rhs = create<IdentifierExpression>("rhs");
|
auto* rhs = create<IdentifierExpression>("rhs");
|
||||||
|
|
||||||
AssignmentStatement stmt;
|
AssignmentStatement stmt(nullptr, rhs);
|
||||||
stmt.set_rhs(rhs);
|
|
||||||
EXPECT_FALSE(stmt.IsValid());
|
EXPECT_FALSE(stmt.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(AssignmentStatementTest, IsValid_MissingRHS) {
|
TEST_F(AssignmentStatementTest, IsValid_MissingRHS) {
|
||||||
auto* lhs = create<IdentifierExpression>("lhs");
|
auto* lhs = create<IdentifierExpression>("lhs");
|
||||||
|
|
||||||
AssignmentStatement stmt;
|
AssignmentStatement stmt(lhs, nullptr);
|
||||||
stmt.set_lhs(lhs);
|
|
||||||
EXPECT_FALSE(stmt.IsValid());
|
EXPECT_FALSE(stmt.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,8 +22,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::BinaryExpression);
|
||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
BinaryExpression::BinaryExpression() : Base() {}
|
|
||||||
|
|
||||||
BinaryExpression::BinaryExpression(BinaryOp op,
|
BinaryExpression::BinaryExpression(BinaryOp op,
|
||||||
Expression* lhs,
|
Expression* lhs,
|
||||||
Expression* rhs)
|
Expression* rhs)
|
||||||
|
|
|
@ -50,8 +50,6 @@ enum class BinaryOp {
|
||||||
/// An binary expression
|
/// An binary expression
|
||||||
class BinaryExpression : public Castable<BinaryExpression, Expression> {
|
class BinaryExpression : public Castable<BinaryExpression, Expression> {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
|
||||||
BinaryExpression();
|
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// @param op the operation type
|
/// @param op the operation type
|
||||||
/// @param lhs the left side of the expression
|
/// @param lhs the left side of the expression
|
||||||
|
@ -70,9 +68,6 @@ class BinaryExpression : public Castable<BinaryExpression, Expression> {
|
||||||
BinaryExpression(BinaryExpression&&);
|
BinaryExpression(BinaryExpression&&);
|
||||||
~BinaryExpression() override;
|
~BinaryExpression() override;
|
||||||
|
|
||||||
/// Sets the binary op type
|
|
||||||
/// @param op the binary op type
|
|
||||||
void set_op(BinaryOp op) { op_ = op; }
|
|
||||||
/// @returns the binary op type
|
/// @returns the binary op type
|
||||||
BinaryOp op() const { return op_; }
|
BinaryOp op() const { return op_; }
|
||||||
|
|
||||||
|
@ -113,15 +108,8 @@ class BinaryExpression : public Castable<BinaryExpression, Expression> {
|
||||||
/// @returns true if the op is modulo
|
/// @returns true if the op is modulo
|
||||||
bool IsModulo() const { return op_ == BinaryOp::kModulo; }
|
bool IsModulo() const { return op_ == BinaryOp::kModulo; }
|
||||||
|
|
||||||
/// Sets the left side of the expression
|
|
||||||
/// @param lhs the left side to set
|
|
||||||
void set_lhs(Expression* lhs) { lhs_ = lhs; }
|
|
||||||
/// @returns the left side expression
|
/// @returns the left side expression
|
||||||
Expression* lhs() const { return lhs_; }
|
Expression* lhs() const { return lhs_; }
|
||||||
|
|
||||||
/// Sets the right side of the expression
|
|
||||||
/// @param rhs the right side to set
|
|
||||||
void set_rhs(Expression* rhs) { rhs_ = rhs; }
|
|
||||||
/// @returns the right side expression
|
/// @returns the right side expression
|
||||||
Expression* rhs() const { return rhs_; }
|
Expression* rhs() const { return rhs_; }
|
||||||
|
|
||||||
|
|
|
@ -46,8 +46,11 @@ TEST_F(BinaryExpressionTest, Creation_WithSource) {
|
||||||
EXPECT_EQ(src.range.begin.column, 2u);
|
EXPECT_EQ(src.range.begin.column, 2u);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BinaryExpressionTest, IsBinaryal) {
|
TEST_F(BinaryExpressionTest, IsBinary) {
|
||||||
BinaryExpression r;
|
auto* lhs = create<IdentifierExpression>("lhs");
|
||||||
|
auto* rhs = create<IdentifierExpression>("rhs");
|
||||||
|
|
||||||
|
BinaryExpression r(BinaryOp::kEqual, lhs, rhs);
|
||||||
EXPECT_TRUE(r.Is<BinaryExpression>());
|
EXPECT_TRUE(r.Is<BinaryExpression>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,9 +65,7 @@ TEST_F(BinaryExpressionTest, IsValid) {
|
||||||
TEST_F(BinaryExpressionTest, IsValid_Null_LHS) {
|
TEST_F(BinaryExpressionTest, IsValid_Null_LHS) {
|
||||||
auto* rhs = create<IdentifierExpression>("rhs");
|
auto* rhs = create<IdentifierExpression>("rhs");
|
||||||
|
|
||||||
BinaryExpression r;
|
BinaryExpression r(BinaryOp::kEqual, nullptr, rhs);
|
||||||
r.set_op(BinaryOp::kEqual);
|
|
||||||
r.set_rhs(rhs);
|
|
||||||
EXPECT_FALSE(r.IsValid());
|
EXPECT_FALSE(r.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,9 +80,7 @@ TEST_F(BinaryExpressionTest, IsValid_Invalid_LHS) {
|
||||||
TEST_F(BinaryExpressionTest, IsValid_Null_RHS) {
|
TEST_F(BinaryExpressionTest, IsValid_Null_RHS) {
|
||||||
auto* lhs = create<IdentifierExpression>("lhs");
|
auto* lhs = create<IdentifierExpression>("lhs");
|
||||||
|
|
||||||
BinaryExpression r;
|
BinaryExpression r(BinaryOp::kEqual, lhs, nullptr);
|
||||||
r.set_op(BinaryOp::kEqual);
|
|
||||||
r.set_lhs(lhs);
|
|
||||||
EXPECT_FALSE(r.IsValid());
|
EXPECT_FALSE(r.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,8 +22,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::BitcastExpression);
|
||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
BitcastExpression::BitcastExpression() : Base() {}
|
|
||||||
|
|
||||||
BitcastExpression::BitcastExpression(type::Type* type, Expression* expr)
|
BitcastExpression::BitcastExpression(type::Type* type, Expression* expr)
|
||||||
: Base(), type_(type), expr_(expr) {}
|
: Base(), type_(type), expr_(expr) {}
|
||||||
|
|
||||||
|
|
|
@ -28,8 +28,6 @@ namespace ast {
|
||||||
/// A bitcast expression
|
/// A bitcast expression
|
||||||
class BitcastExpression : public Castable<BitcastExpression, Expression> {
|
class BitcastExpression : public Castable<BitcastExpression, Expression> {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
|
||||||
BitcastExpression();
|
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// @param type the type
|
/// @param type the type
|
||||||
/// @param expr the expr
|
/// @param expr the expr
|
||||||
|
@ -43,15 +41,8 @@ class BitcastExpression : public Castable<BitcastExpression, Expression> {
|
||||||
BitcastExpression(BitcastExpression&&);
|
BitcastExpression(BitcastExpression&&);
|
||||||
~BitcastExpression() override;
|
~BitcastExpression() override;
|
||||||
|
|
||||||
/// Sets the type
|
|
||||||
/// @param type the type
|
|
||||||
void set_type(type::Type* type) { type_ = type; }
|
|
||||||
/// @returns the left side expression
|
/// @returns the left side expression
|
||||||
type::Type* type() const { return type_; }
|
type::Type* type() const { return type_; }
|
||||||
|
|
||||||
/// Sets the expr
|
|
||||||
/// @param expr the expression
|
|
||||||
void set_expr(Expression* expr) { expr_ = expr; }
|
|
||||||
/// @returns the expression
|
/// @returns the expression
|
||||||
Expression* expr() const { return expr_; }
|
Expression* expr() const { return expr_; }
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,10 @@ TEST_F(BitcastExpressionTest, CreateWithSource) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BitcastExpressionTest, IsBitcast) {
|
TEST_F(BitcastExpressionTest, IsBitcast) {
|
||||||
BitcastExpression exp;
|
type::F32 f32;
|
||||||
|
auto* expr = create<IdentifierExpression>("expr");
|
||||||
|
|
||||||
|
BitcastExpression exp(&f32, expr);
|
||||||
EXPECT_TRUE(exp.Is<BitcastExpression>());
|
EXPECT_TRUE(exp.Is<BitcastExpression>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,16 +62,14 @@ TEST_F(BitcastExpressionTest, IsValid) {
|
||||||
TEST_F(BitcastExpressionTest, IsValid_MissingType) {
|
TEST_F(BitcastExpressionTest, IsValid_MissingType) {
|
||||||
auto* expr = create<IdentifierExpression>("expr");
|
auto* expr = create<IdentifierExpression>("expr");
|
||||||
|
|
||||||
BitcastExpression exp;
|
BitcastExpression exp(nullptr, expr);
|
||||||
exp.set_expr(expr);
|
|
||||||
EXPECT_FALSE(exp.IsValid());
|
EXPECT_FALSE(exp.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BitcastExpressionTest, IsValid_MissingExpr) {
|
TEST_F(BitcastExpressionTest, IsValid_MissingExpr) {
|
||||||
type::F32 f32;
|
type::F32 f32;
|
||||||
|
|
||||||
BitcastExpression exp;
|
BitcastExpression exp(&f32, nullptr);
|
||||||
exp.set_type(&f32);
|
|
||||||
EXPECT_FALSE(exp.IsValid());
|
EXPECT_FALSE(exp.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,8 +22,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::CallExpression);
|
||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
CallExpression::CallExpression() : Base() {}
|
|
||||||
|
|
||||||
CallExpression::CallExpression(Expression* func, ExpressionList params)
|
CallExpression::CallExpression(Expression* func, ExpressionList params)
|
||||||
: Base(), func_(func), params_(params) {}
|
: Base(), func_(func), params_(params) {}
|
||||||
|
|
||||||
|
|
|
@ -27,8 +27,6 @@ namespace ast {
|
||||||
/// A call expression
|
/// A call expression
|
||||||
class CallExpression : public Castable<CallExpression, Expression> {
|
class CallExpression : public Castable<CallExpression, Expression> {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
|
||||||
CallExpression();
|
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// @param func the function
|
/// @param func the function
|
||||||
/// @param params the parameters
|
/// @param params the parameters
|
||||||
|
@ -42,15 +40,8 @@ class CallExpression : public Castable<CallExpression, Expression> {
|
||||||
CallExpression(CallExpression&&);
|
CallExpression(CallExpression&&);
|
||||||
~CallExpression() override;
|
~CallExpression() override;
|
||||||
|
|
||||||
/// Sets the func
|
|
||||||
/// @param func the func
|
|
||||||
void set_func(Expression* func) { func_ = func; }
|
|
||||||
/// @returns the func
|
/// @returns the func
|
||||||
Expression* func() const { return func_; }
|
Expression* func() const { return func_; }
|
||||||
|
|
||||||
/// Sets the parameters
|
|
||||||
/// @param params the parameters
|
|
||||||
void set_params(ExpressionList params) { params_ = params; }
|
|
||||||
/// @returns the parameters
|
/// @returns the parameters
|
||||||
const ExpressionList& params() const { return params_; }
|
const ExpressionList& params() const { return params_; }
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ TEST_F(CallExpressionTest, IsValid) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CallExpressionTest, IsValid_MissingFunction) {
|
TEST_F(CallExpressionTest, IsValid_MissingFunction) {
|
||||||
CallExpression stmt;
|
CallExpression stmt(nullptr, {});
|
||||||
EXPECT_FALSE(stmt.IsValid());
|
EXPECT_FALSE(stmt.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,8 +23,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::CallStatement);
|
||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
CallStatement::CallStatement() : Base() {}
|
|
||||||
|
|
||||||
CallStatement::CallStatement(CallExpression* call) : Base(), call_(call) {}
|
CallStatement::CallStatement(CallExpression* call) : Base(), call_(call) {}
|
||||||
|
|
||||||
CallStatement::CallStatement(CallStatement&&) = default;
|
CallStatement::CallStatement(CallStatement&&) = default;
|
||||||
|
|
|
@ -27,8 +27,6 @@ namespace ast {
|
||||||
/// A call expression
|
/// A call expression
|
||||||
class CallStatement : public Castable<CallStatement, Statement> {
|
class CallStatement : public Castable<CallStatement, Statement> {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
|
||||||
CallStatement();
|
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// @param call the function
|
/// @param call the function
|
||||||
explicit CallStatement(CallExpression* call);
|
explicit CallStatement(CallExpression* call);
|
||||||
|
@ -36,9 +34,6 @@ class CallStatement : public Castable<CallStatement, Statement> {
|
||||||
CallStatement(CallStatement&&);
|
CallStatement(CallStatement&&);
|
||||||
~CallStatement() override;
|
~CallStatement() override;
|
||||||
|
|
||||||
/// Sets the call expression
|
|
||||||
/// @param call the call
|
|
||||||
void set_expr(CallExpression* call) { call_ = call; }
|
|
||||||
/// @returns the call expression
|
/// @returns the call expression
|
||||||
CallExpression* expr() const { return call_; }
|
CallExpression* expr() const { return call_; }
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ TEST_F(CallStatementTest, Creation) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CallStatementTest, IsCall) {
|
TEST_F(CallStatementTest, IsCall) {
|
||||||
CallStatement c;
|
CallStatement c(nullptr);
|
||||||
EXPECT_TRUE(c.Is<CallStatement>());
|
EXPECT_TRUE(c.Is<CallStatement>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,12 +44,13 @@ TEST_F(CallStatementTest, IsValid) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CallStatementTest, IsValid_MissingExpr) {
|
TEST_F(CallStatementTest, IsValid_MissingExpr) {
|
||||||
CallStatement c;
|
CallStatement c(nullptr);
|
||||||
EXPECT_FALSE(c.IsValid());
|
EXPECT_FALSE(c.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CallStatementTest, IsValid_InvalidExpr) {
|
TEST_F(CallStatementTest, IsValid_InvalidExpr) {
|
||||||
CallStatement c(create<CallExpression>());
|
CallExpression stmt(nullptr, {});
|
||||||
|
CallStatement c(&stmt);
|
||||||
EXPECT_FALSE(c.IsValid());
|
EXPECT_FALSE(c.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,11 +52,6 @@ class CaseStatement : public Castable<CaseStatement, Statement> {
|
||||||
CaseStatement(CaseStatement&&);
|
CaseStatement(CaseStatement&&);
|
||||||
~CaseStatement() override;
|
~CaseStatement() override;
|
||||||
|
|
||||||
/// Sets the selectors for the case statement
|
|
||||||
/// @param selectors the selectors to set
|
|
||||||
void set_selectors(CaseSelectorList selectors) {
|
|
||||||
selectors_ = std::move(selectors);
|
|
||||||
}
|
|
||||||
/// @returns the case selectors, empty if none set
|
/// @returns the case selectors, empty if none set
|
||||||
const CaseSelectorList& selectors() const { return selectors_; }
|
const CaseSelectorList& selectors() const { return selectors_; }
|
||||||
/// @returns true if this is a default statement
|
/// @returns true if this is a default statement
|
||||||
|
|
|
@ -82,8 +82,7 @@ TEST_F(CaseStatementTest, IsDefault_WithoutSelectors) {
|
||||||
auto* body = create<BlockStatement>();
|
auto* body = create<BlockStatement>();
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>());
|
||||||
|
|
||||||
CaseStatement c(create<BlockStatement>());
|
CaseStatement c(body);
|
||||||
c.set_body(body);
|
|
||||||
EXPECT_TRUE(c.IsDefault());
|
EXPECT_TRUE(c.IsDefault());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,8 +91,7 @@ TEST_F(CaseStatementTest, IsDefault_WithSelectors) {
|
||||||
CaseSelectorList b;
|
CaseSelectorList b;
|
||||||
b.push_back(create<SintLiteral>(&i32, 2));
|
b.push_back(create<SintLiteral>(&i32, 2));
|
||||||
|
|
||||||
CaseStatement c(create<BlockStatement>());
|
CaseStatement c(b, create<BlockStatement>());
|
||||||
c.set_selectors(b);
|
|
||||||
EXPECT_FALSE(c.IsDefault());
|
EXPECT_FALSE(c.IsDefault());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@ namespace ast {
|
||||||
class DecoratedVariable : public Castable<DecoratedVariable, Variable> {
|
class DecoratedVariable : public Castable<DecoratedVariable, Variable> {
|
||||||
public:
|
public:
|
||||||
/// Create a new empty decorated variable statement
|
/// Create a new empty decorated variable statement
|
||||||
|
/// Note, used by the `Clone` method.
|
||||||
DecoratedVariable();
|
DecoratedVariable();
|
||||||
/// Create a decorated variable from an existing variable
|
/// Create a decorated variable from an existing variable
|
||||||
/// @param var the variable to initialize from
|
/// @param var the variable to initialize from
|
||||||
|
|
|
@ -107,7 +107,8 @@ TEST_F(DecoratedVariableTest, IsValid) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(DecoratedVariableTest, IsDecorated) {
|
TEST_F(DecoratedVariableTest, IsDecorated) {
|
||||||
DecoratedVariable dv;
|
type::I32 t;
|
||||||
|
DecoratedVariable dv(create<Variable>("my_var", StorageClass::kNone, &t));
|
||||||
EXPECT_TRUE(dv.Is<DecoratedVariable>());
|
EXPECT_TRUE(dv.Is<DecoratedVariable>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,17 +51,11 @@ class ElseStatement : public Castable<ElseStatement, Statement> {
|
||||||
ElseStatement(ElseStatement&&);
|
ElseStatement(ElseStatement&&);
|
||||||
~ElseStatement() override;
|
~ElseStatement() override;
|
||||||
|
|
||||||
/// Sets the condition for the else statement
|
|
||||||
/// @param condition the condition to set
|
|
||||||
void set_condition(Expression* condition) { condition_ = condition; }
|
|
||||||
/// @returns the else condition or nullptr if none set
|
/// @returns the else condition or nullptr if none set
|
||||||
Expression* condition() const { return condition_; }
|
Expression* condition() const { return condition_; }
|
||||||
/// @returns true if the else has a condition
|
/// @returns true if the else has a condition
|
||||||
bool HasCondition() const { return condition_ != nullptr; }
|
bool HasCondition() const { return condition_ != nullptr; }
|
||||||
|
|
||||||
/// Sets the else body
|
|
||||||
/// @param body the else body
|
|
||||||
void set_body(BlockStatement* body) { body_ = body; }
|
|
||||||
/// @returns the else body
|
/// @returns the else body
|
||||||
const BlockStatement* body() const { return body_; }
|
const BlockStatement* body() const { return body_; }
|
||||||
/// @returns the else body
|
/// @returns the else body
|
||||||
|
|
|
@ -90,7 +90,7 @@ TEST_F(ElseStatementTest, IsValid_WithNullBodyStatement) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ElseStatementTest, IsValid_InvalidCondition) {
|
TEST_F(ElseStatementTest, IsValid_InvalidCondition) {
|
||||||
auto* cond = create<ScalarConstructorExpression>();
|
auto* cond = create<ScalarConstructorExpression>(nullptr);
|
||||||
ElseStatement e(cond, create<BlockStatement>());
|
ElseStatement e(cond, create<BlockStatement>());
|
||||||
EXPECT_FALSE(e.IsValid());
|
EXPECT_FALSE(e.IsValid());
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,8 +30,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::Function);
|
||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
Function::Function() = default;
|
|
||||||
|
|
||||||
Function::Function(const std::string& name,
|
Function::Function(const std::string& name,
|
||||||
VariableList params,
|
VariableList params,
|
||||||
type::Type* return_type,
|
type::Type* return_type,
|
||||||
|
|
|
@ -50,8 +50,7 @@ class Function : public Castable<Function, Node> {
|
||||||
SetDecoration* set = nullptr;
|
SetDecoration* set = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Create a new empty function statement
|
/// Create a function
|
||||||
Function(); /// Create a function
|
|
||||||
/// @param name the function name
|
/// @param name the function name
|
||||||
/// @param params the function parameters
|
/// @param params the function parameters
|
||||||
/// @param return_type the return type
|
/// @param return_type the return type
|
||||||
|
@ -76,15 +75,8 @@ class Function : public Castable<Function, Node> {
|
||||||
|
|
||||||
~Function() override;
|
~Function() override;
|
||||||
|
|
||||||
/// Sets the function name
|
|
||||||
/// @param name the name to set
|
|
||||||
void set_name(const std::string& name) { name_ = name; }
|
|
||||||
/// @returns the function name
|
/// @returns the function name
|
||||||
const std::string& name() { return name_; }
|
const std::string& name() { return name_; }
|
||||||
|
|
||||||
/// Sets the function parameters
|
|
||||||
/// @param params the function parameters
|
|
||||||
void set_params(VariableList params) { params_ = std::move(params); }
|
|
||||||
/// @returns the function params
|
/// @returns the function params
|
||||||
const VariableList& params() const { return params_; }
|
const VariableList& params() const { return params_; }
|
||||||
|
|
||||||
|
|
|
@ -67,8 +67,8 @@ TEST_F(IfStatementTest, IsValid_WithElseStatements) {
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>());
|
||||||
|
|
||||||
ElseStatementList else_stmts;
|
ElseStatementList else_stmts;
|
||||||
else_stmts.push_back(create<ElseStatement>(create<BlockStatement>()));
|
else_stmts.push_back(create<ElseStatement>(
|
||||||
else_stmts[0]->set_condition(create<IdentifierExpression>("Ident"));
|
create<IdentifierExpression>("Ident"), create<BlockStatement>()));
|
||||||
else_stmts.push_back(create<ElseStatement>(create<BlockStatement>()));
|
else_stmts.push_back(create<ElseStatement>(create<BlockStatement>()));
|
||||||
|
|
||||||
IfStatement stmt(cond, body);
|
IfStatement stmt(cond, body);
|
||||||
|
@ -119,8 +119,8 @@ TEST_F(IfStatementTest, IsValid_NullElseStatement) {
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>());
|
||||||
|
|
||||||
ElseStatementList else_stmts;
|
ElseStatementList else_stmts;
|
||||||
else_stmts.push_back(create<ElseStatement>(create<BlockStatement>()));
|
else_stmts.push_back(create<ElseStatement>(
|
||||||
else_stmts[0]->set_condition(create<IdentifierExpression>("Ident"));
|
create<IdentifierExpression>("Ident"), create<BlockStatement>()));
|
||||||
else_stmts.push_back(create<ElseStatement>(create<BlockStatement>()));
|
else_stmts.push_back(create<ElseStatement>(create<BlockStatement>()));
|
||||||
else_stmts.push_back(nullptr);
|
else_stmts.push_back(nullptr);
|
||||||
|
|
||||||
|
@ -135,8 +135,8 @@ TEST_F(IfStatementTest, IsValid_InvalidElseStatement) {
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>());
|
||||||
|
|
||||||
ElseStatementList else_stmts;
|
ElseStatementList else_stmts;
|
||||||
else_stmts.push_back(create<ElseStatement>(create<BlockStatement>()));
|
else_stmts.push_back(create<ElseStatement>(create<IdentifierExpression>(""),
|
||||||
else_stmts[0]->set_condition(create<IdentifierExpression>(""));
|
create<BlockStatement>()));
|
||||||
|
|
||||||
IfStatement stmt(cond, body);
|
IfStatement stmt(cond, body);
|
||||||
stmt.set_else_statements(else_stmts);
|
stmt.set_else_statements(else_stmts);
|
||||||
|
@ -164,8 +164,8 @@ TEST_F(IfStatementTest, IsValid_ElseNotLast) {
|
||||||
|
|
||||||
ElseStatementList else_stmts;
|
ElseStatementList else_stmts;
|
||||||
else_stmts.push_back(create<ElseStatement>(create<BlockStatement>()));
|
else_stmts.push_back(create<ElseStatement>(create<BlockStatement>()));
|
||||||
else_stmts.push_back(create<ElseStatement>(create<BlockStatement>()));
|
else_stmts.push_back(create<ElseStatement>(
|
||||||
else_stmts[1]->set_condition(create<IdentifierExpression>("ident"));
|
create<IdentifierExpression>("ident"), create<BlockStatement>()));
|
||||||
|
|
||||||
IfStatement stmt(cond, body);
|
IfStatement stmt(cond, body);
|
||||||
stmt.set_else_statements(else_stmts);
|
stmt.set_else_statements(else_stmts);
|
||||||
|
@ -205,11 +205,9 @@ TEST_F(IfStatementTest, ToStr_WithElseStatements) {
|
||||||
else_body->append(create<DiscardStatement>());
|
else_body->append(create<DiscardStatement>());
|
||||||
|
|
||||||
ElseStatementList else_stmts;
|
ElseStatementList else_stmts;
|
||||||
else_stmts.push_back(create<ElseStatement>(create<BlockStatement>()));
|
else_stmts.push_back(create<ElseStatement>(
|
||||||
else_stmts[0]->set_condition(create<IdentifierExpression>("ident"));
|
create<IdentifierExpression>("ident"), else_if_body));
|
||||||
else_stmts[0]->set_body(else_if_body);
|
else_stmts.push_back(create<ElseStatement>(else_body));
|
||||||
else_stmts.push_back(create<ElseStatement>(create<BlockStatement>()));
|
|
||||||
else_stmts[1]->set_body(else_body);
|
|
||||||
|
|
||||||
IfStatement stmt(cond, body);
|
IfStatement stmt(cond, body);
|
||||||
stmt.set_else_statements(else_stmts);
|
stmt.set_else_statements(else_stmts);
|
||||||
|
|
|
@ -29,7 +29,7 @@ class LocationDecoration
|
||||||
/// constructor
|
/// constructor
|
||||||
/// @param value the location value
|
/// @param value the location value
|
||||||
/// @param source the source of this decoration
|
/// @param source the source of this decoration
|
||||||
explicit LocationDecoration(uint32_t value, const Source& source);
|
LocationDecoration(uint32_t value, const Source& source);
|
||||||
~LocationDecoration() override;
|
~LocationDecoration() override;
|
||||||
|
|
||||||
/// @returns the location value
|
/// @returns the location value
|
||||||
|
|
|
@ -22,8 +22,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::MemberAccessorExpression);
|
||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
MemberAccessorExpression::MemberAccessorExpression() = default;
|
|
||||||
|
|
||||||
MemberAccessorExpression::MemberAccessorExpression(Expression* structure,
|
MemberAccessorExpression::MemberAccessorExpression(Expression* structure,
|
||||||
IdentifierExpression* member)
|
IdentifierExpression* member)
|
||||||
: Base(), struct_(structure), member_(member) {}
|
: Base(), struct_(structure), member_(member) {}
|
||||||
|
|
|
@ -30,8 +30,6 @@ namespace ast {
|
||||||
class MemberAccessorExpression
|
class MemberAccessorExpression
|
||||||
: public Castable<MemberAccessorExpression, Expression> {
|
: public Castable<MemberAccessorExpression, Expression> {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
|
||||||
MemberAccessorExpression();
|
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// @param structure the structure
|
/// @param structure the structure
|
||||||
/// @param member the member
|
/// @param member the member
|
||||||
|
@ -47,15 +45,8 @@ class MemberAccessorExpression
|
||||||
MemberAccessorExpression(MemberAccessorExpression&&);
|
MemberAccessorExpression(MemberAccessorExpression&&);
|
||||||
~MemberAccessorExpression() override;
|
~MemberAccessorExpression() override;
|
||||||
|
|
||||||
/// Sets the structure
|
|
||||||
/// @param structure the structure
|
|
||||||
void set_structure(Expression* structure) { struct_ = structure; }
|
|
||||||
/// @returns the structure
|
/// @returns the structure
|
||||||
Expression* structure() const { return struct_; }
|
Expression* structure() const { return struct_; }
|
||||||
|
|
||||||
/// Sets the member
|
|
||||||
/// @param member the member
|
|
||||||
void set_member(IdentifierExpression* member) { member_ = member; }
|
|
||||||
/// @returns the member expression
|
/// @returns the member expression
|
||||||
IdentifierExpression* member() const { return member_; }
|
IdentifierExpression* member() const { return member_; }
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,10 @@ TEST_F(MemberAccessorExpressionTest, Creation_WithSource) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MemberAccessorExpressionTest, IsMemberAccessor) {
|
TEST_F(MemberAccessorExpressionTest, IsMemberAccessor) {
|
||||||
MemberAccessorExpression stmt;
|
auto* str = create<IdentifierExpression>("structure");
|
||||||
|
auto* mem = create<IdentifierExpression>("member");
|
||||||
|
|
||||||
|
MemberAccessorExpression stmt(str, mem);
|
||||||
EXPECT_TRUE(stmt.Is<MemberAccessorExpression>());
|
EXPECT_TRUE(stmt.Is<MemberAccessorExpression>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,8 +63,7 @@ TEST_F(MemberAccessorExpressionTest, IsValid) {
|
||||||
TEST_F(MemberAccessorExpressionTest, IsValid_NullStruct) {
|
TEST_F(MemberAccessorExpressionTest, IsValid_NullStruct) {
|
||||||
auto* mem = create<IdentifierExpression>("member");
|
auto* mem = create<IdentifierExpression>("member");
|
||||||
|
|
||||||
MemberAccessorExpression stmt;
|
MemberAccessorExpression stmt(nullptr, mem);
|
||||||
stmt.set_member(mem);
|
|
||||||
EXPECT_FALSE(stmt.IsValid());
|
EXPECT_FALSE(stmt.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,8 +78,7 @@ TEST_F(MemberAccessorExpressionTest, IsValid_InvalidStruct) {
|
||||||
TEST_F(MemberAccessorExpressionTest, IsValid_NullMember) {
|
TEST_F(MemberAccessorExpressionTest, IsValid_NullMember) {
|
||||||
auto* str = create<IdentifierExpression>("structure");
|
auto* str = create<IdentifierExpression>("structure");
|
||||||
|
|
||||||
MemberAccessorExpression stmt;
|
MemberAccessorExpression stmt(str, nullptr);
|
||||||
stmt.set_structure(str);
|
|
||||||
EXPECT_FALSE(stmt.IsValid());
|
EXPECT_FALSE(stmt.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -139,7 +139,8 @@ TEST_F(ModuleTest, IsValid_Null_Function) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ModuleTest, IsValid_Invalid_Function) {
|
TEST_F(ModuleTest, IsValid_Invalid_Function) {
|
||||||
auto* func = create<Function>();
|
VariableList p;
|
||||||
|
auto* func = create<Function>("", p, nullptr, nullptr);
|
||||||
|
|
||||||
Module m;
|
Module m;
|
||||||
m.AddFunction(func);
|
m.AddFunction(func);
|
||||||
|
|
|
@ -22,8 +22,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::ScalarConstructorExpression);
|
||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
ScalarConstructorExpression::ScalarConstructorExpression() : Base() {}
|
|
||||||
|
|
||||||
ScalarConstructorExpression::ScalarConstructorExpression(Literal* literal)
|
ScalarConstructorExpression::ScalarConstructorExpression(Literal* literal)
|
||||||
: literal_(literal) {}
|
: literal_(literal) {}
|
||||||
|
|
||||||
|
|
|
@ -28,8 +28,6 @@ namespace ast {
|
||||||
class ScalarConstructorExpression
|
class ScalarConstructorExpression
|
||||||
: public Castable<ScalarConstructorExpression, ConstructorExpression> {
|
: public Castable<ScalarConstructorExpression, ConstructorExpression> {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
|
||||||
ScalarConstructorExpression();
|
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// @param literal the const literal
|
/// @param literal the const literal
|
||||||
explicit ScalarConstructorExpression(Literal* literal);
|
explicit ScalarConstructorExpression(Literal* literal);
|
||||||
|
@ -41,9 +39,6 @@ class ScalarConstructorExpression
|
||||||
ScalarConstructorExpression(ScalarConstructorExpression&&);
|
ScalarConstructorExpression(ScalarConstructorExpression&&);
|
||||||
~ScalarConstructorExpression() override;
|
~ScalarConstructorExpression() override;
|
||||||
|
|
||||||
/// Set the literal value
|
|
||||||
/// @param literal the literal
|
|
||||||
void set_literal(Literal* literal) { literal_ = literal; }
|
|
||||||
/// @returns the literal value
|
/// @returns the literal value
|
||||||
Literal* literal() const { return literal_; }
|
Literal* literal() const { return literal_; }
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ TEST_F(ScalarConstructorExpressionTest, IsValid) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ScalarConstructorExpressionTest, IsValid_MissingLiteral) {
|
TEST_F(ScalarConstructorExpressionTest, IsValid_MissingLiteral) {
|
||||||
ScalarConstructorExpression c;
|
ScalarConstructorExpression c(nullptr);
|
||||||
EXPECT_FALSE(c.IsValid());
|
EXPECT_FALSE(c.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,8 +23,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::Struct);
|
||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
Struct::Struct() : Base() {}
|
|
||||||
|
|
||||||
Struct::Struct(StructMemberList members)
|
Struct::Struct(StructMemberList members)
|
||||||
: Base(), members_(std::move(members)) {}
|
: Base(), members_(std::move(members)) {}
|
||||||
|
|
||||||
|
|
|
@ -29,8 +29,6 @@ namespace ast {
|
||||||
/// A struct statement.
|
/// A struct statement.
|
||||||
class Struct : public Castable<Struct, Node> {
|
class Struct : public Castable<Struct, Node> {
|
||||||
public:
|
public:
|
||||||
/// Create a new empty struct statement
|
|
||||||
Struct();
|
|
||||||
/// Create a new struct statement
|
/// Create a new struct statement
|
||||||
/// @param members The struct members
|
/// @param members The struct members
|
||||||
explicit Struct(StructMemberList members);
|
explicit Struct(StructMemberList members);
|
||||||
|
|
|
@ -23,8 +23,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::StructMember);
|
||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
StructMember::StructMember() = default;
|
|
||||||
|
|
||||||
StructMember::StructMember(const std::string& name,
|
StructMember::StructMember(const std::string& name,
|
||||||
type::Type* type,
|
type::Type* type,
|
||||||
StructMemberDecorationList decorations)
|
StructMemberDecorationList decorations)
|
||||||
|
|
|
@ -31,8 +31,6 @@ namespace ast {
|
||||||
/// A struct member statement.
|
/// A struct member statement.
|
||||||
class StructMember : public Castable<StructMember, Node> {
|
class StructMember : public Castable<StructMember, Node> {
|
||||||
public:
|
public:
|
||||||
/// Create a new empty struct member statement
|
|
||||||
StructMember();
|
|
||||||
/// Create a new struct member statement
|
/// Create a new struct member statement
|
||||||
/// @param name The struct member name
|
/// @param name The struct member name
|
||||||
/// @param type The struct member type
|
/// @param type The struct member type
|
||||||
|
@ -54,14 +52,8 @@ class StructMember : public Castable<StructMember, Node> {
|
||||||
|
|
||||||
~StructMember() override;
|
~StructMember() override;
|
||||||
|
|
||||||
/// Sets the name
|
|
||||||
/// @param name the name to set
|
|
||||||
void set_name(const std::string& name) { name_ = name; }
|
|
||||||
/// @returns the name
|
/// @returns the name
|
||||||
const std::string& name() const { return name_; }
|
const std::string& name() const { return name_; }
|
||||||
/// Sets the type
|
|
||||||
/// @param type the type to set
|
|
||||||
void set_type(type::Type* type) { type_ = type; }
|
|
||||||
/// @returns the type
|
/// @returns the type
|
||||||
type::Type* type() const { return type_; }
|
type::Type* type() const { return type_; }
|
||||||
/// Sets the decorations
|
/// Sets the decorations
|
||||||
|
|
|
@ -87,7 +87,7 @@ TEST_F(StructTest, CreationWithSourceAndDecorations) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(StructTest, IsValid) {
|
TEST_F(StructTest, IsValid) {
|
||||||
Struct s;
|
Struct s({});
|
||||||
EXPECT_TRUE(s.IsValid());
|
EXPECT_TRUE(s.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,8 +23,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::SwitchStatement);
|
||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
SwitchStatement::SwitchStatement() : Base() {}
|
|
||||||
|
|
||||||
SwitchStatement::SwitchStatement(Expression* condition, CaseStatementList body)
|
SwitchStatement::SwitchStatement(Expression* condition, CaseStatementList body)
|
||||||
: condition_(condition), body_(body) {}
|
: condition_(condition), body_(body) {}
|
||||||
|
|
||||||
|
|
|
@ -29,8 +29,6 @@ namespace ast {
|
||||||
/// A switch statement
|
/// A switch statement
|
||||||
class SwitchStatement : public Castable<SwitchStatement, Statement> {
|
class SwitchStatement : public Castable<SwitchStatement, Statement> {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
|
||||||
SwitchStatement();
|
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// @param condition the switch condition
|
/// @param condition the switch condition
|
||||||
/// @param body the switch body
|
/// @param body the switch body
|
||||||
|
@ -46,9 +44,6 @@ class SwitchStatement : public Castable<SwitchStatement, Statement> {
|
||||||
SwitchStatement(SwitchStatement&&);
|
SwitchStatement(SwitchStatement&&);
|
||||||
~SwitchStatement() override;
|
~SwitchStatement() override;
|
||||||
|
|
||||||
/// Sets the condition for the switch statement
|
|
||||||
/// @param condition the condition to set
|
|
||||||
void set_condition(Expression* condition) { condition_ = condition; }
|
|
||||||
/// @returns the switch condition or nullptr if none set
|
/// @returns the switch condition or nullptr if none set
|
||||||
Expression* condition() const { return condition_; }
|
Expression* condition() const { return condition_; }
|
||||||
/// @returns true if this is a default statement
|
/// @returns true if this is a default statement
|
||||||
|
|
|
@ -56,7 +56,16 @@ TEST_F(SwitchStatementTest, Creation_WithSource) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(SwitchStatementTest, IsSwitch) {
|
TEST_F(SwitchStatementTest, IsSwitch) {
|
||||||
SwitchStatement stmt;
|
type::I32 i32;
|
||||||
|
|
||||||
|
CaseSelectorList lit;
|
||||||
|
lit.push_back(create<SintLiteral>(&i32, 2));
|
||||||
|
|
||||||
|
auto* ident = create<IdentifierExpression>("ident");
|
||||||
|
CaseStatementList body;
|
||||||
|
body.push_back(create<CaseStatement>(lit, create<BlockStatement>()));
|
||||||
|
|
||||||
|
SwitchStatement stmt(ident, body);
|
||||||
EXPECT_TRUE(stmt.Is<SwitchStatement>());
|
EXPECT_TRUE(stmt.Is<SwitchStatement>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,8 +92,7 @@ TEST_F(SwitchStatementTest, IsValid_Null_Condition) {
|
||||||
CaseStatementList body;
|
CaseStatementList body;
|
||||||
body.push_back(create<CaseStatement>(lit, create<BlockStatement>()));
|
body.push_back(create<CaseStatement>(lit, create<BlockStatement>()));
|
||||||
|
|
||||||
SwitchStatement stmt;
|
SwitchStatement stmt(nullptr, body);
|
||||||
stmt.set_body(body);
|
|
||||||
EXPECT_FALSE(stmt.IsValid());
|
EXPECT_FALSE(stmt.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,14 +40,16 @@ namespace {
|
||||||
using StructTest = TestHelper;
|
using StructTest = TestHelper;
|
||||||
|
|
||||||
TEST_F(StructTest, Creation) {
|
TEST_F(StructTest, Creation) {
|
||||||
auto* impl = create<ast::Struct>();
|
StructMemberList members;
|
||||||
|
auto* impl = create<ast::Struct>(members);
|
||||||
auto* ptr = impl;
|
auto* ptr = impl;
|
||||||
Struct s{"S", impl};
|
Struct s{"S", impl};
|
||||||
EXPECT_EQ(s.impl(), ptr);
|
EXPECT_EQ(s.impl(), ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(StructTest, Is) {
|
TEST_F(StructTest, Is) {
|
||||||
auto* impl = create<ast::Struct>();
|
StructMemberList members;
|
||||||
|
auto* impl = create<ast::Struct>(members);
|
||||||
Struct s{"S", impl};
|
Struct s{"S", impl};
|
||||||
Type* ty = &s;
|
Type* ty = &s;
|
||||||
EXPECT_FALSE(ty->Is<AccessControl>());
|
EXPECT_FALSE(ty->Is<AccessControl>());
|
||||||
|
@ -66,7 +68,8 @@ TEST_F(StructTest, Is) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(StructTest, TypeName) {
|
TEST_F(StructTest, TypeName) {
|
||||||
auto* impl = create<ast::Struct>();
|
StructMemberList members;
|
||||||
|
auto* impl = create<ast::Struct>(members);
|
||||||
Struct s{"my_struct", impl};
|
Struct s{"my_struct", impl};
|
||||||
EXPECT_EQ(s.type_name(), "__struct_my_struct");
|
EXPECT_EQ(s.type_name(), "__struct_my_struct");
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,8 +22,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::TypeConstructorExpression);
|
||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
TypeConstructorExpression::TypeConstructorExpression() : Base() {}
|
|
||||||
|
|
||||||
TypeConstructorExpression::TypeConstructorExpression(type::Type* type,
|
TypeConstructorExpression::TypeConstructorExpression(type::Type* type,
|
||||||
ExpressionList values)
|
ExpressionList values)
|
||||||
: Base(), type_(type), values_(std::move(values)) {}
|
: Base(), type_(type), values_(std::move(values)) {}
|
||||||
|
|
|
@ -28,11 +28,10 @@ namespace ast {
|
||||||
class TypeConstructorExpression
|
class TypeConstructorExpression
|
||||||
: public Castable<TypeConstructorExpression, ConstructorExpression> {
|
: public Castable<TypeConstructorExpression, ConstructorExpression> {
|
||||||
public:
|
public:
|
||||||
TypeConstructorExpression();
|
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// @param type the type
|
/// @param type the type
|
||||||
/// @param values the values
|
/// @param values the values
|
||||||
explicit TypeConstructorExpression(type::Type* type, ExpressionList values);
|
TypeConstructorExpression(type::Type* type, ExpressionList values);
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// @param source the constructor source
|
/// @param source the constructor source
|
||||||
/// @param type the type
|
/// @param type the type
|
||||||
|
@ -44,15 +43,8 @@ class TypeConstructorExpression
|
||||||
TypeConstructorExpression(TypeConstructorExpression&&);
|
TypeConstructorExpression(TypeConstructorExpression&&);
|
||||||
~TypeConstructorExpression() override;
|
~TypeConstructorExpression() override;
|
||||||
|
|
||||||
/// Set the type
|
|
||||||
/// @param type the type
|
|
||||||
void set_type(type::Type* type) { type_ = type; }
|
|
||||||
/// @returns the type
|
/// @returns the type
|
||||||
type::Type* type() const { return type_; }
|
type::Type* type() const { return type_; }
|
||||||
|
|
||||||
/// Set the values
|
|
||||||
/// @param values the values
|
|
||||||
void set_values(ExpressionList values) { values_ = std::move(values); }
|
|
||||||
/// @returns the values
|
/// @returns the values
|
||||||
const ExpressionList& values() const { return values_; }
|
const ExpressionList& values() const { return values_; }
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,11 @@ TEST_F(TypeConstructorExpressionTest, Creation_WithSource) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TypeConstructorExpressionTest, IsTypeConstructor) {
|
TEST_F(TypeConstructorExpressionTest, IsTypeConstructor) {
|
||||||
TypeConstructorExpression t;
|
type::F32 f32;
|
||||||
|
ExpressionList expr;
|
||||||
|
expr.push_back(create<IdentifierExpression>("expr"));
|
||||||
|
|
||||||
|
TypeConstructorExpression t(&f32, expr);
|
||||||
EXPECT_TRUE(t.Is<TypeConstructorExpression>());
|
EXPECT_TRUE(t.Is<TypeConstructorExpression>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,8 +81,7 @@ TEST_F(TypeConstructorExpressionTest, IsValid_NullType) {
|
||||||
ExpressionList expr;
|
ExpressionList expr;
|
||||||
expr.push_back(create<IdentifierExpression>("expr"));
|
expr.push_back(create<IdentifierExpression>("expr"));
|
||||||
|
|
||||||
TypeConstructorExpression t;
|
TypeConstructorExpression t(nullptr, expr);
|
||||||
t.set_values(expr);
|
|
||||||
EXPECT_FALSE(t.IsValid());
|
EXPECT_FALSE(t.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,8 +22,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::UnaryOpExpression);
|
||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
UnaryOpExpression::UnaryOpExpression() : Base() {}
|
|
||||||
|
|
||||||
UnaryOpExpression::UnaryOpExpression(UnaryOp op, Expression* expr)
|
UnaryOpExpression::UnaryOpExpression(UnaryOp op, Expression* expr)
|
||||||
: Base(), op_(op), expr_(expr) {}
|
: Base(), op_(op), expr_(expr) {}
|
||||||
|
|
||||||
|
|
|
@ -28,8 +28,6 @@ namespace ast {
|
||||||
/// A unary op expression
|
/// A unary op expression
|
||||||
class UnaryOpExpression : public Castable<UnaryOpExpression, Expression> {
|
class UnaryOpExpression : public Castable<UnaryOpExpression, Expression> {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
|
||||||
UnaryOpExpression();
|
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// @param op the op
|
/// @param op the op
|
||||||
/// @param expr the expr
|
/// @param expr the expr
|
||||||
|
@ -43,15 +41,8 @@ class UnaryOpExpression : public Castable<UnaryOpExpression, Expression> {
|
||||||
UnaryOpExpression(UnaryOpExpression&&);
|
UnaryOpExpression(UnaryOpExpression&&);
|
||||||
~UnaryOpExpression() override;
|
~UnaryOpExpression() override;
|
||||||
|
|
||||||
/// Sets the op
|
|
||||||
/// @param op the op
|
|
||||||
void set_op(UnaryOp op) { op_ = op; }
|
|
||||||
/// @returns the op
|
/// @returns the op
|
||||||
UnaryOp op() const { return op_; }
|
UnaryOp op() const { return op_; }
|
||||||
|
|
||||||
/// Sets the expr
|
|
||||||
/// @param expr the expression
|
|
||||||
void set_expr(Expression* expr) { expr_ = expr; }
|
|
||||||
/// @returns the expression
|
/// @returns the expression
|
||||||
Expression* expr() const { return expr_; }
|
Expression* expr() const { return expr_; }
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,8 @@ TEST_F(UnaryOpExpressionTest, Creation_WithSource) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(UnaryOpExpressionTest, IsUnaryOp) {
|
TEST_F(UnaryOpExpressionTest, IsUnaryOp) {
|
||||||
UnaryOpExpression u;
|
auto* ident = create<IdentifierExpression>("ident");
|
||||||
|
UnaryOpExpression u(UnaryOp::kNot, ident);
|
||||||
EXPECT_TRUE(u.Is<UnaryOpExpression>());
|
EXPECT_TRUE(u.Is<UnaryOpExpression>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,8 +54,7 @@ TEST_F(UnaryOpExpressionTest, IsValid) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(UnaryOpExpressionTest, IsValid_NullExpression) {
|
TEST_F(UnaryOpExpressionTest, IsValid_NullExpression) {
|
||||||
UnaryOpExpression u;
|
UnaryOpExpression u(UnaryOp::kNot, nullptr);
|
||||||
u.set_op(UnaryOp::kNot);
|
|
||||||
EXPECT_FALSE(u.IsValid());
|
EXPECT_FALSE(u.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,11 +41,9 @@ Variable::Variable(Variable&&) = default;
|
||||||
Variable::~Variable() = default;
|
Variable::~Variable() = default;
|
||||||
|
|
||||||
Variable* Variable::Clone(CloneContext* ctx) const {
|
Variable* Variable::Clone(CloneContext* ctx) const {
|
||||||
auto* cloned = ctx->mod->create<Variable>();
|
auto* cloned =
|
||||||
|
ctx->mod->create<Variable>(name(), storage_class(), ctx->Clone(type()));
|
||||||
cloned->set_source(ctx->Clone(source()));
|
cloned->set_source(ctx->Clone(source()));
|
||||||
cloned->set_name(name());
|
|
||||||
cloned->set_storage_class(storage_class());
|
|
||||||
cloned->set_type(ctx->Clone(type()));
|
|
||||||
cloned->set_constructor(ctx->Clone(constructor()));
|
cloned->set_constructor(ctx->Clone(constructor()));
|
||||||
cloned->set_is_const(is_const());
|
cloned->set_is_const(is_const());
|
||||||
return cloned;
|
return cloned;
|
||||||
|
|
|
@ -78,8 +78,6 @@ namespace ast {
|
||||||
/// The storage class for a formal parameter is always StorageClass::kNone.
|
/// The storage class for a formal parameter is always StorageClass::kNone.
|
||||||
class Variable : public Castable<Variable, Node> {
|
class Variable : public Castable<Variable, Node> {
|
||||||
public:
|
public:
|
||||||
/// Create a new empty variable statement
|
|
||||||
Variable();
|
|
||||||
/// Create a variable
|
/// Create a variable
|
||||||
/// @param name the variables name
|
/// @param name the variables name
|
||||||
/// @param sc the variable storage class
|
/// @param sc the variable storage class
|
||||||
|
@ -149,6 +147,10 @@ class Variable : public Castable<Variable, Node> {
|
||||||
void to_str(std::ostream& out, size_t indent) const override;
|
void to_str(std::ostream& out, size_t indent) const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
/// Constructor
|
||||||
|
/// Used by the DecoratedVariable constructor.
|
||||||
|
Variable();
|
||||||
|
|
||||||
/// Output information for this variable.
|
/// Output information for this variable.
|
||||||
/// @param out the stream to write to
|
/// @param out the stream to write to
|
||||||
/// @param indent number of spaces to indent the node when writing
|
/// @param indent number of spaces to indent the node when writing
|
||||||
|
|
|
@ -22,8 +22,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::VariableDeclStatement);
|
||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
VariableDeclStatement::VariableDeclStatement() : Base() {}
|
|
||||||
|
|
||||||
VariableDeclStatement::VariableDeclStatement(Variable* variable)
|
VariableDeclStatement::VariableDeclStatement(Variable* variable)
|
||||||
: Base(), variable_(variable) {}
|
: Base(), variable_(variable) {}
|
||||||
|
|
||||||
|
|
|
@ -29,8 +29,6 @@ namespace ast {
|
||||||
class VariableDeclStatement
|
class VariableDeclStatement
|
||||||
: public Castable<VariableDeclStatement, Statement> {
|
: public Castable<VariableDeclStatement, Statement> {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
|
||||||
VariableDeclStatement();
|
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// @param variable the variable
|
/// @param variable the variable
|
||||||
explicit VariableDeclStatement(Variable* variable);
|
explicit VariableDeclStatement(Variable* variable);
|
||||||
|
@ -42,9 +40,6 @@ class VariableDeclStatement
|
||||||
VariableDeclStatement(VariableDeclStatement&&);
|
VariableDeclStatement(VariableDeclStatement&&);
|
||||||
~VariableDeclStatement() override;
|
~VariableDeclStatement() override;
|
||||||
|
|
||||||
/// Sets the variable
|
|
||||||
/// @param variable the variable to set
|
|
||||||
void set_variable(Variable* variable) { variable_ = variable; }
|
|
||||||
/// @returns the variable
|
/// @returns the variable
|
||||||
Variable* variable() const { return variable_; }
|
Variable* variable() const { return variable_; }
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,10 @@ TEST_F(VariableDeclStatementTest, Creation_WithSource) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(VariableDeclStatementTest, IsVariableDecl) {
|
TEST_F(VariableDeclStatementTest, IsVariableDecl) {
|
||||||
VariableDeclStatement s;
|
type::F32 f32;
|
||||||
|
auto* var = create<Variable>("a", StorageClass::kNone, &f32);
|
||||||
|
|
||||||
|
VariableDeclStatement s(var);
|
||||||
EXPECT_TRUE(s.Is<VariableDeclStatement>());
|
EXPECT_TRUE(s.Is<VariableDeclStatement>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +65,7 @@ TEST_F(VariableDeclStatementTest, IsValid_InvalidVariable) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(VariableDeclStatementTest, IsValid_NullVariable) {
|
TEST_F(VariableDeclStatementTest, IsValid_NullVariable) {
|
||||||
VariableDeclStatement stmt;
|
VariableDeclStatement stmt(nullptr);
|
||||||
EXPECT_FALSE(stmt.IsValid());
|
EXPECT_FALSE(stmt.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,14 +53,9 @@ TEST_F(VariableTest, CreationWithSource) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(VariableTest, CreationEmpty) {
|
TEST_F(VariableTest, CreationEmpty) {
|
||||||
Source s{Source::Range{Source::Location{27, 4}, Source::Location{27, 7}}};
|
|
||||||
Variable v;
|
|
||||||
v.set_source(s);
|
|
||||||
v.set_storage_class(StorageClass::kWorkgroup);
|
|
||||||
v.set_name("a_var");
|
|
||||||
|
|
||||||
type::I32 t;
|
type::I32 t;
|
||||||
v.set_type(&t);
|
Source s{Source::Range{Source::Location{27, 4}, Source::Location{27, 7}}};
|
||||||
|
Variable v(s, "a_var", StorageClass::kWorkgroup, &t);
|
||||||
|
|
||||||
EXPECT_EQ(v.name(), "a_var");
|
EXPECT_EQ(v.name(), "a_var");
|
||||||
EXPECT_EQ(v.storage_class(), StorageClass::kWorkgroup);
|
EXPECT_EQ(v.storage_class(), StorageClass::kWorkgroup);
|
||||||
|
@ -96,7 +91,7 @@ TEST_F(VariableTest, IsValid_MissingType) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(VariableTest, IsValid_MissingBoth) {
|
TEST_F(VariableTest, IsValid_MissingBoth) {
|
||||||
Variable v;
|
Variable v("", StorageClass::kNone, nullptr);
|
||||||
EXPECT_FALSE(v.IsValid());
|
EXPECT_FALSE(v.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2137,12 +2137,13 @@ bool FunctionEmitter::EmitSwitchStart(const BlockInfo& block_info) {
|
||||||
assert(construct->begin_id == block_info.id);
|
assert(construct->begin_id == block_info.id);
|
||||||
const auto* branch = block_info.basic_block->terminator();
|
const auto* branch = block_info.basic_block->terminator();
|
||||||
|
|
||||||
auto* const switch_stmt =
|
|
||||||
AddStatement(create<ast::SwitchStatement>())->As<ast::SwitchStatement>();
|
|
||||||
const auto selector_id = branch->GetSingleWordInOperand(0);
|
const auto selector_id = branch->GetSingleWordInOperand(0);
|
||||||
// Generate the code for the selector.
|
// Generate the code for the selector.
|
||||||
auto selector = MakeExpression(selector_id);
|
auto selector = MakeExpression(selector_id);
|
||||||
switch_stmt->set_condition(selector.expr);
|
|
||||||
|
ast::CaseStatementList list;
|
||||||
|
auto* swch = create<ast::SwitchStatement>(selector.expr, list);
|
||||||
|
auto* const switch_stmt = AddStatement(swch)->As<ast::SwitchStatement>();
|
||||||
|
|
||||||
// First, push the statement block for the entire switch. All the actual
|
// First, push the statement block for the entire switch. All the actual
|
||||||
// work is done by completion actions of the case/default clauses.
|
// work is done by completion actions of the case/default clauses.
|
||||||
|
@ -2194,12 +2195,6 @@ bool FunctionEmitter::EmitSwitchStart(const BlockInfo& block_info) {
|
||||||
// Push them on in reverse order.
|
// Push them on in reverse order.
|
||||||
const auto last_clause_index = clause_heads.size() - 1;
|
const auto last_clause_index = clause_heads.size() - 1;
|
||||||
for (size_t i = last_clause_index;; --i) {
|
for (size_t i = last_clause_index;; --i) {
|
||||||
// Create the case clause. Temporarily put it in the wrong order
|
|
||||||
// on the case statement list.
|
|
||||||
cases->emplace_back(
|
|
||||||
create<ast::CaseStatement>(create<ast::BlockStatement>()));
|
|
||||||
auto* clause = cases->back();
|
|
||||||
|
|
||||||
// Create a list of integer literals for the selector values leading to
|
// Create a list of integer literals for the selector values leading to
|
||||||
// this case clause.
|
// this case clause.
|
||||||
ast::CaseSelectorList selectors;
|
ast::CaseSelectorList selectors;
|
||||||
|
@ -2220,14 +2215,20 @@ bool FunctionEmitter::EmitSwitchStart(const BlockInfo& block_info) {
|
||||||
create<ast::SintLiteral>(selector.type, value32));
|
create<ast::SintLiteral>(selector.type, value32));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
clause->set_selectors(selectors);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Where does this clause end?
|
// Where does this clause end?
|
||||||
const auto end_id = (i + 1 < clause_heads.size()) ? clause_heads[i + 1]->id
|
const auto end_id = (i + 1 < clause_heads.size()) ? clause_heads[i + 1]->id
|
||||||
: construct->end_id;
|
: construct->end_id;
|
||||||
|
|
||||||
|
// Create the case clause. Temporarily put it in the wrong order
|
||||||
|
// on the case statement list.
|
||||||
|
cases->emplace_back(create<ast::CaseStatement>(selectors, nullptr));
|
||||||
|
auto* clause = cases->back();
|
||||||
|
|
||||||
PushNewStatementBlock(construct, end_id, [clause](StatementBlock* s) {
|
PushNewStatementBlock(construct, end_id, [clause](StatementBlock* s) {
|
||||||
|
// The `set_body` method of CaseStatement can be removed if this set
|
||||||
|
// is removed.
|
||||||
clause->set_body(s->statements_);
|
clause->set_body(s->statements_);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1745,14 +1745,13 @@ Maybe<ast::CaseStatement*> ParserImpl::switch_body() {
|
||||||
auto source = t.source();
|
auto source = t.source();
|
||||||
next(); // Consume the peek
|
next(); // Consume the peek
|
||||||
|
|
||||||
auto* stmt = create<ast::CaseStatement>(create<ast::BlockStatement>());
|
ast::CaseSelectorList selector_list;
|
||||||
stmt->set_source(source);
|
|
||||||
if (t.IsCase()) {
|
if (t.IsCase()) {
|
||||||
auto selectors = expect_case_selectors();
|
auto selectors = expect_case_selectors();
|
||||||
if (selectors.errored)
|
if (selectors.errored)
|
||||||
return Failure::kErrored;
|
return Failure::kErrored;
|
||||||
|
|
||||||
stmt->set_selectors(std::move(selectors.value));
|
selector_list = std::move(selectors.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* use = "case statement";
|
const char* use = "case statement";
|
||||||
|
@ -1767,9 +1766,7 @@ Maybe<ast::CaseStatement*> ParserImpl::switch_body() {
|
||||||
if (!body.matched)
|
if (!body.matched)
|
||||||
return add_error(body.source, "expected case body");
|
return add_error(body.source, "expected case body");
|
||||||
|
|
||||||
stmt->set_body(body.value);
|
return create<ast::CaseStatement>(source, selector_list, body.value);
|
||||||
|
|
||||||
return stmt;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// case_selectors
|
// case_selectors
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include "src/scope_stack.h"
|
#include "src/scope_stack.h"
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
#include "src/ast/type/f32_type.h"
|
||||||
#include "src/ast/variable.h"
|
#include "src/ast/variable.h"
|
||||||
|
|
||||||
namespace tint {
|
namespace tint {
|
||||||
|
@ -31,7 +32,8 @@ TEST_F(ScopeStackTest, Global) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ScopeStackTest, Global_SetWithPointer) {
|
TEST_F(ScopeStackTest, Global_SetWithPointer) {
|
||||||
ast::Variable v;
|
ast::type::F32 f32;
|
||||||
|
ast::Variable v("test", ast::StorageClass::kNone, &f32);
|
||||||
v.set_name("my_var");
|
v.set_name("my_var");
|
||||||
|
|
||||||
ScopeStack<ast::Variable*> s;
|
ScopeStack<ast::Variable*> s;
|
||||||
|
|
|
@ -50,8 +50,7 @@ TEST_F(HlslGeneratorImplTest_Alias, EmitAlias_Struct) {
|
||||||
ast::type::I32 i32;
|
ast::type::I32 i32;
|
||||||
ast::type::F32 f32;
|
ast::type::F32 f32;
|
||||||
|
|
||||||
auto* str = create<ast::Struct>();
|
auto* str = create<ast::Struct>(ast::StructMemberList{
|
||||||
str->set_members({
|
|
||||||
create<ast::StructMember>("a", &f32, ast::StructMemberDecorationList{}),
|
create<ast::StructMember>("a", &f32, ast::StructMemberDecorationList{}),
|
||||||
create<ast::StructMember>(
|
create<ast::StructMember>(
|
||||||
"b", &i32,
|
"b", &i32,
|
||||||
|
|
|
@ -279,8 +279,7 @@ TEST_F(HlslGeneratorImplTest_Function,
|
||||||
members.push_back(create<ast::StructMember>(
|
members.push_back(create<ast::StructMember>(
|
||||||
"coord", &vec4, ast::StructMemberDecorationList{}));
|
"coord", &vec4, ast::StructMemberDecorationList{}));
|
||||||
|
|
||||||
auto* str = create<ast::Struct>();
|
auto* str = create<ast::Struct>(members);
|
||||||
str->set_members(members);
|
|
||||||
|
|
||||||
ast::type::Struct s("Uniforms", str);
|
ast::type::Struct s("Uniforms", str);
|
||||||
|
|
||||||
|
@ -345,8 +344,7 @@ TEST_F(HlslGeneratorImplTest_Function,
|
||||||
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
||||||
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
|
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
|
||||||
|
|
||||||
auto* str = create<ast::Struct>();
|
auto* str = create<ast::Struct>(members);
|
||||||
str->set_members(members);
|
|
||||||
|
|
||||||
ast::type::Struct s("Data", str);
|
ast::type::Struct s("Data", str);
|
||||||
ast::type::AccessControl ac(ast::AccessControl::kReadWrite, &s);
|
ast::type::AccessControl ac(ast::AccessControl::kReadWrite, &s);
|
||||||
|
@ -404,8 +402,7 @@ TEST_F(HlslGeneratorImplTest_Function,
|
||||||
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
||||||
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
|
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
|
||||||
|
|
||||||
auto* str = create<ast::Struct>();
|
auto* str = create<ast::Struct>(members);
|
||||||
str->set_members(members);
|
|
||||||
|
|
||||||
ast::type::Struct s("Data", str);
|
ast::type::Struct s("Data", str);
|
||||||
ast::type::AccessControl ac(ast::AccessControl::kReadOnly, &s);
|
ast::type::AccessControl ac(ast::AccessControl::kReadOnly, &s);
|
||||||
|
@ -463,8 +460,7 @@ TEST_F(HlslGeneratorImplTest_Function,
|
||||||
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
||||||
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
|
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
|
||||||
|
|
||||||
auto* str = create<ast::Struct>();
|
auto* str = create<ast::Struct>(members);
|
||||||
str->set_members(members);
|
|
||||||
|
|
||||||
ast::type::Struct s("Data", str);
|
ast::type::Struct s("Data", str);
|
||||||
ast::type::AccessControl ac(ast::AccessControl::kReadWrite, &s);
|
ast::type::AccessControl ac(ast::AccessControl::kReadWrite, &s);
|
||||||
|
|
|
@ -54,8 +54,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, EmitExpression_MemberAccessor) {
|
||||||
deco.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
|
deco.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
|
||||||
members.push_back(create<ast::StructMember>("mem", &f32, deco));
|
members.push_back(create<ast::StructMember>("mem", &f32, deco));
|
||||||
|
|
||||||
auto* strct = create<ast::Struct>();
|
auto* strct = create<ast::Struct>(members);
|
||||||
strct->set_members(members);
|
|
||||||
|
|
||||||
ast::type::Struct s("Str", strct);
|
ast::type::Struct s("Str", strct);
|
||||||
|
|
||||||
|
@ -98,8 +97,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
||||||
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
|
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
|
||||||
|
|
||||||
auto* str = create<ast::Struct>();
|
auto* str = create<ast::Struct>(members);
|
||||||
str->set_members(members);
|
|
||||||
|
|
||||||
ast::type::Struct s("Data", str);
|
ast::type::Struct s("Data", str);
|
||||||
|
|
||||||
|
@ -142,8 +140,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
||||||
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
|
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
|
||||||
|
|
||||||
auto* str = create<ast::Struct>();
|
auto* str = create<ast::Struct>(members);
|
||||||
str->set_members(members);
|
|
||||||
|
|
||||||
ast::type::Struct s("Data", str);
|
ast::type::Struct s("Data", str);
|
||||||
|
|
||||||
|
@ -180,8 +177,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
ast::type::I32 i32;
|
ast::type::I32 i32;
|
||||||
ast::type::Matrix mat(&f32, 3, 2);
|
ast::type::Matrix mat(&f32, 3, 2);
|
||||||
|
|
||||||
auto* str = create<ast::Struct>();
|
auto* str = create<ast::Struct>(ast::StructMemberList{
|
||||||
str->set_members({
|
|
||||||
create<ast::StructMember>(
|
create<ast::StructMember>(
|
||||||
"z", &i32,
|
"z", &i32,
|
||||||
ast::StructMemberDecorationList{
|
ast::StructMemberDecorationList{
|
||||||
|
@ -249,8 +245,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
||||||
members.push_back(create<ast::StructMember>("a", &mat, b_deco));
|
members.push_back(create<ast::StructMember>("a", &mat, b_deco));
|
||||||
|
|
||||||
auto* str = create<ast::Struct>();
|
auto* str = create<ast::Struct>(members);
|
||||||
str->set_members(members);
|
|
||||||
|
|
||||||
ast::type::Struct s("Data", str);
|
ast::type::Struct s("Data", str);
|
||||||
|
|
||||||
|
@ -305,8 +300,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
||||||
members.push_back(create<ast::StructMember>("a", &mat, b_deco));
|
members.push_back(create<ast::StructMember>("a", &mat, b_deco));
|
||||||
|
|
||||||
auto* str = create<ast::Struct>();
|
auto* str = create<ast::Struct>(members);
|
||||||
str->set_members(members);
|
|
||||||
|
|
||||||
ast::type::Struct s("Data", str);
|
ast::type::Struct s("Data", str);
|
||||||
|
|
||||||
|
@ -356,8 +350,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
||||||
members.push_back(create<ast::StructMember>("a", &mat, b_deco));
|
members.push_back(create<ast::StructMember>("a", &mat, b_deco));
|
||||||
|
|
||||||
auto* str = create<ast::Struct>();
|
auto* str = create<ast::Struct>(members);
|
||||||
str->set_members(members);
|
|
||||||
|
|
||||||
ast::type::Struct s("Data", str);
|
ast::type::Struct s("Data", str);
|
||||||
|
|
||||||
|
@ -399,8 +392,7 @@ TEST_F(
|
||||||
deco.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
|
deco.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
|
||||||
members.push_back(create<ast::StructMember>("a", &mat, deco));
|
members.push_back(create<ast::StructMember>("a", &mat, deco));
|
||||||
|
|
||||||
auto* str = create<ast::Struct>();
|
auto* str = create<ast::Struct>(members);
|
||||||
str->set_members(members);
|
|
||||||
|
|
||||||
ast::type::Struct s("Data", str);
|
ast::type::Struct s("Data", str);
|
||||||
|
|
||||||
|
@ -446,8 +438,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(16, Source{}));
|
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(16, Source{}));
|
||||||
members.push_back(create<ast::StructMember>("a", &mat, b_deco));
|
members.push_back(create<ast::StructMember>("a", &mat, b_deco));
|
||||||
|
|
||||||
auto* str = create<ast::Struct>();
|
auto* str = create<ast::Struct>(members);
|
||||||
str->set_members(members);
|
|
||||||
|
|
||||||
ast::type::Struct s("Data", str);
|
ast::type::Struct s("Data", str);
|
||||||
|
|
||||||
|
@ -494,8 +485,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
a_deco.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
|
a_deco.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
|
||||||
members.push_back(create<ast::StructMember>("a", &ary, a_deco));
|
members.push_back(create<ast::StructMember>("a", &ary, a_deco));
|
||||||
|
|
||||||
auto* str = create<ast::Struct>();
|
auto* str = create<ast::Struct>(members);
|
||||||
str->set_members(members);
|
|
||||||
|
|
||||||
ast::type::Struct s("Data", str);
|
ast::type::Struct s("Data", str);
|
||||||
|
|
||||||
|
@ -539,8 +529,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
a_deco.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
|
a_deco.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
|
||||||
members.push_back(create<ast::StructMember>("a", &ary, a_deco));
|
members.push_back(create<ast::StructMember>("a", &ary, a_deco));
|
||||||
|
|
||||||
auto* str = create<ast::Struct>();
|
auto* str = create<ast::Struct>(members);
|
||||||
str->set_members(members);
|
|
||||||
|
|
||||||
ast::type::Struct s("Data", str);
|
ast::type::Struct s("Data", str);
|
||||||
|
|
||||||
|
@ -596,8 +585,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
||||||
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
|
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
|
||||||
|
|
||||||
auto* str = create<ast::Struct>();
|
auto* str = create<ast::Struct>(members);
|
||||||
str->set_members(members);
|
|
||||||
|
|
||||||
ast::type::Struct s("Data", str);
|
ast::type::Struct s("Data", str);
|
||||||
|
|
||||||
|
@ -643,8 +631,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
a_deco.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
|
a_deco.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
|
||||||
members.push_back(create<ast::StructMember>("a", &ary, a_deco));
|
members.push_back(create<ast::StructMember>("a", &ary, a_deco));
|
||||||
|
|
||||||
auto* str = create<ast::Struct>();
|
auto* str = create<ast::Struct>(members);
|
||||||
str->set_members(members);
|
|
||||||
|
|
||||||
ast::type::Struct s("Data", str);
|
ast::type::Struct s("Data", str);
|
||||||
|
|
||||||
|
@ -696,8 +683,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
||||||
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
|
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
|
||||||
|
|
||||||
auto* str = create<ast::Struct>();
|
auto* str = create<ast::Struct>(members);
|
||||||
str->set_members(members);
|
|
||||||
|
|
||||||
ast::type::Struct s("Data", str);
|
ast::type::Struct s("Data", str);
|
||||||
|
|
||||||
|
@ -748,8 +734,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(16, Source{}));
|
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(16, Source{}));
|
||||||
members.push_back(create<ast::StructMember>("b", &fvec3, b_deco));
|
members.push_back(create<ast::StructMember>("b", &fvec3, b_deco));
|
||||||
|
|
||||||
auto* str = create<ast::Struct>();
|
auto* str = create<ast::Struct>(members);
|
||||||
str->set_members(members);
|
|
||||||
|
|
||||||
ast::type::Struct s("Data", str);
|
ast::type::Struct s("Data", str);
|
||||||
|
|
||||||
|
@ -795,8 +780,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(16, Source{}));
|
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(16, Source{}));
|
||||||
members.push_back(create<ast::StructMember>("b", &fvec3, b_deco));
|
members.push_back(create<ast::StructMember>("b", &fvec3, b_deco));
|
||||||
|
|
||||||
auto* str = create<ast::Struct>();
|
auto* str = create<ast::Struct>(members);
|
||||||
str->set_members(members);
|
|
||||||
|
|
||||||
ast::type::Struct s("Data", str);
|
ast::type::Struct s("Data", str);
|
||||||
|
|
||||||
|
@ -851,8 +835,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
ast::type::Vector ivec3(&i32, 3);
|
ast::type::Vector ivec3(&i32, 3);
|
||||||
ast::type::Vector fvec3(&f32, 3);
|
ast::type::Vector fvec3(&f32, 3);
|
||||||
|
|
||||||
auto* data_str = create<ast::Struct>();
|
auto* data_str = create<ast::Struct>(ast::StructMemberList{
|
||||||
data_str->set_members({
|
|
||||||
create<ast::StructMember>(
|
create<ast::StructMember>(
|
||||||
"a", &ivec3,
|
"a", &ivec3,
|
||||||
ast::StructMemberDecorationList{
|
ast::StructMemberDecorationList{
|
||||||
|
@ -868,8 +851,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
ast::type::Array ary(&data, 4);
|
ast::type::Array ary(&data, 4);
|
||||||
ary.set_decorations({create<ast::StrideDecoration>(32, Source{})});
|
ary.set_decorations({create<ast::StrideDecoration>(32, Source{})});
|
||||||
|
|
||||||
auto* pre_str = create<ast::Struct>();
|
auto* pre_str = create<ast::Struct>(ast::StructMemberList{
|
||||||
pre_str->set_members({
|
|
||||||
create<ast::StructMember>(
|
create<ast::StructMember>(
|
||||||
"c", &ary,
|
"c", &ary,
|
||||||
ast::StructMemberDecorationList{
|
ast::StructMemberDecorationList{
|
||||||
|
@ -924,8 +906,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
ast::StructMemberList members;
|
ast::StructMemberList members;
|
||||||
ast::StructMemberDecorationList deco;
|
ast::StructMemberDecorationList deco;
|
||||||
|
|
||||||
auto* data_str = create<ast::Struct>();
|
auto* data_str = create<ast::Struct>(ast::StructMemberList{
|
||||||
data_str->set_members({
|
|
||||||
create<ast::StructMember>(
|
create<ast::StructMember>(
|
||||||
"a", &ivec3,
|
"a", &ivec3,
|
||||||
ast::StructMemberDecorationList{
|
ast::StructMemberDecorationList{
|
||||||
|
@ -941,8 +922,8 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
ast::type::Array ary(&data, 4);
|
ast::type::Array ary(&data, 4);
|
||||||
ary.set_decorations({create<ast::StrideDecoration>(32, Source{})});
|
ary.set_decorations({create<ast::StrideDecoration>(32, Source{})});
|
||||||
|
|
||||||
auto* pre_str = create<ast::Struct>();
|
auto* pre_str =
|
||||||
pre_str->set_members({create<ast::StructMember>(
|
create<ast::Struct>(ast::StructMemberList{create<ast::StructMember>(
|
||||||
"c", &ary,
|
"c", &ary,
|
||||||
ast::StructMemberDecorationList{
|
ast::StructMemberDecorationList{
|
||||||
create<ast::StructMemberOffsetDecoration>(0, Source{})})});
|
create<ast::StructMemberOffsetDecoration>(0, Source{})})});
|
||||||
|
@ -995,8 +976,7 @@ TEST_F(
|
||||||
ast::type::Vector ivec3(&i32, 3);
|
ast::type::Vector ivec3(&i32, 3);
|
||||||
ast::type::Vector fvec3(&f32, 3);
|
ast::type::Vector fvec3(&f32, 3);
|
||||||
|
|
||||||
auto* data_str = create<ast::Struct>();
|
auto* data_str = create<ast::Struct>(ast::StructMemberList{
|
||||||
data_str->set_members({
|
|
||||||
create<ast::StructMember>(
|
create<ast::StructMember>(
|
||||||
"a", &ivec3,
|
"a", &ivec3,
|
||||||
ast::StructMemberDecorationList{
|
ast::StructMemberDecorationList{
|
||||||
|
@ -1012,8 +992,8 @@ TEST_F(
|
||||||
ast::type::Array ary(&data, 4);
|
ast::type::Array ary(&data, 4);
|
||||||
ary.set_decorations({create<ast::StrideDecoration>(32, Source{})});
|
ary.set_decorations({create<ast::StrideDecoration>(32, Source{})});
|
||||||
|
|
||||||
auto* pre_str = create<ast::Struct>();
|
auto* pre_str =
|
||||||
pre_str->set_members({create<ast::StructMember>(
|
create<ast::Struct>(ast::StructMemberList{create<ast::StructMember>(
|
||||||
"c", &ary,
|
"c", &ary,
|
||||||
ast::StructMemberDecorationList{
|
ast::StructMemberDecorationList{
|
||||||
create<ast::StructMemberOffsetDecoration>(0, Source{})})});
|
create<ast::StructMemberOffsetDecoration>(0, Source{})})});
|
||||||
|
@ -1065,8 +1045,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
ast::type::Vector ivec3(&i32, 3);
|
ast::type::Vector ivec3(&i32, 3);
|
||||||
ast::type::Vector fvec3(&f32, 3);
|
ast::type::Vector fvec3(&f32, 3);
|
||||||
|
|
||||||
auto* data_str = create<ast::Struct>();
|
auto* data_str = create<ast::Struct>(ast::StructMemberList{
|
||||||
data_str->set_members({
|
|
||||||
create<ast::StructMember>(
|
create<ast::StructMember>(
|
||||||
"a", &ivec3,
|
"a", &ivec3,
|
||||||
ast::StructMemberDecorationList{
|
ast::StructMemberDecorationList{
|
||||||
|
@ -1082,8 +1061,8 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
ast::type::Array ary(&data, 4);
|
ast::type::Array ary(&data, 4);
|
||||||
ary.set_decorations({create<ast::StrideDecoration>(32, Source{})});
|
ary.set_decorations({create<ast::StrideDecoration>(32, Source{})});
|
||||||
|
|
||||||
auto* pre_str = create<ast::Struct>();
|
auto* pre_str =
|
||||||
pre_str->set_members({create<ast::StructMember>(
|
create<ast::Struct>(ast::StructMemberList{create<ast::StructMember>(
|
||||||
"c", &ary,
|
"c", &ary,
|
||||||
ast::StructMemberDecorationList{
|
ast::StructMemberDecorationList{
|
||||||
create<ast::StructMemberOffsetDecoration>(0, Source{})})});
|
create<ast::StructMemberOffsetDecoration>(0, Source{})})});
|
||||||
|
@ -1136,8 +1115,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
ast::type::Vector ivec3(&i32, 3);
|
ast::type::Vector ivec3(&i32, 3);
|
||||||
ast::type::Vector fvec3(&f32, 3);
|
ast::type::Vector fvec3(&f32, 3);
|
||||||
|
|
||||||
auto* data_str = create<ast::Struct>();
|
auto* data_str = create<ast::Struct>(ast::StructMemberList{
|
||||||
data_str->set_members({
|
|
||||||
create<ast::StructMember>(
|
create<ast::StructMember>(
|
||||||
"a", &ivec3,
|
"a", &ivec3,
|
||||||
ast::StructMemberDecorationList{
|
ast::StructMemberDecorationList{
|
||||||
|
@ -1153,8 +1131,8 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
ast::type::Array ary(&data, 4);
|
ast::type::Array ary(&data, 4);
|
||||||
ary.set_decorations({create<ast::StrideDecoration>(32, Source{})});
|
ary.set_decorations({create<ast::StrideDecoration>(32, Source{})});
|
||||||
|
|
||||||
auto* pre_str = create<ast::Struct>();
|
auto* pre_str =
|
||||||
pre_str->set_members({create<ast::StructMember>(
|
create<ast::Struct>(ast::StructMemberList{create<ast::StructMember>(
|
||||||
"c", &ary,
|
"c", &ary,
|
||||||
ast::StructMemberDecorationList{
|
ast::StructMemberDecorationList{
|
||||||
create<ast::StructMemberOffsetDecoration>(0, Source{})})});
|
create<ast::StructMemberOffsetDecoration>(0, Source{})})});
|
||||||
|
@ -1218,8 +1196,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
ast::type::Vector ivec3(&i32, 3);
|
ast::type::Vector ivec3(&i32, 3);
|
||||||
ast::type::Vector fvec3(&f32, 3);
|
ast::type::Vector fvec3(&f32, 3);
|
||||||
|
|
||||||
auto* data_str = create<ast::Struct>();
|
auto* data_str = create<ast::Struct>(ast::StructMemberList{
|
||||||
data_str->set_members({
|
|
||||||
create<ast::StructMember>(
|
create<ast::StructMember>(
|
||||||
"a", &ivec3,
|
"a", &ivec3,
|
||||||
ast::StructMemberDecorationList{
|
ast::StructMemberDecorationList{
|
||||||
|
@ -1235,8 +1212,8 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||||
ast::type::Array ary(&data, 4);
|
ast::type::Array ary(&data, 4);
|
||||||
ary.set_decorations({create<ast::StrideDecoration>(32, Source{})});
|
ary.set_decorations({create<ast::StrideDecoration>(32, Source{})});
|
||||||
|
|
||||||
auto* pre_str = create<ast::Struct>();
|
auto* pre_str =
|
||||||
pre_str->set_members({create<ast::StructMember>(
|
create<ast::Struct>(ast::StructMemberList{create<ast::StructMember>(
|
||||||
"c", &ary,
|
"c", &ary,
|
||||||
ast::StructMemberDecorationList{
|
ast::StructMemberDecorationList{
|
||||||
create<ast::StructMemberOffsetDecoration>(0, Source{})})});
|
create<ast::StructMemberOffsetDecoration>(0, Source{})})});
|
||||||
|
|
|
@ -181,8 +181,7 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_StructDecl) {
|
||||||
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
||||||
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
|
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
|
||||||
|
|
||||||
auto* str = create<ast::Struct>();
|
auto* str = create<ast::Struct>(members);
|
||||||
str->set_members(members);
|
|
||||||
|
|
||||||
ast::type::Struct s("S", str);
|
ast::type::Struct s("S", str);
|
||||||
|
|
||||||
|
@ -206,8 +205,7 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Struct) {
|
||||||
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
||||||
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
|
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
|
||||||
|
|
||||||
auto* str = create<ast::Struct>();
|
auto* str = create<ast::Struct>(members);
|
||||||
str->set_members(members);
|
|
||||||
|
|
||||||
ast::type::Struct s("S", str);
|
ast::type::Struct s("S", str);
|
||||||
|
|
||||||
|
@ -231,8 +229,7 @@ TEST_F(HlslGeneratorImplTest_Type, DISABLED_EmitType_Struct_InjectPadding) {
|
||||||
decos.push_back(create<ast::StructMemberOffsetDecoration>(128, Source{}));
|
decos.push_back(create<ast::StructMemberOffsetDecoration>(128, Source{}));
|
||||||
members.push_back(create<ast::StructMember>("c", &f32, decos));
|
members.push_back(create<ast::StructMember>("c", &f32, decos));
|
||||||
|
|
||||||
auto* str = create<ast::Struct>();
|
auto* str = create<ast::Struct>(members);
|
||||||
str->set_members(members);
|
|
||||||
|
|
||||||
ast::type::Struct s("S", str);
|
ast::type::Struct s("S", str);
|
||||||
|
|
||||||
|
@ -258,8 +255,7 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Struct_NameCollision) {
|
||||||
ast::StructMemberDecorationList b_deco;
|
ast::StructMemberDecorationList b_deco;
|
||||||
members.push_back(create<ast::StructMember>("float", &f32, b_deco));
|
members.push_back(create<ast::StructMember>("float", &f32, b_deco));
|
||||||
|
|
||||||
auto* str = create<ast::Struct>();
|
auto* str = create<ast::Struct>(members);
|
||||||
str->set_members(members);
|
|
||||||
|
|
||||||
ast::type::Struct s("S", str);
|
ast::type::Struct s("S", str);
|
||||||
|
|
||||||
|
|
|
@ -61,8 +61,7 @@ TEST_F(MslGeneratorImplTest, EmitConstructedType_Struct) {
|
||||||
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
||||||
members.push_back(create<ast::StructMember>("b", &i32, b_deco));
|
members.push_back(create<ast::StructMember>("b", &i32, b_deco));
|
||||||
|
|
||||||
auto* str = create<ast::Struct>();
|
auto* str = create<ast::Struct>(members);
|
||||||
str->set_members(members);
|
|
||||||
|
|
||||||
ast::type::Struct s("a", str);
|
ast::type::Struct s("a", str);
|
||||||
|
|
||||||
|
@ -86,8 +85,7 @@ TEST_F(MslGeneratorImplTest, EmitConstructedType_AliasStructIdent) {
|
||||||
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
||||||
members.push_back(create<ast::StructMember>("b", &i32, b_deco));
|
members.push_back(create<ast::StructMember>("b", &i32, b_deco));
|
||||||
|
|
||||||
auto* str = create<ast::Struct>();
|
auto* str = create<ast::Struct>(members);
|
||||||
str->set_members(members);
|
|
||||||
|
|
||||||
ast::type::Struct s("b", str);
|
ast::type::Struct s("b", str);
|
||||||
ast::type::Alias alias("a", &s);
|
ast::type::Alias alias("a", &s);
|
||||||
|
|
|
@ -295,8 +295,7 @@ TEST_F(MslGeneratorImplTest,
|
||||||
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
||||||
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
|
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
|
||||||
|
|
||||||
auto* str = create<ast::Struct>();
|
auto* str = create<ast::Struct>(members);
|
||||||
str->set_members(members);
|
|
||||||
|
|
||||||
ast::type::Struct s("Data", str);
|
ast::type::Struct s("Data", str);
|
||||||
ast::type::AccessControl ac(ast::AccessControl::kReadWrite, &s);
|
ast::type::AccessControl ac(ast::AccessControl::kReadWrite, &s);
|
||||||
|
@ -363,8 +362,7 @@ TEST_F(MslGeneratorImplTest,
|
||||||
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
||||||
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
|
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
|
||||||
|
|
||||||
auto* str = create<ast::Struct>();
|
auto* str = create<ast::Struct>(members);
|
||||||
str->set_members(members);
|
|
||||||
|
|
||||||
ast::type::Struct s("Data", str);
|
ast::type::Struct s("Data", str);
|
||||||
ast::type::AccessControl ac(ast::AccessControl::kReadOnly, &s);
|
ast::type::AccessControl ac(ast::AccessControl::kReadOnly, &s);
|
||||||
|
@ -731,8 +729,7 @@ TEST_F(MslGeneratorImplTest,
|
||||||
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
||||||
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
|
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
|
||||||
|
|
||||||
auto* str = create<ast::Struct>();
|
auto* str = create<ast::Struct>(members);
|
||||||
str->set_members(members);
|
|
||||||
|
|
||||||
ast::type::Struct s("Data", str);
|
ast::type::Struct s("Data", str);
|
||||||
ast::type::AccessControl ac(ast::AccessControl::kReadWrite, &s);
|
ast::type::AccessControl ac(ast::AccessControl::kReadWrite, &s);
|
||||||
|
@ -818,8 +815,7 @@ TEST_F(MslGeneratorImplTest,
|
||||||
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
||||||
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
|
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
|
||||||
|
|
||||||
auto* str = create<ast::Struct>();
|
auto* str = create<ast::Struct>(members);
|
||||||
str->set_members(members);
|
|
||||||
|
|
||||||
ast::type::Struct s("Data", str);
|
ast::type::Struct s("Data", str);
|
||||||
ast::type::AccessControl ac(ast::AccessControl::kReadOnly, &s);
|
ast::type::AccessControl ac(ast::AccessControl::kReadOnly, &s);
|
||||||
|
|
|
@ -168,8 +168,7 @@ TEST_F(MslGeneratorImplTest, calculate_alignment_size_struct) {
|
||||||
decos.push_back(create<ast::StructMemberOffsetDecoration>(128, Source{}));
|
decos.push_back(create<ast::StructMemberOffsetDecoration>(128, Source{}));
|
||||||
members.push_back(create<ast::StructMember>("c", &f32, decos));
|
members.push_back(create<ast::StructMember>("c", &f32, decos));
|
||||||
|
|
||||||
auto* str = create<ast::Struct>();
|
auto* str = create<ast::Struct>(members);
|
||||||
str->set_members(members);
|
|
||||||
|
|
||||||
ast::type::Struct s("S", str);
|
ast::type::Struct s("S", str);
|
||||||
|
|
||||||
|
@ -193,8 +192,7 @@ TEST_F(MslGeneratorImplTest, calculate_alignment_size_struct_of_struct) {
|
||||||
decos.push_back(create<ast::StructMemberOffsetDecoration>(32, Source{}));
|
decos.push_back(create<ast::StructMemberOffsetDecoration>(32, Source{}));
|
||||||
members.push_back(create<ast::StructMember>("c", &f32, decos));
|
members.push_back(create<ast::StructMember>("c", &f32, decos));
|
||||||
|
|
||||||
auto* inner_str = create<ast::Struct>();
|
auto* inner_str = create<ast::Struct>(members);
|
||||||
inner_str->set_members(members);
|
|
||||||
|
|
||||||
ast::type::Struct inner_s("Inner", inner_str);
|
ast::type::Struct inner_s("Inner", inner_str);
|
||||||
|
|
||||||
|
@ -207,8 +205,7 @@ TEST_F(MslGeneratorImplTest, calculate_alignment_size_struct_of_struct) {
|
||||||
decos.push_back(create<ast::StructMemberOffsetDecoration>(64, Source{}));
|
decos.push_back(create<ast::StructMemberOffsetDecoration>(64, Source{}));
|
||||||
members.push_back(create<ast::StructMember>("f", &f32, decos));
|
members.push_back(create<ast::StructMember>("f", &f32, decos));
|
||||||
|
|
||||||
auto* outer_str = create<ast::Struct>();
|
auto* outer_str = create<ast::Struct>(members);
|
||||||
outer_str->set_members(members);
|
|
||||||
|
|
||||||
ast::type::Struct outer_s("Outer", outer_str);
|
ast::type::Struct outer_s("Outer", outer_str);
|
||||||
|
|
||||||
|
|
|
@ -183,8 +183,7 @@ TEST_F(MslGeneratorImplTest, EmitType_Struct) {
|
||||||
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
||||||
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
|
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
|
||||||
|
|
||||||
auto* str = create<ast::Struct>();
|
auto* str = create<ast::Struct>(members);
|
||||||
str->set_members(members);
|
|
||||||
|
|
||||||
ast::type::Struct s("S", str);
|
ast::type::Struct s("S", str);
|
||||||
|
|
||||||
|
@ -204,8 +203,7 @@ TEST_F(MslGeneratorImplTest, EmitType_StructDecl) {
|
||||||
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
||||||
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
|
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
|
||||||
|
|
||||||
auto* str = create<ast::Struct>();
|
auto* str = create<ast::Struct>(members);
|
||||||
str->set_members(members);
|
|
||||||
|
|
||||||
ast::type::Struct s("S", str);
|
ast::type::Struct s("S", str);
|
||||||
|
|
||||||
|
@ -221,8 +219,7 @@ TEST_F(MslGeneratorImplTest, EmitType_Struct_InjectPadding) {
|
||||||
ast::type::I32 i32;
|
ast::type::I32 i32;
|
||||||
ast::type::F32 f32;
|
ast::type::F32 f32;
|
||||||
|
|
||||||
auto* str = create<ast::Struct>();
|
auto* str = create<ast::Struct>(ast::StructMemberList{
|
||||||
str->set_members({
|
|
||||||
create<ast::StructMember>(
|
create<ast::StructMember>(
|
||||||
"a", &i32,
|
"a", &i32,
|
||||||
ast::StructMemberDecorationList{
|
ast::StructMemberDecorationList{
|
||||||
|
@ -262,8 +259,7 @@ TEST_F(MslGeneratorImplTest, EmitType_Struct_NameCollision) {
|
||||||
ast::StructMemberDecorationList b_deco;
|
ast::StructMemberDecorationList b_deco;
|
||||||
members.push_back(create<ast::StructMember>("float", &f32, b_deco));
|
members.push_back(create<ast::StructMember>("float", &f32, b_deco));
|
||||||
|
|
||||||
auto* str = create<ast::Struct>();
|
auto* str = create<ast::Struct>(members);
|
||||||
str->set_members(members);
|
|
||||||
|
|
||||||
ast::type::Struct s("S", str);
|
ast::type::Struct s("S", str);
|
||||||
|
|
||||||
|
|
|
@ -90,8 +90,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Struct) {
|
||||||
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
||||||
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
|
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
|
||||||
|
|
||||||
auto* str = create<ast::Struct>();
|
auto* str = create<ast::Struct>(members);
|
||||||
str->set_members(members);
|
|
||||||
|
|
||||||
ast::type::Struct s("S", str);
|
ast::type::Struct s("S", str);
|
||||||
|
|
||||||
|
|
|
@ -279,7 +279,7 @@ TEST_F(BuilderTest_Type, ReturnsGeneratedPtr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BuilderTest_Type, GenerateStruct_Empty) {
|
TEST_F(BuilderTest_Type, GenerateStruct_Empty) {
|
||||||
auto* s = create<ast::Struct>();
|
auto* s = create<ast::Struct>(ast::StructMemberList{});
|
||||||
ast::type::Struct s_type("S", s);
|
ast::type::Struct s_type("S", s);
|
||||||
|
|
||||||
auto id = b.GenerateTypeIfNeeded(&s_type);
|
auto id = b.GenerateTypeIfNeeded(&s_type);
|
||||||
|
|
|
@ -51,8 +51,7 @@ TEST_F(WgslGeneratorImplTest, EmitConstructedType_Struct) {
|
||||||
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
||||||
members.push_back(create<ast::StructMember>("b", &i32, b_deco));
|
members.push_back(create<ast::StructMember>("b", &i32, b_deco));
|
||||||
|
|
||||||
auto* str = create<ast::Struct>();
|
auto* str = create<ast::Struct>(members);
|
||||||
str->set_members(members);
|
|
||||||
|
|
||||||
ast::type::Struct s("A", str);
|
ast::type::Struct s("A", str);
|
||||||
ast::type::Alias alias("B", &s);
|
ast::type::Alias alias("B", &s);
|
||||||
|
@ -80,8 +79,7 @@ TEST_F(WgslGeneratorImplTest, EmitAlias_ToStruct) {
|
||||||
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
||||||
members.push_back(create<ast::StructMember>("b", &i32, b_deco));
|
members.push_back(create<ast::StructMember>("b", &i32, b_deco));
|
||||||
|
|
||||||
auto* str = create<ast::Struct>();
|
auto* str = create<ast::Struct>(members);
|
||||||
str->set_members(members);
|
|
||||||
|
|
||||||
ast::type::Struct s("A", str);
|
ast::type::Struct s("A", str);
|
||||||
ast::type::Alias alias("B", &s);
|
ast::type::Alias alias("B", &s);
|
||||||
|
|
|
@ -185,8 +185,7 @@ TEST_F(WgslGeneratorImplTest, EmitType_Struct) {
|
||||||
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
||||||
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
|
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
|
||||||
|
|
||||||
auto* str = create<ast::Struct>();
|
auto* str = create<ast::Struct>(members);
|
||||||
str->set_members(members);
|
|
||||||
|
|
||||||
ast::type::Struct s("S", str);
|
ast::type::Struct s("S", str);
|
||||||
|
|
||||||
|
@ -206,8 +205,7 @@ TEST_F(WgslGeneratorImplTest, EmitType_StructDecl) {
|
||||||
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
||||||
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
|
members.push_back(create<ast::StructMember>("b", &f32, b_deco));
|
||||||
|
|
||||||
auto* str = create<ast::Struct>();
|
auto* str = create<ast::Struct>(members);
|
||||||
str->set_members(members);
|
|
||||||
|
|
||||||
ast::type::Struct s("S", str);
|
ast::type::Struct s("S", str);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue