diff --git a/Source/WebGPU/WGSL/AST/ASTAssignmentStatement.h b/Source/WebGPU/WGSL/AST/ASTAssignmentStatement.h index 12cd5fcbfe5f4..bef25a49931b5 100644 --- a/Source/WebGPU/WGSL/AST/ASTAssignmentStatement.h +++ b/Source/WebGPU/WGSL/AST/ASTAssignmentStatement.h @@ -31,19 +31,19 @@ namespace WGSL::AST { class AssignmentStatement final : public Statement { - WTF_MAKE_FAST_ALLOCATED; + WGSL_AST_BUILDER_NODE(AssignmentStatement); public: + NodeKind kind() const override; + Expression& lhs() { return m_lhs.get(); } + Expression& rhs() { return m_rhs.get(); } + +private: AssignmentStatement(SourceSpan span, Expression::Ref&& lhs, Expression::Ref&& rhs) : Statement(span) , m_lhs(WTFMove(lhs)) , m_rhs(WTFMove(rhs)) { } - NodeKind kind() const override; - Expression& lhs() { return m_lhs.get(); } - Expression& rhs() { return m_rhs.get(); } - -private: Expression::Ref m_lhs; Expression::Ref m_rhs; }; diff --git a/Source/WebGPU/WGSL/AST/ASTBreakStatement.h b/Source/WebGPU/WGSL/AST/ASTBreakStatement.h index 256fb9304fcfd..e7096307e3a6f 100644 --- a/Source/WebGPU/WGSL/AST/ASTBreakStatement.h +++ b/Source/WebGPU/WGSL/AST/ASTBreakStatement.h @@ -33,13 +33,14 @@ namespace WGSL::AST { class BreakStatement final : public Statement { - WTF_MAKE_FAST_ALLOCATED; + WGSL_AST_BUILDER_NODE(BreakStatement); public: + NodeKind kind() const override; + +private: BreakStatement(SourceSpan span) : Statement(span) { } - - NodeKind kind() const override; }; } // namespace WGSL::AST diff --git a/Source/WebGPU/WGSL/AST/ASTCompoundAssignmentStatement.h b/Source/WebGPU/WGSL/AST/ASTCompoundAssignmentStatement.h index eb2f0c46fcf8d..f27dc0523d014 100644 --- a/Source/WebGPU/WGSL/AST/ASTCompoundAssignmentStatement.h +++ b/Source/WebGPU/WGSL/AST/ASTCompoundAssignmentStatement.h @@ -31,8 +31,14 @@ namespace WGSL::AST { class CompoundAssignmentStatement : public Statement { - WTF_MAKE_FAST_ALLOCATED; + WGSL_AST_BUILDER_NODE(CompoundAssignmentStatement); public: + NodeKind kind() const override; + Expression& leftExpression() { return m_leftExpression; } + Expression& rightExpression() { return m_rightExpression; } + BinaryOperation operation() const { return m_operation; } + +private: CompoundAssignmentStatement(SourceSpan span, Expression::Ref&& lhs, Expression::Ref&& rhs, BinaryOperation operation) : Statement(span) , m_leftExpression(WTFMove(lhs)) @@ -40,12 +46,6 @@ class CompoundAssignmentStatement : public Statement { , m_operation(operation) { } - NodeKind kind() const override; - Expression& leftExpression() { return m_leftExpression; } - Expression& rightExpression() { return m_rightExpression; } - BinaryOperation operation() const { return m_operation; } - -private: Expression::Ref m_leftExpression; Expression::Ref m_rightExpression; BinaryOperation m_operation; diff --git a/Source/WebGPU/WGSL/AST/ASTCompoundStatement.h b/Source/WebGPU/WGSL/AST/ASTCompoundStatement.h index 9e7a1d6f51153..851965596555c 100644 --- a/Source/WebGPU/WGSL/AST/ASTCompoundStatement.h +++ b/Source/WebGPU/WGSL/AST/ASTCompoundStatement.h @@ -30,21 +30,20 @@ namespace WGSL::AST { class CompoundStatement final : public Statement { - WTF_MAKE_FAST_ALLOCATED; + WGSL_AST_BUILDER_NODE(CompoundStatement); public: + using Ref = std::reference_wrapper; - using Ref = UniqueRef; + NodeKind kind() const override; + Statement::List& statements() { return m_statements; } + const Statement::List& statements() const { return m_statements; } +private: CompoundStatement(SourceSpan span, Statement::List&& statements) : Statement(span) , m_statements(WTFMove(statements)) { } - NodeKind kind() const override; - Statement::List& statements() { return m_statements; } - const Statement::List& statements() const { return m_statements; } - -private: Statement::List m_statements; }; diff --git a/Source/WebGPU/WGSL/AST/ASTContinueStatement.h b/Source/WebGPU/WGSL/AST/ASTContinueStatement.h index 9f3c6a7ee5a72..7361b165e5da8 100644 --- a/Source/WebGPU/WGSL/AST/ASTContinueStatement.h +++ b/Source/WebGPU/WGSL/AST/ASTContinueStatement.h @@ -32,13 +32,14 @@ namespace WGSL::AST { class ContinueStatement final : public Statement { - WTF_MAKE_FAST_ALLOCATED; + WGSL_AST_BUILDER_NODE(ContinueStatement); public: + NodeKind kind() const override; + +private: ContinueStatement(SourceSpan span) : Statement(span) { } - - NodeKind kind() const override; }; } // namespace WGSL::AST diff --git a/Source/WebGPU/WGSL/AST/ASTDecrementIncrementStatement.h b/Source/WebGPU/WGSL/AST/ASTDecrementIncrementStatement.h index 7f01747b04fe8..e1c576d3692ef 100644 --- a/Source/WebGPU/WGSL/AST/ASTDecrementIncrementStatement.h +++ b/Source/WebGPU/WGSL/AST/ASTDecrementIncrementStatement.h @@ -31,23 +31,22 @@ namespace WGSL::AST { class DecrementIncrementStatement final : public Statement { - WTF_MAKE_FAST_ALLOCATED; + WGSL_AST_BUILDER_NODE(DecrementIncrementStatement); public: - enum class Operation : uint8_t { Decrement, Increment, }; + NodeKind kind() const override; + Expression& expression() { return m_expression; } + +private: DecrementIncrementStatement(SourceSpan span, Expression::Ref&& expression) : Statement(span) , m_expression(WTFMove(expression)) { } - NodeKind kind() const override; - Expression& expression() { return m_expression; } - -private: Expression::Ref m_expression; }; diff --git a/Source/WebGPU/WGSL/AST/ASTDiscardStatement.h b/Source/WebGPU/WGSL/AST/ASTDiscardStatement.h index 55cec39b6fcba..94cdd5ee8b2a6 100644 --- a/Source/WebGPU/WGSL/AST/ASTDiscardStatement.h +++ b/Source/WebGPU/WGSL/AST/ASTDiscardStatement.h @@ -25,20 +25,19 @@ #pragma once -#pragma once - #include "ASTStatement.h" namespace WGSL::AST { class DiscardStatement final : public Statement { - WTF_MAKE_FAST_ALLOCATED; + WGSL_AST_BUILDER_NODE(DiscardStatement); public: + NodeKind kind() const override; + +private: DiscardStatement(SourceSpan span) : Statement(span) { } - - NodeKind kind() const override; }; } // namespace WGSL::AST diff --git a/Source/WebGPU/WGSL/AST/ASTForStatement.h b/Source/WebGPU/WGSL/AST/ASTForStatement.h index 4e7401553fc79..c4caf9c7cf49e 100644 --- a/Source/WebGPU/WGSL/AST/ASTForStatement.h +++ b/Source/WebGPU/WGSL/AST/ASTForStatement.h @@ -31,27 +31,27 @@ namespace WGSL::AST { class ForStatement final : public Statement { - WTF_MAKE_FAST_ALLOCATED; + WGSL_AST_BUILDER_NODE(ForStatement); public: - ForStatement(SourceSpan span, Statement::Ptr&& initializer, Expression::Ptr test, Statement::Ptr&& update, CompoundStatement&& body) - : Statement(span) - , m_initializer(WTFMove(initializer)) - , m_test(test) - , m_update(WTFMove(update)) - , m_body(WTFMove(body)) - { } - NodeKind kind() const override; - Statement* maybeInitializer() { return m_initializer.get(); } + Statement* maybeInitializer() { return m_initializer; } Expression* maybeTest() { return m_test; } - Statement* maybeUpdate() { return m_update.get(); } + Statement* maybeUpdate() { return m_update; } CompoundStatement& body() { return m_body; } private: + ForStatement(SourceSpan span, Statement::Ptr initializer, Expression::Ptr test, Statement::Ptr update, CompoundStatement::Ref&& body) + : Statement(span) + , m_initializer(initializer) + , m_test(test) + , m_update(update) + , m_body(WTFMove(body)) + { } + Statement::Ptr m_initializer; Expression::Ptr m_test; Statement::Ptr m_update; - CompoundStatement m_body; + CompoundStatement::Ref m_body; }; } // namespace WGSL::AST diff --git a/Source/WebGPU/WGSL/AST/ASTFunction.h b/Source/WebGPU/WGSL/AST/ASTFunction.h index 9f97e10c118bd..0efdfa5c7b6d5 100644 --- a/Source/WebGPU/WGSL/AST/ASTFunction.h +++ b/Source/WebGPU/WGSL/AST/ASTFunction.h @@ -47,16 +47,16 @@ class Function final : public Declaration { Attribute::List& attributes() { return m_attributes; } Attribute::List& returnAttributes() { return m_returnAttributes; } TypeName* maybeReturnType() { return m_returnType; } - CompoundStatement& body() { return m_body; } + CompoundStatement& body() { return m_body.get(); } const Identifier& name() const { return m_name; } const Parameter::List& parameters() const { return m_parameters; } const Attribute::List& attributes() const { return m_attributes; } const Attribute::List& returnAttributes() const { return m_returnAttributes; } const TypeName* maybeReturnType() const { return m_returnType; } - const CompoundStatement& body() const { return m_body; } + const CompoundStatement& body() const { return m_body.get(); } private: - Function(SourceSpan span, Identifier&& name, Parameter::List&& parameters, TypeName::Ptr returnType, CompoundStatement&& body, Attribute::List&& attributes, Attribute::List&& returnAttributes) + Function(SourceSpan span, Identifier&& name, Parameter::List&& parameters, TypeName::Ptr returnType, CompoundStatement::Ref&& body, Attribute::List&& attributes, Attribute::List&& returnAttributes) : Declaration(span) , m_name(WTFMove(name)) , m_parameters(WTFMove(parameters)) @@ -71,7 +71,7 @@ class Function final : public Declaration { Attribute::List m_attributes; Attribute::List m_returnAttributes; TypeName::Ptr m_returnType; - CompoundStatement m_body; + CompoundStatement::Ref m_body; }; } // namespace WGSL::AST diff --git a/Source/WebGPU/WGSL/AST/ASTIfStatement.h b/Source/WebGPU/WGSL/AST/ASTIfStatement.h index 7b5d4a4e63517..6810ff1c6e5cd 100644 --- a/Source/WebGPU/WGSL/AST/ASTIfStatement.h +++ b/Source/WebGPU/WGSL/AST/ASTIfStatement.h @@ -32,25 +32,25 @@ namespace WGSL::AST { class IfStatement final : public Statement { - WTF_MAKE_FAST_ALLOCATED; + WGSL_AST_BUILDER_NODE(IfStatement); public: - IfStatement(SourceSpan span, Expression::Ref&& test, CompoundStatement&& trueBody, Statement::Ptr&& falseBody, Attribute::List&& attributes) + NodeKind kind() const override; + Expression& test() { return m_test.get(); } + CompoundStatement& trueBody() { return m_trueBody.get(); } + Statement* maybeFalseBody() { return m_falseBody; } + Attribute::List& attributes() { return m_attributes; } + +private: + IfStatement(SourceSpan span, Expression::Ref&& test, CompoundStatement::Ref&& trueBody, Statement::Ptr falseBody, Attribute::List&& attributes) : Statement(span) , m_test(WTFMove(test)) , m_trueBody(WTFMove(trueBody)) - , m_falseBody(WTFMove(falseBody)) + , m_falseBody(falseBody) , m_attributes(WTFMove(attributes)) { } - NodeKind kind() const override; - Expression& test() { return m_test.get(); } - CompoundStatement& trueBody() { return m_trueBody; } - Statement* maybeFalseBody() { return m_falseBody.get(); } - Attribute::List& attributes() { return m_attributes; } - -private: Expression::Ref m_test; - CompoundStatement m_trueBody; + CompoundStatement::Ref m_trueBody; Statement::Ptr m_falseBody; Attribute::List m_attributes; }; diff --git a/Source/WebGPU/WGSL/AST/ASTLoopStatement.h b/Source/WebGPU/WGSL/AST/ASTLoopStatement.h index 0a4a2321a9500..57c1ed4f7cc52 100644 --- a/Source/WebGPU/WGSL/AST/ASTLoopStatement.h +++ b/Source/WebGPU/WGSL/AST/ASTLoopStatement.h @@ -31,19 +31,19 @@ namespace WGSL::AST { class LoopStatement final : public Statement { - WTF_MAKE_FAST_ALLOCATED; + WGSL_AST_BUILDER_NODE(LoopStatement); public: + NodeKind kind() const override; + CompoundStatement& body() { return m_body.get(); } + CompoundStatement& continuingBody() { return m_continuingBody.get(); } + +private: LoopStatement(SourceSpan span, CompoundStatement::Ref&& body, CompoundStatement::Ref&& continuingBody) : Statement(span) , m_body(WTFMove(body)) , m_continuingBody(WTFMove(continuingBody)) { } - NodeKind kind() const override; - CompoundStatement& body() { return m_body.get(); } - CompoundStatement& continuingBody() { return m_continuingBody.get(); } - -private: CompoundStatement::Ref m_body; CompoundStatement::Ref m_continuingBody; }; diff --git a/Source/WebGPU/WGSL/AST/ASTPhonyStatement.h b/Source/WebGPU/WGSL/AST/ASTPhonyStatement.h index e79ef93bd08bf..b67aae9ca4bd2 100644 --- a/Source/WebGPU/WGSL/AST/ASTPhonyStatement.h +++ b/Source/WebGPU/WGSL/AST/ASTPhonyStatement.h @@ -31,17 +31,17 @@ namespace WGSL::AST { class PhonyAssignmentStatement final : public Statement { - WTF_MAKE_FAST_ALLOCATED; + WGSL_AST_BUILDER_NODE(PhonyAssignmentStatement); public: + NodeKind kind() const override; + Expression& rhs() { return m_rhs.get(); } + +private: PhonyAssignmentStatement(SourceSpan span, Expression::Ref&& rhs) : Statement(span) , m_rhs(WTFMove(rhs)) { } - NodeKind kind() const override; - Expression& rhs() { return m_rhs.get(); } - -private: Expression::Ref m_rhs; }; diff --git a/Source/WebGPU/WGSL/AST/ASTReturnStatement.h b/Source/WebGPU/WGSL/AST/ASTReturnStatement.h index c4a09ddec1e92..869815a2b2a2f 100644 --- a/Source/WebGPU/WGSL/AST/ASTReturnStatement.h +++ b/Source/WebGPU/WGSL/AST/ASTReturnStatement.h @@ -31,17 +31,17 @@ namespace WGSL::AST { class ReturnStatement final : public Statement { - WTF_MAKE_FAST_ALLOCATED; + WGSL_AST_BUILDER_NODE(ReturnStatement); public: + NodeKind kind() const override; + Expression* maybeExpression() { return m_expression; } + +private: ReturnStatement(SourceSpan span, Expression::Ptr expression) : Statement(span) , m_expression(expression) { } - NodeKind kind() const override; - Expression* maybeExpression() { return m_expression; } - -private: Expression::Ptr m_expression; }; diff --git a/Source/WebGPU/WGSL/AST/ASTStatement.h b/Source/WebGPU/WGSL/AST/ASTStatement.h index 79c7726b0eee8..9c2853c389dcc 100644 --- a/Source/WebGPU/WGSL/AST/ASTStatement.h +++ b/Source/WebGPU/WGSL/AST/ASTStatement.h @@ -25,19 +25,20 @@ #pragma once +#include "ASTBuilder.h" #include "ASTNode.h" - -#include +#include namespace WGSL::AST { class Statement : public Node { - WTF_MAKE_FAST_ALLOCATED; + WGSL_AST_BUILDER_NODE(Statement); public: - using Ref = UniqueRef; - using Ptr = std::unique_ptr; - using List = UniqueRefVector; + using Ref = std::reference_wrapper; + using Ptr = Statement*; + using List = ReferenceWrapperVector; +protected: Statement(SourceSpan span) : Node(span) { } diff --git a/Source/WebGPU/WGSL/AST/ASTStaticAssertStatement.h b/Source/WebGPU/WGSL/AST/ASTStaticAssertStatement.h index 41cbf08d44761..ff72d347d2e99 100644 --- a/Source/WebGPU/WGSL/AST/ASTStaticAssertStatement.h +++ b/Source/WebGPU/WGSL/AST/ASTStaticAssertStatement.h @@ -31,17 +31,17 @@ namespace WGSL::AST { class StaticAssertStatement final : public Statement { - WTF_MAKE_FAST_ALLOCATED; + WGSL_AST_BUILDER_NODE(StaticAssertStatement); public: + NodeKind kind() const final; + Expression& expression() { return m_expression.get(); } + +private: StaticAssertStatement(SourceSpan span, Expression::Ref&& expression) : Statement(span) , m_expression(WTFMove(expression)) { } - NodeKind kind() const final; - Expression& expression() { return m_expression.get(); } - -private: Expression::Ref m_expression; }; diff --git a/Source/WebGPU/WGSL/AST/ASTSwitchStatement.h b/Source/WebGPU/WGSL/AST/ASTSwitchStatement.h index 5cb45a1253d6b..6af7453689156 100644 --- a/Source/WebGPU/WGSL/AST/ASTSwitchStatement.h +++ b/Source/WebGPU/WGSL/AST/ASTSwitchStatement.h @@ -30,13 +30,14 @@ namespace WGSL::AST { class SwitchStatement final : public Statement { - WTF_MAKE_FAST_ALLOCATED; + WGSL_AST_BUILDER_NODE(SwitchStatement); public: + NodeKind kind() const final; + +private: SwitchStatement(SourceSpan span) : Statement(span) { } - - NodeKind kind() const final; }; } // namespace WGSL::AST diff --git a/Source/WebGPU/WGSL/AST/ASTVariable.h b/Source/WebGPU/WGSL/AST/ASTVariable.h index e5970060334bf..4ba692fc44be1 100644 --- a/Source/WebGPU/WGSL/AST/ASTVariable.h +++ b/Source/WebGPU/WGSL/AST/ASTVariable.h @@ -25,6 +25,7 @@ #pragma once +#include "ASTAttribute.h" #include "ASTAttribute.h" #include "ASTDeclaration.h" #include "ASTExpression.h" diff --git a/Source/WebGPU/WGSL/AST/ASTVariableStatement.h b/Source/WebGPU/WGSL/AST/ASTVariableStatement.h index f25b2d79bc916..45aeec5ca6ea6 100644 --- a/Source/WebGPU/WGSL/AST/ASTVariableStatement.h +++ b/Source/WebGPU/WGSL/AST/ASTVariableStatement.h @@ -31,17 +31,17 @@ namespace WGSL::AST { class VariableStatement final : public Statement { - WTF_MAKE_FAST_ALLOCATED; + WGSL_AST_BUILDER_NODE(VariableStatement); public: + NodeKind kind() const override; + Variable& variable() { return m_variable.get(); } + +private: VariableStatement(SourceSpan span, Variable::Ref&& variable) : Statement(span) , m_variable(WTFMove(variable)) { } - NodeKind kind() const override; - Variable& variable() { return m_variable.get(); } - -private: Variable::Ref m_variable; }; diff --git a/Source/WebGPU/WGSL/AST/ASTWhileStatement.h b/Source/WebGPU/WGSL/AST/ASTWhileStatement.h index 45361d9c0cab5..a5fa70125654f 100644 --- a/Source/WebGPU/WGSL/AST/ASTWhileStatement.h +++ b/Source/WebGPU/WGSL/AST/ASTWhileStatement.h @@ -31,19 +31,19 @@ namespace WGSL::AST { class WhileStatement final : public Statement { - WTF_MAKE_FAST_ALLOCATED; + WGSL_AST_BUILDER_NODE(WhileStatement); public: + NodeKind kind() const final; + Expression& test() { return m_test.get(); } + CompoundStatement& body() { return m_body.get(); } + +private: WhileStatement(SourceSpan span, Expression::Ref&& test, CompoundStatement::Ref&& body) : Statement(span) , m_test(WTFMove(test)) , m_body(WTFMove(body)) { } - NodeKind kind() const final; - Expression& test() { return m_test.get(); } - CompoundStatement& body() { return m_body.get(); } - -private: Expression::Ref m_test; CompoundStatement::Ref m_body; }; diff --git a/Source/WebGPU/WGSL/EntryPointRewriter.cpp b/Source/WebGPU/WGSL/EntryPointRewriter.cpp index 03d4e71d32b79..f3124dfd06525 100644 --- a/Source/WebGPU/WGSL/EntryPointRewriter.cpp +++ b/Source/WebGPU/WGSL/EntryPointRewriter.cpp @@ -204,7 +204,7 @@ void EntryPointRewriter::materialize(Vector& path, MemberOrParameter& da } if (!path.size()) { - m_materializations.append(makeUniqueRef( + m_materializations.append(m_shaderModule.astBuilder().construct( SourceSpan::empty(), m_shaderModule.astBuilder().construct( SourceSpan::empty(), @@ -230,7 +230,7 @@ void EntryPointRewriter::materialize(Vector& path, MemberOrParameter& da ); } path.removeLast(); - m_materializations.append(makeUniqueRef( + m_materializations.append(m_shaderModule.astBuilder().construct( SourceSpan::empty(), WTFMove(lhs), *rhs @@ -240,7 +240,7 @@ void EntryPointRewriter::materialize(Vector& path, MemberOrParameter& da void EntryPointRewriter::visit(Vector& path, MemberOrParameter&& data) { if (auto* structType = std::get_if(data.type.resolvedType())) { - m_materializations.append(makeUniqueRef( + m_materializations.append(m_shaderModule.astBuilder().construct( SourceSpan::empty(), m_shaderModule.astBuilder().construct( SourceSpan::empty(), diff --git a/Source/WebGPU/WGSL/Parser.cpp b/Source/WebGPU/WGSL/Parser.cpp index 75373ab2fc024..70067f7a25e18 100644 --- a/Source/WebGPU/WGSL/Parser.cpp +++ b/Source/WebGPU/WGSL/Parser.cpp @@ -827,24 +827,23 @@ Result Parser::parseStatement() switch (current().type) { case TokenType::BraceLeft: { PARSE(compoundStmt, CompoundStatement); - return { makeUniqueRef(WTFMove(compoundStmt)) }; + return { compoundStmt }; } case TokenType::KeywordIf: { // FIXME: Handle attributes attached to statement. - PARSE(ifStmt, IfStatement); - return { makeUniqueRef(WTFMove(ifStmt)) }; + return parseIfStatement(); } case TokenType::KeywordReturn: { PARSE(returnStmt, ReturnStatement); CONSUME_TYPE(Semicolon); - return { makeUniqueRef(WTFMove(returnStmt)) }; + return { returnStmt }; } case TokenType::KeywordConst: case TokenType::KeywordLet: case TokenType::KeywordVar: { PARSE(variable, Variable); CONSUME_TYPE(Semicolon); - return { makeUniqueRef(CURRENT_SOURCE_SPAN(), WTFMove(variable)) }; + RETURN_ARENA_NODE(VariableStatement, WTFMove(variable)); } case TokenType::Identifier: { // FIXME: there will be other cases here eventually for function calls @@ -859,21 +858,20 @@ Result Parser::parseStatement() CONSUME_TYPE(Semicolon); if (maybeOp) - RETURN_NODE_UNIQUE_REF(CompoundAssignmentStatement, WTFMove(lhs), WTFMove(rhs), *maybeOp); + RETURN_ARENA_NODE(CompoundAssignmentStatement, WTFMove(lhs), WTFMove(rhs), *maybeOp); - RETURN_NODE_UNIQUE_REF(AssignmentStatement, WTFMove(lhs), WTFMove(rhs)); + RETURN_ARENA_NODE(AssignmentStatement, WTFMove(lhs), WTFMove(rhs)); } case TokenType::KeywordFor: { // FIXME: Handle attributes attached to statement. - PARSE(forStmt, ForStatement); - return { makeUniqueRef(WTFMove(forStmt)) }; + return parseForStatement(); } case TokenType::Underbar : { consume(); CONSUME_TYPE(Equal); PARSE(rhs, Expression); CONSUME_TYPE(Semicolon); - RETURN_NODE_UNIQUE_REF(PhonyAssignmentStatement, WTFMove(rhs)); + RETURN_ARENA_NODE(PhonyAssignmentStatement, WTFMove(rhs)); } default: FAIL("Not a valid statement"_s); @@ -881,7 +879,7 @@ Result Parser::parseStatement() } template -Result Parser::parseCompoundStatement() +Result Parser::parseCompoundStatement() { START_PARSE(); @@ -895,11 +893,11 @@ Result Parser::parseCompoundStatement() CONSUME_TYPE(BraceRight); - RETURN_NODE(CompoundStatement, WTFMove(statements)); + RETURN_ARENA_NODE(CompoundStatement, WTFMove(statements)); } template -Result Parser::parseIfStatement() +Result Parser::parseIfStatement() { START_PARSE(); @@ -909,31 +907,31 @@ Result Parser::parseIfStatement() } template -Result Parser::parseIfStatementWithAttributes(AST::Attribute::List&& attributes, SourcePosition _startOfElementPosition) +Result Parser::parseIfStatementWithAttributes(AST::Attribute::List&& attributes, SourcePosition _startOfElementPosition) { CONSUME_TYPE(KeywordIf); PARSE(testExpr, Expression); PARSE(thenStmt, CompoundStatement); - AST::Statement::Ptr maybeElseStmt; + AST::Statement::Ptr maybeElseStmt = nullptr; if (current().type == TokenType::KeywordElse) { consume(); // The syntax following an 'else' keyword can be either an 'if' // statement or a brace-delimited compound statement. if (current().type == TokenType::KeywordIf) { PARSE(elseStmt, IfStatementWithAttributes, { }, _startOfElementPosition); - maybeElseStmt = WTF::makeUnique(WTFMove(elseStmt)); + maybeElseStmt = &elseStmt.get(); } else { PARSE(elseStmt, CompoundStatement); - maybeElseStmt = WTF::makeUnique(WTFMove(elseStmt)); + maybeElseStmt = &elseStmt.get(); } } - RETURN_NODE(IfStatement, WTFMove(testExpr), WTFMove(thenStmt), WTFMove(maybeElseStmt), WTFMove(attributes)); + RETURN_ARENA_NODE(IfStatement, WTFMove(testExpr), WTFMove(thenStmt), maybeElseStmt, WTFMove(attributes)); } template -Result Parser::parseForStatement() +Result Parser::parseForStatement() { START_PARSE(); @@ -948,7 +946,7 @@ Result Parser::parseForStatement() if (current().type != TokenType::Semicolon) { // FIXME: this should be for_init PARSE(variable, Variable); - maybeInitializer = makeUnique(CURRENT_SOURCE_SPAN(), WTFMove(variable)); + maybeInitializer = &MAKE_ARENA_NODE(VariableStatement, WTFMove(variable)); } CONSUME_TYPE(Semicolon); @@ -966,22 +964,22 @@ Result Parser::parseForStatement() PARSE(body, CompoundStatement); - RETURN_NODE(ForStatement, WTFMove(maybeInitializer), WTFMove(maybeTest), WTFMove(maybeUpdate), WTFMove(body)); + RETURN_ARENA_NODE(ForStatement, maybeInitializer, maybeTest, maybeUpdate, WTFMove(body)); } template -Result Parser::parseReturnStatement() +Result Parser::parseReturnStatement() { START_PARSE(); CONSUME_TYPE(KeywordReturn); if (current().type == TokenType::Semicolon) { - RETURN_NODE(ReturnStatement, { }); + RETURN_ARENA_NODE(ReturnStatement, nullptr); } PARSE(expr, Expression); - RETURN_NODE(ReturnStatement, &expr.get()); + RETURN_ARENA_NODE(ReturnStatement, &expr.get()); } template diff --git a/Source/WebGPU/WGSL/ParserPrivate.h b/Source/WebGPU/WGSL/ParserPrivate.h index 9196c9eb72069..9691210bd898e 100644 --- a/Source/WebGPU/WGSL/ParserPrivate.h +++ b/Source/WebGPU/WGSL/ParserPrivate.h @@ -73,11 +73,11 @@ class Parser { Result parseFunction(AST::Attribute::List&&); Result> parseParameter(); Result parseStatement(); - Result parseCompoundStatement(); - Result parseIfStatement(); - Result parseIfStatementWithAttributes(AST::Attribute::List&&, SourcePosition _startOfElementPosition); - Result parseForStatement(); - Result parseReturnStatement(); + Result parseCompoundStatement(); + Result parseIfStatement(); + Result parseIfStatementWithAttributes(AST::Attribute::List&&, SourcePosition _startOfElementPosition); + Result parseForStatement(); + Result parseReturnStatement(); Result parseShortCircuitExpression(AST::Expression::Ref&&, TokenType, AST::BinaryOperation); Result parseRelationalExpression(); Result parseRelationalExpressionPostUnary(AST::Expression::Ref&& lhs);