From 3ffec80c636e22576e73a22f0e4677e51181c6b8 Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Mon, 6 Apr 2020 19:37:37 +0000 Subject: [PATCH] Add list helpers This CL adds various using statements for the std::vector> constructs found in the AST. Change-Id: Ic9a2357cd73b2aafd99e961a38727f2f9874cde5 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/18920 Reviewed-by: David Neto --- src/ast/as_expression.h | 1 - src/ast/call_expression.cc | 4 +- src/ast/call_expression.h | 16 ++-- src/ast/call_expression_test.cc | 10 +-- src/ast/case_statement.cc | 4 +- src/ast/case_statement.h | 16 ++-- src/ast/case_statement_test.cc | 14 ++-- src/ast/cast_expression.h | 1 - src/ast/decorated_variable.h | 9 +-- src/ast/decorated_variable_test.cc | 2 +- src/ast/else_statement.cc | 9 +-- src/ast/else_statement.h | 21 +++-- src/ast/else_statement_test.cc | 12 +-- src/ast/entry_point.h | 5 ++ src/ast/expression.h | 6 ++ src/ast/fallthrough_statement.h | 3 - src/ast/function.cc | 4 +- src/ast/function.h | 25 +++--- src/ast/function_test.cc | 32 ++++---- src/ast/identifier_expression.h | 1 - src/ast/if_statement.cc | 4 +- src/ast/if_statement.h | 33 +++----- src/ast/if_statement_test.cc | 78 +++++++++---------- src/ast/import.h | 5 ++ src/ast/loop_statement.cc | 7 +- src/ast/loop_statement.h | 25 +++--- src/ast/loop_statement_test.cc | 43 +++++----- src/ast/module.h | 24 ++---- src/ast/module_test.cc | 3 +- src/ast/regardless_statement.cc | 12 ++- src/ast/regardless_statement.h | 13 ++-- src/ast/regardless_statement_test.cc | 16 ++-- src/ast/statement.h | 6 ++ src/ast/struct.cc | 5 +- src/ast/struct.h | 17 ++-- src/ast/struct_member.cc | 16 ++-- src/ast/struct_member.h | 29 ++++--- src/ast/struct_member_decoration.h | 6 ++ src/ast/struct_member_test.cc | 6 +- src/ast/struct_test.cc | 31 ++++---- src/ast/switch_statement.cc | 12 ++- src/ast/switch_statement.h | 16 ++-- src/ast/switch_statement_test.cc | 43 +++++----- src/ast/type_constructor_expression.cc | 12 ++- src/ast/type_constructor_expression.h | 17 ++-- src/ast/type_constructor_expression_test.cc | 17 ++-- src/ast/unary_method_expression.cc | 12 ++- src/ast/unary_method_expression.h | 17 ++-- src/ast/unary_method_expression_test.cc | 13 ++-- src/ast/unless_statement.cc | 4 +- src/ast/unless_statement.h | 14 ++-- src/ast/unless_statement_test.cc | 16 ++-- src/ast/variable.h | 4 + src/ast/variable_decoration.h | 5 ++ src/reader/spirv/parser_impl.cc | 9 +-- src/reader/wgsl/parser_impl.cc | 52 ++++++------- src/reader/wgsl/parser_impl.h | 28 ++++--- .../builder_constructor_expression_test.cc | 6 +- .../spirv/builder_function_variable_test.cc | 6 +- .../spirv/builder_global_variable_test.cc | 10 +-- .../spirv/builder_ident_expression_test.cc | 4 +- src/writer/spirv/builder_return_test.cc | 2 +- src/writer/spirv/builder_type_test.cc | 14 ++-- src/writer/wgsl/generator_impl.cc | 5 +- src/writer/wgsl/generator_impl.h | 8 +- .../wgsl/generator_impl_alias_type_test.cc | 6 +- src/writer/wgsl/generator_impl_call_test.cc | 2 +- src/writer/wgsl/generator_impl_case_test.cc | 5 +- .../wgsl/generator_impl_constructor_test.cc | 21 +++-- src/writer/wgsl/generator_impl_else_test.cc | 5 +- .../wgsl/generator_impl_function_test.cc | 6 +- src/writer/wgsl/generator_impl_if_test.cc | 25 +++--- src/writer/wgsl/generator_impl_loop_test.cc | 7 +- .../wgsl/generator_impl_regardless_test.cc | 3 +- src/writer/wgsl/generator_impl_switch_test.cc | 7 +- src/writer/wgsl/generator_impl_type_test.cc | 12 +-- .../wgsl/generator_impl_unary_method_test.cc | 5 +- src/writer/wgsl/generator_impl_unless_test.cc | 3 +- .../wgsl/generator_impl_variable_test.cc | 5 +- 79 files changed, 476 insertions(+), 556 deletions(-) diff --git a/src/ast/as_expression.h b/src/ast/as_expression.h index e2d1cc167a..16b4f91e91 100644 --- a/src/ast/as_expression.h +++ b/src/ast/as_expression.h @@ -17,7 +17,6 @@ #include #include -#include #include "src/ast/expression.h" #include "src/ast/literal.h" diff --git a/src/ast/call_expression.cc b/src/ast/call_expression.cc index 6dad233da4..5cc9e73f4f 100644 --- a/src/ast/call_expression.cc +++ b/src/ast/call_expression.cc @@ -20,12 +20,12 @@ namespace ast { CallExpression::CallExpression() : Expression() {} CallExpression::CallExpression(std::unique_ptr func, - std::vector> params) + ExpressionList params) : Expression(), func_(std::move(func)), params_(std::move(params)) {} CallExpression::CallExpression(const Source& source, std::unique_ptr func, - std::vector> params) + ExpressionList params) : Expression(source), func_(std::move(func)), params_(std::move(params)) {} CallExpression::~CallExpression() = default; diff --git a/src/ast/call_expression.h b/src/ast/call_expression.h index 56df9b91cf..597cf437b3 100644 --- a/src/ast/call_expression.h +++ b/src/ast/call_expression.h @@ -17,7 +17,6 @@ #include #include -#include #include "src/ast/expression.h" #include "src/ast/literal.h" @@ -33,15 +32,14 @@ class CallExpression : public Expression { /// Constructor /// @param func the function /// @param params the parameters - CallExpression(std::unique_ptr func, - std::vector> params); + CallExpression(std::unique_ptr func, ExpressionList params); /// Constructor /// @param source the call expression source /// @param func the function /// @param params the parameters CallExpression(const Source& source, std::unique_ptr func, - std::vector> params); + ExpressionList params); /// Move constructor CallExpression(CallExpression&&) = default; ~CallExpression() override; @@ -54,13 +52,9 @@ class CallExpression : public Expression { /// Sets the parameters /// @param params the parameters - void set_params(std::vector> params) { - params_ = std::move(params); - } + void set_params(ExpressionList params) { params_ = std::move(params); } /// @returns the parameters - const std::vector>& params() const { - return params_; - } + const ExpressionList& params() const { return params_; } /// @returns true if this is a call expression bool IsCall() const override { return true; } @@ -77,7 +71,7 @@ class CallExpression : public Expression { CallExpression(const CallExpression&) = delete; std::unique_ptr func_; - std::vector> params_; + ExpressionList params_; }; } // namespace ast diff --git a/src/ast/call_expression_test.cc b/src/ast/call_expression_test.cc index 1425f062d7..e88627fd92 100644 --- a/src/ast/call_expression_test.cc +++ b/src/ast/call_expression_test.cc @@ -25,7 +25,7 @@ using CallExpressionTest = testing::Test; TEST_F(CallExpressionTest, Creation) { auto func = std::make_unique("func"); - std::vector> params; + ExpressionList params; params.push_back(std::make_unique("param1")); params.push_back(std::make_unique("param2")); @@ -69,7 +69,7 @@ TEST_F(CallExpressionTest, IsValid_MissingFunction) { TEST_F(CallExpressionTest, IsValid_NullParam) { auto func = std::make_unique("func"); - std::vector> params; + ExpressionList params; params.push_back(std::make_unique("param1")); params.push_back(nullptr); params.push_back(std::make_unique("param2")); @@ -80,7 +80,7 @@ TEST_F(CallExpressionTest, IsValid_NullParam) { TEST_F(CallExpressionTest, IsValid_InvalidFunction) { auto func = std::make_unique(""); - std::vector> params; + ExpressionList params; params.push_back(std::make_unique("param1")); CallExpression stmt(std::move(func), std::move(params)); @@ -89,7 +89,7 @@ TEST_F(CallExpressionTest, IsValid_InvalidFunction) { TEST_F(CallExpressionTest, IsValid_InvalidParam) { auto func = std::make_unique("func"); - std::vector> params; + ExpressionList params; params.push_back(std::make_unique("")); CallExpression stmt(std::move(func), std::move(params)); @@ -111,7 +111,7 @@ TEST_F(CallExpressionTest, ToStr_NoParams) { TEST_F(CallExpressionTest, ToStr_WithParams) { auto func = std::make_unique("func"); - std::vector> params; + ExpressionList params; params.push_back(std::make_unique("param1")); params.push_back(std::make_unique("param2")); diff --git a/src/ast/case_statement.cc b/src/ast/case_statement.cc index 98e3a475ce..51412a1f9d 100644 --- a/src/ast/case_statement.cc +++ b/src/ast/case_statement.cc @@ -20,12 +20,12 @@ namespace ast { CaseStatement::CaseStatement() : Statement() {} CaseStatement::CaseStatement(std::unique_ptr condition, - std::vector> body) + StatementList body) : Statement(), condition_(std::move(condition)), body_(std::move(body)) {} CaseStatement::CaseStatement(const Source& source, std::unique_ptr condition, - std::vector> body) + StatementList body) : Statement(source), condition_(std::move(condition)), body_(std::move(body)) {} diff --git a/src/ast/case_statement.h b/src/ast/case_statement.h index 8a3ae09d41..b8db59933b 100644 --- a/src/ast/case_statement.h +++ b/src/ast/case_statement.h @@ -35,15 +35,14 @@ class CaseStatement : public Statement { /// Constructor /// @param condition the case condition /// @param body the case body - CaseStatement(std::unique_ptr condition, - std::vector> body); + CaseStatement(std::unique_ptr condition, StatementList body); /// Constructor /// @param source the source information /// @param condition the case condition /// @param body the case body CaseStatement(const Source& source, std::unique_ptr condition, - std::vector> body); + StatementList body); /// Move constructor CaseStatement(CaseStatement&&) = default; ~CaseStatement() override; @@ -60,11 +59,9 @@ class CaseStatement : public Statement { /// Sets the case body /// @param body the case body - void set_body(std::vector> body) { - body_ = std::move(body); - } + void set_body(StatementList body) { body_ = std::move(body); } /// @returns the case body - const std::vector>& body() const { return body_; } + const StatementList& body() const { return body_; } /// @returns true if this is a case statement bool IsCase() const override { return true; } @@ -81,9 +78,12 @@ class CaseStatement : public Statement { CaseStatement(const CaseStatement&) = delete; std::unique_ptr condition_; - std::vector> body_; + StatementList body_; }; +/// A list of unique case statements +using CaseStatementList = std::vector>; + } // namespace ast } // namespace tint diff --git a/src/ast/case_statement_test.cc b/src/ast/case_statement_test.cc index 27b94c57de..b88b0fe81b 100644 --- a/src/ast/case_statement_test.cc +++ b/src/ast/case_statement_test.cc @@ -29,7 +29,7 @@ using CaseStatementTest = testing::Test; TEST_F(CaseStatementTest, Creation) { ast::type::BoolType bool_type; auto b = std::make_unique(&bool_type, true); - std::vector> stmts; + StatementList stmts; stmts.push_back(std::make_unique()); auto bool_ptr = b.get(); @@ -44,7 +44,7 @@ TEST_F(CaseStatementTest, Creation) { TEST_F(CaseStatementTest, Creation_WithSource) { ast::type::BoolType bool_type; auto b = std::make_unique(&bool_type, true); - std::vector> stmts; + StatementList stmts; stmts.push_back(std::make_unique()); CaseStatement c(Source{20, 2}, std::move(b), std::move(stmts)); @@ -54,7 +54,7 @@ TEST_F(CaseStatementTest, Creation_WithSource) { } TEST_F(CaseStatementTest, IsDefault_WithoutCondition) { - std::vector> stmts; + StatementList stmts; stmts.push_back(std::make_unique()); CaseStatement c; @@ -83,7 +83,7 @@ TEST_F(CaseStatementTest, IsValid) { TEST_F(CaseStatementTest, IsValid_NullBodyStatement) { ast::type::BoolType bool_type; auto b = std::make_unique(&bool_type, true); - std::vector> stmts; + StatementList stmts; stmts.push_back(std::make_unique()); stmts.push_back(nullptr); @@ -94,7 +94,7 @@ TEST_F(CaseStatementTest, IsValid_NullBodyStatement) { TEST_F(CaseStatementTest, IsValid_InvalidBodyStatement) { ast::type::BoolType bool_type; auto b = std::make_unique(&bool_type, true); - std::vector> stmts; + StatementList stmts; stmts.push_back(std::make_unique()); CaseStatement c(std::move(b), std::move(stmts)); @@ -104,7 +104,7 @@ TEST_F(CaseStatementTest, IsValid_InvalidBodyStatement) { TEST_F(CaseStatementTest, ToStr_WithCondition) { ast::type::BoolType bool_type; auto b = std::make_unique(&bool_type, true); - std::vector> stmts; + StatementList stmts; stmts.push_back(std::make_unique()); CaseStatement c(std::move(b), std::move(stmts)); @@ -117,7 +117,7 @@ TEST_F(CaseStatementTest, ToStr_WithCondition) { } TEST_F(CaseStatementTest, ToStr_WithoutCondition) { - std::vector> stmts; + StatementList stmts; stmts.push_back(std::make_unique()); CaseStatement c(nullptr, std::move(stmts)); diff --git a/src/ast/cast_expression.h b/src/ast/cast_expression.h index 52966a296a..69bfbf5f56 100644 --- a/src/ast/cast_expression.h +++ b/src/ast/cast_expression.h @@ -17,7 +17,6 @@ #include #include -#include #include "src/ast/expression.h" #include "src/ast/literal.h" diff --git a/src/ast/decorated_variable.h b/src/ast/decorated_variable.h index 4008a48b13..5f05416e5c 100644 --- a/src/ast/decorated_variable.h +++ b/src/ast/decorated_variable.h @@ -17,7 +17,6 @@ #include #include -#include #include "src/ast/variable.h" #include "src/ast/variable_decoration.h" @@ -40,13 +39,11 @@ class DecoratedVariable : public Variable { /// Sets a decoration to the variable /// @param decos the decorations to set - void set_decorations(std::vector> decos) { + void set_decorations(VariableDecorationList decos) { decorations_ = std::move(decos); } /// @returns the decorations attached to this variable - const std::vector>& decorations() const { - return decorations_; - } + const VariableDecorationList& decorations() const { return decorations_; } /// @returns true if this is a decorated variable bool IsDecorated() const override { return true; } @@ -61,7 +58,7 @@ class DecoratedVariable : public Variable { private: DecoratedVariable(const DecoratedVariable&) = delete; - std::vector> decorations_; + VariableDecorationList decorations_; }; } // namespace ast diff --git a/src/ast/decorated_variable_test.cc b/src/ast/decorated_variable_test.cc index 6d96f8e1e8..11954abed8 100644 --- a/src/ast/decorated_variable_test.cc +++ b/src/ast/decorated_variable_test.cc @@ -72,7 +72,7 @@ TEST_F(DecoratedVariableTest, to_str) { DecoratedVariable dv(std::move(var)); dv.set_constructor(std::make_unique("expr")); - std::vector> decos; + VariableDecorationList decos; decos.push_back(std::make_unique(2)); decos.push_back(std::make_unique(1)); diff --git a/src/ast/else_statement.cc b/src/ast/else_statement.cc index 307daec353..b879a4f1cf 100644 --- a/src/ast/else_statement.cc +++ b/src/ast/else_statement.cc @@ -19,20 +19,19 @@ namespace ast { ElseStatement::ElseStatement() : Statement() {} -ElseStatement::ElseStatement(std::vector> body) +ElseStatement::ElseStatement(StatementList body) : Statement(), body_(std::move(body)) {} ElseStatement::ElseStatement(std::unique_ptr condition, - std::vector> body) + StatementList body) : Statement(), condition_(std::move(condition)), body_(std::move(body)) {} -ElseStatement::ElseStatement(const Source& source, - std::vector> body) +ElseStatement::ElseStatement(const Source& source, StatementList body) : Statement(source), body_(std::move(body)) {} ElseStatement::ElseStatement(const Source& source, std::unique_ptr condition, - std::vector> body) + StatementList body) : Statement(source), condition_(std::move(condition)), body_(std::move(body)) {} diff --git a/src/ast/else_statement.h b/src/ast/else_statement.h index 66511f3149..a935bb461e 100644 --- a/src/ast/else_statement.h +++ b/src/ast/else_statement.h @@ -32,24 +32,22 @@ class ElseStatement : public Statement { ElseStatement(); /// Constructor /// @param body the else body - explicit ElseStatement(std::vector> body); + explicit ElseStatement(StatementList body); /// Constructor /// @param condition the else condition /// @param body the else body - ElseStatement(std::unique_ptr condition, - std::vector> body); + ElseStatement(std::unique_ptr condition, StatementList body); /// Constructor /// @param source the source information /// @param body the else body - ElseStatement(const Source& source, - std::vector> body); + ElseStatement(const Source& source, StatementList body); /// Constructor /// @param source the source information /// @param condition the else condition /// @param body the else body ElseStatement(const Source& source, std::unique_ptr condition, - std::vector> body); + StatementList body); /// Move constructor ElseStatement(ElseStatement&&) = default; ~ElseStatement() override; @@ -66,11 +64,9 @@ class ElseStatement : public Statement { /// Sets the else body /// @param body the else body - void set_body(std::vector> body) { - body_ = std::move(body); - } + void set_body(StatementList body) { body_ = std::move(body); } /// @returns the else body - const std::vector>& body() const { return body_; } + const StatementList& body() const { return body_; } /// @returns true if this is a else statement bool IsElse() const override { return true; } @@ -87,9 +83,12 @@ class ElseStatement : public Statement { ElseStatement(const ElseStatement&) = delete; std::unique_ptr condition_; - std::vector> body_; + StatementList body_; }; +/// A list of unique else statements +using ElseStatementList = std::vector>; + } // namespace ast } // namespace tint diff --git a/src/ast/else_statement_test.cc b/src/ast/else_statement_test.cc index 8e5143d24e..bfa0c7705f 100644 --- a/src/ast/else_statement_test.cc +++ b/src/ast/else_statement_test.cc @@ -31,7 +31,7 @@ TEST_F(ElseStatementTest, Creation) { ast::type::BoolType bool_type; auto cond = std::make_unique( std::make_unique(&bool_type, true)); - std::vector> body; + StatementList body; body.push_back(std::make_unique()); auto cond_ptr = cond.get(); @@ -74,7 +74,7 @@ TEST_F(ElseStatementTest, IsValid) { } TEST_F(ElseStatementTest, IsValid_WithBody) { - std::vector> body; + StatementList body; body.push_back(std::make_unique()); ElseStatement e(std::move(body)); @@ -82,7 +82,7 @@ TEST_F(ElseStatementTest, IsValid_WithBody) { } TEST_F(ElseStatementTest, IsValid_WithNullBodyStatement) { - std::vector> body; + StatementList body; body.push_back(std::make_unique()); body.push_back(nullptr); @@ -97,7 +97,7 @@ TEST_F(ElseStatementTest, IsValid_InvalidCondition) { } TEST_F(ElseStatementTest, IsValid_InvalidBodyStatement) { - std::vector> body; + StatementList body; body.push_back(std::make_unique()); ElseStatement e(std::move(body)); @@ -108,7 +108,7 @@ TEST_F(ElseStatementTest, ToStr) { ast::type::BoolType bool_type; auto cond = std::make_unique( std::make_unique(&bool_type, true)); - std::vector> body; + StatementList body; body.push_back(std::make_unique()); ElseStatement e(std::move(cond), std::move(body)); @@ -126,7 +126,7 @@ TEST_F(ElseStatementTest, ToStr) { } TEST_F(ElseStatementTest, ToStr_NoCondition) { - std::vector> body; + StatementList body; body.push_back(std::make_unique()); ElseStatement e(std::move(body)); diff --git a/src/ast/entry_point.h b/src/ast/entry_point.h index 40ca20fc38..3b4086e2c3 100644 --- a/src/ast/entry_point.h +++ b/src/ast/entry_point.h @@ -15,8 +15,10 @@ #ifndef SRC_AST_ENTRY_POINT_H_ #define SRC_AST_ENTRY_POINT_H_ +#include #include #include +#include #include "src/ast/node.h" #include "src/ast/pipeline_stage.h" @@ -83,6 +85,9 @@ class EntryPoint : public Node { std::string fn_name_; }; +/// A list of unique entry points. +using EntryPointList = std::vector>; + } // namespace ast } // namespace tint diff --git a/src/ast/expression.h b/src/ast/expression.h index 63695b2345..065755f356 100644 --- a/src/ast/expression.h +++ b/src/ast/expression.h @@ -15,6 +15,9 @@ #ifndef SRC_AST_EXPRESSION_H_ #define SRC_AST_EXPRESSION_H_ +#include +#include + #include "src/ast/node.h" #include "src/ast/type/type.h" @@ -105,6 +108,9 @@ class Expression : public Node { type::Type* result_type_ = nullptr; }; +/// A list of unique expressions +using ExpressionList = std::vector>; + } // namespace ast } // namespace tint diff --git a/src/ast/fallthrough_statement.h b/src/ast/fallthrough_statement.h index 34cd092353..d9a8675bd6 100644 --- a/src/ast/fallthrough_statement.h +++ b/src/ast/fallthrough_statement.h @@ -15,9 +15,6 @@ #ifndef SRC_AST_FALLTHROUGH_STATEMENT_H_ #define SRC_AST_FALLTHROUGH_STATEMENT_H_ -#include -#include - #include "src/ast/expression.h" #include "src/ast/statement.h" #include "src/ast/statement_condition.h" diff --git a/src/ast/function.cc b/src/ast/function.cc index 4aa7c524c4..abe5809365 100644 --- a/src/ast/function.cc +++ b/src/ast/function.cc @@ -20,7 +20,7 @@ namespace tint { namespace ast { Function::Function(const std::string& name, - std::vector> params, + VariableList params, type::Type* return_type) : Node(), name_(name), @@ -29,7 +29,7 @@ Function::Function(const std::string& name, Function::Function(const Source& source, const std::string& name, - std::vector> params, + VariableList params, type::Type* return_type) : Node(source), name_(name), diff --git a/src/ast/function.h b/src/ast/function.h index 71afe7c459..06ea1946ce 100644 --- a/src/ast/function.h +++ b/src/ast/function.h @@ -40,7 +40,7 @@ class Function : public Node { /// @param params the function parameters /// @param return_type the return type Function(const std::string& name, - std::vector> params, + VariableList params, type::Type* return_type); /// Create a function /// @param source the variable source @@ -49,7 +49,7 @@ class Function : public Node { /// @param return_type the return type Function(const Source& source, const std::string& name, - std::vector> params, + VariableList params, type::Type* return_type); /// Move constructor Function(Function&&) = default; @@ -64,13 +64,9 @@ class Function : public Node { /// Sets the function parameters /// @param params the function parameters - void set_params(std::vector> params) { - params_ = std::move(params); - } + void set_params(VariableList params) { params_ = std::move(params); } /// @returns the function params - const std::vector>& params() const { - return params_; - } + const VariableList& params() const { return params_; } /// Sets the return type of the function /// @param type the return type @@ -80,11 +76,9 @@ class Function : public Node { /// Sets the body of the function /// @param body the function body - void set_body(std::vector> body) { - body_ = std::move(body); - } + void set_body(StatementList body) { body_ = std::move(body); } /// @returns the function body - const std::vector>& body() const { return body_; } + const StatementList& body() const { return body_; } /// @returns true if the name and type are both present bool IsValid() const override; @@ -101,11 +95,14 @@ class Function : public Node { Function(const Function&) = delete; std::string name_; - std::vector> params_; + VariableList params_; type::Type* return_type_ = nullptr; - std::vector> body_; + StatementList body_; }; +/// A list of unique functions +using FunctionList = std::vector>; + } // namespace ast } // namespace tint diff --git a/src/ast/function_test.cc b/src/ast/function_test.cc index 0e9e2bf258..adac67db7d 100644 --- a/src/ast/function_test.cc +++ b/src/ast/function_test.cc @@ -31,7 +31,7 @@ TEST_F(FunctionTest, Creation) { type::VoidType void_type; type::I32Type i32; - std::vector> params; + VariableList params; params.push_back( std::make_unique("var", StorageClass::kNone, &i32)); auto var_ptr = params[0].get(); @@ -47,7 +47,7 @@ TEST_F(FunctionTest, Creation_WithSource) { type::VoidType void_type; type::I32Type i32; - std::vector> params; + VariableList params; params.push_back( std::make_unique("var", StorageClass::kNone, &i32)); @@ -61,11 +61,11 @@ TEST_F(FunctionTest, IsValid) { type::VoidType void_type; type::I32Type i32; - std::vector> params; + VariableList params; params.push_back( std::make_unique("var", StorageClass::kNone, &i32)); - std::vector> body; + StatementList body; body.push_back(std::make_unique()); Function f("func", std::move(params), &void_type); @@ -77,7 +77,7 @@ TEST_F(FunctionTest, IsValid_EmptyName) { type::VoidType void_type; type::I32Type i32; - std::vector> params; + VariableList params; params.push_back( std::make_unique("var", StorageClass::kNone, &i32)); @@ -88,7 +88,7 @@ TEST_F(FunctionTest, IsValid_EmptyName) { TEST_F(FunctionTest, IsValid_MissingReturnType) { type::I32Type i32; - std::vector> params; + VariableList params; params.push_back( std::make_unique("var", StorageClass::kNone, &i32)); @@ -100,7 +100,7 @@ TEST_F(FunctionTest, IsValid_NullParam) { type::VoidType void_type; type::I32Type i32; - std::vector> params; + VariableList params; params.push_back( std::make_unique("var", StorageClass::kNone, &i32)); params.push_back(nullptr); @@ -112,7 +112,7 @@ TEST_F(FunctionTest, IsValid_NullParam) { TEST_F(FunctionTest, IsValid_InvalidParam) { type::VoidType void_type; - std::vector> params; + VariableList params; params.push_back( std::make_unique("var", StorageClass::kNone, nullptr)); @@ -124,11 +124,11 @@ TEST_F(FunctionTest, IsValid_NullBodyStatement) { type::VoidType void_type; type::I32Type i32; - std::vector> params; + VariableList params; params.push_back( std::make_unique("var", StorageClass::kNone, &i32)); - std::vector> body; + StatementList body; body.push_back(std::make_unique()); body.push_back(nullptr); @@ -141,11 +141,11 @@ TEST_F(FunctionTest, IsValid_InvalidBodyStatement) { type::VoidType void_type; type::I32Type i32; - std::vector> params; + VariableList params; params.push_back( std::make_unique("var", StorageClass::kNone, &i32)); - std::vector> body; + StatementList body; body.push_back(std::make_unique()); body.push_back(nullptr); @@ -158,7 +158,7 @@ TEST_F(FunctionTest, ToStr) { type::VoidType void_type; type::I32Type i32; - std::vector> body; + StatementList body; body.push_back(std::make_unique()); Function f("func", {}, &void_type); @@ -178,11 +178,11 @@ TEST_F(FunctionTest, ToStr_WithParams) { type::VoidType void_type; type::I32Type i32; - std::vector> params; + VariableList params; params.push_back( std::make_unique("var", StorageClass::kNone, &i32)); - std::vector> body; + StatementList body; body.push_back(std::make_unique()); Function f("func", std::move(params), &void_type); @@ -216,7 +216,7 @@ TEST_F(FunctionTest, TypeName_WithParams) { type::I32Type i32; type::F32Type f32; - std::vector> params; + VariableList params; params.push_back( std::make_unique("var1", StorageClass::kNone, &i32)); params.push_back( diff --git a/src/ast/identifier_expression.h b/src/ast/identifier_expression.h index 38adc73fb1..3e46129994 100644 --- a/src/ast/identifier_expression.h +++ b/src/ast/identifier_expression.h @@ -15,7 +15,6 @@ #ifndef SRC_AST_IDENTIFIER_EXPRESSION_H_ #define SRC_AST_IDENTIFIER_EXPRESSION_H_ -#include #include #include #include diff --git a/src/ast/if_statement.cc b/src/ast/if_statement.cc index f000f2e461..671cac3a3a 100644 --- a/src/ast/if_statement.cc +++ b/src/ast/if_statement.cc @@ -22,12 +22,12 @@ namespace ast { IfStatement::IfStatement() : Statement() {} IfStatement::IfStatement(std::unique_ptr condition, - std::vector> body) + StatementList body) : Statement(), condition_(std::move(condition)), body_(std::move(body)) {} IfStatement::IfStatement(const Source& source, std::unique_ptr condition, - std::vector> body) + StatementList body) : Statement(source), condition_(std::move(condition)), body_(std::move(body)) {} diff --git a/src/ast/if_statement.h b/src/ast/if_statement.h index f628b1ca90..30f2e66140 100644 --- a/src/ast/if_statement.h +++ b/src/ast/if_statement.h @@ -17,7 +17,6 @@ #include #include -#include #include "src/ast/else_statement.h" #include "src/ast/expression.h" @@ -34,15 +33,14 @@ class IfStatement : public Statement { /// Constructor /// @param condition the if condition /// @param body the if body - IfStatement(std::unique_ptr condition, - std::vector> body); + IfStatement(std::unique_ptr condition, StatementList body); /// Constructor /// @param source the source information /// @param condition the if condition /// @param body the if body IfStatement(const Source& source, std::unique_ptr condition, - std::vector> body); + StatementList body); /// Move constructor IfStatement(IfStatement&&) = default; ~IfStatement() override; @@ -57,32 +55,23 @@ class IfStatement : public Statement { /// Sets the if body /// @param body the if body - void set_body(std::vector> body) { - body_ = std::move(body); - } + void set_body(StatementList body) { body_ = std::move(body); } /// @returns the if body - const std::vector>& body() const { return body_; } + const StatementList& body() const { return body_; } /// Sets the else statements /// @param else_statements the else statements to set - void set_else_statements( - std::vector> else_statements) { + void set_else_statements(ElseStatementList else_statements) { else_statements_ = std::move(else_statements); } /// @returns the else statements - const std::vector>& else_statements() const { - return else_statements_; - } + const ElseStatementList& else_statements() const { return else_statements_; } /// Sets the premerge statements /// @param premerge the premerge statements - void set_premerge(std::vector> premerge) { - premerge_ = std::move(premerge); - } + void set_premerge(StatementList premerge) { premerge_ = std::move(premerge); } /// @returns the premerge statements - const std::vector>& premerge() const { - return premerge_; - } + const StatementList& premerge() const { return premerge_; } /// @returns true if this is a if statement bool IsIf() const override { return true; } @@ -99,9 +88,9 @@ class IfStatement : public Statement { IfStatement(const IfStatement&) = delete; std::unique_ptr condition_; - std::vector> body_; - std::vector> else_statements_; - std::vector> premerge_; + StatementList body_; + ElseStatementList else_statements_; + StatementList premerge_; }; } // namespace ast diff --git a/src/ast/if_statement_test.cc b/src/ast/if_statement_test.cc index 6d6abd47ec..4786ece659 100644 --- a/src/ast/if_statement_test.cc +++ b/src/ast/if_statement_test.cc @@ -27,7 +27,7 @@ using IfStatementTest = testing::Test; TEST_F(IfStatementTest, Creation) { auto cond = std::make_unique("cond"); - std::vector> body; + StatementList body; body.push_back(std::make_unique()); auto cond_ptr = cond.get(); @@ -41,7 +41,7 @@ TEST_F(IfStatementTest, Creation) { TEST_F(IfStatementTest, Creation_WithSource) { auto cond = std::make_unique("cond"); - std::vector> body; + StatementList body; body.push_back(std::make_unique()); IfStatement stmt(Source{20, 2}, std::move(cond), std::move(body)); @@ -57,7 +57,7 @@ TEST_F(IfStatementTest, IsIf) { TEST_F(IfStatementTest, IsValid) { auto cond = std::make_unique("cond"); - std::vector> body; + StatementList body; body.push_back(std::make_unique()); IfStatement stmt(std::move(cond), std::move(body)); @@ -66,10 +66,10 @@ TEST_F(IfStatementTest, IsValid) { TEST_F(IfStatementTest, IsValid_WithElseStatements) { auto cond = std::make_unique("cond"); - std::vector> body; + StatementList body; body.push_back(std::make_unique()); - std::vector> else_stmts; + ElseStatementList else_stmts; else_stmts.push_back(std::make_unique()); else_stmts[0]->set_condition(std::make_unique("Ident")); else_stmts.push_back(std::make_unique()); @@ -81,13 +81,13 @@ TEST_F(IfStatementTest, IsValid_WithElseStatements) { TEST_F(IfStatementTest, IsValid_WithPremerge) { auto cond = std::make_unique("cond"); - std::vector> body; + StatementList body; body.push_back(std::make_unique()); - std::vector> else_stmts; + ElseStatementList else_stmts; else_stmts.push_back(std::make_unique()); - std::vector> premerge; + StatementList premerge; premerge.push_back(std::make_unique()); IfStatement stmt(std::move(cond), std::move(body)); @@ -97,7 +97,7 @@ TEST_F(IfStatementTest, IsValid_WithPremerge) { } TEST_F(IfStatementTest, IsValid_MissingCondition) { - std::vector> body; + StatementList body; body.push_back(std::make_unique()); IfStatement stmt(nullptr, std::move(body)); @@ -106,7 +106,7 @@ TEST_F(IfStatementTest, IsValid_MissingCondition) { TEST_F(IfStatementTest, IsValid_InvalidCondition) { auto cond = std::make_unique(""); - std::vector> body; + StatementList body; body.push_back(std::make_unique()); IfStatement stmt(std::move(cond), std::move(body)); @@ -115,7 +115,7 @@ TEST_F(IfStatementTest, IsValid_InvalidCondition) { TEST_F(IfStatementTest, IsValid_NullBodyStatement) { auto cond = std::make_unique("cond"); - std::vector> body; + StatementList body; body.push_back(std::make_unique()); body.push_back(nullptr); @@ -125,7 +125,7 @@ TEST_F(IfStatementTest, IsValid_NullBodyStatement) { TEST_F(IfStatementTest, IsValid_InvalidBodyStatement) { auto cond = std::make_unique("cond"); - std::vector> body; + StatementList body; body.push_back(std::make_unique()); body.push_back(std::make_unique()); @@ -135,10 +135,10 @@ TEST_F(IfStatementTest, IsValid_InvalidBodyStatement) { TEST_F(IfStatementTest, IsValid_NullElseStatement) { auto cond = std::make_unique("cond"); - std::vector> body; + StatementList body; body.push_back(std::make_unique()); - std::vector> else_stmts; + ElseStatementList else_stmts; else_stmts.push_back(std::make_unique()); else_stmts[0]->set_condition(std::make_unique("Ident")); else_stmts.push_back(std::make_unique()); @@ -151,10 +151,10 @@ TEST_F(IfStatementTest, IsValid_NullElseStatement) { TEST_F(IfStatementTest, IsValid_InvalidElseStatement) { auto cond = std::make_unique("cond"); - std::vector> body; + StatementList body; body.push_back(std::make_unique()); - std::vector> else_stmts; + ElseStatementList else_stmts; else_stmts.push_back(std::make_unique()); else_stmts[0]->set_condition(std::make_unique("")); @@ -165,13 +165,13 @@ TEST_F(IfStatementTest, IsValid_InvalidElseStatement) { TEST_F(IfStatementTest, IsValid_NullPremergeStatement) { auto cond = std::make_unique("cond"); - std::vector> body; + StatementList body; body.push_back(std::make_unique()); - std::vector> else_stmts; + ElseStatementList else_stmts; else_stmts.push_back(std::make_unique()); - std::vector> premerge; + StatementList premerge; premerge.push_back(std::make_unique()); premerge.push_back(nullptr); @@ -183,13 +183,13 @@ TEST_F(IfStatementTest, IsValid_NullPremergeStatement) { TEST_F(IfStatementTest, IsValid_InvalidPremergeStatement) { auto cond = std::make_unique("cond"); - std::vector> body; + StatementList body; body.push_back(std::make_unique()); - std::vector> else_stmts; + ElseStatementList else_stmts; else_stmts.push_back(std::make_unique()); - std::vector> premerge; + StatementList premerge; premerge.push_back(std::make_unique()); IfStatement stmt(std::move(cond), std::move(body)); @@ -200,14 +200,14 @@ TEST_F(IfStatementTest, IsValid_InvalidPremergeStatement) { TEST_F(IfStatementTest, IsValid_PremergeWithElseIf) { auto cond = std::make_unique("cond"); - std::vector> body; + StatementList body; body.push_back(std::make_unique()); - std::vector> else_stmts; + ElseStatementList else_stmts; else_stmts.push_back(std::make_unique()); else_stmts[0]->set_condition(std::make_unique("ident")); - std::vector> premerge; + StatementList premerge; premerge.push_back(std::make_unique()); IfStatement stmt(std::move(cond), std::move(body)); @@ -218,10 +218,10 @@ TEST_F(IfStatementTest, IsValid_PremergeWithElseIf) { TEST_F(IfStatementTest, IsValid_PremergeWithoutElse) { auto cond = std::make_unique("cond"); - std::vector> body; + StatementList body; body.push_back(std::make_unique()); - std::vector> premerge; + StatementList premerge; premerge.push_back(std::make_unique()); IfStatement stmt(std::move(cond), std::move(body)); @@ -231,10 +231,10 @@ TEST_F(IfStatementTest, IsValid_PremergeWithoutElse) { TEST_F(IfStatementTest, IsValid_MultipleElseWiththoutCondition) { auto cond = std::make_unique("cond"); - std::vector> body; + StatementList body; body.push_back(std::make_unique()); - std::vector> else_stmts; + ElseStatementList else_stmts; else_stmts.push_back(std::make_unique()); else_stmts.push_back(std::make_unique()); @@ -245,10 +245,10 @@ TEST_F(IfStatementTest, IsValid_MultipleElseWiththoutCondition) { TEST_F(IfStatementTest, IsValid_ElseNotLast) { auto cond = std::make_unique("cond"); - std::vector> body; + StatementList body; body.push_back(std::make_unique()); - std::vector> else_stmts; + ElseStatementList else_stmts; else_stmts.push_back(std::make_unique()); else_stmts.push_back(std::make_unique()); else_stmts[1]->set_condition(std::make_unique("ident")); @@ -260,7 +260,7 @@ TEST_F(IfStatementTest, IsValid_ElseNotLast) { TEST_F(IfStatementTest, ToStr) { auto cond = std::make_unique("cond"); - std::vector> body; + StatementList body; body.push_back(std::make_unique()); IfStatement stmt(std::move(cond), std::move(body)); @@ -280,17 +280,17 @@ TEST_F(IfStatementTest, ToStr) { TEST_F(IfStatementTest, ToStr_WithElseStatements) { auto cond = std::make_unique("cond"); - std::vector> body; + StatementList body; body.push_back(std::make_unique()); - std::vector> else_if_body; + StatementList else_if_body; else_if_body.push_back(std::make_unique()); - std::vector> else_body; + StatementList else_body; else_body.push_back(std::make_unique()); else_body.push_back(std::make_unique()); - std::vector> else_stmts; + ElseStatementList else_stmts; else_stmts.push_back(std::make_unique()); else_stmts[0]->set_condition(std::make_unique("ident")); else_stmts[0]->set_body(std::move(else_if_body)); @@ -329,13 +329,13 @@ TEST_F(IfStatementTest, ToStr_WithElseStatements) { TEST_F(IfStatementTest, ToStr_WithPremerge) { auto cond = std::make_unique("cond"); - std::vector> body; + StatementList body; body.push_back(std::make_unique()); - std::vector> else_stmts; + ElseStatementList else_stmts; else_stmts.push_back(std::make_unique()); - std::vector> premerge; + StatementList premerge; premerge.push_back(std::make_unique()); IfStatement stmt(std::move(cond), std::move(body)); diff --git a/src/ast/import.h b/src/ast/import.h index cb67c25c04..c3d6b82abf 100644 --- a/src/ast/import.h +++ b/src/ast/import.h @@ -15,8 +15,10 @@ #ifndef SRC_AST_IMPORT_H_ #define SRC_AST_IMPORT_H_ +#include #include #include +#include #include "src/ast/node.h" @@ -70,6 +72,9 @@ class Import : public Node { std::string name_; }; +/// A list of unique imports +using ImportList = std::vector>; + } // namespace ast } // namespace tint diff --git a/src/ast/loop_statement.cc b/src/ast/loop_statement.cc index 97efc069d0..3a853c68c3 100644 --- a/src/ast/loop_statement.cc +++ b/src/ast/loop_statement.cc @@ -19,13 +19,12 @@ namespace ast { LoopStatement::LoopStatement() : Statement() {} -LoopStatement::LoopStatement(std::vector> body, - std::vector> continuing) +LoopStatement::LoopStatement(StatementList body, StatementList continuing) : Statement(), body_(std::move(body)), continuing_(std::move(continuing)) {} LoopStatement::LoopStatement(const Source& source, - std::vector> body, - std::vector> continuing) + StatementList body, + StatementList continuing) : Statement(source), body_(std::move(body)), continuing_(std::move(continuing)) {} diff --git a/src/ast/loop_statement.h b/src/ast/loop_statement.h index e7bd755f07..c70a0cff90 100644 --- a/src/ast/loop_statement.h +++ b/src/ast/loop_statement.h @@ -15,9 +15,7 @@ #ifndef SRC_AST_LOOP_STATEMENT_H_ #define SRC_AST_LOOP_STATEMENT_H_ -#include #include -#include #include "src/ast/statement.h" @@ -32,36 +30,31 @@ class LoopStatement : public Statement { /// Constructor /// @param body the body statements /// @param continuing the continuing statements - LoopStatement(std::vector> body, - std::vector> continuing); + LoopStatement(StatementList body, StatementList continuing); /// Constructor /// @param source the loop statement source /// @param body the body statements /// @param continuing the continuing statements LoopStatement(const Source& source, - std::vector> body, - std::vector> continuing); + StatementList body, + StatementList continuing); /// Move constructor LoopStatement(LoopStatement&&) = default; ~LoopStatement() override; /// Sets the body statements /// @param body the body statements - void set_body(std::vector> body) { - body_ = std::move(body); - } + void set_body(StatementList body) { body_ = std::move(body); } /// @returns the body statements - const std::vector>& body() const { return body_; } + const StatementList& body() const { return body_; } /// Sets the continuing statements /// @param continuing the continuing statements - void set_continuing(std::vector> continuing) { + void set_continuing(StatementList continuing) { continuing_ = std::move(continuing); } /// @returns the continuing statements - const std::vector>& continuing() const { - return continuing_; - } + const StatementList& continuing() const { return continuing_; } /// @returns true if there are continuing statements in the loop bool has_continuing() const { return !continuing_.empty(); } @@ -79,8 +72,8 @@ class LoopStatement : public Statement { private: LoopStatement(const LoopStatement&) = delete; - std::vector> body_; - std::vector> continuing_; + StatementList body_; + StatementList continuing_; }; } // namespace ast diff --git a/src/ast/loop_statement_test.cc b/src/ast/loop_statement_test.cc index 37788d51c0..dad5c6b20b 100644 --- a/src/ast/loop_statement_test.cc +++ b/src/ast/loop_statement_test.cc @@ -14,6 +14,7 @@ #include "src/ast/loop_statement.h" +#include #include #include "gtest/gtest.h" @@ -28,11 +29,11 @@ namespace { using LoopStatementTest = testing::Test; TEST_F(LoopStatementTest, Creation) { - std::vector> body; + StatementList body; body.push_back(std::make_unique()); auto b_ptr = body[0].get(); - std::vector> continuing; + StatementList continuing; continuing.push_back(std::make_unique()); auto c_ptr = continuing[0].get(); @@ -44,10 +45,10 @@ TEST_F(LoopStatementTest, Creation) { } TEST_F(LoopStatementTest, Creation_WithSource) { - std::vector> body; + StatementList body; body.push_back(std::make_unique()); - std::vector> continuing; + StatementList continuing; continuing.push_back(std::make_unique()); LoopStatement l(Source{20, 2}, std::move(body), std::move(continuing)); @@ -62,7 +63,7 @@ TEST_F(LoopStatementTest, IsLoop) { } TEST_F(LoopStatementTest, HasContinuing_WithoutContinuing) { - std::vector> body; + StatementList body; body.push_back(std::make_unique()); LoopStatement l(std::move(body), {}); @@ -70,10 +71,10 @@ TEST_F(LoopStatementTest, HasContinuing_WithoutContinuing) { } TEST_F(LoopStatementTest, HasContinuing_WithContinuing) { - std::vector> body; + StatementList body; body.push_back(std::make_unique()); - std::vector> continuing; + StatementList continuing; continuing.push_back(std::make_unique()); LoopStatement l(std::move(body), std::move(continuing)); @@ -81,10 +82,10 @@ TEST_F(LoopStatementTest, HasContinuing_WithContinuing) { } TEST_F(LoopStatementTest, IsValid) { - std::vector> body; + StatementList body; body.push_back(std::make_unique()); - std::vector> continuing; + StatementList continuing; continuing.push_back(std::make_unique()); LoopStatement l(std::move(body), std::move(continuing)); @@ -92,7 +93,7 @@ TEST_F(LoopStatementTest, IsValid) { } TEST_F(LoopStatementTest, IsValid_WithoutContinuing) { - std::vector> body; + StatementList body; body.push_back(std::make_unique()); LoopStatement l(std::move(body), {}); @@ -105,11 +106,11 @@ TEST_F(LoopStatementTest, IsValid_WithoutBody) { } TEST_F(LoopStatementTest, IsValid_NullBodyStatement) { - std::vector> body; + StatementList body; body.push_back(std::make_unique()); body.push_back(nullptr); - std::vector> continuing; + StatementList continuing; continuing.push_back(std::make_unique()); LoopStatement l(std::move(body), std::move(continuing)); @@ -117,11 +118,11 @@ TEST_F(LoopStatementTest, IsValid_NullBodyStatement) { } TEST_F(LoopStatementTest, IsValid_InvalidBodyStatement) { - std::vector> body; + StatementList body; body.push_back(std::make_unique()); body.push_back(std::make_unique()); - std::vector> continuing; + StatementList continuing; continuing.push_back(std::make_unique()); LoopStatement l(std::move(body), std::move(continuing)); @@ -129,10 +130,10 @@ TEST_F(LoopStatementTest, IsValid_InvalidBodyStatement) { } TEST_F(LoopStatementTest, IsValid_NullContinuingStatement) { - std::vector> body; + StatementList body; body.push_back(std::make_unique()); - std::vector> continuing; + StatementList continuing; continuing.push_back(std::make_unique()); continuing.push_back(nullptr); @@ -141,10 +142,10 @@ TEST_F(LoopStatementTest, IsValid_NullContinuingStatement) { } TEST_F(LoopStatementTest, IsValid_InvalidContinuingStatement) { - std::vector> body; + StatementList body; body.push_back(std::make_unique()); - std::vector> continuing; + StatementList continuing; continuing.push_back(std::make_unique()); continuing.push_back(std::make_unique()); @@ -153,7 +154,7 @@ TEST_F(LoopStatementTest, IsValid_InvalidContinuingStatement) { } TEST_F(LoopStatementTest, ToStr) { - std::vector> body; + StatementList body; body.push_back(std::make_unique()); LoopStatement l(std::move(body), {}); @@ -166,10 +167,10 @@ TEST_F(LoopStatementTest, ToStr) { } TEST_F(LoopStatementTest, ToStr_WithContinuing) { - std::vector> body; + StatementList body; body.push_back(std::make_unique()); - std::vector> continuing; + StatementList continuing; continuing.push_back(std::make_unique()); LoopStatement l(std::move(body), std::move(continuing)); diff --git a/src/ast/module.h b/src/ast/module.h index cfe26e7b77..8bada47575 100644 --- a/src/ast/module.h +++ b/src/ast/module.h @@ -43,9 +43,7 @@ class Module { imports_.push_back(std::move(import)); } /// @returns the imports for this module - const std::vector>& imports() const { - return imports_; - } + const ImportList& imports() const { return imports_; } /// Find the import of the given name /// @param name The import name to search for /// @returns the import with the given name if found, nullptr otherwise. @@ -57,9 +55,7 @@ class Module { global_variables_.push_back(std::move(var)); } /// @returns the global variables for the module - const std::vector>& global_variables() const { - return global_variables_; - } + const VariableList& global_variables() const { return global_variables_; } /// Adds an entry point to the module /// @param ep the entry point to add @@ -67,9 +63,7 @@ class Module { entry_points_.push_back(std::move(ep)); } /// @returns the entry points in the module - const std::vector>& entry_points() const { - return entry_points_; - } + const EntryPointList& entry_points() const { return entry_points_; } /// Adds a type alias to the module /// @param type the alias to add @@ -85,9 +79,7 @@ class Module { functions_.push_back(std::move(func)); } /// @returns the modules functions - const std::vector>& functions() const { - return functions_; - } + const FunctionList& functions() const { return functions_; } /// @returns true if all required fields in the AST are present. bool IsValid() const; @@ -98,12 +90,12 @@ class Module { private: Module(const Module&) = delete; - std::vector> imports_; - std::vector> global_variables_; - std::vector> entry_points_; + ImportList imports_; + VariableList global_variables_; + EntryPointList entry_points_; // The alias types are owned by the type manager std::vector alias_types_; - std::vector> functions_; + FunctionList functions_; }; } // namespace ast diff --git a/src/ast/module_test.cc b/src/ast/module_test.cc index 2742bd4daf..f9f596882d 100644 --- a/src/ast/module_test.cc +++ b/src/ast/module_test.cc @@ -163,8 +163,7 @@ TEST_F(ModuleTest, IsValid_Null_Alias) { TEST_F(ModuleTest, IsValid_Function) { type::F32Type f32; - auto func = std::make_unique( - "main", std::vector>(), &f32); + auto func = std::make_unique("main", VariableList(), &f32); Module m; m.AddFunction(std::move(func)); diff --git a/src/ast/regardless_statement.cc b/src/ast/regardless_statement.cc index 052ea3d42a..3e1c52ab8b 100644 --- a/src/ast/regardless_statement.cc +++ b/src/ast/regardless_statement.cc @@ -19,15 +19,13 @@ namespace ast { RegardlessStatement::RegardlessStatement() : Statement() {} -RegardlessStatement::RegardlessStatement( - std::unique_ptr condition, - std::vector> body) +RegardlessStatement::RegardlessStatement(std::unique_ptr condition, + StatementList body) : Statement(), condition_(std::move(condition)), body_(std::move(body)) {} -RegardlessStatement::RegardlessStatement( - const Source& source, - std::unique_ptr condition, - std::vector> body) +RegardlessStatement::RegardlessStatement(const Source& source, + std::unique_ptr condition, + StatementList body) : Statement(source), condition_(std::move(condition)), body_(std::move(body)) {} diff --git a/src/ast/regardless_statement.h b/src/ast/regardless_statement.h index 06e2959b27..aad9fc75b0 100644 --- a/src/ast/regardless_statement.h +++ b/src/ast/regardless_statement.h @@ -17,7 +17,6 @@ #include #include -#include #include "src/ast/expression.h" #include "src/ast/statement.h" @@ -34,14 +33,14 @@ class RegardlessStatement : public Statement { /// @param condition the condition expression /// @param body the body statements RegardlessStatement(std::unique_ptr condition, - std::vector> body); + StatementList body); /// Constructor /// @param source the regardless statement source /// @param condition the condition expression /// @param body the body statements RegardlessStatement(const Source& source, std::unique_ptr condition, - std::vector> body); + StatementList body); /// Move constructor RegardlessStatement(RegardlessStatement&&) = default; ~RegardlessStatement() override; @@ -56,11 +55,9 @@ class RegardlessStatement : public Statement { /// Sets the body statements /// @param body the body statements - void set_body(std::vector> body) { - body_ = std::move(body); - } + void set_body(StatementList body) { body_ = std::move(body); } /// @returns the body statements - const std::vector>& body() const { return body_; } + const StatementList& body() const { return body_; } /// @returns true if this is an regardless statement bool IsRegardless() const override { return true; } @@ -77,7 +74,7 @@ class RegardlessStatement : public Statement { RegardlessStatement(const RegardlessStatement&) = delete; std::unique_ptr condition_; - std::vector> body_; + StatementList body_; }; } // namespace ast diff --git a/src/ast/regardless_statement_test.cc b/src/ast/regardless_statement_test.cc index cf15f1fdc5..955ae07f2e 100644 --- a/src/ast/regardless_statement_test.cc +++ b/src/ast/regardless_statement_test.cc @@ -29,7 +29,7 @@ using RegardlessStatementTest = testing::Test; TEST_F(RegardlessStatementTest, Creation) { auto ident = std::make_unique("ident"); - std::vector> stmts; + StatementList stmts; stmts.push_back(std::make_unique()); auto ident_ptr = ident.get(); @@ -43,7 +43,7 @@ TEST_F(RegardlessStatementTest, Creation) { TEST_F(RegardlessStatementTest, Creation_WithSource) { auto ident = std::make_unique("ident"); - std::vector> stmts; + StatementList stmts; stmts.push_back(std::make_unique()); RegardlessStatement r(Source{20, 2}, std::move(ident), std::move(stmts)); @@ -59,7 +59,7 @@ TEST_F(RegardlessStatementTest, IsRegardless) { TEST_F(RegardlessStatementTest, IsValid) { auto ident = std::make_unique("ident"); - std::vector> stmts; + StatementList stmts; stmts.push_back(std::make_unique()); RegardlessStatement r(std::move(ident), std::move(stmts)); @@ -67,7 +67,7 @@ TEST_F(RegardlessStatementTest, IsValid) { } TEST_F(RegardlessStatementTest, IsValid_NullCondition) { - std::vector> stmts; + StatementList stmts; stmts.push_back(std::make_unique()); RegardlessStatement r; @@ -77,7 +77,7 @@ TEST_F(RegardlessStatementTest, IsValid_NullCondition) { TEST_F(RegardlessStatementTest, IsValid_InvalidCondition) { auto ident = std::make_unique(""); - std::vector> stmts; + StatementList stmts; stmts.push_back(std::make_unique()); RegardlessStatement r(std::move(ident), std::move(stmts)); @@ -86,7 +86,7 @@ TEST_F(RegardlessStatementTest, IsValid_InvalidCondition) { TEST_F(RegardlessStatementTest, IsValid_NullBodyStatement) { auto ident = std::make_unique("ident"); - std::vector> stmts; + StatementList stmts; stmts.push_back(std::make_unique()); stmts.push_back(nullptr); @@ -98,7 +98,7 @@ TEST_F(RegardlessStatementTest, IsValid_NullBodyStatement) { TEST_F(RegardlessStatementTest, IsValid_InvalidBodyStatement) { auto ident = std::make_unique("ident"); - std::vector> stmts; + StatementList stmts; stmts.push_back(std::make_unique()); stmts.push_back(std::make_unique()); @@ -108,7 +108,7 @@ TEST_F(RegardlessStatementTest, IsValid_InvalidBodyStatement) { TEST_F(RegardlessStatementTest, ToStr) { auto ident = std::make_unique("ident"); - std::vector> stmts; + StatementList stmts; stmts.push_back(std::make_unique()); RegardlessStatement r(std::move(ident), std::move(stmts)); diff --git a/src/ast/statement.h b/src/ast/statement.h index d14ee318c1..ee9b13bedf 100644 --- a/src/ast/statement.h +++ b/src/ast/statement.h @@ -15,6 +15,9 @@ #ifndef SRC_AST_STATEMENT_H_ #define SRC_AST_STATEMENT_H_ +#include +#include + #include "src/ast/node.h" namespace tint { @@ -116,6 +119,9 @@ class Statement : public Node { Statement(const Statement&) = delete; }; +/// A list of unique statements +using StatementList = std::vector>; + } // namespace ast } // namespace tint diff --git a/src/ast/struct.cc b/src/ast/struct.cc index e643e2b9e0..73df8f8af3 100644 --- a/src/ast/struct.cc +++ b/src/ast/struct.cc @@ -19,13 +19,12 @@ namespace ast { Struct::Struct() : Node() {} -Struct::Struct(StructDecoration decoration, - std::vector> members) +Struct::Struct(StructDecoration decoration, StructMemberList members) : Node(), decoration_(decoration), members_(std::move(members)) {} Struct::Struct(const Source& source, StructDecoration decoration, - std::vector> members) + StructMemberList members) : Node(source), decoration_(decoration), members_(std::move(members)) {} Struct::~Struct() = default; diff --git a/src/ast/struct.h b/src/ast/struct.h index b7b157ca8f..76dcd2ece8 100644 --- a/src/ast/struct.h +++ b/src/ast/struct.h @@ -15,11 +15,9 @@ #ifndef SRC_AST_STRUCT_H_ #define SRC_AST_STRUCT_H_ -#include #include #include #include -#include #include "src/ast/node.h" #include "src/ast/struct_decoration.h" @@ -36,15 +34,14 @@ class Struct : public Node { /// Create a new struct statement /// @param decoration The struct decorations /// @param members The struct members - Struct(StructDecoration decoration, - std::vector> members); + Struct(StructDecoration decoration, StructMemberList members); /// Create a new struct statement /// @param source The input source for the import statement /// @param decoration The struct decorations /// @param members The struct members Struct(const Source& source, StructDecoration decoration, - std::vector> members); + StructMemberList members); /// Move constructor Struct(Struct&&) = default; @@ -58,13 +55,9 @@ class Struct : public Node { /// Sets the struct members /// @param members the members to set - void set_members(std::vector> members) { - members_ = std::move(members); - } + void set_members(StructMemberList members) { members_ = std::move(members); } /// @returns the members - const std::vector>& members() const { - return members_; - } + const StructMemberList& members() const { return members_; } /// @returns true if the node is valid bool IsValid() const override; @@ -78,7 +71,7 @@ class Struct : public Node { Struct(const Struct&) = delete; StructDecoration decoration_ = StructDecoration::kNone; - std::vector> members_; + StructMemberList members_; }; } // namespace ast diff --git a/src/ast/struct_member.cc b/src/ast/struct_member.cc index 2a95131917..a002c6edba 100644 --- a/src/ast/struct_member.cc +++ b/src/ast/struct_member.cc @@ -17,17 +17,15 @@ namespace tint { namespace ast { -StructMember::StructMember( - const std::string& name, - type::Type* type, - std::vector> decorations) +StructMember::StructMember(const std::string& name, + type::Type* type, + StructMemberDecorationList decorations) : Node(), name_(name), type_(type), decorations_(std::move(decorations)) {} -StructMember::StructMember( - const Source& source, - const std::string& name, - type::Type* type, - std::vector> decorations) +StructMember::StructMember(const Source& source, + const std::string& name, + type::Type* type, + StructMemberDecorationList decorations) : Node(source), name_(name), type_(type), diff --git a/src/ast/struct_member.h b/src/ast/struct_member.h index 0aceb8176f..07af25d477 100644 --- a/src/ast/struct_member.h +++ b/src/ast/struct_member.h @@ -37,20 +37,18 @@ class StructMember : public Node { /// @param name The struct member name /// @param type The struct member type /// @param decorations The struct member decorations - StructMember( - const std::string& name, - type::Type* type, - std::vector> decorations); + StructMember(const std::string& name, + type::Type* type, + StructMemberDecorationList decorations); /// Create a new struct member statement /// @param source The input source for the struct member statement /// @param name The struct member name /// @param type The struct member type /// @param decorations The struct member decorations - StructMember( - const Source& source, - const std::string& name, - type::Type* type, - std::vector> decorations); + StructMember(const Source& source, + const std::string& name, + type::Type* type, + StructMemberDecorationList decorations); /// Move constructor StructMember(StructMember&&) = default; @@ -68,15 +66,11 @@ class StructMember : public Node { type::Type* type() const { return type_; } /// Sets the decorations /// @param decorations the decorations - void set_decorations( - std::vector> decorations) { + void set_decorations(StructMemberDecorationList decorations) { decorations_ = std::move(decorations); } /// @returns the decorations - const std::vector>& decorations() - const { - return decorations_; - } + const StructMemberDecorationList& decorations() const { return decorations_; } /// @returns true if the node is valid bool IsValid() const override; @@ -91,9 +85,12 @@ class StructMember : public Node { std::string name_; type::Type* type_ = nullptr; - std::vector> decorations_; + StructMemberDecorationList decorations_; }; +/// A list of unique struct members +using StructMemberList = std::vector>; + } // namespace ast } // namespace tint diff --git a/src/ast/struct_member_decoration.h b/src/ast/struct_member_decoration.h index 525bb64e04..e7a49ba3a2 100644 --- a/src/ast/struct_member_decoration.h +++ b/src/ast/struct_member_decoration.h @@ -15,7 +15,9 @@ #ifndef SRC_AST_STRUCT_MEMBER_DECORATION_H_ #define SRC_AST_STRUCT_MEMBER_DECORATION_H_ +#include #include +#include namespace tint { namespace ast { @@ -40,6 +42,10 @@ class StructMemberDecoration { StructMemberDecoration(); }; +/// A list of unique struct member decorations +using StructMemberDecorationList = + std::vector>; + } // namespace ast } // namespace tint diff --git a/src/ast/struct_member_test.cc b/src/ast/struct_member_test.cc index c16495986a..b6f3ded90b 100644 --- a/src/ast/struct_member_test.cc +++ b/src/ast/struct_member_test.cc @@ -29,7 +29,7 @@ using StructMemberTest = testing::Test; TEST_F(StructMemberTest, Creation) { type::I32Type i32; - std::vector> decorations; + StructMemberDecorationList decorations; decorations.emplace_back(std::make_unique(4)); StructMember st{"a", &i32, std::move(decorations)}; @@ -72,7 +72,7 @@ TEST_F(StructMemberTest, IsValid_NullType) { TEST_F(StructMemberTest, IsValid_Null_Decoration) { type::I32Type i32; - std::vector> decorations; + StructMemberDecorationList decorations; decorations.emplace_back(std::make_unique(4)); decorations.push_back(nullptr); @@ -82,7 +82,7 @@ TEST_F(StructMemberTest, IsValid_Null_Decoration) { TEST_F(StructMemberTest, ToStr) { type::I32Type i32; - std::vector> decorations; + StructMemberDecorationList decorations; decorations.emplace_back(std::make_unique(4)); StructMember st{"a", &i32, std::move(decorations)}; diff --git a/src/ast/struct_test.cc b/src/ast/struct_test.cc index b2145257dd..15dbad94a1 100644 --- a/src/ast/struct_test.cc +++ b/src/ast/struct_test.cc @@ -14,6 +14,7 @@ #include "src/ast/struct.h" +#include #include #include @@ -30,9 +31,9 @@ using StructTest = testing::Test; TEST_F(StructTest, Creation) { type::I32Type i32; - std::vector> members; - members.push_back(std::make_unique( - "a", &i32, std::vector>())); + StructMemberList members; + members.push_back( + std::make_unique("a", &i32, StructMemberDecorationList())); Struct s{StructDecoration::kNone, std::move(members)}; EXPECT_EQ(s.members().size(), 1); @@ -44,9 +45,9 @@ TEST_F(StructTest, Creation) { TEST_F(StructTest, CreationWithSource) { type::I32Type i32; Source source{27, 4}; - std::vector> members; - members.emplace_back(std::make_unique( - "a", &i32, std::vector>())); + StructMemberList members; + members.emplace_back( + std::make_unique("a", &i32, StructMemberDecorationList())); Struct s{source, StructDecoration::kNone, std::move(members)}; EXPECT_EQ(s.members().size(), 1); @@ -62,9 +63,9 @@ TEST_F(StructTest, IsValid) { TEST_F(StructTest, IsValid_Null_StructMember) { type::I32Type i32; - std::vector> members; - members.push_back(std::make_unique( - "a", &i32, std::vector>())); + StructMemberList members; + members.push_back( + std::make_unique("a", &i32, StructMemberDecorationList())); members.push_back(nullptr); Struct s{StructDecoration::kNone, std::move(members)}; @@ -73,9 +74,9 @@ TEST_F(StructTest, IsValid_Null_StructMember) { TEST_F(StructTest, IsValid_Invalid_StructMember) { type::I32Type i32; - std::vector> members; - members.push_back(std::make_unique( - "", &i32, std::vector>())); + StructMemberList members; + members.push_back( + std::make_unique("", &i32, StructMemberDecorationList())); Struct s{StructDecoration::kNone, std::move(members)}; EXPECT_FALSE(s.IsValid()); @@ -84,9 +85,9 @@ TEST_F(StructTest, IsValid_Invalid_StructMember) { TEST_F(StructTest, ToStr) { type::I32Type i32; Source source{27, 4}; - std::vector> members; - members.emplace_back(std::make_unique( - "a", &i32, std::vector>())); + StructMemberList members; + members.emplace_back( + std::make_unique("a", &i32, StructMemberDecorationList())); Struct s{source, StructDecoration::kNone, std::move(members)}; diff --git a/src/ast/switch_statement.cc b/src/ast/switch_statement.cc index 3512187d96..483f3d9d8f 100644 --- a/src/ast/switch_statement.cc +++ b/src/ast/switch_statement.cc @@ -21,15 +21,13 @@ namespace ast { SwitchStatement::SwitchStatement() : Statement() {} -SwitchStatement::SwitchStatement( - std::unique_ptr condition, - std::vector> body) +SwitchStatement::SwitchStatement(std::unique_ptr condition, + CaseStatementList body) : Statement(), condition_(std::move(condition)), body_(std::move(body)) {} -SwitchStatement::SwitchStatement( - const Source& source, - std::unique_ptr condition, - std::vector> body) +SwitchStatement::SwitchStatement(const Source& source, + std::unique_ptr condition, + CaseStatementList body) : Statement(source), condition_(std::move(condition)), body_(std::move(body)) {} diff --git a/src/ast/switch_statement.h b/src/ast/switch_statement.h index 9d13995f84..dceaef7b92 100644 --- a/src/ast/switch_statement.h +++ b/src/ast/switch_statement.h @@ -17,8 +17,8 @@ #include #include -#include +#include "src/ast/case_statement.h" #include "src/ast/expression.h" #include "src/ast/literal.h" #include "src/ast/statement.h" @@ -36,14 +36,14 @@ class SwitchStatement : public Statement { /// @param condition the switch condition /// @param body the switch body SwitchStatement(std::unique_ptr condition, - std::vector> body); + CaseStatementList body); /// Constructor /// @param source the source information /// @param condition the switch condition /// @param body the switch body SwitchStatement(const Source& source, std::unique_ptr condition, - std::vector> body); + CaseStatementList body); /// Move constructor SwitchStatement(SwitchStatement&&) = default; ~SwitchStatement() override; @@ -60,13 +60,9 @@ class SwitchStatement : public Statement { /// Sets the switch body /// @param body the switch body - void set_body(std::vector> body) { - body_ = std::move(body); - } + void set_body(CaseStatementList body) { body_ = std::move(body); } /// @returns the Switch body - const std::vector>& body() const { - return body_; - } + const CaseStatementList& body() const { return body_; } /// @returns true if this is a switch statement bool IsSwitch() const override { return true; } @@ -83,7 +79,7 @@ class SwitchStatement : public Statement { SwitchStatement(const SwitchStatement&) = delete; std::unique_ptr condition_; - std::vector> body_; + CaseStatementList body_; }; } // namespace ast diff --git a/src/ast/switch_statement_test.cc b/src/ast/switch_statement_test.cc index 4bb71f5bff..08ea6f33f6 100644 --- a/src/ast/switch_statement_test.cc +++ b/src/ast/switch_statement_test.cc @@ -32,9 +32,9 @@ TEST_F(SwitchStatementTest, Creation) { ast::type::BoolType bool_type; auto lit = std::make_unique(&bool_type, true); auto ident = std::make_unique("ident"); - std::vector> body; - body.push_back(std::make_unique( - std::move(lit), std::vector>())); + CaseStatementList body; + body.push_back( + std::make_unique(std::move(lit), StatementList())); auto ident_ptr = ident.get(); auto case_ptr = body[0].get(); @@ -48,8 +48,7 @@ TEST_F(SwitchStatementTest, Creation) { TEST_F(SwitchStatementTest, Creation_WithSource) { auto ident = std::make_unique("ident"); - SwitchStatement stmt(Source{20, 2}, std::move(ident), - std::vector>()); + SwitchStatement stmt(Source{20, 2}, std::move(ident), CaseStatementList()); auto src = stmt.source(); EXPECT_EQ(src.line, 20); EXPECT_EQ(src.column, 2); @@ -64,9 +63,9 @@ TEST_F(SwitchStatementTest, IsValid) { ast::type::BoolType bool_type; auto lit = std::make_unique(&bool_type, true); auto ident = std::make_unique("ident"); - std::vector> body; - body.push_back(std::make_unique( - std::move(lit), std::vector>())); + CaseStatementList body; + body.push_back( + std::make_unique(std::move(lit), StatementList())); SwitchStatement stmt(std::move(ident), std::move(body)); EXPECT_TRUE(stmt.IsValid()); @@ -75,9 +74,9 @@ TEST_F(SwitchStatementTest, IsValid) { TEST_F(SwitchStatementTest, IsValid_Null_Condition) { ast::type::BoolType bool_type; auto lit = std::make_unique(&bool_type, true); - std::vector> body; - body.push_back(std::make_unique( - std::move(lit), std::vector>())); + CaseStatementList body; + body.push_back( + std::make_unique(std::move(lit), StatementList())); SwitchStatement stmt; stmt.set_body(std::move(body)); @@ -88,9 +87,9 @@ TEST_F(SwitchStatementTest, IsValid_Invalid_Condition) { ast::type::BoolType bool_type; auto lit = std::make_unique(&bool_type, true); auto ident = std::make_unique(""); - std::vector> body; - body.push_back(std::make_unique( - std::move(lit), std::vector>())); + CaseStatementList body; + body.push_back( + std::make_unique(std::move(lit), StatementList())); SwitchStatement stmt(std::move(ident), std::move(body)); EXPECT_FALSE(stmt.IsValid()); @@ -100,9 +99,9 @@ TEST_F(SwitchStatementTest, IsValid_Null_BodyStatement) { ast::type::BoolType bool_type; auto lit = std::make_unique(&bool_type, true); auto ident = std::make_unique("ident"); - std::vector> body; - body.push_back(std::make_unique( - std::move(lit), std::vector>())); + CaseStatementList body; + body.push_back( + std::make_unique(std::move(lit), StatementList())); body.push_back(nullptr); SwitchStatement stmt(std::move(ident), std::move(body)); @@ -112,10 +111,10 @@ TEST_F(SwitchStatementTest, IsValid_Null_BodyStatement) { TEST_F(SwitchStatementTest, IsValid_Invalid_BodyStatement) { auto ident = std::make_unique("ident"); - std::vector> case_body; + StatementList case_body; case_body.push_back(nullptr); - std::vector> body; + CaseStatementList body; body.push_back( std::make_unique(nullptr, std::move(case_body))); @@ -141,9 +140,9 @@ TEST_F(SwitchStatementTest, ToStr) { ast::type::BoolType bool_type; auto lit = std::make_unique(&bool_type, true); auto ident = std::make_unique("ident"); - std::vector> body; - body.push_back(std::make_unique( - std::move(lit), std::vector>())); + CaseStatementList body; + body.push_back( + std::make_unique(std::move(lit), StatementList())); SwitchStatement stmt(std::move(ident), std::move(body)); std::ostringstream out; diff --git a/src/ast/type_constructor_expression.cc b/src/ast/type_constructor_expression.cc index 4b33bbcb1a..f5559027e3 100644 --- a/src/ast/type_constructor_expression.cc +++ b/src/ast/type_constructor_expression.cc @@ -20,15 +20,13 @@ namespace ast { TypeConstructorExpression::TypeConstructorExpression() : ConstructorExpression() {} -TypeConstructorExpression::TypeConstructorExpression( - type::Type* type, - std::vector> values) +TypeConstructorExpression::TypeConstructorExpression(type::Type* type, + ExpressionList values) : ConstructorExpression(), type_(type), values_(std::move(values)) {} -TypeConstructorExpression::TypeConstructorExpression( - const Source& source, - type::Type* type, - std::vector> values) +TypeConstructorExpression::TypeConstructorExpression(const Source& source, + type::Type* type, + ExpressionList values) : ConstructorExpression(source), type_(type), values_(std::move(values)) {} TypeConstructorExpression::~TypeConstructorExpression() = default; diff --git a/src/ast/type_constructor_expression.h b/src/ast/type_constructor_expression.h index fdc3941994..a6e6abaabd 100644 --- a/src/ast/type_constructor_expression.h +++ b/src/ast/type_constructor_expression.h @@ -17,7 +17,6 @@ #include #include -#include #include "src/ast/constructor_expression.h" #include "src/ast/type/type.h" @@ -32,16 +31,14 @@ class TypeConstructorExpression : public ConstructorExpression { /// Constructor /// @param type the type /// @param values the values - explicit TypeConstructorExpression( - type::Type* type, - std::vector> values); + explicit TypeConstructorExpression(type::Type* type, ExpressionList values); /// Constructor /// @param source the constructor source /// @param type the type /// @param values the constructor values TypeConstructorExpression(const Source& source, type::Type* type, - std::vector> values); + ExpressionList values); /// Move constructor TypeConstructorExpression(TypeConstructorExpression&&) = default; ~TypeConstructorExpression() override; @@ -57,13 +54,9 @@ class TypeConstructorExpression : public ConstructorExpression { /// Set the values /// @param values the values - void set_values(std::vector> values) { - values_ = std::move(values); - } + void set_values(ExpressionList values) { values_ = std::move(values); } /// @returns the values - const std::vector>& values() const { - return values_; - } + const ExpressionList& values() const { return values_; } /// @returns true if the node is valid bool IsValid() const override; @@ -77,7 +70,7 @@ class TypeConstructorExpression : public ConstructorExpression { TypeConstructorExpression(const TypeConstructorExpression&) = delete; type::Type* type_ = nullptr; - std::vector> values_; + ExpressionList values_; }; } // namespace ast diff --git a/src/ast/type_constructor_expression_test.cc b/src/ast/type_constructor_expression_test.cc index 4166995440..ad4e01a7b7 100644 --- a/src/ast/type_constructor_expression_test.cc +++ b/src/ast/type_constructor_expression_test.cc @@ -16,7 +16,6 @@ #include #include -#include #include "gtest/gtest.h" #include "src/ast/constructor_expression.h" @@ -32,7 +31,7 @@ using TypeConstructorExpressionTest = testing::Test; TEST_F(TypeConstructorExpressionTest, Creation) { type::F32Type f32; - std::vector> expr; + ExpressionList expr; expr.push_back(std::make_unique("expr")); auto expr_ptr = expr[0].get(); @@ -44,7 +43,7 @@ TEST_F(TypeConstructorExpressionTest, Creation) { TEST_F(TypeConstructorExpressionTest, Creation_WithSource) { type::F32Type f32; - std::vector> expr; + ExpressionList expr; expr.push_back(std::make_unique("expr")); TypeConstructorExpression t(Source{20, 2}, &f32, std::move(expr)); @@ -60,7 +59,7 @@ TEST_F(TypeConstructorExpressionTest, IsTypeConstructor) { TEST_F(TypeConstructorExpressionTest, IsValid) { type::F32Type f32; - std::vector> expr; + ExpressionList expr; expr.push_back(std::make_unique("expr")); TypeConstructorExpression t(&f32, std::move(expr)); @@ -68,7 +67,7 @@ TEST_F(TypeConstructorExpressionTest, IsValid) { } TEST_F(TypeConstructorExpressionTest, IsValid_NullType) { - std::vector> expr; + ExpressionList expr; expr.push_back(std::make_unique("expr")); TypeConstructorExpression t; @@ -78,7 +77,7 @@ TEST_F(TypeConstructorExpressionTest, IsValid_NullType) { TEST_F(TypeConstructorExpressionTest, IsValid_NullValue) { type::F32Type f32; - std::vector> expr; + ExpressionList expr; expr.push_back(std::make_unique("expr")); expr.push_back(nullptr); @@ -88,7 +87,7 @@ TEST_F(TypeConstructorExpressionTest, IsValid_NullValue) { TEST_F(TypeConstructorExpressionTest, IsValid_InvalidValue) { type::F32Type f32; - std::vector> expr; + ExpressionList expr; expr.push_back(std::make_unique("")); TypeConstructorExpression t(&f32, std::move(expr)); @@ -97,7 +96,7 @@ TEST_F(TypeConstructorExpressionTest, IsValid_InvalidValue) { TEST_F(TypeConstructorExpressionTest, IsValid_EmptyValue) { type::F32Type f32; - std::vector> expr; + ExpressionList expr; TypeConstructorExpression t(&f32, std::move(expr)); EXPECT_FALSE(t.IsValid()); @@ -106,7 +105,7 @@ TEST_F(TypeConstructorExpressionTest, IsValid_EmptyValue) { TEST_F(TypeConstructorExpressionTest, ToStr) { type::F32Type f32; type::VectorType vec(&f32, 3); - std::vector> expr; + ExpressionList expr; expr.push_back(std::make_unique("expr_1")); expr.push_back(std::make_unique("expr_2")); expr.push_back(std::make_unique("expr_3")); diff --git a/src/ast/unary_method_expression.cc b/src/ast/unary_method_expression.cc index 5898fee0d8..9c8a77cb5c 100644 --- a/src/ast/unary_method_expression.cc +++ b/src/ast/unary_method_expression.cc @@ -19,15 +19,13 @@ namespace ast { UnaryMethodExpression::UnaryMethodExpression() : Expression() {} -UnaryMethodExpression::UnaryMethodExpression( - UnaryMethod op, - std::vector> params) +UnaryMethodExpression::UnaryMethodExpression(UnaryMethod op, + ExpressionList params) : Expression(), op_(op), params_(std::move(params)) {} -UnaryMethodExpression::UnaryMethodExpression( - const Source& source, - UnaryMethod op, - std::vector> params) +UnaryMethodExpression::UnaryMethodExpression(const Source& source, + UnaryMethod op, + ExpressionList params) : Expression(source), op_(op), params_(std::move(params)) {} UnaryMethodExpression::~UnaryMethodExpression() = default; diff --git a/src/ast/unary_method_expression.h b/src/ast/unary_method_expression.h index 8e67471128..58c86c5249 100644 --- a/src/ast/unary_method_expression.h +++ b/src/ast/unary_method_expression.h @@ -15,9 +15,7 @@ #ifndef SRC_AST_UNARY_METHOD_EXPRESSION_H_ #define SRC_AST_UNARY_METHOD_EXPRESSION_H_ -#include #include -#include #include "src/ast/expression.h" #include "src/ast/literal.h" @@ -34,15 +32,14 @@ class UnaryMethodExpression : public Expression { /// Constructor /// @param op the op /// @param params the params - UnaryMethodExpression(UnaryMethod op, - std::vector> params); + UnaryMethodExpression(UnaryMethod op, ExpressionList params); /// Constructor /// @param source the unary method source /// @param op the op /// @param params the params UnaryMethodExpression(const Source& source, UnaryMethod op, - std::vector> params); + ExpressionList params); /// Move constructor UnaryMethodExpression(UnaryMethodExpression&&) = default; ~UnaryMethodExpression() override; @@ -55,13 +52,9 @@ class UnaryMethodExpression : public Expression { /// Sets the params /// @param params the parameters - void set_params(std::vector> params) { - params_ = std::move(params); - } + void set_params(ExpressionList params) { params_ = std::move(params); } /// @returns the params - const std::vector>& params() const { - return params_; - } + const ExpressionList& params() const { return params_; } /// @returns true if this is an as expression bool IsUnaryMethod() const override { return true; } @@ -78,7 +71,7 @@ class UnaryMethodExpression : public Expression { UnaryMethodExpression(const UnaryMethodExpression&) = delete; UnaryMethod op_ = UnaryMethod::kAny; - std::vector> params_; + ExpressionList params_; }; } // namespace ast diff --git a/src/ast/unary_method_expression_test.cc b/src/ast/unary_method_expression_test.cc index 2d51e63978..92f265e1b4 100644 --- a/src/ast/unary_method_expression_test.cc +++ b/src/ast/unary_method_expression_test.cc @@ -14,6 +14,7 @@ #include "src/ast/unary_method_expression.h" +#include #include #include "gtest/gtest.h" @@ -26,7 +27,7 @@ namespace { using UnaryMethodExpressionTest = testing::Test; TEST_F(UnaryMethodExpressionTest, Creation) { - std::vector> params; + ExpressionList params; params.push_back(std::make_unique("ident")); auto ident_ptr = params[0].get(); @@ -38,7 +39,7 @@ TEST_F(UnaryMethodExpressionTest, Creation) { } TEST_F(UnaryMethodExpressionTest, Creation_WithSource) { - std::vector> params; + ExpressionList params; params.push_back(std::make_unique("ident")); UnaryMethodExpression u(Source{20, 2}, UnaryMethod::kAll, std::move(params)); @@ -53,7 +54,7 @@ TEST_F(UnaryMethodExpressionTest, IsUnaryMethod) { } TEST_F(UnaryMethodExpressionTest, IsValid) { - std::vector> params; + ExpressionList params; params.push_back(std::make_unique("ident")); UnaryMethodExpression u(UnaryMethod::kAll, std::move(params)); @@ -61,7 +62,7 @@ TEST_F(UnaryMethodExpressionTest, IsValid) { } TEST_F(UnaryMethodExpressionTest, IsValid_NullParam) { - std::vector> params; + ExpressionList params; params.push_back(std::make_unique("ident")); params.push_back(nullptr); @@ -70,7 +71,7 @@ TEST_F(UnaryMethodExpressionTest, IsValid_NullParam) { } TEST_F(UnaryMethodExpressionTest, IsValid_InvalidParam) { - std::vector> params; + ExpressionList params; params.push_back(std::make_unique("")); UnaryMethodExpression u(UnaryMethod::kAll, std::move(params)); @@ -84,7 +85,7 @@ TEST_F(UnaryMethodExpressionTest, IsValid_EmptyParams) { } TEST_F(UnaryMethodExpressionTest, ToStr) { - std::vector> params; + ExpressionList params; params.push_back(std::make_unique("ident")); UnaryMethodExpression u(UnaryMethod::kAll, std::move(params)); diff --git a/src/ast/unless_statement.cc b/src/ast/unless_statement.cc index 10f287df16..051d205d33 100644 --- a/src/ast/unless_statement.cc +++ b/src/ast/unless_statement.cc @@ -20,12 +20,12 @@ namespace ast { UnlessStatement::UnlessStatement() : Statement() {} UnlessStatement::UnlessStatement(std::unique_ptr condition, - std::vector> body) + StatementList body) : Statement(), condition_(std::move(condition)), body_(std::move(body)) {} UnlessStatement::UnlessStatement(const Source& source, std::unique_ptr condition, - std::vector> body) + StatementList body) : Statement(source), condition_(std::move(condition)), body_(std::move(body)) {} diff --git a/src/ast/unless_statement.h b/src/ast/unless_statement.h index 26440b408b..d3a4451225 100644 --- a/src/ast/unless_statement.h +++ b/src/ast/unless_statement.h @@ -17,7 +17,6 @@ #include #include -#include #include "src/ast/expression.h" #include "src/ast/statement.h" @@ -33,15 +32,14 @@ class UnlessStatement : public Statement { /// Constructor /// @param condition the condition expression /// @param body the body statements - UnlessStatement(std::unique_ptr condition, - std::vector> body); + UnlessStatement(std::unique_ptr condition, StatementList body); /// Constructor /// @param source the unless statement source /// @param condition the condition expression /// @param body the body statements UnlessStatement(const Source& source, std::unique_ptr condition, - std::vector> body); + StatementList body); /// Move constructor UnlessStatement(UnlessStatement&&) = default; ~UnlessStatement() override; @@ -56,11 +54,9 @@ class UnlessStatement : public Statement { /// Sets the body statements /// @param body the body statements - void set_body(std::vector> body) { - body_ = std::move(body); - } + void set_body(StatementList body) { body_ = std::move(body); } /// @returns the body statements - const std::vector>& body() const { return body_; } + const StatementList& body() const { return body_; } /// @returns true if this is an unless statement bool IsUnless() const override { return true; } @@ -77,7 +73,7 @@ class UnlessStatement : public Statement { UnlessStatement(const UnlessStatement&) = delete; std::unique_ptr condition_; - std::vector> body_; + StatementList body_; }; } // namespace ast diff --git a/src/ast/unless_statement_test.cc b/src/ast/unless_statement_test.cc index 5cb94433c0..6937f9b9b4 100644 --- a/src/ast/unless_statement_test.cc +++ b/src/ast/unless_statement_test.cc @@ -27,7 +27,7 @@ using UnlessStatementTest = testing::Test; TEST_F(UnlessStatementTest, Creation) { auto ident = std::make_unique("ident"); - std::vector> body; + StatementList body; body.push_back(std::make_unique()); auto ident_ptr = ident.get(); @@ -41,7 +41,7 @@ TEST_F(UnlessStatementTest, Creation) { TEST_F(UnlessStatementTest, Creation_WithSource) { auto ident = std::make_unique("ident"); - std::vector> body; + StatementList body; body.push_back(std::make_unique()); UnlessStatement u(Source{20, 2}, std::move(ident), std::move(body)); @@ -57,7 +57,7 @@ TEST_F(UnlessStatementTest, IsUnless) { TEST_F(UnlessStatementTest, IsValid) { auto ident = std::make_unique("ident"); - std::vector> body; + StatementList body; body.push_back(std::make_unique()); UnlessStatement u(std::move(ident), std::move(body)); @@ -65,7 +65,7 @@ TEST_F(UnlessStatementTest, IsValid) { } TEST_F(UnlessStatementTest, IsValid_NullCondition) { - std::vector> body; + StatementList body; body.push_back(std::make_unique()); UnlessStatement u; @@ -75,7 +75,7 @@ TEST_F(UnlessStatementTest, IsValid_NullCondition) { TEST_F(UnlessStatementTest, IsValid_InvalidCondition) { auto ident = std::make_unique(""); - std::vector> body; + StatementList body; body.push_back(std::make_unique()); UnlessStatement u(std::move(ident), std::move(body)); @@ -84,7 +84,7 @@ TEST_F(UnlessStatementTest, IsValid_InvalidCondition) { TEST_F(UnlessStatementTest, IsValid_NullBodyStatement) { auto ident = std::make_unique("ident"); - std::vector> body; + StatementList body; body.push_back(std::make_unique()); body.push_back(nullptr); @@ -94,7 +94,7 @@ TEST_F(UnlessStatementTest, IsValid_NullBodyStatement) { TEST_F(UnlessStatementTest, IsValid_InvalidBodyStatement) { auto ident = std::make_unique("ident"); - std::vector> body; + StatementList body; body.push_back(std::make_unique()); body.push_back(std::make_unique()); @@ -104,7 +104,7 @@ TEST_F(UnlessStatementTest, IsValid_InvalidBodyStatement) { TEST_F(UnlessStatementTest, ToStr) { auto ident = std::make_unique("ident"); - std::vector> body; + StatementList body; body.push_back(std::make_unique()); UnlessStatement u(std::move(ident), std::move(body)); diff --git a/src/ast/variable.h b/src/ast/variable.h index b97b83b08a..196b3f87dc 100644 --- a/src/ast/variable.h +++ b/src/ast/variable.h @@ -19,6 +19,7 @@ #include #include #include +#include #include "src/ast/expression.h" #include "src/ast/node.h" @@ -170,6 +171,9 @@ class Variable : public Node { std::unique_ptr constructor_; }; +/// A list of unique variables +using VariableList = std::vector>; + } // namespace ast } // namespace tint diff --git a/src/ast/variable_decoration.h b/src/ast/variable_decoration.h index 2e7bd04ecd..a46853337a 100644 --- a/src/ast/variable_decoration.h +++ b/src/ast/variable_decoration.h @@ -15,8 +15,10 @@ #ifndef SRC_AST_VARIABLE_DECORATION_H_ #define SRC_AST_VARIABLE_DECORATION_H_ +#include #include #include +#include namespace tint { namespace ast { @@ -57,6 +59,9 @@ class VariableDecoration { VariableDecoration(); }; +/// A list of unique variable decorations +using VariableDecorationList = std::vector>; + } // namespace ast } // namespace tint diff --git a/src/reader/spirv/parser_impl.cc b/src/reader/spirv/parser_impl.cc index 4b25c611ce..0dc415e3c2 100644 --- a/src/reader/spirv/parser_impl.cc +++ b/src/reader/spirv/parser_impl.cc @@ -549,7 +549,7 @@ ast::type::Type* ParserImpl::ConvertType( } // Compute members - std::vector> ast_members; + ast::StructMemberList ast_members; const auto members = struct_ty->element_types(); for (uint32_t member_index = 0; member_index < members.size(); ++member_index) { @@ -558,8 +558,7 @@ ast::type::Type* ParserImpl::ConvertType( // Already emitted diagnostics. return nullptr; } - std::vector> - ast_member_decorations; + ast::StructMemberDecorationList ast_member_decorations; for (auto& deco : GetDecorationsForMember(type_id, member_index)) { auto ast_member_decoration = ConvertMemberDecoration(deco); if (ast_member_decoration == nullptr) { @@ -710,7 +709,7 @@ std::unique_ptr ParserImpl::MakeVariable(uint32_t id, auto ast_var = std::make_unique(Name(id), sc, type); - std::vector> ast_decorations; + ast::VariableDecorationList ast_decorations; for (auto& deco : GetDecorationsFor(id)) { if (deco.empty()) { Fail() << "malformed decoration on ID " << id << ": it is empty"; @@ -774,7 +773,7 @@ bool ParserImpl::EmitFunction(const spvtools::opt::Function& f) { << f.result_id(); } - std::vector> ast_params; + ast::VariableList ast_params; f.ForEachParam([this, &ast_params](const spvtools::opt::Instruction* param) { auto* ast_type = ConvertType(param->type_id()); if (ast_type != nullptr) { diff --git a/src/reader/wgsl/parser_impl.cc b/src/reader/wgsl/parser_impl.cc index 5916e707cc..dcc72292b4 100644 --- a/src/reader/wgsl/parser_impl.cc +++ b/src/reader/wgsl/parser_impl.cc @@ -15,6 +15,7 @@ #include "src/reader/wgsl/parser_impl.h" #include +#include #include "src/ast/array_accessor_expression.h" #include "src/ast/as_expression.h" @@ -396,9 +397,8 @@ std::unique_ptr ParserImpl::global_constant_decl() { // variable_decoration_list // : ATTR_LEFT variable_decoration (COMMA variable_decoration)* ATTR_RIGHT -std::vector> -ParserImpl::variable_decoration_list() { - std::vector> decos; +ast::VariableDecorationList ParserImpl::variable_decoration_list() { + ast::VariableDecorationList decos; auto t = peek(); if (!t.IsAttrLeft()) @@ -1045,7 +1045,7 @@ ast::StructDecoration ParserImpl::struct_decoration() { // struct_body_decl // : BRACKET_LEFT struct_member* BRACKET_RIGHT -std::vector> ParserImpl::struct_body_decl() { +ast::StructMemberList ParserImpl::struct_body_decl() { auto t = peek(); if (!t.IsBracketLeft()) return {}; @@ -1056,7 +1056,7 @@ std::vector> ParserImpl::struct_body_decl() { if (t.IsBracketRight()) return {}; - std::vector> members; + ast::StructMemberList members; for (;;) { auto mem = struct_member(); if (has_error()) @@ -1116,8 +1116,7 @@ std::unique_ptr ParserImpl::struct_member() { // : // | ATTR_LEFT (struct_member_decoration COMMA)* // struct_member_decoration ATTR_RIGHT -std::vector> -ParserImpl::struct_member_decoration_decl() { +ast::StructMemberDecorationList ParserImpl::struct_member_decoration_decl() { auto t = peek(); if (!t.IsAttrLeft()) return {}; @@ -1130,7 +1129,7 @@ ParserImpl::struct_member_decoration_decl() { return {}; } - std::vector> decos; + ast::StructMemberDecorationList decos; bool found_offset = false; for (;;) { auto deco = struct_member_decoration(); @@ -1266,11 +1265,11 @@ std::unique_ptr ParserImpl::function_header() { // param_list // : // | (variable_ident_decl COMMA)* variable_ident_decl -std::vector> ParserImpl::param_list() { +ast::VariableList ParserImpl::param_list() { auto t = peek(); auto source = t.source(); - std::vector> ret; + ast::VariableList ret; std::string name; ast::type::Type* type; @@ -1380,7 +1379,7 @@ ast::PipelineStage ParserImpl::pipeline_stage() { // body_stmt // : BRACKET_LEFT statements BRACKET_RIGHT -std::vector> ParserImpl::body_stmt() { +ast::StatementList ParserImpl::body_stmt() { auto t = peek(); if (!t.IsBracketLeft()) return {}; @@ -1429,8 +1428,8 @@ std::unique_ptr ParserImpl::paren_rhs_stmt() { // statements // : statement* -std::vector> ParserImpl::statements() { - std::vector> ret; +ast::StatementList ParserImpl::statements() { + ast::StatementList ret; for (;;) { auto stmt = statement(); @@ -1782,12 +1781,12 @@ std::unique_ptr ParserImpl::if_stmt() { // elseif_stmt // : ELSE_IF paren_rhs_stmt body_stmt elseif_stmt? -std::vector> ParserImpl::elseif_stmt() { +ast::ElseStatementList ParserImpl::elseif_stmt() { auto t = peek(); if (!t.IsElseIf()) return {}; - std::vector> ret; + ast::ElseStatementList ret; for (;;) { auto source = t.source(); next(); // Consume the peek @@ -1846,7 +1845,7 @@ std::unique_ptr ParserImpl::else_stmt() { // premerge_stmt // : PREMERGE body_stmt -std::vector> ParserImpl::premerge_stmt() { +ast::StatementList ParserImpl::premerge_stmt() { auto t = peek(); if (!t.IsPremerge()) return {}; @@ -1931,7 +1930,7 @@ std::unique_ptr ParserImpl::switch_stmt() { return nullptr; } - std::vector> body; + ast::CaseStatementList body; for (;;) { auto stmt = switch_body(); if (has_error()) @@ -2006,8 +2005,8 @@ std::unique_ptr ParserImpl::switch_body() { // : // | statement case_body // | FALLTHROUGH SEMICOLON -std::vector> ParserImpl::case_body() { - std::vector> ret; +ast::StatementList ParserImpl::case_body() { + ast::StatementList ret; for (;;) { auto t = peek(); if (t.IsFallthrough()) { @@ -2072,7 +2071,7 @@ std::unique_ptr ParserImpl::loop_stmt() { // continuing_stmt // : CONTINUING body_stmt -std::vector> ParserImpl::continuing_stmt() { +ast::StatementList ParserImpl::continuing_stmt() { auto t = peek(); if (!t.IsContinuing()) return {}; @@ -2148,7 +2147,7 @@ std::unique_ptr ParserImpl::const_expr() { return nullptr; } - std::vector> params; + ast::ExpressionList params; auto param = const_expr(); if (has_error()) return nullptr; @@ -2313,8 +2312,7 @@ std::unique_ptr ParserImpl::primary_expression() { // argument_expression_list // : (logical_or_expression COMMA)* logical_or_expression -std::vector> -ParserImpl::argument_expression_list() { +ast::ExpressionList ParserImpl::argument_expression_list() { auto arg = logical_or_expression(); if (has_error()) return {}; @@ -2323,7 +2321,7 @@ ParserImpl::argument_expression_list() { return {}; } - std::vector> ret; + ast::ExpressionList ret; ret.push_back(std::move(arg)); for (;;) { @@ -2379,7 +2377,7 @@ std::unique_ptr ParserImpl::postfix_expr( next(); // Consume the peek t = peek(); - std::vector> params; + ast::ExpressionList params; if (!t.IsParenRight() && !t.IsEof()) { params = argument_expression_list(); if (has_error()) @@ -2501,7 +2499,7 @@ std::unique_ptr ParserImpl::unary_expression() { set_error(t, "missing identifier for method call"); return nullptr; } - std::vector> ident; + ast::ExpressionList ident; ident.push_back( std::make_unique(source, t.to_str())); @@ -2531,7 +2529,7 @@ std::unique_ptr ParserImpl::unary_expression() { set_error(t, "missing identifier for method call"); return nullptr; } - std::vector> ident; + ast::ExpressionList ident; ident.push_back( std::make_unique(source, t.to_str())); diff --git a/src/reader/wgsl/parser_impl.h b/src/reader/wgsl/parser_impl.h index ad39e3d5b7..6027d1ebe1 100644 --- a/src/reader/wgsl/parser_impl.h +++ b/src/reader/wgsl/parser_impl.h @@ -20,12 +20,12 @@ #include #include #include -#include #include "src/ast/assignment_statement.h" #include "src/ast/builtin.h" #include "src/ast/constructor_expression.h" #include "src/ast/derivative_modifier.h" +#include "src/ast/else_statement.h" #include "src/ast/entry_point.h" #include "src/ast/function.h" #include "src/ast/import.h" @@ -113,9 +113,8 @@ class ParserImpl { /// @returns the const object or nullptr std::unique_ptr global_constant_decl(); /// Parses a `variable_decoration_list` grammar element - /// @returns a vector of parsed variable decorations - std::vector> - variable_decoration_list(); + /// @returns the parsed variable decorations + ast::VariableDecorationList variable_decoration_list(); /// Parses a `variable_decoration` grammar element /// @returns the variable decoration or nullptr if an error is encountered std::unique_ptr variable_decoration(); @@ -152,14 +151,13 @@ class ParserImpl { ast::StructDecoration struct_decoration(); /// Parses a `struct_body_decl` grammar element /// @returns the struct members - std::vector> struct_body_decl(); + ast::StructMemberList struct_body_decl(); /// Parses a `struct_member` grammar element /// @returns the struct member or nullptr std::unique_ptr struct_member(); /// Parses a `struct_member_decoration_decl` grammar element /// @returns the list of decorations - std::vector> - struct_member_decoration_decl(); + ast::StructMemberDecorationList struct_member_decoration_decl(); /// Parses a `struct_member_decoration` grammar element /// @returns the decoration or nullptr if none found std::unique_ptr struct_member_decoration(); @@ -174,7 +172,7 @@ class ParserImpl { std::unique_ptr function_header(); /// Parses a `param_list` grammar element /// @returns the parsed variables - std::vector> param_list(); + ast::VariableList param_list(); /// Parses a `entry_point_decl` grammar element /// @returns the EntryPoint or nullptr on error std::unique_ptr entry_point_decl(); @@ -183,13 +181,13 @@ class ParserImpl { ast::PipelineStage pipeline_stage(); /// Parses a `body_stmt` grammar element /// @returns the parsed statements - std::vector> body_stmt(); + ast::StatementList body_stmt(); /// Parses a `paren_rhs_stmt` grammar element /// @returns the parsed element or nullptr std::unique_ptr paren_rhs_stmt(); /// Parses a `statements` grammar element /// @returns the statements parsed - std::vector> statements(); + ast::StatementList statements(); /// Parses a `statement` grammar element /// @returns the parsed statement or nullptr std::unique_ptr statement(); @@ -207,13 +205,13 @@ class ParserImpl { std::unique_ptr if_stmt(); /// Parses a `elseif_stmt` grammar element /// @returns the parsed elements - std::vector> elseif_stmt(); + ast::ElseStatementList elseif_stmt(); /// Parses a `else_stmt` grammar element /// @returns the parsed statement or nullptr std::unique_ptr else_stmt(); /// Parses a `premerge_stmt` grammar element /// @returns the parsed statements - std::vector> premerge_stmt(); + ast::StatementList premerge_stmt(); /// Parses a `unless_stmt` grammar element /// @returns the parsed element or nullptr std::unique_ptr unless_stmt(); @@ -228,13 +226,13 @@ class ParserImpl { std::unique_ptr switch_body(); /// Parses a `case_body` grammar element /// @returns the parsed statements - std::vector> case_body(); + ast::StatementList case_body(); /// Parses a `loop_stmt` grammar element /// @returns the parsed loop or nullptr std::unique_ptr loop_stmt(); /// Parses a `continuing_stmt` grammar element /// @returns the parsed statements - std::vector> continuing_stmt(); + ast::StatementList continuing_stmt(); /// Parses a `const_literal` grammar element /// @returns the const literal parsed or nullptr if none found std::unique_ptr const_literal(); @@ -246,7 +244,7 @@ class ParserImpl { std::unique_ptr primary_expression(); /// Parses a `argument_expression_list` grammar element /// @returns the list of arguments - std::vector> argument_expression_list(); + ast::ExpressionList argument_expression_list(); /// Parses the recursive portion of the postfix_expression /// @param prefix the left side of the expression /// @returns the parsed expression or nullptr diff --git a/src/writer/spirv/builder_constructor_expression_test.cc b/src/writer/spirv/builder_constructor_expression_test.cc index 7a5fa2f668..8e8d86e3b8 100644 --- a/src/writer/spirv/builder_constructor_expression_test.cc +++ b/src/writer/spirv/builder_constructor_expression_test.cc @@ -51,7 +51,7 @@ TEST_F(BuilderTest, Constructor_Type) { ast::type::F32Type f32; ast::type::VectorType vec(&f32, 3); - std::vector> vals; + ast::ExpressionList vals; vals.push_back(std::make_unique( std::make_unique(&f32, 1.0f))); vals.push_back(std::make_unique( @@ -77,7 +77,7 @@ TEST_F(BuilderTest, Constructor_Type_Dedups) { ast::type::F32Type f32; ast::type::VectorType vec(&f32, 3); - std::vector> vals; + ast::ExpressionList vals; vals.push_back(std::make_unique( std::make_unique(&f32, 1.0f))); vals.push_back(std::make_unique( @@ -103,7 +103,7 @@ TEST_F(BuilderTest, Constructor_NonConst_Type_Fails) { std::make_unique( std::make_unique(&f32, 3.0f))); - std::vector> vals; + ast::ExpressionList vals; vals.push_back(std::make_unique( std::make_unique(&f32, 1.0f))); vals.push_back(std::move(rel)); diff --git a/src/writer/spirv/builder_function_variable_test.cc b/src/writer/spirv/builder_function_variable_test.cc index e97f0efe66..108d5858cd 100644 --- a/src/writer/spirv/builder_function_variable_test.cc +++ b/src/writer/spirv/builder_function_variable_test.cc @@ -62,7 +62,7 @@ TEST_F(BuilderTest, FunctionVar_WithConstantConstructor) { ast::type::F32Type f32; ast::type::VectorType vec(&f32, 3); - std::vector> vals; + ast::ExpressionList vals; vals.push_back(std::make_unique( std::make_unique(&f32, 1.0f))); vals.push_back(std::make_unique( @@ -109,7 +109,7 @@ TEST_F(BuilderTest, DISABLED_FunctionVar_WithNonConstantConstructor) { std::make_unique( std::make_unique(&f32, 3.0f))); - std::vector> vals; + ast::ExpressionList vals; vals.push_back(std::make_unique( std::make_unique(&f32, 1.0f))); vals.push_back(std::move(rel)); @@ -147,7 +147,7 @@ TEST_F(BuilderTest, FunctionVar_Const) { ast::type::F32Type f32; ast::type::VectorType vec(&f32, 3); - std::vector> vals; + ast::ExpressionList vals; vals.push_back(std::make_unique( std::make_unique(&f32, 1.0f))); vals.push_back(std::make_unique( diff --git a/src/writer/spirv/builder_global_variable_test.cc b/src/writer/spirv/builder_global_variable_test.cc index 09fed56b42..45919250a8 100644 --- a/src/writer/spirv/builder_global_variable_test.cc +++ b/src/writer/spirv/builder_global_variable_test.cc @@ -71,7 +71,7 @@ TEST_F(BuilderTest, GlobalVar_WithConstructor) { ast::type::F32Type f32; ast::type::VectorType vec(&f32, 3); - std::vector> vals; + ast::ExpressionList vals; vals.push_back(std::make_unique( std::make_unique(&f32, 1.0f))); vals.push_back(std::make_unique( @@ -105,7 +105,7 @@ TEST_F(BuilderTest, GlobalVar_Const) { ast::type::F32Type f32; ast::type::VectorType vec(&f32, 3); - std::vector> vals; + ast::ExpressionList vals; vals.push_back(std::make_unique( std::make_unique(&f32, 1.0f))); vals.push_back(std::make_unique( @@ -136,7 +136,7 @@ TEST_F(BuilderTest, GlobalVar_WithLocation) { ast::type::F32Type f32; auto v = std::make_unique("var", ast::StorageClass::kOutput, &f32); - std::vector> decos; + ast::VariableDecorationList decos; decos.push_back(std::make_unique(5)); ast::DecoratedVariable dv(std::move(v)); @@ -157,7 +157,7 @@ TEST_F(BuilderTest, GlobalVar_WithBindingAndSet) { ast::type::F32Type f32; auto v = std::make_unique("var", ast::StorageClass::kOutput, &f32); - std::vector> decos; + ast::VariableDecorationList decos; decos.push_back(std::make_unique(2)); decos.push_back(std::make_unique(3)); @@ -180,7 +180,7 @@ TEST_F(BuilderTest, GlobalVar_WithBuiltin) { ast::type::F32Type f32; auto v = std::make_unique("var", ast::StorageClass::kOutput, &f32); - std::vector> decos; + ast::VariableDecorationList decos; decos.push_back( std::make_unique(ast::Builtin::kPosition)); diff --git a/src/writer/spirv/builder_ident_expression_test.cc b/src/writer/spirv/builder_ident_expression_test.cc index 0983c72da6..235c9e209f 100644 --- a/src/writer/spirv/builder_ident_expression_test.cc +++ b/src/writer/spirv/builder_ident_expression_test.cc @@ -36,7 +36,7 @@ TEST_F(BuilderTest, IdentifierExpression_GlobalConst) { ast::type::F32Type f32; ast::type::VectorType vec(&f32, 3); - std::vector> vals; + ast::ExpressionList vals; vals.push_back(std::make_unique( std::make_unique(&f32, 1.0f))); vals.push_back(std::make_unique( @@ -87,7 +87,7 @@ TEST_F(BuilderTest, IdentifierExpression_FunctionConst) { ast::type::F32Type f32; ast::type::VectorType vec(&f32, 3); - std::vector> vals; + ast::ExpressionList vals; vals.push_back(std::make_unique( std::make_unique(&f32, 1.0f))); vals.push_back(std::make_unique( diff --git a/src/writer/spirv/builder_return_test.cc b/src/writer/spirv/builder_return_test.cc index 2792876f89..91c0f56e2f 100644 --- a/src/writer/spirv/builder_return_test.cc +++ b/src/writer/spirv/builder_return_test.cc @@ -47,7 +47,7 @@ TEST_F(BuilderTest, Return_WithValue) { ast::type::F32Type f32; ast::type::VectorType vec(&f32, 3); - std::vector> vals; + ast::ExpressionList vals; vals.push_back(std::make_unique( std::make_unique(&f32, 1.0f))); vals.push_back(std::make_unique( diff --git a/src/writer/spirv/builder_type_test.cc b/src/writer/spirv/builder_type_test.cc index 064ce920ab..765c24b575 100644 --- a/src/writer/spirv/builder_type_test.cc +++ b/src/writer/spirv/builder_type_test.cc @@ -277,8 +277,8 @@ TEST_F(BuilderTest_Type, GenerateStruct_Empty) { TEST_F(BuilderTest_Type, GenerateStruct) { ast::type::F32Type f32; - std::vector> decos; - std::vector> members; + ast::StructMemberDecorationList decos; + ast::StructMemberList members; members.push_back( std::make_unique("a", &f32, std::move(decos))); @@ -303,8 +303,8 @@ OpMemberName %1 0 "a" TEST_F(BuilderTest_Type, GenerateStruct_Decorated) { ast::type::F32Type f32; - std::vector> decos; - std::vector> members; + ast::StructMemberDecorationList decos; + ast::StructMemberList members; members.push_back( std::make_unique("a", &f32, std::move(decos))); @@ -331,12 +331,12 @@ OpMemberName %1 0 "a" TEST_F(BuilderTest_Type, GenerateStruct_DecoratedMembers) { ast::type::F32Type f32; - std::vector> a_decos; + ast::StructMemberDecorationList a_decos; a_decos.push_back(std::make_unique(0)); - std::vector> b_decos; + ast::StructMemberDecorationList b_decos; b_decos.push_back(std::make_unique(8)); - std::vector> members; + ast::StructMemberList members; members.push_back( std::make_unique("a", &f32, std::move(a_decos))); members.push_back( diff --git a/src/writer/wgsl/generator_impl.cc b/src/writer/wgsl/generator_impl.cc index edc12bb16f..f16a358777 100644 --- a/src/writer/wgsl/generator_impl.cc +++ b/src/writer/wgsl/generator_impl.cc @@ -690,8 +690,7 @@ bool GeneratorImpl::EmitUnaryOp(ast::UnaryOpExpression* expr) { return true; } -bool GeneratorImpl::EmitStatementBlock( - const std::vector>& statements) { +bool GeneratorImpl::EmitStatementBlock(const ast::StatementList& statements) { out_ << " {" << std::endl; increment_indent(); @@ -710,7 +709,7 @@ bool GeneratorImpl::EmitStatementBlock( } bool GeneratorImpl::EmitStatementBlockAndNewline( - const std::vector>& statements) { + const ast::StatementList& statements) { const bool result = EmitStatementBlock(statements); if (result) { out_ << std::endl; diff --git a/src/writer/wgsl/generator_impl.h b/src/writer/wgsl/generator_impl.h index d8b26b3ada..dca64ad6bc 100644 --- a/src/writer/wgsl/generator_impl.h +++ b/src/writer/wgsl/generator_impl.h @@ -15,10 +15,8 @@ #ifndef SRC_WRITER_WGSL_GENERATOR_IMPL_H_ #define SRC_WRITER_WGSL_GENERATOR_IMPL_H_ -#include #include #include -#include #include "src/ast/array_accessor_expression.h" #include "src/ast/constructor_expression.h" @@ -179,13 +177,11 @@ class GeneratorImpl { /// Handles a brace-enclosed list of statements. /// @param statements the statements to output /// @returns true if the statements were emitted - bool EmitStatementBlock( - const std::vector>& statements); + bool EmitStatementBlock(const ast::StatementList& statements); /// Handles a brace-enclosed list of statements and trailing newline. /// @param statements the statements to output /// @returns true if the statements were emitted - bool EmitStatementBlockAndNewline( - const std::vector>& statements); + bool EmitStatementBlockAndNewline(const ast::StatementList& statements); /// Handles statement /// @param stmt the statement to emit /// @returns true if the statement was emitted diff --git a/src/writer/wgsl/generator_impl_alias_type_test.cc b/src/writer/wgsl/generator_impl_alias_type_test.cc index ef4d6f31cc..70891dca33 100644 --- a/src/writer/wgsl/generator_impl_alias_type_test.cc +++ b/src/writer/wgsl/generator_impl_alias_type_test.cc @@ -43,11 +43,11 @@ TEST_F(GeneratorImplTest, EmitAliasType_Struct) { ast::type::I32Type i32; ast::type::F32Type f32; - std::vector> members; + ast::StructMemberList members; members.push_back(std::make_unique( - "a", &f32, std::vector>{})); + "a", &f32, ast::StructMemberDecorationList{})); - std::vector> b_deco; + ast::StructMemberDecorationList b_deco; b_deco.push_back(std::make_unique(4)); members.push_back( std::make_unique("b", &i32, std::move(b_deco))); diff --git a/src/writer/wgsl/generator_impl_call_test.cc b/src/writer/wgsl/generator_impl_call_test.cc index 639c23122e..25f0083c68 100644 --- a/src/writer/wgsl/generator_impl_call_test.cc +++ b/src/writer/wgsl/generator_impl_call_test.cc @@ -37,7 +37,7 @@ TEST_F(GeneratorImplTest, EmitExpression_Call_WithoutParams) { TEST_F(GeneratorImplTest, EmitExpression_Call_WithParams) { auto id = std::make_unique("my_func"); - std::vector> params; + ast::ExpressionList params; params.push_back(std::make_unique("param1")); params.push_back(std::make_unique("param2")); ast::CallExpression call(std::move(id), std::move(params)); diff --git a/src/writer/wgsl/generator_impl_case_test.cc b/src/writer/wgsl/generator_impl_case_test.cc index d23c7853db..d1c3fd197d 100644 --- a/src/writer/wgsl/generator_impl_case_test.cc +++ b/src/writer/wgsl/generator_impl_case_test.cc @@ -13,7 +13,6 @@ // limitations under the License. #include -#include #include "gtest/gtest.h" #include "src/ast/break_statement.h" @@ -34,7 +33,7 @@ TEST_F(GeneratorImplTest, Emit_Case) { ast::type::I32Type i32; auto cond = std::make_unique(&i32, 5); - std::vector> body; + ast::StatementList body; body.push_back(std::make_unique()); ast::CaseStatement c(std::move(cond), std::move(body)); @@ -52,7 +51,7 @@ TEST_F(GeneratorImplTest, Emit_Case) { TEST_F(GeneratorImplTest, Emit_Case_Default) { ast::CaseStatement c; - std::vector> body; + ast::StatementList body; body.push_back(std::make_unique()); c.set_body(std::move(body)); diff --git a/src/writer/wgsl/generator_impl_constructor_test.cc b/src/writer/wgsl/generator_impl_constructor_test.cc index 4b3cd9a7f6..44b65d2087 100644 --- a/src/writer/wgsl/generator_impl_constructor_test.cc +++ b/src/writer/wgsl/generator_impl_constructor_test.cc @@ -12,9 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include -#include - #include "gtest/gtest.h" #include "src/ast/bool_literal.h" #include "src/ast/float_literal.h" @@ -81,7 +78,7 @@ TEST_F(GeneratorImplTest, EmitConstructor_Type_Float) { ast::type::F32Type f32; auto lit = std::make_unique(&f32, -1.2e-5); - std::vector> values; + ast::ExpressionList values; values.push_back( std::make_unique(std::move(lit))); @@ -96,7 +93,7 @@ TEST_F(GeneratorImplTest, EmitConstructor_Type_Bool) { ast::type::BoolType b; auto lit = std::make_unique(&b, true); - std::vector> values; + ast::ExpressionList values; values.push_back( std::make_unique(std::move(lit))); @@ -111,7 +108,7 @@ TEST_F(GeneratorImplTest, EmitConstructor_Type_Int) { ast::type::I32Type i32; auto lit = std::make_unique(&i32, -12345); - std::vector> values; + ast::ExpressionList values; values.push_back( std::make_unique(std::move(lit))); @@ -126,7 +123,7 @@ TEST_F(GeneratorImplTest, EmitConstructor_Type_Uint) { ast::type::U32Type u32; auto lit = std::make_unique(&u32, 12345); - std::vector> values; + ast::ExpressionList values; values.push_back( std::make_unique(std::move(lit))); @@ -144,7 +141,7 @@ TEST_F(GeneratorImplTest, EmitConstructor_Type_Vec) { auto lit1 = std::make_unique(&f32, 1.f); auto lit2 = std::make_unique(&f32, 2.f); auto lit3 = std::make_unique(&f32, 3.f); - std::vector> values; + ast::ExpressionList values; values.push_back( std::make_unique(std::move(lit1))); values.push_back( @@ -165,13 +162,13 @@ TEST_F(GeneratorImplTest, EmitConstructor_Type_Mat) { ast::type::VectorType vec(&f32, 2); - std::vector> mat_values; + ast::ExpressionList mat_values; for (size_t i = 0; i < 3; i++) { auto lit1 = std::make_unique(&f32, 1.f + (i * 2)); auto lit2 = std::make_unique(&f32, 2.f + (i * 2)); - std::vector> values; + ast::ExpressionList values; values.push_back( std::make_unique(std::move(lit1))); values.push_back( @@ -196,14 +193,14 @@ TEST_F(GeneratorImplTest, EmitConstructor_Type_Array) { ast::type::VectorType vec(&f32, 3); ast::type::ArrayType ary(&vec, 3); - std::vector> ary_values; + ast::ExpressionList ary_values; for (size_t i = 0; i < 3; i++) { auto lit1 = std::make_unique(&f32, 1.f + (i * 3)); auto lit2 = std::make_unique(&f32, 2.f + (i * 3)); auto lit3 = std::make_unique(&f32, 3.f + (i * 3)); - std::vector> values; + ast::ExpressionList values; values.push_back( std::make_unique(std::move(lit1))); values.push_back( diff --git a/src/writer/wgsl/generator_impl_else_test.cc b/src/writer/wgsl/generator_impl_else_test.cc index 561babf9ac..52fc4a0b9d 100644 --- a/src/writer/wgsl/generator_impl_else_test.cc +++ b/src/writer/wgsl/generator_impl_else_test.cc @@ -13,7 +13,6 @@ // limitations under the License. #include -#include #include "gtest/gtest.h" #include "src/ast/else_statement.h" @@ -29,7 +28,7 @@ namespace { using GeneratorImplTest = testing::Test; TEST_F(GeneratorImplTest, Emit_Else) { - std::vector> body; + ast::StatementList body; body.push_back(std::make_unique()); ast::ElseStatement e(std::move(body)); @@ -46,7 +45,7 @@ TEST_F(GeneratorImplTest, Emit_Else) { TEST_F(GeneratorImplTest, Emit_ElseWithCondition) { auto cond = std::make_unique("cond"); - std::vector> body; + ast::StatementList body; body.push_back(std::make_unique()); ast::ElseStatement e(std::move(cond), std::move(body)); diff --git a/src/writer/wgsl/generator_impl_function_test.cc b/src/writer/wgsl/generator_impl_function_test.cc index 53fa44c21e..274f789aa1 100644 --- a/src/writer/wgsl/generator_impl_function_test.cc +++ b/src/writer/wgsl/generator_impl_function_test.cc @@ -30,7 +30,7 @@ namespace { using GeneratorImplTest = testing::Test; TEST_F(GeneratorImplTest, Emit_Function) { - std::vector> body; + ast::StatementList body; body.push_back(std::make_unique()); body.push_back(std::make_unique()); @@ -50,13 +50,13 @@ TEST_F(GeneratorImplTest, Emit_Function) { } TEST_F(GeneratorImplTest, Emit_Function_WithParams) { - std::vector> body; + ast::StatementList body; body.push_back(std::make_unique()); body.push_back(std::make_unique()); ast::type::F32Type f32; ast::type::I32Type i32; - std::vector> params; + ast::VariableList params; params.push_back( std::make_unique("a", ast::StorageClass::kNone, &f32)); params.push_back( diff --git a/src/writer/wgsl/generator_impl_if_test.cc b/src/writer/wgsl/generator_impl_if_test.cc index 274c7c0d64..99609ecc39 100644 --- a/src/writer/wgsl/generator_impl_if_test.cc +++ b/src/writer/wgsl/generator_impl_if_test.cc @@ -12,9 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include -#include - #include "gtest/gtest.h" #include "src/ast/else_statement.h" #include "src/ast/identifier_expression.h" @@ -31,7 +28,7 @@ using GeneratorImplTest = testing::Test; TEST_F(GeneratorImplTest, Emit_If) { auto cond = std::make_unique("cond"); - std::vector> body; + ast::StatementList body; body.push_back(std::make_unique()); ast::IfStatement i(std::move(cond), std::move(body)); @@ -49,15 +46,15 @@ TEST_F(GeneratorImplTest, Emit_If) { TEST_F(GeneratorImplTest, Emit_IfWithElseIf) { auto else_cond = std::make_unique("else_cond"); - std::vector> else_body; + ast::StatementList else_body; else_body.push_back(std::make_unique()); - std::vector> elses; + ast::ElseStatementList elses; elses.push_back(std::make_unique(std::move(else_cond), std::move(else_body))); auto cond = std::make_unique("cond"); - std::vector> body; + ast::StatementList body; body.push_back(std::make_unique()); ast::IfStatement i(std::move(cond), std::move(body)); @@ -76,14 +73,14 @@ TEST_F(GeneratorImplTest, Emit_IfWithElseIf) { } TEST_F(GeneratorImplTest, Emit_IfWithElse) { - std::vector> else_body; + ast::StatementList else_body; else_body.push_back(std::make_unique()); - std::vector> elses; + ast::ElseStatementList elses; elses.push_back(std::make_unique(std::move(else_body))); auto cond = std::make_unique("cond"); - std::vector> body; + ast::StatementList body; body.push_back(std::make_unique()); ast::IfStatement i(std::move(cond), std::move(body)); @@ -104,19 +101,19 @@ TEST_F(GeneratorImplTest, Emit_IfWithElse) { TEST_F(GeneratorImplTest, Emit_IfWithMultiple) { auto else_cond = std::make_unique("else_cond"); - std::vector> else_body; + ast::StatementList else_body; else_body.push_back(std::make_unique()); - std::vector> else_body_2; + ast::StatementList else_body_2; else_body_2.push_back(std::make_unique()); - std::vector> elses; + ast::ElseStatementList elses; elses.push_back(std::make_unique(std::move(else_cond), std::move(else_body))); elses.push_back(std::make_unique(std::move(else_body_2))); auto cond = std::make_unique("cond"); - std::vector> body; + ast::StatementList body; body.push_back(std::make_unique()); ast::IfStatement i(std::move(cond), std::move(body)); diff --git a/src/writer/wgsl/generator_impl_loop_test.cc b/src/writer/wgsl/generator_impl_loop_test.cc index beb2a5ccd3..4ddc0dae95 100644 --- a/src/writer/wgsl/generator_impl_loop_test.cc +++ b/src/writer/wgsl/generator_impl_loop_test.cc @@ -13,7 +13,6 @@ // limitations under the License. #include -#include #include "gtest/gtest.h" #include "src/ast/kill_statement.h" @@ -29,7 +28,7 @@ namespace { using GeneratorImplTest = testing::Test; TEST_F(GeneratorImplTest, Emit_Loop) { - std::vector> body; + ast::StatementList body; body.push_back(std::make_unique()); ast::LoopStatement l(std::move(body), {}); @@ -45,10 +44,10 @@ TEST_F(GeneratorImplTest, Emit_Loop) { } TEST_F(GeneratorImplTest, Emit_LoopWithContinuing) { - std::vector> body; + ast::StatementList body; body.push_back(std::make_unique()); - std::vector> continuing; + ast::StatementList continuing; continuing.push_back(std::make_unique()); ast::LoopStatement l(std::move(body), std::move(continuing)); diff --git a/src/writer/wgsl/generator_impl_regardless_test.cc b/src/writer/wgsl/generator_impl_regardless_test.cc index 4561921913..3a62297bcc 100644 --- a/src/writer/wgsl/generator_impl_regardless_test.cc +++ b/src/writer/wgsl/generator_impl_regardless_test.cc @@ -13,7 +13,6 @@ // limitations under the License. #include -#include #include "gtest/gtest.h" #include "src/ast/identifier_expression.h" @@ -32,7 +31,7 @@ using GeneratorImplTest = testing::Test; TEST_F(GeneratorImplTest, Emit_Regardless) { auto cond = std::make_unique("cond"); - std::vector> body; + ast::StatementList body; body.push_back(std::make_unique()); body.push_back(std::make_unique()); diff --git a/src/writer/wgsl/generator_impl_switch_test.cc b/src/writer/wgsl/generator_impl_switch_test.cc index af82f6d0be..b784f21aef 100644 --- a/src/writer/wgsl/generator_impl_switch_test.cc +++ b/src/writer/wgsl/generator_impl_switch_test.cc @@ -13,7 +13,6 @@ // limitations under the License. #include -#include #include "gtest/gtest.h" #include "src/ast/break_statement.h" @@ -33,19 +32,19 @@ using GeneratorImplTest = testing::Test; TEST_F(GeneratorImplTest, Emit_Switch) { auto def = std::make_unique(); - std::vector> def_body; + ast::StatementList def_body; def_body.push_back(std::make_unique()); def->set_body(std::move(def_body)); ast::type::I32Type i32; auto case_val = std::make_unique(&i32, 5); - std::vector> case_body; + ast::StatementList case_body; case_body.push_back(std::make_unique()); auto case_stmt = std::make_unique(std::move(case_val), std::move(case_body)); - std::vector> body; + ast::CaseStatementList body; body.push_back(std::move(case_stmt)); body.push_back(std::move(def)); diff --git a/src/writer/wgsl/generator_impl_type_test.cc b/src/writer/wgsl/generator_impl_type_test.cc index 86e2489a75..b9705b88fd 100644 --- a/src/writer/wgsl/generator_impl_type_test.cc +++ b/src/writer/wgsl/generator_impl_type_test.cc @@ -110,11 +110,11 @@ TEST_F(GeneratorImplTest, EmitType_Struct) { ast::type::I32Type i32; ast::type::F32Type f32; - std::vector> members; + ast::StructMemberList members; members.push_back(std::make_unique( - "a", &i32, std::vector>{})); + "a", &i32, ast::StructMemberDecorationList{})); - std::vector> b_deco; + ast::StructMemberDecorationList b_deco; b_deco.push_back(std::make_unique(4)); members.push_back( std::make_unique("b", &f32, std::move(b_deco))); @@ -136,11 +136,11 @@ TEST_F(GeneratorImplTest, EmitType_Struct_WithDecoration) { ast::type::I32Type i32; ast::type::F32Type f32; - std::vector> members; + ast::StructMemberList members; members.push_back(std::make_unique( - "a", &i32, std::vector>{})); + "a", &i32, ast::StructMemberDecorationList{})); - std::vector> b_deco; + ast::StructMemberDecorationList b_deco; b_deco.push_back(std::make_unique(4)); members.push_back( std::make_unique("b", &f32, std::move(b_deco))); diff --git a/src/writer/wgsl/generator_impl_unary_method_test.cc b/src/writer/wgsl/generator_impl_unary_method_test.cc index 32455bfc91..83eff87594 100644 --- a/src/writer/wgsl/generator_impl_unary_method_test.cc +++ b/src/writer/wgsl/generator_impl_unary_method_test.cc @@ -13,7 +13,6 @@ // limitations under the License. #include -#include #include "gtest/gtest.h" #include "src/ast/identifier_expression.h" @@ -38,7 +37,7 @@ TEST_P(UnaryMethodTest, Emit) { auto params = GetParam(); auto expr = std::make_unique("expr"); - std::vector> ops; + ast::ExpressionList ops; ops.push_back(std::move(expr)); ast::UnaryMethodExpression method(params.method, std::move(ops)); @@ -62,7 +61,7 @@ TEST_P(UnaryMethodTest_MultiParam, Emit) { auto expr1 = std::make_unique("expr1"); auto expr2 = std::make_unique("expr2"); - std::vector> ops; + ast::ExpressionList ops; ops.push_back(std::move(expr1)); ops.push_back(std::move(expr2)); diff --git a/src/writer/wgsl/generator_impl_unless_test.cc b/src/writer/wgsl/generator_impl_unless_test.cc index 47c206bb76..721f877c0f 100644 --- a/src/writer/wgsl/generator_impl_unless_test.cc +++ b/src/writer/wgsl/generator_impl_unless_test.cc @@ -13,7 +13,6 @@ // limitations under the License. #include -#include #include "gtest/gtest.h" #include "src/ast/identifier_expression.h" @@ -32,7 +31,7 @@ using GeneratorImplTest = testing::Test; TEST_F(GeneratorImplTest, Emit_Unless) { auto cond = std::make_unique("cond"); - std::vector> body; + ast::StatementList body; body.push_back(std::make_unique()); body.push_back(std::make_unique()); diff --git a/src/writer/wgsl/generator_impl_variable_test.cc b/src/writer/wgsl/generator_impl_variable_test.cc index dce656aa63..8d2d2bb334 100644 --- a/src/writer/wgsl/generator_impl_variable_test.cc +++ b/src/writer/wgsl/generator_impl_variable_test.cc @@ -13,7 +13,6 @@ // limitations under the License. #include -#include #include "gtest/gtest.h" #include "src/ast/binding_decoration.h" @@ -55,7 +54,7 @@ TEST_F(GeneratorImplTest, EmitVariable_StorageClass) { TEST_F(GeneratorImplTest, EmitVariable_Decorated) { ast::type::F32Type f32; - std::vector> decos; + ast::VariableDecorationList decos; decos.push_back(std::make_unique(2)); ast::DecoratedVariable dv; @@ -72,7 +71,7 @@ TEST_F(GeneratorImplTest, EmitVariable_Decorated) { TEST_F(GeneratorImplTest, EmitVariable_Decorated_Multiple) { ast::type::F32Type f32; - std::vector> decos; + ast::VariableDecorationList decos; decos.push_back( std::make_unique(ast::Builtin::kPosition)); decos.push_back(std::make_unique(0));