From 5792783e72f61060de9cf4a953d5518a56171569 Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Wed, 2 Dec 2020 15:18:59 +0000 Subject: [PATCH] Revert "[ast] Remove unused constructors and setters." This reverts commit 4d28b2793512069dc23f88b2804f3594dbd80d45. Reason for revert: Seeing weird build breakage ... Original change's description: > [ast] Remove unused constructors and setters. > > This CL removes unused default constructors and various set methods > from the AST classes where they are not longer required. > > Change-Id: Ic437911c62d8c9e4354a1fa6bdc8483ce7511daf > Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34641 > Auto-Submit: dan sinclair > Reviewed-by: Ben Clayton > Commit-Queue: dan sinclair TBR=dsinclair@chromium.org,bclayton@google.com Change-Id: I9d5bf6fd6d47131650c964cad4e17a1cbe86b040 No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34682 Reviewed-by: dan sinclair Commit-Queue: dan sinclair --- src/ast/array_accessor_expression.cc | 2 + src/ast/array_accessor_expression.h | 5 + src/ast/array_accessor_expression_test.cc | 11 +- src/ast/assignment_statement.cc | 2 + src/ast/assignment_statement.h | 9 ++ src/ast/assignment_statement_test.cc | 6 +- src/ast/binary_expression.cc | 2 + src/ast/binary_expression.h | 12 ++ src/ast/binary_expression_test.cc | 15 +-- src/ast/bitcast_expression.cc | 2 + src/ast/bitcast_expression.h | 9 ++ src/ast/bitcast_expression_test.cc | 11 +- src/ast/call_expression.cc | 2 + src/ast/call_expression.h | 9 ++ src/ast/call_expression_test.cc | 2 +- src/ast/call_statement.cc | 2 + src/ast/call_statement.h | 5 + src/ast/call_statement_test.cc | 7 +- src/ast/case_statement.h | 5 + src/ast/case_statement_test.cc | 6 +- src/ast/decorated_variable.h | 1 - src/ast/decorated_variable_test.cc | 3 +- src/ast/else_statement.h | 6 + src/ast/else_statement_test.cc | 2 +- src/ast/function.cc | 2 + src/ast/function.h | 10 +- src/ast/if_statement_test.cc | 24 ++-- src/ast/location_decoration.h | 2 +- src/ast/member_accessor_expression.cc | 2 + src/ast/member_accessor_expression.h | 9 ++ src/ast/member_accessor_expression_test.cc | 11 +- src/ast/module_test.cc | 3 +- src/ast/scalar_constructor_expression.cc | 2 + src/ast/scalar_constructor_expression.h | 5 + src/ast/scalar_constructor_expression_test.cc | 2 +- src/ast/struct.cc | 2 + src/ast/struct.h | 2 + src/ast/struct_member.cc | 2 + src/ast/struct_member.h | 8 ++ src/ast/struct_test.cc | 2 +- src/ast/switch_statement.cc | 2 + src/ast/switch_statement.h | 5 + src/ast/switch_statement_test.cc | 14 +-- src/ast/type/struct_type_test.cc | 9 +- src/ast/type_constructor_expression.cc | 2 + src/ast/type_constructor_expression.h | 10 +- src/ast/type_constructor_expression_test.cc | 9 +- src/ast/unary_op_expression.cc | 2 + src/ast/unary_op_expression.h | 9 ++ src/ast/unary_op_expression_test.cc | 6 +- src/ast/variable.cc | 6 +- src/ast/variable.h | 6 +- src/ast/variable_decl_statement.cc | 2 + src/ast/variable_decl_statement.h | 5 + src/ast/variable_decl_statement_test.cc | 7 +- src/ast/variable_test.cc | 11 +- src/reader/spirv/function.cc | 21 ++-- src/reader/wgsl/parser_impl.cc | 9 +- src/scope_stack_test.cc | 4 +- .../hlsl/generator_impl_alias_type_test.cc | 3 +- .../hlsl/generator_impl_function_test.cc | 12 +- .../generator_impl_member_accessor_test.cc | 119 +++++++++++------- src/writer/hlsl/generator_impl_type_test.cc | 12 +- .../msl/generator_impl_alias_type_test.cc | 6 +- .../msl/generator_impl_function_test.cc | 12 +- src/writer/msl/generator_impl_test.cc | 9 +- src/writer/msl/generator_impl_type_test.cc | 12 +- ...rator_impl_variable_decl_statement_test.cc | 3 +- src/writer/spirv/builder_type_test.cc | 2 +- .../wgsl/generator_impl_alias_type_test.cc | 6 +- src/writer/wgsl/generator_impl_type_test.cc | 6 +- 71 files changed, 376 insertions(+), 189 deletions(-) diff --git a/src/ast/array_accessor_expression.cc b/src/ast/array_accessor_expression.cc index 79d5075405..75f3bf545c 100644 --- a/src/ast/array_accessor_expression.cc +++ b/src/ast/array_accessor_expression.cc @@ -20,6 +20,8 @@ namespace tint { namespace ast { +ArrayAccessorExpression::ArrayAccessorExpression() : Base() {} + ArrayAccessorExpression::ArrayAccessorExpression(Expression* array, Expression* idx_expr) : Base(), array_(array), idx_expr_(idx_expr) {} diff --git a/src/ast/array_accessor_expression.h b/src/ast/array_accessor_expression.h index 73cbdacc34..9cc98f75ea 100644 --- a/src/ast/array_accessor_expression.h +++ b/src/ast/array_accessor_expression.h @@ -28,6 +28,8 @@ namespace ast { class ArrayAccessorExpression : public Castable { public: + /// Constructor + ArrayAccessorExpression(); /// Constructor /// @param array the array /// @param idx_expr the index expression @@ -43,6 +45,9 @@ class ArrayAccessorExpression ArrayAccessorExpression(ArrayAccessorExpression&&); ~ArrayAccessorExpression() override; + /// Sets the array + /// @param array the array + void set_array(Expression* array) { array_ = array; } /// @returns the array Expression* array() const { return array_; } diff --git a/src/ast/array_accessor_expression_test.cc b/src/ast/array_accessor_expression_test.cc index 9526284065..f657815d57 100644 --- a/src/ast/array_accessor_expression_test.cc +++ b/src/ast/array_accessor_expression_test.cc @@ -43,10 +43,7 @@ TEST_F(ArrayAccessorExpressionTest, CreateWithSource) { } TEST_F(ArrayAccessorExpressionTest, IsArrayAccessor) { - auto* ary = create("ary"); - auto* idx = create("idx"); - - ArrayAccessorExpression exp(ary, idx); + ArrayAccessorExpression exp; EXPECT_TRUE(exp.Is()); } @@ -61,14 +58,16 @@ TEST_F(ArrayAccessorExpressionTest, IsValid) { TEST_F(ArrayAccessorExpressionTest, IsValid_MissingArray) { auto* idx = create("idx"); - ArrayAccessorExpression exp(nullptr, idx); + ArrayAccessorExpression exp; + exp.set_idx_expr(idx); EXPECT_FALSE(exp.IsValid()); } TEST_F(ArrayAccessorExpressionTest, IsValid_MissingIndex) { auto* ary = create("ary"); - ArrayAccessorExpression exp(ary, nullptr); + ArrayAccessorExpression exp; + exp.set_array(ary); EXPECT_FALSE(exp.IsValid()); } diff --git a/src/ast/assignment_statement.cc b/src/ast/assignment_statement.cc index 69f82f5046..fe72839cfc 100644 --- a/src/ast/assignment_statement.cc +++ b/src/ast/assignment_statement.cc @@ -20,6 +20,8 @@ namespace tint { namespace ast { +AssignmentStatement::AssignmentStatement() : Base() {} + AssignmentStatement::AssignmentStatement(Expression* lhs, Expression* rhs) : Base(), lhs_(lhs), rhs_(rhs) {} diff --git a/src/ast/assignment_statement.h b/src/ast/assignment_statement.h index 558ae426f9..2b61bd879b 100644 --- a/src/ast/assignment_statement.h +++ b/src/ast/assignment_statement.h @@ -28,6 +28,8 @@ namespace ast { /// An assignment statement class AssignmentStatement : public Castable { public: + /// Constructor + AssignmentStatement(); /// Constructor /// @param lhs the left side of the expression /// @param rhs the right side of the expression @@ -41,8 +43,15 @@ class AssignmentStatement : public Castable { AssignmentStatement(AssignmentStatement&&); ~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 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 Expression* rhs() const { return rhs_; } diff --git a/src/ast/assignment_statement_test.cc b/src/ast/assignment_statement_test.cc index 8fa68a4096..b804363821 100644 --- a/src/ast/assignment_statement_test.cc +++ b/src/ast/assignment_statement_test.cc @@ -61,14 +61,16 @@ TEST_F(AssignmentStatementTest, IsValid) { TEST_F(AssignmentStatementTest, IsValid_MissingLHS) { auto* rhs = create("rhs"); - AssignmentStatement stmt(nullptr, rhs); + AssignmentStatement stmt; + stmt.set_rhs(rhs); EXPECT_FALSE(stmt.IsValid()); } TEST_F(AssignmentStatementTest, IsValid_MissingRHS) { auto* lhs = create("lhs"); - AssignmentStatement stmt(lhs, nullptr); + AssignmentStatement stmt; + stmt.set_lhs(lhs); EXPECT_FALSE(stmt.IsValid()); } diff --git a/src/ast/binary_expression.cc b/src/ast/binary_expression.cc index f7ce959cb5..e6f3555b34 100644 --- a/src/ast/binary_expression.cc +++ b/src/ast/binary_expression.cc @@ -20,6 +20,8 @@ namespace tint { namespace ast { +BinaryExpression::BinaryExpression() : Base() {} + BinaryExpression::BinaryExpression(BinaryOp op, Expression* lhs, Expression* rhs) diff --git a/src/ast/binary_expression.h b/src/ast/binary_expression.h index d042e6d5a5..783954f6cb 100644 --- a/src/ast/binary_expression.h +++ b/src/ast/binary_expression.h @@ -50,6 +50,8 @@ enum class BinaryOp { /// An binary expression class BinaryExpression : public Castable { public: + /// Constructor + BinaryExpression(); /// Constructor /// @param op the operation type /// @param lhs the left side of the expression @@ -68,6 +70,9 @@ class BinaryExpression : public Castable { BinaryExpression(BinaryExpression&&); ~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 BinaryOp op() const { return op_; } @@ -108,8 +113,15 @@ class BinaryExpression : public Castable { /// @returns true if the op is modulo 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 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 Expression* rhs() const { return rhs_; } diff --git a/src/ast/binary_expression_test.cc b/src/ast/binary_expression_test.cc index 6494a78c05..2242b24dda 100644 --- a/src/ast/binary_expression_test.cc +++ b/src/ast/binary_expression_test.cc @@ -46,11 +46,8 @@ TEST_F(BinaryExpressionTest, Creation_WithSource) { EXPECT_EQ(src.range.begin.column, 2u); } -TEST_F(BinaryExpressionTest, IsBinary) { - auto* lhs = create("lhs"); - auto* rhs = create("rhs"); - - BinaryExpression r(BinaryOp::kEqual, lhs, rhs); +TEST_F(BinaryExpressionTest, IsBinaryal) { + BinaryExpression r; EXPECT_TRUE(r.Is()); } @@ -65,7 +62,9 @@ TEST_F(BinaryExpressionTest, IsValid) { TEST_F(BinaryExpressionTest, IsValid_Null_LHS) { auto* rhs = create("rhs"); - BinaryExpression r(BinaryOp::kEqual, nullptr, rhs); + BinaryExpression r; + r.set_op(BinaryOp::kEqual); + r.set_rhs(rhs); EXPECT_FALSE(r.IsValid()); } @@ -80,7 +79,9 @@ TEST_F(BinaryExpressionTest, IsValid_Invalid_LHS) { TEST_F(BinaryExpressionTest, IsValid_Null_RHS) { auto* lhs = create("lhs"); - BinaryExpression r(BinaryOp::kEqual, lhs, nullptr); + BinaryExpression r; + r.set_op(BinaryOp::kEqual); + r.set_lhs(lhs); EXPECT_FALSE(r.IsValid()); } diff --git a/src/ast/bitcast_expression.cc b/src/ast/bitcast_expression.cc index 8b7fb213bc..8d30b6aa7c 100644 --- a/src/ast/bitcast_expression.cc +++ b/src/ast/bitcast_expression.cc @@ -20,6 +20,8 @@ namespace tint { namespace ast { +BitcastExpression::BitcastExpression() : Base() {} + BitcastExpression::BitcastExpression(type::Type* type, Expression* expr) : Base(), type_(type), expr_(expr) {} diff --git a/src/ast/bitcast_expression.h b/src/ast/bitcast_expression.h index b846b736ab..f736071777 100644 --- a/src/ast/bitcast_expression.h +++ b/src/ast/bitcast_expression.h @@ -28,6 +28,8 @@ namespace ast { /// A bitcast expression class BitcastExpression : public Castable { public: + /// Constructor + BitcastExpression(); /// Constructor /// @param type the type /// @param expr the expr @@ -41,8 +43,15 @@ class BitcastExpression : public Castable { BitcastExpression(BitcastExpression&&); ~BitcastExpression() override; + /// Sets the type + /// @param type the type + void set_type(type::Type* type) { type_ = type; } /// @returns the left side expression type::Type* type() const { return type_; } + + /// Sets the expr + /// @param expr the expression + void set_expr(Expression* expr) { expr_ = expr; } /// @returns the expression Expression* expr() const { return expr_; } diff --git a/src/ast/bitcast_expression_test.cc b/src/ast/bitcast_expression_test.cc index 1c8afc1634..51d48c9a31 100644 --- a/src/ast/bitcast_expression_test.cc +++ b/src/ast/bitcast_expression_test.cc @@ -44,10 +44,7 @@ TEST_F(BitcastExpressionTest, CreateWithSource) { } TEST_F(BitcastExpressionTest, IsBitcast) { - type::F32 f32; - auto* expr = create("expr"); - - BitcastExpression exp(&f32, expr); + BitcastExpression exp; EXPECT_TRUE(exp.Is()); } @@ -62,14 +59,16 @@ TEST_F(BitcastExpressionTest, IsValid) { TEST_F(BitcastExpressionTest, IsValid_MissingType) { auto* expr = create("expr"); - BitcastExpression exp(nullptr, expr); + BitcastExpression exp; + exp.set_expr(expr); EXPECT_FALSE(exp.IsValid()); } TEST_F(BitcastExpressionTest, IsValid_MissingExpr) { type::F32 f32; - BitcastExpression exp(&f32, nullptr); + BitcastExpression exp; + exp.set_type(&f32); EXPECT_FALSE(exp.IsValid()); } diff --git a/src/ast/call_expression.cc b/src/ast/call_expression.cc index 6839f6c0e2..fdee36ef1a 100644 --- a/src/ast/call_expression.cc +++ b/src/ast/call_expression.cc @@ -20,6 +20,8 @@ namespace tint { namespace ast { +CallExpression::CallExpression() : Base() {} + CallExpression::CallExpression(Expression* func, ExpressionList params) : Base(), func_(func), params_(params) {} diff --git a/src/ast/call_expression.h b/src/ast/call_expression.h index faa8dcba4d..3c12822bd6 100644 --- a/src/ast/call_expression.h +++ b/src/ast/call_expression.h @@ -27,6 +27,8 @@ namespace ast { /// A call expression class CallExpression : public Castable { public: + /// Constructor + CallExpression(); /// Constructor /// @param func the function /// @param params the parameters @@ -40,8 +42,15 @@ class CallExpression : public Castable { CallExpression(CallExpression&&); ~CallExpression() override; + /// Sets the func + /// @param func the func + void set_func(Expression* func) { func_ = func; } /// @returns the func Expression* func() const { return func_; } + + /// Sets the parameters + /// @param params the parameters + void set_params(ExpressionList params) { params_ = params; } /// @returns the parameters const ExpressionList& params() const { return params_; } diff --git a/src/ast/call_expression_test.cc b/src/ast/call_expression_test.cc index be8407258e..0d309533d3 100644 --- a/src/ast/call_expression_test.cc +++ b/src/ast/call_expression_test.cc @@ -59,7 +59,7 @@ TEST_F(CallExpressionTest, IsValid) { } TEST_F(CallExpressionTest, IsValid_MissingFunction) { - CallExpression stmt(nullptr, {}); + CallExpression stmt; EXPECT_FALSE(stmt.IsValid()); } diff --git a/src/ast/call_statement.cc b/src/ast/call_statement.cc index b02d521ba4..9158fbb988 100644 --- a/src/ast/call_statement.cc +++ b/src/ast/call_statement.cc @@ -21,6 +21,8 @@ namespace tint { namespace ast { +CallStatement::CallStatement() : Base() {} + CallStatement::CallStatement(CallExpression* call) : Base(), call_(call) {} CallStatement::CallStatement(CallStatement&&) = default; diff --git a/src/ast/call_statement.h b/src/ast/call_statement.h index 2af758258d..026e61f346 100644 --- a/src/ast/call_statement.h +++ b/src/ast/call_statement.h @@ -27,6 +27,8 @@ namespace ast { /// A call expression class CallStatement : public Castable { public: + /// Constructor + CallStatement(); /// Constructor /// @param call the function explicit CallStatement(CallExpression* call); @@ -34,6 +36,9 @@ class CallStatement : public Castable { CallStatement(CallStatement&&); ~CallStatement() override; + /// Sets the call expression + /// @param call the call + void set_expr(CallExpression* call) { call_ = call; } /// @returns the call expression CallExpression* expr() const { return call_; } diff --git a/src/ast/call_statement_test.cc b/src/ast/call_statement_test.cc index 8a0e7b5726..4a6a5fec2c 100644 --- a/src/ast/call_statement_test.cc +++ b/src/ast/call_statement_test.cc @@ -33,7 +33,7 @@ TEST_F(CallStatementTest, Creation) { } TEST_F(CallStatementTest, IsCall) { - CallStatement c(nullptr); + CallStatement c; EXPECT_TRUE(c.Is()); } @@ -44,13 +44,12 @@ TEST_F(CallStatementTest, IsValid) { } TEST_F(CallStatementTest, IsValid_MissingExpr) { - CallStatement c(nullptr); + CallStatement c; EXPECT_FALSE(c.IsValid()); } TEST_F(CallStatementTest, IsValid_InvalidExpr) { - CallExpression stmt(nullptr, {}); - CallStatement c(&stmt); + CallStatement c(create()); EXPECT_FALSE(c.IsValid()); } diff --git a/src/ast/case_statement.h b/src/ast/case_statement.h index cea4327e17..9ed2deb30b 100644 --- a/src/ast/case_statement.h +++ b/src/ast/case_statement.h @@ -52,6 +52,11 @@ class CaseStatement : public Castable { CaseStatement(CaseStatement&&); ~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 const CaseSelectorList& selectors() const { return selectors_; } /// @returns true if this is a default statement diff --git a/src/ast/case_statement_test.cc b/src/ast/case_statement_test.cc index ba62191549..5600173f07 100644 --- a/src/ast/case_statement_test.cc +++ b/src/ast/case_statement_test.cc @@ -82,7 +82,8 @@ TEST_F(CaseStatementTest, IsDefault_WithoutSelectors) { auto* body = create(); body->append(create()); - CaseStatement c(body); + CaseStatement c(create()); + c.set_body(body); EXPECT_TRUE(c.IsDefault()); } @@ -91,7 +92,8 @@ TEST_F(CaseStatementTest, IsDefault_WithSelectors) { CaseSelectorList b; b.push_back(create(&i32, 2)); - CaseStatement c(b, create()); + CaseStatement c(create()); + c.set_selectors(b); EXPECT_FALSE(c.IsDefault()); } diff --git a/src/ast/decorated_variable.h b/src/ast/decorated_variable.h index 8a0b12cf05..b78abbc862 100644 --- a/src/ast/decorated_variable.h +++ b/src/ast/decorated_variable.h @@ -28,7 +28,6 @@ namespace ast { class DecoratedVariable : public Castable { public: /// Create a new empty decorated variable statement - /// Note, used by the `Clone` method. DecoratedVariable(); /// Create a decorated variable from an existing variable /// @param var the variable to initialize from diff --git a/src/ast/decorated_variable_test.cc b/src/ast/decorated_variable_test.cc index d31a7cfce1..63a4340006 100644 --- a/src/ast/decorated_variable_test.cc +++ b/src/ast/decorated_variable_test.cc @@ -107,8 +107,7 @@ TEST_F(DecoratedVariableTest, IsValid) { } TEST_F(DecoratedVariableTest, IsDecorated) { - type::I32 t; - DecoratedVariable dv(create("my_var", StorageClass::kNone, &t)); + DecoratedVariable dv; EXPECT_TRUE(dv.Is()); } diff --git a/src/ast/else_statement.h b/src/ast/else_statement.h index f39a1f0fe4..01be9a8dfd 100644 --- a/src/ast/else_statement.h +++ b/src/ast/else_statement.h @@ -51,11 +51,17 @@ class ElseStatement : public Castable { ElseStatement(ElseStatement&&); ~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 Expression* condition() const { return condition_; } /// @returns true if the else has a condition 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 const BlockStatement* body() const { return body_; } /// @returns the else body diff --git a/src/ast/else_statement_test.cc b/src/ast/else_statement_test.cc index 166d805a1e..40ac0e0978 100644 --- a/src/ast/else_statement_test.cc +++ b/src/ast/else_statement_test.cc @@ -90,7 +90,7 @@ TEST_F(ElseStatementTest, IsValid_WithNullBodyStatement) { } TEST_F(ElseStatementTest, IsValid_InvalidCondition) { - auto* cond = create(nullptr); + auto* cond = create(); ElseStatement e(cond, create()); EXPECT_FALSE(e.IsValid()); } diff --git a/src/ast/function.cc b/src/ast/function.cc index ea0bb622e1..5f53799db3 100644 --- a/src/ast/function.cc +++ b/src/ast/function.cc @@ -28,6 +28,8 @@ namespace tint { namespace ast { +Function::Function() = default; + Function::Function(const std::string& name, VariableList params, type::Type* return_type, diff --git a/src/ast/function.h b/src/ast/function.h index 26f2125cb9..a7afe1e753 100644 --- a/src/ast/function.h +++ b/src/ast/function.h @@ -50,7 +50,8 @@ class Function : public Castable { SetDecoration* set = nullptr; }; - /// Create a function + /// Create a new empty function statement + Function(); /// Create a function /// @param name the function name /// @param params the function parameters /// @param return_type the return type @@ -75,8 +76,15 @@ class Function : public Castable { ~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 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 const VariableList& params() const { return params_; } diff --git a/src/ast/if_statement_test.cc b/src/ast/if_statement_test.cc index a87930a5dd..45e99ba509 100644 --- a/src/ast/if_statement_test.cc +++ b/src/ast/if_statement_test.cc @@ -67,8 +67,8 @@ TEST_F(IfStatementTest, IsValid_WithElseStatements) { body->append(create()); ElseStatementList else_stmts; - else_stmts.push_back(create( - create("Ident"), create())); + else_stmts.push_back(create(create())); + else_stmts[0]->set_condition(create("Ident")); else_stmts.push_back(create(create())); IfStatement stmt(cond, body); @@ -119,8 +119,8 @@ TEST_F(IfStatementTest, IsValid_NullElseStatement) { body->append(create()); ElseStatementList else_stmts; - else_stmts.push_back(create( - create("Ident"), create())); + else_stmts.push_back(create(create())); + else_stmts[0]->set_condition(create("Ident")); else_stmts.push_back(create(create())); else_stmts.push_back(nullptr); @@ -135,8 +135,8 @@ TEST_F(IfStatementTest, IsValid_InvalidElseStatement) { body->append(create()); ElseStatementList else_stmts; - else_stmts.push_back(create(create(""), - create())); + else_stmts.push_back(create(create())); + else_stmts[0]->set_condition(create("")); IfStatement stmt(cond, body); stmt.set_else_statements(else_stmts); @@ -164,8 +164,8 @@ TEST_F(IfStatementTest, IsValid_ElseNotLast) { ElseStatementList else_stmts; else_stmts.push_back(create(create())); - else_stmts.push_back(create( - create("ident"), create())); + else_stmts.push_back(create(create())); + else_stmts[1]->set_condition(create("ident")); IfStatement stmt(cond, body); stmt.set_else_statements(else_stmts); @@ -205,9 +205,11 @@ TEST_F(IfStatementTest, ToStr_WithElseStatements) { else_body->append(create()); ElseStatementList else_stmts; - else_stmts.push_back(create( - create("ident"), else_if_body)); - else_stmts.push_back(create(else_body)); + else_stmts.push_back(create(create())); + else_stmts[0]->set_condition(create("ident")); + else_stmts[0]->set_body(else_if_body); + else_stmts.push_back(create(create())); + else_stmts[1]->set_body(else_body); IfStatement stmt(cond, body); stmt.set_else_statements(else_stmts); diff --git a/src/ast/location_decoration.h b/src/ast/location_decoration.h index dc641e492d..560c3d69a5 100644 --- a/src/ast/location_decoration.h +++ b/src/ast/location_decoration.h @@ -29,7 +29,7 @@ class LocationDecoration /// constructor /// @param value the location value /// @param source the source of this decoration - LocationDecoration(uint32_t value, const Source& source); + explicit LocationDecoration(uint32_t value, const Source& source); ~LocationDecoration() override; /// @returns the location value diff --git a/src/ast/member_accessor_expression.cc b/src/ast/member_accessor_expression.cc index 0345d35ed3..8f8184631d 100644 --- a/src/ast/member_accessor_expression.cc +++ b/src/ast/member_accessor_expression.cc @@ -20,6 +20,8 @@ namespace tint { namespace ast { +MemberAccessorExpression::MemberAccessorExpression() = default; + MemberAccessorExpression::MemberAccessorExpression(Expression* structure, IdentifierExpression* member) : Base(), struct_(structure), member_(member) {} diff --git a/src/ast/member_accessor_expression.h b/src/ast/member_accessor_expression.h index 3b9b09a2f4..4b4f8590ca 100644 --- a/src/ast/member_accessor_expression.h +++ b/src/ast/member_accessor_expression.h @@ -30,6 +30,8 @@ namespace ast { class MemberAccessorExpression : public Castable { public: + /// Constructor + MemberAccessorExpression(); /// Constructor /// @param structure the structure /// @param member the member @@ -45,8 +47,15 @@ class MemberAccessorExpression MemberAccessorExpression(MemberAccessorExpression&&); ~MemberAccessorExpression() override; + /// Sets the structure + /// @param structure the structure + void set_structure(Expression* structure) { struct_ = structure; } /// @returns the structure Expression* structure() const { return struct_; } + + /// Sets the member + /// @param member the member + void set_member(IdentifierExpression* member) { member_ = member; } /// @returns the member expression IdentifierExpression* member() const { return member_; } diff --git a/src/ast/member_accessor_expression_test.cc b/src/ast/member_accessor_expression_test.cc index d307b80c6e..331157fbe4 100644 --- a/src/ast/member_accessor_expression_test.cc +++ b/src/ast/member_accessor_expression_test.cc @@ -45,10 +45,7 @@ TEST_F(MemberAccessorExpressionTest, Creation_WithSource) { } TEST_F(MemberAccessorExpressionTest, IsMemberAccessor) { - auto* str = create("structure"); - auto* mem = create("member"); - - MemberAccessorExpression stmt(str, mem); + MemberAccessorExpression stmt; EXPECT_TRUE(stmt.Is()); } @@ -63,7 +60,8 @@ TEST_F(MemberAccessorExpressionTest, IsValid) { TEST_F(MemberAccessorExpressionTest, IsValid_NullStruct) { auto* mem = create("member"); - MemberAccessorExpression stmt(nullptr, mem); + MemberAccessorExpression stmt; + stmt.set_member(mem); EXPECT_FALSE(stmt.IsValid()); } @@ -78,7 +76,8 @@ TEST_F(MemberAccessorExpressionTest, IsValid_InvalidStruct) { TEST_F(MemberAccessorExpressionTest, IsValid_NullMember) { auto* str = create("structure"); - MemberAccessorExpression stmt(str, nullptr); + MemberAccessorExpression stmt; + stmt.set_structure(str); EXPECT_FALSE(stmt.IsValid()); } diff --git a/src/ast/module_test.cc b/src/ast/module_test.cc index a26b62ba91..0bdbf49c4d 100644 --- a/src/ast/module_test.cc +++ b/src/ast/module_test.cc @@ -139,8 +139,7 @@ TEST_F(ModuleTest, IsValid_Null_Function) { } TEST_F(ModuleTest, IsValid_Invalid_Function) { - VariableList p; - auto* func = create("", p, nullptr, nullptr); + auto* func = create(); Module m; m.AddFunction(func); diff --git a/src/ast/scalar_constructor_expression.cc b/src/ast/scalar_constructor_expression.cc index 90b83f7b45..7a68042e6b 100644 --- a/src/ast/scalar_constructor_expression.cc +++ b/src/ast/scalar_constructor_expression.cc @@ -20,6 +20,8 @@ namespace tint { namespace ast { +ScalarConstructorExpression::ScalarConstructorExpression() : Base() {} + ScalarConstructorExpression::ScalarConstructorExpression(Literal* literal) : literal_(literal) {} diff --git a/src/ast/scalar_constructor_expression.h b/src/ast/scalar_constructor_expression.h index 5a3fd6551e..05ce2167d3 100644 --- a/src/ast/scalar_constructor_expression.h +++ b/src/ast/scalar_constructor_expression.h @@ -28,6 +28,8 @@ namespace ast { class ScalarConstructorExpression : public Castable { public: + /// Constructor + ScalarConstructorExpression(); /// Constructor /// @param literal the const literal explicit ScalarConstructorExpression(Literal* literal); @@ -39,6 +41,9 @@ class ScalarConstructorExpression ScalarConstructorExpression(ScalarConstructorExpression&&); ~ScalarConstructorExpression() override; + /// Set the literal value + /// @param literal the literal + void set_literal(Literal* literal) { literal_ = literal; } /// @returns the literal value Literal* literal() const { return literal_; } diff --git a/src/ast/scalar_constructor_expression_test.cc b/src/ast/scalar_constructor_expression_test.cc index 01683564db..60e4185fa2 100644 --- a/src/ast/scalar_constructor_expression_test.cc +++ b/src/ast/scalar_constructor_expression_test.cc @@ -48,7 +48,7 @@ TEST_F(ScalarConstructorExpressionTest, IsValid) { } TEST_F(ScalarConstructorExpressionTest, IsValid_MissingLiteral) { - ScalarConstructorExpression c(nullptr); + ScalarConstructorExpression c; EXPECT_FALSE(c.IsValid()); } diff --git a/src/ast/struct.cc b/src/ast/struct.cc index 2db5e45e6a..bb076475af 100644 --- a/src/ast/struct.cc +++ b/src/ast/struct.cc @@ -21,6 +21,8 @@ namespace tint { namespace ast { +Struct::Struct() : Base() {} + Struct::Struct(StructMemberList members) : Base(), members_(std::move(members)) {} diff --git a/src/ast/struct.h b/src/ast/struct.h index ab49a0fa6e..0b37d2824f 100644 --- a/src/ast/struct.h +++ b/src/ast/struct.h @@ -29,6 +29,8 @@ namespace ast { /// A struct statement. class Struct : public Castable { public: + /// Create a new empty struct statement + Struct(); /// Create a new struct statement /// @param members The struct members explicit Struct(StructMemberList members); diff --git a/src/ast/struct_member.cc b/src/ast/struct_member.cc index 9cdb902695..cefbeded7e 100644 --- a/src/ast/struct_member.cc +++ b/src/ast/struct_member.cc @@ -21,6 +21,8 @@ namespace tint { namespace ast { +StructMember::StructMember() = default; + StructMember::StructMember(const std::string& name, type::Type* type, StructMemberDecorationList decorations) diff --git a/src/ast/struct_member.h b/src/ast/struct_member.h index 406476701c..a659e8713f 100644 --- a/src/ast/struct_member.h +++ b/src/ast/struct_member.h @@ -31,6 +31,8 @@ namespace ast { /// A struct member statement. class StructMember : public Castable { public: + /// Create a new empty struct member statement + StructMember(); /// Create a new struct member statement /// @param name The struct member name /// @param type The struct member type @@ -52,8 +54,14 @@ class StructMember : public Castable { ~StructMember() override; + /// Sets the name + /// @param name the name to set + void set_name(const std::string& name) { name_ = name; } /// @returns the 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 type::Type* type() const { return type_; } /// Sets the decorations diff --git a/src/ast/struct_test.cc b/src/ast/struct_test.cc index b615bc8123..11e9bb89f9 100644 --- a/src/ast/struct_test.cc +++ b/src/ast/struct_test.cc @@ -87,7 +87,7 @@ TEST_F(StructTest, CreationWithSourceAndDecorations) { } TEST_F(StructTest, IsValid) { - Struct s({}); + Struct s; EXPECT_TRUE(s.IsValid()); } diff --git a/src/ast/switch_statement.cc b/src/ast/switch_statement.cc index 7ee3abc35e..18140b6c32 100644 --- a/src/ast/switch_statement.cc +++ b/src/ast/switch_statement.cc @@ -21,6 +21,8 @@ namespace tint { namespace ast { +SwitchStatement::SwitchStatement() : Base() {} + SwitchStatement::SwitchStatement(Expression* condition, CaseStatementList body) : condition_(condition), body_(body) {} diff --git a/src/ast/switch_statement.h b/src/ast/switch_statement.h index d44a45fde5..53c80ca0dd 100644 --- a/src/ast/switch_statement.h +++ b/src/ast/switch_statement.h @@ -29,6 +29,8 @@ namespace ast { /// A switch statement class SwitchStatement : public Castable { public: + /// Constructor + SwitchStatement(); /// Constructor /// @param condition the switch condition /// @param body the switch body @@ -44,6 +46,9 @@ class SwitchStatement : public Castable { SwitchStatement(SwitchStatement&&); ~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 Expression* condition() const { return condition_; } /// @returns true if this is a default statement diff --git a/src/ast/switch_statement_test.cc b/src/ast/switch_statement_test.cc index df82f3d373..14d90e6d26 100644 --- a/src/ast/switch_statement_test.cc +++ b/src/ast/switch_statement_test.cc @@ -56,16 +56,7 @@ TEST_F(SwitchStatementTest, Creation_WithSource) { } TEST_F(SwitchStatementTest, IsSwitch) { - type::I32 i32; - - CaseSelectorList lit; - lit.push_back(create(&i32, 2)); - - auto* ident = create("ident"); - CaseStatementList body; - body.push_back(create(lit, create())); - - SwitchStatement stmt(ident, body); + SwitchStatement stmt; EXPECT_TRUE(stmt.Is()); } @@ -92,7 +83,8 @@ TEST_F(SwitchStatementTest, IsValid_Null_Condition) { CaseStatementList body; body.push_back(create(lit, create())); - SwitchStatement stmt(nullptr, body); + SwitchStatement stmt; + stmt.set_body(body); EXPECT_FALSE(stmt.IsValid()); } diff --git a/src/ast/type/struct_type_test.cc b/src/ast/type/struct_type_test.cc index 3dd11f1a3f..1a915a2007 100644 --- a/src/ast/type/struct_type_test.cc +++ b/src/ast/type/struct_type_test.cc @@ -40,16 +40,14 @@ namespace { using StructTest = TestHelper; TEST_F(StructTest, Creation) { - StructMemberList members; - auto* impl = create(members); + auto* impl = create(); auto* ptr = impl; Struct s{"S", impl}; EXPECT_EQ(s.impl(), ptr); } TEST_F(StructTest, Is) { - StructMemberList members; - auto* impl = create(members); + auto* impl = create(); Struct s{"S", impl}; Type* ty = &s; EXPECT_FALSE(ty->Is()); @@ -68,8 +66,7 @@ TEST_F(StructTest, Is) { } TEST_F(StructTest, TypeName) { - StructMemberList members; - auto* impl = create(members); + auto* impl = create(); Struct s{"my_struct", impl}; EXPECT_EQ(s.type_name(), "__struct_my_struct"); } diff --git a/src/ast/type_constructor_expression.cc b/src/ast/type_constructor_expression.cc index 455912a4d4..8717833cfb 100644 --- a/src/ast/type_constructor_expression.cc +++ b/src/ast/type_constructor_expression.cc @@ -20,6 +20,8 @@ namespace tint { namespace ast { +TypeConstructorExpression::TypeConstructorExpression() : Base() {} + TypeConstructorExpression::TypeConstructorExpression(type::Type* type, ExpressionList values) : Base(), type_(type), values_(std::move(values)) {} diff --git a/src/ast/type_constructor_expression.h b/src/ast/type_constructor_expression.h index 7f239dc438..12b0e97208 100644 --- a/src/ast/type_constructor_expression.h +++ b/src/ast/type_constructor_expression.h @@ -28,10 +28,11 @@ namespace ast { class TypeConstructorExpression : public Castable { public: + TypeConstructorExpression(); /// Constructor /// @param type the type /// @param values the values - TypeConstructorExpression(type::Type* type, ExpressionList values); + explicit TypeConstructorExpression(type::Type* type, ExpressionList values); /// Constructor /// @param source the constructor source /// @param type the type @@ -43,8 +44,15 @@ class TypeConstructorExpression TypeConstructorExpression(TypeConstructorExpression&&); ~TypeConstructorExpression() override; + /// Set the type + /// @param type the type + void set_type(type::Type* type) { type_ = type; } /// @returns the 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 const ExpressionList& values() const { return values_; } diff --git a/src/ast/type_constructor_expression_test.cc b/src/ast/type_constructor_expression_test.cc index d7efed7e5c..477faf5e86 100644 --- a/src/ast/type_constructor_expression_test.cc +++ b/src/ast/type_constructor_expression_test.cc @@ -52,11 +52,7 @@ TEST_F(TypeConstructorExpressionTest, Creation_WithSource) { } TEST_F(TypeConstructorExpressionTest, IsTypeConstructor) { - type::F32 f32; - ExpressionList expr; - expr.push_back(create("expr")); - - TypeConstructorExpression t(&f32, expr); + TypeConstructorExpression t; EXPECT_TRUE(t.Is()); } @@ -81,7 +77,8 @@ TEST_F(TypeConstructorExpressionTest, IsValid_NullType) { ExpressionList expr; expr.push_back(create("expr")); - TypeConstructorExpression t(nullptr, expr); + TypeConstructorExpression t; + t.set_values(expr); EXPECT_FALSE(t.IsValid()); } diff --git a/src/ast/unary_op_expression.cc b/src/ast/unary_op_expression.cc index b33d034fae..c5bc38c520 100644 --- a/src/ast/unary_op_expression.cc +++ b/src/ast/unary_op_expression.cc @@ -20,6 +20,8 @@ namespace tint { namespace ast { +UnaryOpExpression::UnaryOpExpression() : Base() {} + UnaryOpExpression::UnaryOpExpression(UnaryOp op, Expression* expr) : Base(), op_(op), expr_(expr) {} diff --git a/src/ast/unary_op_expression.h b/src/ast/unary_op_expression.h index 4fbefd5de4..d2c5e42d9d 100644 --- a/src/ast/unary_op_expression.h +++ b/src/ast/unary_op_expression.h @@ -28,6 +28,8 @@ namespace ast { /// A unary op expression class UnaryOpExpression : public Castable { public: + /// Constructor + UnaryOpExpression(); /// Constructor /// @param op the op /// @param expr the expr @@ -41,8 +43,15 @@ class UnaryOpExpression : public Castable { UnaryOpExpression(UnaryOpExpression&&); ~UnaryOpExpression() override; + /// Sets the op + /// @param op the op + void set_op(UnaryOp op) { op_ = op; } /// @returns the op UnaryOp op() const { return op_; } + + /// Sets the expr + /// @param expr the expression + void set_expr(Expression* expr) { expr_ = expr; } /// @returns the expression Expression* expr() const { return expr_; } diff --git a/src/ast/unary_op_expression_test.cc b/src/ast/unary_op_expression_test.cc index 5e3ec1f349..ea6e516286 100644 --- a/src/ast/unary_op_expression_test.cc +++ b/src/ast/unary_op_expression_test.cc @@ -42,8 +42,7 @@ TEST_F(UnaryOpExpressionTest, Creation_WithSource) { } TEST_F(UnaryOpExpressionTest, IsUnaryOp) { - auto* ident = create("ident"); - UnaryOpExpression u(UnaryOp::kNot, ident); + UnaryOpExpression u; EXPECT_TRUE(u.Is()); } @@ -54,7 +53,8 @@ TEST_F(UnaryOpExpressionTest, IsValid) { } TEST_F(UnaryOpExpressionTest, IsValid_NullExpression) { - UnaryOpExpression u(UnaryOp::kNot, nullptr); + UnaryOpExpression u; + u.set_op(UnaryOp::kNot); EXPECT_FALSE(u.IsValid()); } diff --git a/src/ast/variable.cc b/src/ast/variable.cc index 8e4886725a..01ae068d41 100644 --- a/src/ast/variable.cc +++ b/src/ast/variable.cc @@ -39,9 +39,11 @@ Variable::Variable(Variable&&) = default; Variable::~Variable() = default; Variable* Variable::Clone(CloneContext* ctx) const { - auto* cloned = - ctx->mod->create(name(), storage_class(), ctx->Clone(type())); + auto* cloned = ctx->mod->create(); 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_is_const(is_const()); return cloned; diff --git a/src/ast/variable.h b/src/ast/variable.h index 72de0f1243..43fe16c1e3 100644 --- a/src/ast/variable.h +++ b/src/ast/variable.h @@ -78,6 +78,8 @@ namespace ast { /// The storage class for a formal parameter is always StorageClass::kNone. class Variable : public Castable { public: + /// Create a new empty variable statement + Variable(); /// Create a variable /// @param name the variables name /// @param sc the variable storage class @@ -147,10 +149,6 @@ class Variable : public Castable { void to_str(std::ostream& out, size_t indent) const override; protected: - /// Constructor - /// Used by the DecoratedVariable constructor. - Variable(); - /// Output information for this variable. /// @param out the stream to write to /// @param indent number of spaces to indent the node when writing diff --git a/src/ast/variable_decl_statement.cc b/src/ast/variable_decl_statement.cc index 0b3feeaff4..f1ec4d35af 100644 --- a/src/ast/variable_decl_statement.cc +++ b/src/ast/variable_decl_statement.cc @@ -20,6 +20,8 @@ namespace tint { namespace ast { +VariableDeclStatement::VariableDeclStatement() : Base() {} + VariableDeclStatement::VariableDeclStatement(Variable* variable) : Base(), variable_(variable) {} diff --git a/src/ast/variable_decl_statement.h b/src/ast/variable_decl_statement.h index 6ec374864d..bdf5ed24a9 100644 --- a/src/ast/variable_decl_statement.h +++ b/src/ast/variable_decl_statement.h @@ -29,6 +29,8 @@ namespace ast { class VariableDeclStatement : public Castable { public: + /// Constructor + VariableDeclStatement(); /// Constructor /// @param variable the variable explicit VariableDeclStatement(Variable* variable); @@ -40,6 +42,9 @@ class VariableDeclStatement VariableDeclStatement(VariableDeclStatement&&); ~VariableDeclStatement() override; + /// Sets the variable + /// @param variable the variable to set + void set_variable(Variable* variable) { variable_ = variable; } /// @returns the variable Variable* variable() const { return variable_; } diff --git a/src/ast/variable_decl_statement_test.cc b/src/ast/variable_decl_statement_test.cc index daa7c2a086..afd15380d9 100644 --- a/src/ast/variable_decl_statement_test.cc +++ b/src/ast/variable_decl_statement_test.cc @@ -43,10 +43,7 @@ TEST_F(VariableDeclStatementTest, Creation_WithSource) { } TEST_F(VariableDeclStatementTest, IsVariableDecl) { - type::F32 f32; - auto* var = create("a", StorageClass::kNone, &f32); - - VariableDeclStatement s(var); + VariableDeclStatement s; EXPECT_TRUE(s.Is()); } @@ -65,7 +62,7 @@ TEST_F(VariableDeclStatementTest, IsValid_InvalidVariable) { } TEST_F(VariableDeclStatementTest, IsValid_NullVariable) { - VariableDeclStatement stmt(nullptr); + VariableDeclStatement stmt; EXPECT_FALSE(stmt.IsValid()); } diff --git a/src/ast/variable_test.cc b/src/ast/variable_test.cc index 9f22a9417c..0b8bf9bc21 100644 --- a/src/ast/variable_test.cc +++ b/src/ast/variable_test.cc @@ -53,9 +53,14 @@ TEST_F(VariableTest, CreationWithSource) { } TEST_F(VariableTest, CreationEmpty) { - type::I32 t; Source s{Source::Range{Source::Location{27, 4}, Source::Location{27, 7}}}; - Variable v(s, "a_var", StorageClass::kWorkgroup, &t); + Variable v; + v.set_source(s); + v.set_storage_class(StorageClass::kWorkgroup); + v.set_name("a_var"); + + type::I32 t; + v.set_type(&t); EXPECT_EQ(v.name(), "a_var"); EXPECT_EQ(v.storage_class(), StorageClass::kWorkgroup); @@ -91,7 +96,7 @@ TEST_F(VariableTest, IsValid_MissingType) { } TEST_F(VariableTest, IsValid_MissingBoth) { - Variable v("", StorageClass::kNone, nullptr); + Variable v; EXPECT_FALSE(v.IsValid()); } diff --git a/src/reader/spirv/function.cc b/src/reader/spirv/function.cc index e5d812b512..30b74b1f40 100644 --- a/src/reader/spirv/function.cc +++ b/src/reader/spirv/function.cc @@ -2137,13 +2137,12 @@ bool FunctionEmitter::EmitSwitchStart(const BlockInfo& block_info) { assert(construct->begin_id == block_info.id); const auto* branch = block_info.basic_block->terminator(); + auto* const switch_stmt = + AddStatement(create())->As(); const auto selector_id = branch->GetSingleWordInOperand(0); // Generate the code for the selector. auto selector = MakeExpression(selector_id); - - ast::CaseStatementList list; - auto* swch = create(selector.expr, list); - auto* const switch_stmt = AddStatement(swch)->As(); + switch_stmt->set_condition(selector.expr); // First, push the statement block for the entire switch. All the actual // work is done by completion actions of the case/default clauses. @@ -2195,6 +2194,12 @@ bool FunctionEmitter::EmitSwitchStart(const BlockInfo& block_info) { // Push them on in reverse order. const auto last_clause_index = clause_heads.size() - 1; 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(create())); + auto* clause = cases->back(); + // Create a list of integer literals for the selector values leading to // this case clause. ast::CaseSelectorList selectors; @@ -2215,20 +2220,14 @@ bool FunctionEmitter::EmitSwitchStart(const BlockInfo& block_info) { create(selector.type, value32)); } } + clause->set_selectors(selectors); } // Where does this clause end? const auto end_id = (i + 1 < clause_heads.size()) ? clause_heads[i + 1]->id : construct->end_id; - // Create the case clause. Temporarily put it in the wrong order - // on the case statement list. - cases->emplace_back(create(selectors, nullptr)); - auto* clause = cases->back(); - 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_); }); diff --git a/src/reader/wgsl/parser_impl.cc b/src/reader/wgsl/parser_impl.cc index f43a85ad38..ada6e7837a 100644 --- a/src/reader/wgsl/parser_impl.cc +++ b/src/reader/wgsl/parser_impl.cc @@ -1745,13 +1745,14 @@ Maybe ParserImpl::switch_body() { auto source = t.source(); next(); // Consume the peek - ast::CaseSelectorList selector_list; + auto* stmt = create(create()); + stmt->set_source(source); if (t.IsCase()) { auto selectors = expect_case_selectors(); if (selectors.errored) return Failure::kErrored; - selector_list = std::move(selectors.value); + stmt->set_selectors(std::move(selectors.value)); } const char* use = "case statement"; @@ -1766,7 +1767,9 @@ Maybe ParserImpl::switch_body() { if (!body.matched) return add_error(body.source, "expected case body"); - return create(source, selector_list, body.value); + stmt->set_body(body.value); + + return stmt; } // case_selectors diff --git a/src/scope_stack_test.cc b/src/scope_stack_test.cc index f1d81531d5..f1f5551cc9 100644 --- a/src/scope_stack_test.cc +++ b/src/scope_stack_test.cc @@ -14,7 +14,6 @@ #include "src/scope_stack.h" #include "gtest/gtest.h" -#include "src/ast/type/f32_type.h" #include "src/ast/variable.h" namespace tint { @@ -32,8 +31,7 @@ TEST_F(ScopeStackTest, Global) { } TEST_F(ScopeStackTest, Global_SetWithPointer) { - ast::type::F32 f32; - ast::Variable v("test", ast::StorageClass::kNone, &f32); + ast::Variable v; v.set_name("my_var"); ScopeStack s; diff --git a/src/writer/hlsl/generator_impl_alias_type_test.cc b/src/writer/hlsl/generator_impl_alias_type_test.cc index 4a637b5272..1aa406a52e 100644 --- a/src/writer/hlsl/generator_impl_alias_type_test.cc +++ b/src/writer/hlsl/generator_impl_alias_type_test.cc @@ -50,7 +50,8 @@ TEST_F(HlslGeneratorImplTest_Alias, EmitAlias_Struct) { ast::type::I32 i32; ast::type::F32 f32; - auto* str = create(ast::StructMemberList{ + auto* str = create(); + str->set_members({ create("a", &f32, ast::StructMemberDecorationList{}), create( "b", &i32, diff --git a/src/writer/hlsl/generator_impl_function_test.cc b/src/writer/hlsl/generator_impl_function_test.cc index 487230e4c2..db623f664c 100644 --- a/src/writer/hlsl/generator_impl_function_test.cc +++ b/src/writer/hlsl/generator_impl_function_test.cc @@ -279,7 +279,8 @@ TEST_F(HlslGeneratorImplTest_Function, members.push_back(create( "coord", &vec4, ast::StructMemberDecorationList{})); - auto* str = create(members); + auto* str = create(); + str->set_members(members); ast::type::Struct s("Uniforms", str); @@ -344,7 +345,8 @@ TEST_F(HlslGeneratorImplTest_Function, b_deco.push_back(create(4, Source{})); members.push_back(create("b", &f32, b_deco)); - auto* str = create(members); + auto* str = create(); + str->set_members(members); ast::type::Struct s("Data", str); ast::type::AccessControl ac(ast::AccessControl::kReadWrite, &s); @@ -402,7 +404,8 @@ TEST_F(HlslGeneratorImplTest_Function, b_deco.push_back(create(4, Source{})); members.push_back(create("b", &f32, b_deco)); - auto* str = create(members); + auto* str = create(); + str->set_members(members); ast::type::Struct s("Data", str); ast::type::AccessControl ac(ast::AccessControl::kReadOnly, &s); @@ -460,7 +463,8 @@ TEST_F(HlslGeneratorImplTest_Function, b_deco.push_back(create(4, Source{})); members.push_back(create("b", &f32, b_deco)); - auto* str = create(members); + auto* str = create(); + str->set_members(members); ast::type::Struct s("Data", str); ast::type::AccessControl ac(ast::AccessControl::kReadWrite, &s); diff --git a/src/writer/hlsl/generator_impl_member_accessor_test.cc b/src/writer/hlsl/generator_impl_member_accessor_test.cc index 516d397591..145e0c71cd 100644 --- a/src/writer/hlsl/generator_impl_member_accessor_test.cc +++ b/src/writer/hlsl/generator_impl_member_accessor_test.cc @@ -54,7 +54,8 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, EmitExpression_MemberAccessor) { deco.push_back(create(0, Source{})); members.push_back(create("mem", &f32, deco)); - auto* strct = create(members); + auto* strct = create(); + strct->set_members(members); ast::type::Struct s("Str", strct); @@ -97,7 +98,8 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, b_deco.push_back(create(4, Source{})); members.push_back(create("b", &f32, b_deco)); - auto* str = create(members); + auto* str = create(); + str->set_members(members); ast::type::Struct s("Data", str); @@ -140,7 +142,8 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, b_deco.push_back(create(4, Source{})); members.push_back(create("b", &f32, b_deco)); - auto* str = create(members); + auto* str = create(); + str->set_members(members); ast::type::Struct s("Data", str); @@ -177,7 +180,8 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, ast::type::I32 i32; ast::type::Matrix mat(&f32, 3, 2); - auto* str = create(ast::StructMemberList{ + auto* str = create(); + str->set_members({ create( "z", &i32, ast::StructMemberDecorationList{ @@ -245,7 +249,8 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, b_deco.push_back(create(4, Source{})); members.push_back(create("a", &mat, b_deco)); - auto* str = create(members); + auto* str = create(); + str->set_members(members); ast::type::Struct s("Data", str); @@ -300,7 +305,8 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, b_deco.push_back(create(4, Source{})); members.push_back(create("a", &mat, b_deco)); - auto* str = create(members); + auto* str = create(); + str->set_members(members); ast::type::Struct s("Data", str); @@ -350,7 +356,8 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, b_deco.push_back(create(4, Source{})); members.push_back(create("a", &mat, b_deco)); - auto* str = create(members); + auto* str = create(); + str->set_members(members); ast::type::Struct s("Data", str); @@ -392,7 +399,8 @@ TEST_F( deco.push_back(create(0, Source{})); members.push_back(create("a", &mat, deco)); - auto* str = create(members); + auto* str = create(); + str->set_members(members); ast::type::Struct s("Data", str); @@ -438,7 +446,8 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, b_deco.push_back(create(16, Source{})); members.push_back(create("a", &mat, b_deco)); - auto* str = create(members); + auto* str = create(); + str->set_members(members); ast::type::Struct s("Data", str); @@ -485,7 +494,8 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, a_deco.push_back(create(0, Source{})); members.push_back(create("a", &ary, a_deco)); - auto* str = create(members); + auto* str = create(); + str->set_members(members); ast::type::Struct s("Data", str); @@ -529,7 +539,8 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, a_deco.push_back(create(0, Source{})); members.push_back(create("a", &ary, a_deco)); - auto* str = create(members); + auto* str = create(); + str->set_members(members); ast::type::Struct s("Data", str); @@ -585,7 +596,8 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, b_deco.push_back(create(4, Source{})); members.push_back(create("b", &f32, b_deco)); - auto* str = create(members); + auto* str = create(); + str->set_members(members); ast::type::Struct s("Data", str); @@ -631,7 +643,8 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, a_deco.push_back(create(0, Source{})); members.push_back(create("a", &ary, a_deco)); - auto* str = create(members); + auto* str = create(); + str->set_members(members); ast::type::Struct s("Data", str); @@ -683,7 +696,8 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, b_deco.push_back(create(4, Source{})); members.push_back(create("b", &f32, b_deco)); - auto* str = create(members); + auto* str = create(); + str->set_members(members); ast::type::Struct s("Data", str); @@ -734,7 +748,8 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, b_deco.push_back(create(16, Source{})); members.push_back(create("b", &fvec3, b_deco)); - auto* str = create(members); + auto* str = create(); + str->set_members(members); ast::type::Struct s("Data", str); @@ -780,7 +795,8 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, b_deco.push_back(create(16, Source{})); members.push_back(create("b", &fvec3, b_deco)); - auto* str = create(members); + auto* str = create(); + str->set_members(members); ast::type::Struct s("Data", str); @@ -835,7 +851,8 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, ast::type::Vector ivec3(&i32, 3); ast::type::Vector fvec3(&f32, 3); - auto* data_str = create(ast::StructMemberList{ + auto* data_str = create(); + data_str->set_members({ create( "a", &ivec3, ast::StructMemberDecorationList{ @@ -851,7 +868,8 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, ast::type::Array ary(&data, 4); ary.set_decorations({create(32, Source{})}); - auto* pre_str = create(ast::StructMemberList{ + auto* pre_str = create(); + pre_str->set_members({ create( "c", &ary, ast::StructMemberDecorationList{ @@ -906,7 +924,8 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, ast::StructMemberList members; ast::StructMemberDecorationList deco; - auto* data_str = create(ast::StructMemberList{ + auto* data_str = create(); + data_str->set_members({ create( "a", &ivec3, ast::StructMemberDecorationList{ @@ -922,11 +941,11 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, ast::type::Array ary(&data, 4); ary.set_decorations({create(32, Source{})}); - auto* pre_str = - create(ast::StructMemberList{create( - "c", &ary, - ast::StructMemberDecorationList{ - create(0, Source{})})}); + auto* pre_str = create(); + pre_str->set_members({create( + "c", &ary, + ast::StructMemberDecorationList{ + create(0, Source{})})}); ast::type::Struct pre_struct("Pre", pre_str); @@ -976,7 +995,8 @@ TEST_F( ast::type::Vector ivec3(&i32, 3); ast::type::Vector fvec3(&f32, 3); - auto* data_str = create(ast::StructMemberList{ + auto* data_str = create(); + data_str->set_members({ create( "a", &ivec3, ast::StructMemberDecorationList{ @@ -992,11 +1012,11 @@ TEST_F( ast::type::Array ary(&data, 4); ary.set_decorations({create(32, Source{})}); - auto* pre_str = - create(ast::StructMemberList{create( - "c", &ary, - ast::StructMemberDecorationList{ - create(0, Source{})})}); + auto* pre_str = create(); + pre_str->set_members({create( + "c", &ary, + ast::StructMemberDecorationList{ + create(0, Source{})})}); ast::type::Struct pre_struct("Pre", pre_str); @@ -1045,7 +1065,8 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, ast::type::Vector ivec3(&i32, 3); ast::type::Vector fvec3(&f32, 3); - auto* data_str = create(ast::StructMemberList{ + auto* data_str = create(); + data_str->set_members({ create( "a", &ivec3, ast::StructMemberDecorationList{ @@ -1061,11 +1082,11 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, ast::type::Array ary(&data, 4); ary.set_decorations({create(32, Source{})}); - auto* pre_str = - create(ast::StructMemberList{create( - "c", &ary, - ast::StructMemberDecorationList{ - create(0, Source{})})}); + auto* pre_str = create(); + pre_str->set_members({create( + "c", &ary, + ast::StructMemberDecorationList{ + create(0, Source{})})}); ast::type::Struct pre_struct("Pre", pre_str); @@ -1115,7 +1136,8 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, ast::type::Vector ivec3(&i32, 3); ast::type::Vector fvec3(&f32, 3); - auto* data_str = create(ast::StructMemberList{ + auto* data_str = create(); + data_str->set_members({ create( "a", &ivec3, ast::StructMemberDecorationList{ @@ -1131,11 +1153,11 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, ast::type::Array ary(&data, 4); ary.set_decorations({create(32, Source{})}); - auto* pre_str = - create(ast::StructMemberList{create( - "c", &ary, - ast::StructMemberDecorationList{ - create(0, Source{})})}); + auto* pre_str = create(); + pre_str->set_members({create( + "c", &ary, + ast::StructMemberDecorationList{ + create(0, Source{})})}); ast::type::Struct pre_struct("Pre", pre_str); @@ -1196,7 +1218,8 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, ast::type::Vector ivec3(&i32, 3); ast::type::Vector fvec3(&f32, 3); - auto* data_str = create(ast::StructMemberList{ + auto* data_str = create(); + data_str->set_members({ create( "a", &ivec3, ast::StructMemberDecorationList{ @@ -1212,11 +1235,11 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, ast::type::Array ary(&data, 4); ary.set_decorations({create(32, Source{})}); - auto* pre_str = - create(ast::StructMemberList{create( - "c", &ary, - ast::StructMemberDecorationList{ - create(0, Source{})})}); + auto* pre_str = create(); + pre_str->set_members({create( + "c", &ary, + ast::StructMemberDecorationList{ + create(0, Source{})})}); ast::type::Struct pre_struct("Pre", pre_str); diff --git a/src/writer/hlsl/generator_impl_type_test.cc b/src/writer/hlsl/generator_impl_type_test.cc index b2156f71d2..e8fcb64795 100644 --- a/src/writer/hlsl/generator_impl_type_test.cc +++ b/src/writer/hlsl/generator_impl_type_test.cc @@ -181,7 +181,8 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_StructDecl) { b_deco.push_back(create(4, Source{})); members.push_back(create("b", &f32, b_deco)); - auto* str = create(members); + auto* str = create(); + str->set_members(members); ast::type::Struct s("S", str); @@ -205,7 +206,8 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Struct) { b_deco.push_back(create(4, Source{})); members.push_back(create("b", &f32, b_deco)); - auto* str = create(members); + auto* str = create(); + str->set_members(members); ast::type::Struct s("S", str); @@ -229,7 +231,8 @@ TEST_F(HlslGeneratorImplTest_Type, DISABLED_EmitType_Struct_InjectPadding) { decos.push_back(create(128, Source{})); members.push_back(create("c", &f32, decos)); - auto* str = create(members); + auto* str = create(); + str->set_members(members); ast::type::Struct s("S", str); @@ -255,7 +258,8 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Struct_NameCollision) { ast::StructMemberDecorationList b_deco; members.push_back(create("float", &f32, b_deco)); - auto* str = create(members); + auto* str = create(); + str->set_members(members); ast::type::Struct s("S", str); diff --git a/src/writer/msl/generator_impl_alias_type_test.cc b/src/writer/msl/generator_impl_alias_type_test.cc index d2b4e841d3..ac4b895705 100644 --- a/src/writer/msl/generator_impl_alias_type_test.cc +++ b/src/writer/msl/generator_impl_alias_type_test.cc @@ -61,7 +61,8 @@ TEST_F(MslGeneratorImplTest, EmitConstructedType_Struct) { b_deco.push_back(create(4, Source{})); members.push_back(create("b", &i32, b_deco)); - auto* str = create(members); + auto* str = create(); + str->set_members(members); ast::type::Struct s("a", str); @@ -85,7 +86,8 @@ TEST_F(MslGeneratorImplTest, EmitConstructedType_AliasStructIdent) { b_deco.push_back(create(4, Source{})); members.push_back(create("b", &i32, b_deco)); - auto* str = create(members); + auto* str = create(); + str->set_members(members); ast::type::Struct s("b", str); ast::type::Alias alias("a", &s); diff --git a/src/writer/msl/generator_impl_function_test.cc b/src/writer/msl/generator_impl_function_test.cc index 1f9d0e9df4..51697e97be 100644 --- a/src/writer/msl/generator_impl_function_test.cc +++ b/src/writer/msl/generator_impl_function_test.cc @@ -295,7 +295,8 @@ TEST_F(MslGeneratorImplTest, b_deco.push_back(create(4, Source{})); members.push_back(create("b", &f32, b_deco)); - auto* str = create(members); + auto* str = create(); + str->set_members(members); ast::type::Struct s("Data", str); ast::type::AccessControl ac(ast::AccessControl::kReadWrite, &s); @@ -362,7 +363,8 @@ TEST_F(MslGeneratorImplTest, b_deco.push_back(create(4, Source{})); members.push_back(create("b", &f32, b_deco)); - auto* str = create(members); + auto* str = create(); + str->set_members(members); ast::type::Struct s("Data", str); ast::type::AccessControl ac(ast::AccessControl::kReadOnly, &s); @@ -729,7 +731,8 @@ TEST_F(MslGeneratorImplTest, b_deco.push_back(create(4, Source{})); members.push_back(create("b", &f32, b_deco)); - auto* str = create(members); + auto* str = create(); + str->set_members(members); ast::type::Struct s("Data", str); ast::type::AccessControl ac(ast::AccessControl::kReadWrite, &s); @@ -815,7 +818,8 @@ TEST_F(MslGeneratorImplTest, b_deco.push_back(create(4, Source{})); members.push_back(create("b", &f32, b_deco)); - auto* str = create(members); + auto* str = create(); + str->set_members(members); ast::type::Struct s("Data", str); ast::type::AccessControl ac(ast::AccessControl::kReadOnly, &s); diff --git a/src/writer/msl/generator_impl_test.cc b/src/writer/msl/generator_impl_test.cc index b366f44525..15f488a278 100644 --- a/src/writer/msl/generator_impl_test.cc +++ b/src/writer/msl/generator_impl_test.cc @@ -168,7 +168,8 @@ TEST_F(MslGeneratorImplTest, calculate_alignment_size_struct) { decos.push_back(create(128, Source{})); members.push_back(create("c", &f32, decos)); - auto* str = create(members); + auto* str = create(); + str->set_members(members); ast::type::Struct s("S", str); @@ -192,7 +193,8 @@ TEST_F(MslGeneratorImplTest, calculate_alignment_size_struct_of_struct) { decos.push_back(create(32, Source{})); members.push_back(create("c", &f32, decos)); - auto* inner_str = create(members); + auto* inner_str = create(); + inner_str->set_members(members); ast::type::Struct inner_s("Inner", inner_str); @@ -205,7 +207,8 @@ TEST_F(MslGeneratorImplTest, calculate_alignment_size_struct_of_struct) { decos.push_back(create(64, Source{})); members.push_back(create("f", &f32, decos)); - auto* outer_str = create(members); + auto* outer_str = create(); + outer_str->set_members(members); ast::type::Struct outer_s("Outer", outer_str); diff --git a/src/writer/msl/generator_impl_type_test.cc b/src/writer/msl/generator_impl_type_test.cc index e3a58eea08..02340e93f1 100644 --- a/src/writer/msl/generator_impl_type_test.cc +++ b/src/writer/msl/generator_impl_type_test.cc @@ -183,7 +183,8 @@ TEST_F(MslGeneratorImplTest, EmitType_Struct) { b_deco.push_back(create(4, Source{})); members.push_back(create("b", &f32, b_deco)); - auto* str = create(members); + auto* str = create(); + str->set_members(members); ast::type::Struct s("S", str); @@ -203,7 +204,8 @@ TEST_F(MslGeneratorImplTest, EmitType_StructDecl) { b_deco.push_back(create(4, Source{})); members.push_back(create("b", &f32, b_deco)); - auto* str = create(members); + auto* str = create(); + str->set_members(members); ast::type::Struct s("S", str); @@ -219,7 +221,8 @@ TEST_F(MslGeneratorImplTest, EmitType_Struct_InjectPadding) { ast::type::I32 i32; ast::type::F32 f32; - auto* str = create(ast::StructMemberList{ + auto* str = create(); + str->set_members({ create( "a", &i32, ast::StructMemberDecorationList{ @@ -259,7 +262,8 @@ TEST_F(MslGeneratorImplTest, EmitType_Struct_NameCollision) { ast::StructMemberDecorationList b_deco; members.push_back(create("float", &f32, b_deco)); - auto* str = create(members); + auto* str = create(); + str->set_members(members); ast::type::Struct s("S", str); diff --git a/src/writer/msl/generator_impl_variable_decl_statement_test.cc b/src/writer/msl/generator_impl_variable_decl_statement_test.cc index 03a20b54bd..315dfa5cae 100644 --- a/src/writer/msl/generator_impl_variable_decl_statement_test.cc +++ b/src/writer/msl/generator_impl_variable_decl_statement_test.cc @@ -90,7 +90,8 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Struct) { b_deco.push_back(create(4, Source{})); members.push_back(create("b", &f32, b_deco)); - auto* str = create(members); + auto* str = create(); + str->set_members(members); ast::type::Struct s("S", str); diff --git a/src/writer/spirv/builder_type_test.cc b/src/writer/spirv/builder_type_test.cc index 219fbe1f16..f1c98d4e3e 100644 --- a/src/writer/spirv/builder_type_test.cc +++ b/src/writer/spirv/builder_type_test.cc @@ -279,7 +279,7 @@ TEST_F(BuilderTest_Type, ReturnsGeneratedPtr) { } TEST_F(BuilderTest_Type, GenerateStruct_Empty) { - auto* s = create(ast::StructMemberList{}); + auto* s = create(); ast::type::Struct s_type("S", s); auto id = b.GenerateTypeIfNeeded(&s_type); diff --git a/src/writer/wgsl/generator_impl_alias_type_test.cc b/src/writer/wgsl/generator_impl_alias_type_test.cc index c2ac83d265..693c75d035 100644 --- a/src/writer/wgsl/generator_impl_alias_type_test.cc +++ b/src/writer/wgsl/generator_impl_alias_type_test.cc @@ -51,7 +51,8 @@ TEST_F(WgslGeneratorImplTest, EmitConstructedType_Struct) { b_deco.push_back(create(4, Source{})); members.push_back(create("b", &i32, b_deco)); - auto* str = create(members); + auto* str = create(); + str->set_members(members); ast::type::Struct s("A", str); ast::type::Alias alias("B", &s); @@ -79,7 +80,8 @@ TEST_F(WgslGeneratorImplTest, EmitAlias_ToStruct) { b_deco.push_back(create(4, Source{})); members.push_back(create("b", &i32, b_deco)); - auto* str = create(members); + auto* str = create(); + str->set_members(members); ast::type::Struct s("A", str); ast::type::Alias alias("B", &s); diff --git a/src/writer/wgsl/generator_impl_type_test.cc b/src/writer/wgsl/generator_impl_type_test.cc index 7693db28bb..202e8fc5dc 100644 --- a/src/writer/wgsl/generator_impl_type_test.cc +++ b/src/writer/wgsl/generator_impl_type_test.cc @@ -185,7 +185,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_Struct) { b_deco.push_back(create(4, Source{})); members.push_back(create("b", &f32, b_deco)); - auto* str = create(members); + auto* str = create(); + str->set_members(members); ast::type::Struct s("S", str); @@ -205,7 +206,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_StructDecl) { b_deco.push_back(create(4, Source{})); members.push_back(create("b", &f32, b_deco)); - auto* str = create(members); + auto* str = create(); + str->set_members(members); ast::type::Struct s("S", str);