Add list helpers

This CL adds various using statements for the

std::vector<std::unique_ptr<CLASS>> constructs found in the AST.
Change-Id: Ic9a2357cd73b2aafd99e961a38727f2f9874cde5
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/18920
Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
dan sinclair 2020-04-06 19:37:37 +00:00 committed by dan sinclair
parent a71e1a50c8
commit 3ffec80c63
79 changed files with 476 additions and 556 deletions

View File

@ -17,7 +17,6 @@
#include <memory>
#include <utility>
#include <vector>
#include "src/ast/expression.h"
#include "src/ast/literal.h"

View File

@ -20,12 +20,12 @@ namespace ast {
CallExpression::CallExpression() : Expression() {}
CallExpression::CallExpression(std::unique_ptr<Expression> func,
std::vector<std::unique_ptr<Expression>> params)
ExpressionList params)
: Expression(), func_(std::move(func)), params_(std::move(params)) {}
CallExpression::CallExpression(const Source& source,
std::unique_ptr<Expression> func,
std::vector<std::unique_ptr<Expression>> params)
ExpressionList params)
: Expression(source), func_(std::move(func)), params_(std::move(params)) {}
CallExpression::~CallExpression() = default;

View File

@ -17,7 +17,6 @@
#include <memory>
#include <utility>
#include <vector>
#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<Expression> func,
std::vector<std::unique_ptr<Expression>> params);
CallExpression(std::unique_ptr<Expression> 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<Expression> func,
std::vector<std::unique_ptr<Expression>> 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<std::unique_ptr<Expression>> params) {
params_ = std::move(params);
}
void set_params(ExpressionList params) { params_ = std::move(params); }
/// @returns the parameters
const std::vector<std::unique_ptr<Expression>>& 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<Expression> func_;
std::vector<std::unique_ptr<Expression>> params_;
ExpressionList params_;
};
} // namespace ast

View File

@ -25,7 +25,7 @@ using CallExpressionTest = testing::Test;
TEST_F(CallExpressionTest, Creation) {
auto func = std::make_unique<IdentifierExpression>("func");
std::vector<std::unique_ptr<Expression>> params;
ExpressionList params;
params.push_back(std::make_unique<IdentifierExpression>("param1"));
params.push_back(std::make_unique<IdentifierExpression>("param2"));
@ -69,7 +69,7 @@ TEST_F(CallExpressionTest, IsValid_MissingFunction) {
TEST_F(CallExpressionTest, IsValid_NullParam) {
auto func = std::make_unique<IdentifierExpression>("func");
std::vector<std::unique_ptr<Expression>> params;
ExpressionList params;
params.push_back(std::make_unique<IdentifierExpression>("param1"));
params.push_back(nullptr);
params.push_back(std::make_unique<IdentifierExpression>("param2"));
@ -80,7 +80,7 @@ TEST_F(CallExpressionTest, IsValid_NullParam) {
TEST_F(CallExpressionTest, IsValid_InvalidFunction) {
auto func = std::make_unique<IdentifierExpression>("");
std::vector<std::unique_ptr<Expression>> params;
ExpressionList params;
params.push_back(std::make_unique<IdentifierExpression>("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<IdentifierExpression>("func");
std::vector<std::unique_ptr<Expression>> params;
ExpressionList params;
params.push_back(std::make_unique<IdentifierExpression>(""));
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<IdentifierExpression>("func");
std::vector<std::unique_ptr<Expression>> params;
ExpressionList params;
params.push_back(std::make_unique<IdentifierExpression>("param1"));
params.push_back(std::make_unique<IdentifierExpression>("param2"));

View File

@ -20,12 +20,12 @@ namespace ast {
CaseStatement::CaseStatement() : Statement() {}
CaseStatement::CaseStatement(std::unique_ptr<Literal> condition,
std::vector<std::unique_ptr<Statement>> body)
StatementList body)
: Statement(), condition_(std::move(condition)), body_(std::move(body)) {}
CaseStatement::CaseStatement(const Source& source,
std::unique_ptr<Literal> condition,
std::vector<std::unique_ptr<Statement>> body)
StatementList body)
: Statement(source),
condition_(std::move(condition)),
body_(std::move(body)) {}

View File

@ -35,15 +35,14 @@ class CaseStatement : public Statement {
/// Constructor
/// @param condition the case condition
/// @param body the case body
CaseStatement(std::unique_ptr<Literal> condition,
std::vector<std::unique_ptr<Statement>> body);
CaseStatement(std::unique_ptr<Literal> 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<Literal> condition,
std::vector<std::unique_ptr<Statement>> 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<std::unique_ptr<Statement>> body) {
body_ = std::move(body);
}
void set_body(StatementList body) { body_ = std::move(body); }
/// @returns the case body
const std::vector<std::unique_ptr<Statement>>& 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<Literal> condition_;
std::vector<std::unique_ptr<Statement>> body_;
StatementList body_;
};
/// A list of unique case statements
using CaseStatementList = std::vector<std::unique_ptr<CaseStatement>>;
} // namespace ast
} // namespace tint

View File

@ -29,7 +29,7 @@ using CaseStatementTest = testing::Test;
TEST_F(CaseStatementTest, Creation) {
ast::type::BoolType bool_type;
auto b = std::make_unique<BoolLiteral>(&bool_type, true);
std::vector<std::unique_ptr<Statement>> stmts;
StatementList stmts;
stmts.push_back(std::make_unique<NopStatement>());
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<BoolLiteral>(&bool_type, true);
std::vector<std::unique_ptr<Statement>> stmts;
StatementList stmts;
stmts.push_back(std::make_unique<NopStatement>());
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<std::unique_ptr<Statement>> stmts;
StatementList stmts;
stmts.push_back(std::make_unique<NopStatement>());
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<BoolLiteral>(&bool_type, true);
std::vector<std::unique_ptr<Statement>> stmts;
StatementList stmts;
stmts.push_back(std::make_unique<NopStatement>());
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<BoolLiteral>(&bool_type, true);
std::vector<std::unique_ptr<Statement>> stmts;
StatementList stmts;
stmts.push_back(std::make_unique<IfStatement>());
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<BoolLiteral>(&bool_type, true);
std::vector<std::unique_ptr<Statement>> stmts;
StatementList stmts;
stmts.push_back(std::make_unique<NopStatement>());
CaseStatement c(std::move(b), std::move(stmts));
@ -117,7 +117,7 @@ TEST_F(CaseStatementTest, ToStr_WithCondition) {
}
TEST_F(CaseStatementTest, ToStr_WithoutCondition) {
std::vector<std::unique_ptr<Statement>> stmts;
StatementList stmts;
stmts.push_back(std::make_unique<NopStatement>());
CaseStatement c(nullptr, std::move(stmts));

View File

@ -17,7 +17,6 @@
#include <memory>
#include <utility>
#include <vector>
#include "src/ast/expression.h"
#include "src/ast/literal.h"

View File

@ -17,7 +17,6 @@
#include <memory>
#include <utility>
#include <vector>
#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<std::unique_ptr<VariableDecoration>> decos) {
void set_decorations(VariableDecorationList decos) {
decorations_ = std::move(decos);
}
/// @returns the decorations attached to this variable
const std::vector<std::unique_ptr<VariableDecoration>>& 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<std::unique_ptr<VariableDecoration>> decorations_;
VariableDecorationList decorations_;
};
} // namespace ast

View File

@ -72,7 +72,7 @@ TEST_F(DecoratedVariableTest, to_str) {
DecoratedVariable dv(std::move(var));
dv.set_constructor(std::make_unique<IdentifierExpression>("expr"));
std::vector<std::unique_ptr<VariableDecoration>> decos;
VariableDecorationList decos;
decos.push_back(std::make_unique<BindingDecoration>(2));
decos.push_back(std::make_unique<SetDecoration>(1));

View File

@ -19,20 +19,19 @@ namespace ast {
ElseStatement::ElseStatement() : Statement() {}
ElseStatement::ElseStatement(std::vector<std::unique_ptr<Statement>> body)
ElseStatement::ElseStatement(StatementList body)
: Statement(), body_(std::move(body)) {}
ElseStatement::ElseStatement(std::unique_ptr<Expression> condition,
std::vector<std::unique_ptr<Statement>> body)
StatementList body)
: Statement(), condition_(std::move(condition)), body_(std::move(body)) {}
ElseStatement::ElseStatement(const Source& source,
std::vector<std::unique_ptr<Statement>> body)
ElseStatement::ElseStatement(const Source& source, StatementList body)
: Statement(source), body_(std::move(body)) {}
ElseStatement::ElseStatement(const Source& source,
std::unique_ptr<Expression> condition,
std::vector<std::unique_ptr<Statement>> body)
StatementList body)
: Statement(source),
condition_(std::move(condition)),
body_(std::move(body)) {}

View File

@ -32,24 +32,22 @@ class ElseStatement : public Statement {
ElseStatement();
/// Constructor
/// @param body the else body
explicit ElseStatement(std::vector<std::unique_ptr<Statement>> body);
explicit ElseStatement(StatementList body);
/// Constructor
/// @param condition the else condition
/// @param body the else body
ElseStatement(std::unique_ptr<Expression> condition,
std::vector<std::unique_ptr<Statement>> body);
ElseStatement(std::unique_ptr<Expression> condition, StatementList body);
/// Constructor
/// @param source the source information
/// @param body the else body
ElseStatement(const Source& source,
std::vector<std::unique_ptr<Statement>> 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<Expression> condition,
std::vector<std::unique_ptr<Statement>> 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<std::unique_ptr<Statement>> body) {
body_ = std::move(body);
}
void set_body(StatementList body) { body_ = std::move(body); }
/// @returns the else body
const std::vector<std::unique_ptr<Statement>>& 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<Expression> condition_;
std::vector<std::unique_ptr<Statement>> body_;
StatementList body_;
};
/// A list of unique else statements
using ElseStatementList = std::vector<std::unique_ptr<ElseStatement>>;
} // namespace ast
} // namespace tint

View File

@ -31,7 +31,7 @@ TEST_F(ElseStatementTest, Creation) {
ast::type::BoolType bool_type;
auto cond = std::make_unique<ScalarConstructorExpression>(
std::make_unique<BoolLiteral>(&bool_type, true));
std::vector<std::unique_ptr<Statement>> body;
StatementList body;
body.push_back(std::make_unique<NopStatement>());
auto cond_ptr = cond.get();
@ -74,7 +74,7 @@ TEST_F(ElseStatementTest, IsValid) {
}
TEST_F(ElseStatementTest, IsValid_WithBody) {
std::vector<std::unique_ptr<Statement>> body;
StatementList body;
body.push_back(std::make_unique<NopStatement>());
ElseStatement e(std::move(body));
@ -82,7 +82,7 @@ TEST_F(ElseStatementTest, IsValid_WithBody) {
}
TEST_F(ElseStatementTest, IsValid_WithNullBodyStatement) {
std::vector<std::unique_ptr<Statement>> body;
StatementList body;
body.push_back(std::make_unique<NopStatement>());
body.push_back(nullptr);
@ -97,7 +97,7 @@ TEST_F(ElseStatementTest, IsValid_InvalidCondition) {
}
TEST_F(ElseStatementTest, IsValid_InvalidBodyStatement) {
std::vector<std::unique_ptr<Statement>> body;
StatementList body;
body.push_back(std::make_unique<IfStatement>());
ElseStatement e(std::move(body));
@ -108,7 +108,7 @@ TEST_F(ElseStatementTest, ToStr) {
ast::type::BoolType bool_type;
auto cond = std::make_unique<ScalarConstructorExpression>(
std::make_unique<BoolLiteral>(&bool_type, true));
std::vector<std::unique_ptr<Statement>> body;
StatementList body;
body.push_back(std::make_unique<NopStatement>());
ElseStatement e(std::move(cond), std::move(body));
@ -126,7 +126,7 @@ TEST_F(ElseStatementTest, ToStr) {
}
TEST_F(ElseStatementTest, ToStr_NoCondition) {
std::vector<std::unique_ptr<Statement>> body;
StatementList body;
body.push_back(std::make_unique<NopStatement>());
ElseStatement e(std::move(body));

View File

@ -15,8 +15,10 @@
#ifndef SRC_AST_ENTRY_POINT_H_
#define SRC_AST_ENTRY_POINT_H_
#include <memory>
#include <ostream>
#include <string>
#include <vector>
#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<std::unique_ptr<EntryPoint>>;
} // namespace ast
} // namespace tint

View File

@ -15,6 +15,9 @@
#ifndef SRC_AST_EXPRESSION_H_
#define SRC_AST_EXPRESSION_H_
#include <memory>
#include <vector>
#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<std::unique_ptr<Expression>>;
} // namespace ast
} // namespace tint

View File

@ -15,9 +15,6 @@
#ifndef SRC_AST_FALLTHROUGH_STATEMENT_H_
#define SRC_AST_FALLTHROUGH_STATEMENT_H_
#include <memory>
#include <utility>
#include "src/ast/expression.h"
#include "src/ast/statement.h"
#include "src/ast/statement_condition.h"

View File

@ -20,7 +20,7 @@ namespace tint {
namespace ast {
Function::Function(const std::string& name,
std::vector<std::unique_ptr<Variable>> 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<std::unique_ptr<Variable>> params,
VariableList params,
type::Type* return_type)
: Node(source),
name_(name),

View File

@ -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<std::unique_ptr<Variable>> 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<std::unique_ptr<Variable>> 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<std::unique_ptr<Variable>> params) {
params_ = std::move(params);
}
void set_params(VariableList params) { params_ = std::move(params); }
/// @returns the function params
const std::vector<std::unique_ptr<Variable>>& 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<std::unique_ptr<Statement>> body) {
body_ = std::move(body);
}
void set_body(StatementList body) { body_ = std::move(body); }
/// @returns the function body
const std::vector<std::unique_ptr<Statement>>& 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<std::unique_ptr<Variable>> params_;
VariableList params_;
type::Type* return_type_ = nullptr;
std::vector<std::unique_ptr<Statement>> body_;
StatementList body_;
};
/// A list of unique functions
using FunctionList = std::vector<std::unique_ptr<Function>>;
} // namespace ast
} // namespace tint

View File

@ -31,7 +31,7 @@ TEST_F(FunctionTest, Creation) {
type::VoidType void_type;
type::I32Type i32;
std::vector<std::unique_ptr<Variable>> params;
VariableList params;
params.push_back(
std::make_unique<Variable>("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<std::unique_ptr<Variable>> params;
VariableList params;
params.push_back(
std::make_unique<Variable>("var", StorageClass::kNone, &i32));
@ -61,11 +61,11 @@ TEST_F(FunctionTest, IsValid) {
type::VoidType void_type;
type::I32Type i32;
std::vector<std::unique_ptr<Variable>> params;
VariableList params;
params.push_back(
std::make_unique<Variable>("var", StorageClass::kNone, &i32));
std::vector<std::unique_ptr<Statement>> body;
StatementList body;
body.push_back(std::make_unique<NopStatement>());
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<std::unique_ptr<Variable>> params;
VariableList params;
params.push_back(
std::make_unique<Variable>("var", StorageClass::kNone, &i32));
@ -88,7 +88,7 @@ TEST_F(FunctionTest, IsValid_EmptyName) {
TEST_F(FunctionTest, IsValid_MissingReturnType) {
type::I32Type i32;
std::vector<std::unique_ptr<Variable>> params;
VariableList params;
params.push_back(
std::make_unique<Variable>("var", StorageClass::kNone, &i32));
@ -100,7 +100,7 @@ TEST_F(FunctionTest, IsValid_NullParam) {
type::VoidType void_type;
type::I32Type i32;
std::vector<std::unique_ptr<Variable>> params;
VariableList params;
params.push_back(
std::make_unique<Variable>("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<std::unique_ptr<Variable>> params;
VariableList params;
params.push_back(
std::make_unique<Variable>("var", StorageClass::kNone, nullptr));
@ -124,11 +124,11 @@ TEST_F(FunctionTest, IsValid_NullBodyStatement) {
type::VoidType void_type;
type::I32Type i32;
std::vector<std::unique_ptr<Variable>> params;
VariableList params;
params.push_back(
std::make_unique<Variable>("var", StorageClass::kNone, &i32));
std::vector<std::unique_ptr<Statement>> body;
StatementList body;
body.push_back(std::make_unique<NopStatement>());
body.push_back(nullptr);
@ -141,11 +141,11 @@ TEST_F(FunctionTest, IsValid_InvalidBodyStatement) {
type::VoidType void_type;
type::I32Type i32;
std::vector<std::unique_ptr<Variable>> params;
VariableList params;
params.push_back(
std::make_unique<Variable>("var", StorageClass::kNone, &i32));
std::vector<std::unique_ptr<Statement>> body;
StatementList body;
body.push_back(std::make_unique<NopStatement>());
body.push_back(nullptr);
@ -158,7 +158,7 @@ TEST_F(FunctionTest, ToStr) {
type::VoidType void_type;
type::I32Type i32;
std::vector<std::unique_ptr<Statement>> body;
StatementList body;
body.push_back(std::make_unique<NopStatement>());
Function f("func", {}, &void_type);
@ -178,11 +178,11 @@ TEST_F(FunctionTest, ToStr_WithParams) {
type::VoidType void_type;
type::I32Type i32;
std::vector<std::unique_ptr<Variable>> params;
VariableList params;
params.push_back(
std::make_unique<Variable>("var", StorageClass::kNone, &i32));
std::vector<std::unique_ptr<Statement>> body;
StatementList body;
body.push_back(std::make_unique<NopStatement>());
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<std::unique_ptr<Variable>> params;
VariableList params;
params.push_back(
std::make_unique<Variable>("var1", StorageClass::kNone, &i32));
params.push_back(

View File

@ -15,7 +15,6 @@
#ifndef SRC_AST_IDENTIFIER_EXPRESSION_H_
#define SRC_AST_IDENTIFIER_EXPRESSION_H_
#include <memory>
#include <string>
#include <utility>
#include <vector>

View File

@ -22,12 +22,12 @@ namespace ast {
IfStatement::IfStatement() : Statement() {}
IfStatement::IfStatement(std::unique_ptr<Expression> condition,
std::vector<std::unique_ptr<Statement>> body)
StatementList body)
: Statement(), condition_(std::move(condition)), body_(std::move(body)) {}
IfStatement::IfStatement(const Source& source,
std::unique_ptr<Expression> condition,
std::vector<std::unique_ptr<Statement>> body)
StatementList body)
: Statement(source),
condition_(std::move(condition)),
body_(std::move(body)) {}

View File

@ -17,7 +17,6 @@
#include <memory>
#include <utility>
#include <vector>
#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<Expression> condition,
std::vector<std::unique_ptr<Statement>> body);
IfStatement(std::unique_ptr<Expression> 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<Expression> condition,
std::vector<std::unique_ptr<Statement>> 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<std::unique_ptr<Statement>> body) {
body_ = std::move(body);
}
void set_body(StatementList body) { body_ = std::move(body); }
/// @returns the if body
const std::vector<std::unique_ptr<Statement>>& 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<std::unique_ptr<ElseStatement>> else_statements) {
void set_else_statements(ElseStatementList else_statements) {
else_statements_ = std::move(else_statements);
}
/// @returns the else statements
const std::vector<std::unique_ptr<ElseStatement>>& 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<std::unique_ptr<Statement>> premerge) {
premerge_ = std::move(premerge);
}
void set_premerge(StatementList premerge) { premerge_ = std::move(premerge); }
/// @returns the premerge statements
const std::vector<std::unique_ptr<Statement>>& 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<Expression> condition_;
std::vector<std::unique_ptr<Statement>> body_;
std::vector<std::unique_ptr<ElseStatement>> else_statements_;
std::vector<std::unique_ptr<Statement>> premerge_;
StatementList body_;
ElseStatementList else_statements_;
StatementList premerge_;
};
} // namespace ast

View File

@ -27,7 +27,7 @@ using IfStatementTest = testing::Test;
TEST_F(IfStatementTest, Creation) {
auto cond = std::make_unique<IdentifierExpression>("cond");
std::vector<std::unique_ptr<Statement>> body;
StatementList body;
body.push_back(std::make_unique<NopStatement>());
auto cond_ptr = cond.get();
@ -41,7 +41,7 @@ TEST_F(IfStatementTest, Creation) {
TEST_F(IfStatementTest, Creation_WithSource) {
auto cond = std::make_unique<IdentifierExpression>("cond");
std::vector<std::unique_ptr<Statement>> body;
StatementList body;
body.push_back(std::make_unique<NopStatement>());
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<IdentifierExpression>("cond");
std::vector<std::unique_ptr<Statement>> body;
StatementList body;
body.push_back(std::make_unique<NopStatement>());
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<IdentifierExpression>("cond");
std::vector<std::unique_ptr<Statement>> body;
StatementList body;
body.push_back(std::make_unique<NopStatement>());
std::vector<std::unique_ptr<ElseStatement>> else_stmts;
ElseStatementList else_stmts;
else_stmts.push_back(std::make_unique<ElseStatement>());
else_stmts[0]->set_condition(std::make_unique<IdentifierExpression>("Ident"));
else_stmts.push_back(std::make_unique<ElseStatement>());
@ -81,13 +81,13 @@ TEST_F(IfStatementTest, IsValid_WithElseStatements) {
TEST_F(IfStatementTest, IsValid_WithPremerge) {
auto cond = std::make_unique<IdentifierExpression>("cond");
std::vector<std::unique_ptr<Statement>> body;
StatementList body;
body.push_back(std::make_unique<NopStatement>());
std::vector<std::unique_ptr<ElseStatement>> else_stmts;
ElseStatementList else_stmts;
else_stmts.push_back(std::make_unique<ElseStatement>());
std::vector<std::unique_ptr<Statement>> premerge;
StatementList premerge;
premerge.push_back(std::make_unique<NopStatement>());
IfStatement stmt(std::move(cond), std::move(body));
@ -97,7 +97,7 @@ TEST_F(IfStatementTest, IsValid_WithPremerge) {
}
TEST_F(IfStatementTest, IsValid_MissingCondition) {
std::vector<std::unique_ptr<Statement>> body;
StatementList body;
body.push_back(std::make_unique<NopStatement>());
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<IdentifierExpression>("");
std::vector<std::unique_ptr<Statement>> body;
StatementList body;
body.push_back(std::make_unique<NopStatement>());
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<IdentifierExpression>("cond");
std::vector<std::unique_ptr<Statement>> body;
StatementList body;
body.push_back(std::make_unique<NopStatement>());
body.push_back(nullptr);
@ -125,7 +125,7 @@ TEST_F(IfStatementTest, IsValid_NullBodyStatement) {
TEST_F(IfStatementTest, IsValid_InvalidBodyStatement) {
auto cond = std::make_unique<IdentifierExpression>("cond");
std::vector<std::unique_ptr<Statement>> body;
StatementList body;
body.push_back(std::make_unique<NopStatement>());
body.push_back(std::make_unique<IfStatement>());
@ -135,10 +135,10 @@ TEST_F(IfStatementTest, IsValid_InvalidBodyStatement) {
TEST_F(IfStatementTest, IsValid_NullElseStatement) {
auto cond = std::make_unique<IdentifierExpression>("cond");
std::vector<std::unique_ptr<Statement>> body;
StatementList body;
body.push_back(std::make_unique<NopStatement>());
std::vector<std::unique_ptr<ElseStatement>> else_stmts;
ElseStatementList else_stmts;
else_stmts.push_back(std::make_unique<ElseStatement>());
else_stmts[0]->set_condition(std::make_unique<IdentifierExpression>("Ident"));
else_stmts.push_back(std::make_unique<ElseStatement>());
@ -151,10 +151,10 @@ TEST_F(IfStatementTest, IsValid_NullElseStatement) {
TEST_F(IfStatementTest, IsValid_InvalidElseStatement) {
auto cond = std::make_unique<IdentifierExpression>("cond");
std::vector<std::unique_ptr<Statement>> body;
StatementList body;
body.push_back(std::make_unique<NopStatement>());
std::vector<std::unique_ptr<ElseStatement>> else_stmts;
ElseStatementList else_stmts;
else_stmts.push_back(std::make_unique<ElseStatement>());
else_stmts[0]->set_condition(std::make_unique<IdentifierExpression>(""));
@ -165,13 +165,13 @@ TEST_F(IfStatementTest, IsValid_InvalidElseStatement) {
TEST_F(IfStatementTest, IsValid_NullPremergeStatement) {
auto cond = std::make_unique<IdentifierExpression>("cond");
std::vector<std::unique_ptr<Statement>> body;
StatementList body;
body.push_back(std::make_unique<NopStatement>());
std::vector<std::unique_ptr<ElseStatement>> else_stmts;
ElseStatementList else_stmts;
else_stmts.push_back(std::make_unique<ElseStatement>());
std::vector<std::unique_ptr<Statement>> premerge;
StatementList premerge;
premerge.push_back(std::make_unique<NopStatement>());
premerge.push_back(nullptr);
@ -183,13 +183,13 @@ TEST_F(IfStatementTest, IsValid_NullPremergeStatement) {
TEST_F(IfStatementTest, IsValid_InvalidPremergeStatement) {
auto cond = std::make_unique<IdentifierExpression>("cond");
std::vector<std::unique_ptr<Statement>> body;
StatementList body;
body.push_back(std::make_unique<NopStatement>());
std::vector<std::unique_ptr<ElseStatement>> else_stmts;
ElseStatementList else_stmts;
else_stmts.push_back(std::make_unique<ElseStatement>());
std::vector<std::unique_ptr<Statement>> premerge;
StatementList premerge;
premerge.push_back(std::make_unique<IfStatement>());
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<IdentifierExpression>("cond");
std::vector<std::unique_ptr<Statement>> body;
StatementList body;
body.push_back(std::make_unique<NopStatement>());
std::vector<std::unique_ptr<ElseStatement>> else_stmts;
ElseStatementList else_stmts;
else_stmts.push_back(std::make_unique<ElseStatement>());
else_stmts[0]->set_condition(std::make_unique<IdentifierExpression>("ident"));
std::vector<std::unique_ptr<Statement>> premerge;
StatementList premerge;
premerge.push_back(std::make_unique<NopStatement>());
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<IdentifierExpression>("cond");
std::vector<std::unique_ptr<Statement>> body;
StatementList body;
body.push_back(std::make_unique<NopStatement>());
std::vector<std::unique_ptr<Statement>> premerge;
StatementList premerge;
premerge.push_back(std::make_unique<NopStatement>());
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<IdentifierExpression>("cond");
std::vector<std::unique_ptr<Statement>> body;
StatementList body;
body.push_back(std::make_unique<NopStatement>());
std::vector<std::unique_ptr<ElseStatement>> else_stmts;
ElseStatementList else_stmts;
else_stmts.push_back(std::make_unique<ElseStatement>());
else_stmts.push_back(std::make_unique<ElseStatement>());
@ -245,10 +245,10 @@ TEST_F(IfStatementTest, IsValid_MultipleElseWiththoutCondition) {
TEST_F(IfStatementTest, IsValid_ElseNotLast) {
auto cond = std::make_unique<IdentifierExpression>("cond");
std::vector<std::unique_ptr<Statement>> body;
StatementList body;
body.push_back(std::make_unique<NopStatement>());
std::vector<std::unique_ptr<ElseStatement>> else_stmts;
ElseStatementList else_stmts;
else_stmts.push_back(std::make_unique<ElseStatement>());
else_stmts.push_back(std::make_unique<ElseStatement>());
else_stmts[1]->set_condition(std::make_unique<IdentifierExpression>("ident"));
@ -260,7 +260,7 @@ TEST_F(IfStatementTest, IsValid_ElseNotLast) {
TEST_F(IfStatementTest, ToStr) {
auto cond = std::make_unique<IdentifierExpression>("cond");
std::vector<std::unique_ptr<Statement>> body;
StatementList body;
body.push_back(std::make_unique<NopStatement>());
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<IdentifierExpression>("cond");
std::vector<std::unique_ptr<Statement>> body;
StatementList body;
body.push_back(std::make_unique<NopStatement>());
std::vector<std::unique_ptr<Statement>> else_if_body;
StatementList else_if_body;
else_if_body.push_back(std::make_unique<KillStatement>());
std::vector<std::unique_ptr<Statement>> else_body;
StatementList else_body;
else_body.push_back(std::make_unique<NopStatement>());
else_body.push_back(std::make_unique<KillStatement>());
std::vector<std::unique_ptr<ElseStatement>> else_stmts;
ElseStatementList else_stmts;
else_stmts.push_back(std::make_unique<ElseStatement>());
else_stmts[0]->set_condition(std::make_unique<IdentifierExpression>("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<IdentifierExpression>("cond");
std::vector<std::unique_ptr<Statement>> body;
StatementList body;
body.push_back(std::make_unique<NopStatement>());
std::vector<std::unique_ptr<ElseStatement>> else_stmts;
ElseStatementList else_stmts;
else_stmts.push_back(std::make_unique<ElseStatement>());
std::vector<std::unique_ptr<Statement>> premerge;
StatementList premerge;
premerge.push_back(std::make_unique<NopStatement>());
IfStatement stmt(std::move(cond), std::move(body));

View File

@ -15,8 +15,10 @@
#ifndef SRC_AST_IMPORT_H_
#define SRC_AST_IMPORT_H_
#include <memory>
#include <ostream>
#include <string>
#include <vector>
#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<std::unique_ptr<Import>>;
} // namespace ast
} // namespace tint

View File

@ -19,13 +19,12 @@ namespace ast {
LoopStatement::LoopStatement() : Statement() {}
LoopStatement::LoopStatement(std::vector<std::unique_ptr<Statement>> body,
std::vector<std::unique_ptr<Statement>> continuing)
LoopStatement::LoopStatement(StatementList body, StatementList continuing)
: Statement(), body_(std::move(body)), continuing_(std::move(continuing)) {}
LoopStatement::LoopStatement(const Source& source,
std::vector<std::unique_ptr<Statement>> body,
std::vector<std::unique_ptr<Statement>> continuing)
StatementList body,
StatementList continuing)
: Statement(source),
body_(std::move(body)),
continuing_(std::move(continuing)) {}

View File

@ -15,9 +15,7 @@
#ifndef SRC_AST_LOOP_STATEMENT_H_
#define SRC_AST_LOOP_STATEMENT_H_
#include <memory>
#include <utility>
#include <vector>
#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<std::unique_ptr<Statement>> body,
std::vector<std::unique_ptr<Statement>> 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<std::unique_ptr<Statement>> body,
std::vector<std::unique_ptr<Statement>> 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<std::unique_ptr<Statement>> body) {
body_ = std::move(body);
}
void set_body(StatementList body) { body_ = std::move(body); }
/// @returns the body statements
const std::vector<std::unique_ptr<Statement>>& body() const { return body_; }
const StatementList& body() const { return body_; }
/// Sets the continuing statements
/// @param continuing the continuing statements
void set_continuing(std::vector<std::unique_ptr<Statement>> continuing) {
void set_continuing(StatementList continuing) {
continuing_ = std::move(continuing);
}
/// @returns the continuing statements
const std::vector<std::unique_ptr<Statement>>& 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<std::unique_ptr<Statement>> body_;
std::vector<std::unique_ptr<Statement>> continuing_;
StatementList body_;
StatementList continuing_;
};
} // namespace ast

View File

@ -14,6 +14,7 @@
#include "src/ast/loop_statement.h"
#include <memory>
#include <sstream>
#include "gtest/gtest.h"
@ -28,11 +29,11 @@ namespace {
using LoopStatementTest = testing::Test;
TEST_F(LoopStatementTest, Creation) {
std::vector<std::unique_ptr<Statement>> body;
StatementList body;
body.push_back(std::make_unique<KillStatement>());
auto b_ptr = body[0].get();
std::vector<std::unique_ptr<Statement>> continuing;
StatementList continuing;
continuing.push_back(std::make_unique<NopStatement>());
auto c_ptr = continuing[0].get();
@ -44,10 +45,10 @@ TEST_F(LoopStatementTest, Creation) {
}
TEST_F(LoopStatementTest, Creation_WithSource) {
std::vector<std::unique_ptr<Statement>> body;
StatementList body;
body.push_back(std::make_unique<KillStatement>());
std::vector<std::unique_ptr<Statement>> continuing;
StatementList continuing;
continuing.push_back(std::make_unique<NopStatement>());
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<std::unique_ptr<Statement>> body;
StatementList body;
body.push_back(std::make_unique<KillStatement>());
LoopStatement l(std::move(body), {});
@ -70,10 +71,10 @@ TEST_F(LoopStatementTest, HasContinuing_WithoutContinuing) {
}
TEST_F(LoopStatementTest, HasContinuing_WithContinuing) {
std::vector<std::unique_ptr<Statement>> body;
StatementList body;
body.push_back(std::make_unique<KillStatement>());
std::vector<std::unique_ptr<Statement>> continuing;
StatementList continuing;
continuing.push_back(std::make_unique<NopStatement>());
LoopStatement l(std::move(body), std::move(continuing));
@ -81,10 +82,10 @@ TEST_F(LoopStatementTest, HasContinuing_WithContinuing) {
}
TEST_F(LoopStatementTest, IsValid) {
std::vector<std::unique_ptr<Statement>> body;
StatementList body;
body.push_back(std::make_unique<KillStatement>());
std::vector<std::unique_ptr<Statement>> continuing;
StatementList continuing;
continuing.push_back(std::make_unique<NopStatement>());
LoopStatement l(std::move(body), std::move(continuing));
@ -92,7 +93,7 @@ TEST_F(LoopStatementTest, IsValid) {
}
TEST_F(LoopStatementTest, IsValid_WithoutContinuing) {
std::vector<std::unique_ptr<Statement>> body;
StatementList body;
body.push_back(std::make_unique<KillStatement>());
LoopStatement l(std::move(body), {});
@ -105,11 +106,11 @@ TEST_F(LoopStatementTest, IsValid_WithoutBody) {
}
TEST_F(LoopStatementTest, IsValid_NullBodyStatement) {
std::vector<std::unique_ptr<Statement>> body;
StatementList body;
body.push_back(std::make_unique<KillStatement>());
body.push_back(nullptr);
std::vector<std::unique_ptr<Statement>> continuing;
StatementList continuing;
continuing.push_back(std::make_unique<NopStatement>());
LoopStatement l(std::move(body), std::move(continuing));
@ -117,11 +118,11 @@ TEST_F(LoopStatementTest, IsValid_NullBodyStatement) {
}
TEST_F(LoopStatementTest, IsValid_InvalidBodyStatement) {
std::vector<std::unique_ptr<Statement>> body;
StatementList body;
body.push_back(std::make_unique<KillStatement>());
body.push_back(std::make_unique<IfStatement>());
std::vector<std::unique_ptr<Statement>> continuing;
StatementList continuing;
continuing.push_back(std::make_unique<NopStatement>());
LoopStatement l(std::move(body), std::move(continuing));
@ -129,10 +130,10 @@ TEST_F(LoopStatementTest, IsValid_InvalidBodyStatement) {
}
TEST_F(LoopStatementTest, IsValid_NullContinuingStatement) {
std::vector<std::unique_ptr<Statement>> body;
StatementList body;
body.push_back(std::make_unique<KillStatement>());
std::vector<std::unique_ptr<Statement>> continuing;
StatementList continuing;
continuing.push_back(std::make_unique<NopStatement>());
continuing.push_back(nullptr);
@ -141,10 +142,10 @@ TEST_F(LoopStatementTest, IsValid_NullContinuingStatement) {
}
TEST_F(LoopStatementTest, IsValid_InvalidContinuingStatement) {
std::vector<std::unique_ptr<Statement>> body;
StatementList body;
body.push_back(std::make_unique<KillStatement>());
std::vector<std::unique_ptr<Statement>> continuing;
StatementList continuing;
continuing.push_back(std::make_unique<NopStatement>());
continuing.push_back(std::make_unique<IfStatement>());
@ -153,7 +154,7 @@ TEST_F(LoopStatementTest, IsValid_InvalidContinuingStatement) {
}
TEST_F(LoopStatementTest, ToStr) {
std::vector<std::unique_ptr<Statement>> body;
StatementList body;
body.push_back(std::make_unique<KillStatement>());
LoopStatement l(std::move(body), {});
@ -166,10 +167,10 @@ TEST_F(LoopStatementTest, ToStr) {
}
TEST_F(LoopStatementTest, ToStr_WithContinuing) {
std::vector<std::unique_ptr<Statement>> body;
StatementList body;
body.push_back(std::make_unique<KillStatement>());
std::vector<std::unique_ptr<Statement>> continuing;
StatementList continuing;
continuing.push_back(std::make_unique<NopStatement>());
LoopStatement l(std::move(body), std::move(continuing));

View File

@ -43,9 +43,7 @@ class Module {
imports_.push_back(std::move(import));
}
/// @returns the imports for this module
const std::vector<std::unique_ptr<Import>>& 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<std::unique_ptr<Variable>>& 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<std::unique_ptr<EntryPoint>>& 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<std::unique_ptr<Function>>& 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<std::unique_ptr<Import>> imports_;
std::vector<std::unique_ptr<Variable>> global_variables_;
std::vector<std::unique_ptr<EntryPoint>> entry_points_;
ImportList imports_;
VariableList global_variables_;
EntryPointList entry_points_;
// The alias types are owned by the type manager
std::vector<type::AliasType*> alias_types_;
std::vector<std::unique_ptr<Function>> functions_;
FunctionList functions_;
};
} // namespace ast

View File

@ -163,8 +163,7 @@ TEST_F(ModuleTest, IsValid_Null_Alias) {
TEST_F(ModuleTest, IsValid_Function) {
type::F32Type f32;
auto func = std::make_unique<Function>(
"main", std::vector<std::unique_ptr<Variable>>(), &f32);
auto func = std::make_unique<Function>("main", VariableList(), &f32);
Module m;
m.AddFunction(std::move(func));

View File

@ -19,15 +19,13 @@ namespace ast {
RegardlessStatement::RegardlessStatement() : Statement() {}
RegardlessStatement::RegardlessStatement(
std::unique_ptr<Expression> condition,
std::vector<std::unique_ptr<Statement>> body)
RegardlessStatement::RegardlessStatement(std::unique_ptr<Expression> condition,
StatementList body)
: Statement(), condition_(std::move(condition)), body_(std::move(body)) {}
RegardlessStatement::RegardlessStatement(
const Source& source,
std::unique_ptr<Expression> condition,
std::vector<std::unique_ptr<Statement>> body)
RegardlessStatement::RegardlessStatement(const Source& source,
std::unique_ptr<Expression> condition,
StatementList body)
: Statement(source),
condition_(std::move(condition)),
body_(std::move(body)) {}

View File

@ -17,7 +17,6 @@
#include <memory>
#include <utility>
#include <vector>
#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<Expression> condition,
std::vector<std::unique_ptr<Statement>> 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<Expression> condition,
std::vector<std::unique_ptr<Statement>> 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<std::unique_ptr<Statement>> body) {
body_ = std::move(body);
}
void set_body(StatementList body) { body_ = std::move(body); }
/// @returns the body statements
const std::vector<std::unique_ptr<Statement>>& 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<Expression> condition_;
std::vector<std::unique_ptr<Statement>> body_;
StatementList body_;
};
} // namespace ast

View File

@ -29,7 +29,7 @@ using RegardlessStatementTest = testing::Test;
TEST_F(RegardlessStatementTest, Creation) {
auto ident = std::make_unique<IdentifierExpression>("ident");
std::vector<std::unique_ptr<Statement>> stmts;
StatementList stmts;
stmts.push_back(std::make_unique<KillStatement>());
auto ident_ptr = ident.get();
@ -43,7 +43,7 @@ TEST_F(RegardlessStatementTest, Creation) {
TEST_F(RegardlessStatementTest, Creation_WithSource) {
auto ident = std::make_unique<IdentifierExpression>("ident");
std::vector<std::unique_ptr<Statement>> stmts;
StatementList stmts;
stmts.push_back(std::make_unique<KillStatement>());
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<IdentifierExpression>("ident");
std::vector<std::unique_ptr<Statement>> stmts;
StatementList stmts;
stmts.push_back(std::make_unique<KillStatement>());
RegardlessStatement r(std::move(ident), std::move(stmts));
@ -67,7 +67,7 @@ TEST_F(RegardlessStatementTest, IsValid) {
}
TEST_F(RegardlessStatementTest, IsValid_NullCondition) {
std::vector<std::unique_ptr<Statement>> stmts;
StatementList stmts;
stmts.push_back(std::make_unique<KillStatement>());
RegardlessStatement r;
@ -77,7 +77,7 @@ TEST_F(RegardlessStatementTest, IsValid_NullCondition) {
TEST_F(RegardlessStatementTest, IsValid_InvalidCondition) {
auto ident = std::make_unique<IdentifierExpression>("");
std::vector<std::unique_ptr<Statement>> stmts;
StatementList stmts;
stmts.push_back(std::make_unique<KillStatement>());
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<IdentifierExpression>("ident");
std::vector<std::unique_ptr<Statement>> stmts;
StatementList stmts;
stmts.push_back(std::make_unique<KillStatement>());
stmts.push_back(nullptr);
@ -98,7 +98,7 @@ TEST_F(RegardlessStatementTest, IsValid_NullBodyStatement) {
TEST_F(RegardlessStatementTest, IsValid_InvalidBodyStatement) {
auto ident = std::make_unique<IdentifierExpression>("ident");
std::vector<std::unique_ptr<Statement>> stmts;
StatementList stmts;
stmts.push_back(std::make_unique<KillStatement>());
stmts.push_back(std::make_unique<IfStatement>());
@ -108,7 +108,7 @@ TEST_F(RegardlessStatementTest, IsValid_InvalidBodyStatement) {
TEST_F(RegardlessStatementTest, ToStr) {
auto ident = std::make_unique<IdentifierExpression>("ident");
std::vector<std::unique_ptr<Statement>> stmts;
StatementList stmts;
stmts.push_back(std::make_unique<KillStatement>());
RegardlessStatement r(std::move(ident), std::move(stmts));

View File

@ -15,6 +15,9 @@
#ifndef SRC_AST_STATEMENT_H_
#define SRC_AST_STATEMENT_H_
#include <memory>
#include <vector>
#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<std::unique_ptr<Statement>>;
} // namespace ast
} // namespace tint

View File

@ -19,13 +19,12 @@ namespace ast {
Struct::Struct() : Node() {}
Struct::Struct(StructDecoration decoration,
std::vector<std::unique_ptr<StructMember>> members)
Struct::Struct(StructDecoration decoration, StructMemberList members)
: Node(), decoration_(decoration), members_(std::move(members)) {}
Struct::Struct(const Source& source,
StructDecoration decoration,
std::vector<std::unique_ptr<StructMember>> members)
StructMemberList members)
: Node(source), decoration_(decoration), members_(std::move(members)) {}
Struct::~Struct() = default;

View File

@ -15,11 +15,9 @@
#ifndef SRC_AST_STRUCT_H_
#define SRC_AST_STRUCT_H_
#include <memory>
#include <ostream>
#include <string>
#include <utility>
#include <vector>
#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<std::unique_ptr<StructMember>> 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<std::unique_ptr<StructMember>> 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<std::unique_ptr<StructMember>> members) {
members_ = std::move(members);
}
void set_members(StructMemberList members) { members_ = std::move(members); }
/// @returns the members
const std::vector<std::unique_ptr<StructMember>>& 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<std::unique_ptr<StructMember>> members_;
StructMemberList members_;
};
} // namespace ast

View File

@ -17,17 +17,15 @@
namespace tint {
namespace ast {
StructMember::StructMember(
const std::string& name,
type::Type* type,
std::vector<std::unique_ptr<StructMemberDecoration>> 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<std::unique_ptr<StructMemberDecoration>> decorations)
StructMember::StructMember(const Source& source,
const std::string& name,
type::Type* type,
StructMemberDecorationList decorations)
: Node(source),
name_(name),
type_(type),

View File

@ -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<std::unique_ptr<StructMemberDecoration>> 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<std::unique_ptr<StructMemberDecoration>> 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<std::unique_ptr<StructMemberDecoration>> decorations) {
void set_decorations(StructMemberDecorationList decorations) {
decorations_ = std::move(decorations);
}
/// @returns the decorations
const std::vector<std::unique_ptr<StructMemberDecoration>>& 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<std::unique_ptr<StructMemberDecoration>> decorations_;
StructMemberDecorationList decorations_;
};
/// A list of unique struct members
using StructMemberList = std::vector<std::unique_ptr<StructMember>>;
} // namespace ast
} // namespace tint

View File

@ -15,7 +15,9 @@
#ifndef SRC_AST_STRUCT_MEMBER_DECORATION_H_
#define SRC_AST_STRUCT_MEMBER_DECORATION_H_
#include <memory>
#include <string>
#include <vector>
namespace tint {
namespace ast {
@ -40,6 +42,10 @@ class StructMemberDecoration {
StructMemberDecoration();
};
/// A list of unique struct member decorations
using StructMemberDecorationList =
std::vector<std::unique_ptr<StructMemberDecoration>>;
} // namespace ast
} // namespace tint

View File

@ -29,7 +29,7 @@ using StructMemberTest = testing::Test;
TEST_F(StructMemberTest, Creation) {
type::I32Type i32;
std::vector<std::unique_ptr<StructMemberDecoration>> decorations;
StructMemberDecorationList decorations;
decorations.emplace_back(std::make_unique<StructMemberOffsetDecoration>(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<std::unique_ptr<StructMemberDecoration>> decorations;
StructMemberDecorationList decorations;
decorations.emplace_back(std::make_unique<StructMemberOffsetDecoration>(4));
decorations.push_back(nullptr);
@ -82,7 +82,7 @@ TEST_F(StructMemberTest, IsValid_Null_Decoration) {
TEST_F(StructMemberTest, ToStr) {
type::I32Type i32;
std::vector<std::unique_ptr<StructMemberDecoration>> decorations;
StructMemberDecorationList decorations;
decorations.emplace_back(std::make_unique<StructMemberOffsetDecoration>(4));
StructMember st{"a", &i32, std::move(decorations)};

View File

@ -14,6 +14,7 @@
#include "src/ast/struct.h"
#include <memory>
#include <sstream>
#include <utility>
@ -30,9 +31,9 @@ using StructTest = testing::Test;
TEST_F(StructTest, Creation) {
type::I32Type i32;
std::vector<std::unique_ptr<StructMember>> members;
members.push_back(std::make_unique<StructMember>(
"a", &i32, std::vector<std::unique_ptr<StructMemberDecoration>>()));
StructMemberList members;
members.push_back(
std::make_unique<StructMember>("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<std::unique_ptr<StructMember>> members;
members.emplace_back(std::make_unique<StructMember>(
"a", &i32, std::vector<std::unique_ptr<StructMemberDecoration>>()));
StructMemberList members;
members.emplace_back(
std::make_unique<StructMember>("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<std::unique_ptr<StructMember>> members;
members.push_back(std::make_unique<StructMember>(
"a", &i32, std::vector<std::unique_ptr<StructMemberDecoration>>()));
StructMemberList members;
members.push_back(
std::make_unique<StructMember>("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<std::unique_ptr<StructMember>> members;
members.push_back(std::make_unique<StructMember>(
"", &i32, std::vector<std::unique_ptr<StructMemberDecoration>>()));
StructMemberList members;
members.push_back(
std::make_unique<StructMember>("", &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<std::unique_ptr<StructMember>> members;
members.emplace_back(std::make_unique<StructMember>(
"a", &i32, std::vector<std::unique_ptr<StructMemberDecoration>>()));
StructMemberList members;
members.emplace_back(
std::make_unique<StructMember>("a", &i32, StructMemberDecorationList()));
Struct s{source, StructDecoration::kNone, std::move(members)};

View File

@ -21,15 +21,13 @@ namespace ast {
SwitchStatement::SwitchStatement() : Statement() {}
SwitchStatement::SwitchStatement(
std::unique_ptr<Expression> condition,
std::vector<std::unique_ptr<CaseStatement>> body)
SwitchStatement::SwitchStatement(std::unique_ptr<Expression> condition,
CaseStatementList body)
: Statement(), condition_(std::move(condition)), body_(std::move(body)) {}
SwitchStatement::SwitchStatement(
const Source& source,
std::unique_ptr<Expression> condition,
std::vector<std::unique_ptr<CaseStatement>> body)
SwitchStatement::SwitchStatement(const Source& source,
std::unique_ptr<Expression> condition,
CaseStatementList body)
: Statement(source),
condition_(std::move(condition)),
body_(std::move(body)) {}

View File

@ -17,8 +17,8 @@
#include <memory>
#include <utility>
#include <vector>
#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<Expression> condition,
std::vector<std::unique_ptr<CaseStatement>> 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<Expression> condition,
std::vector<std::unique_ptr<CaseStatement>> 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<std::unique_ptr<CaseStatement>> body) {
body_ = std::move(body);
}
void set_body(CaseStatementList body) { body_ = std::move(body); }
/// @returns the Switch body
const std::vector<std::unique_ptr<CaseStatement>>& 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<Expression> condition_;
std::vector<std::unique_ptr<CaseStatement>> body_;
CaseStatementList body_;
};
} // namespace ast

View File

@ -32,9 +32,9 @@ TEST_F(SwitchStatementTest, Creation) {
ast::type::BoolType bool_type;
auto lit = std::make_unique<BoolLiteral>(&bool_type, true);
auto ident = std::make_unique<IdentifierExpression>("ident");
std::vector<std::unique_ptr<CaseStatement>> body;
body.push_back(std::make_unique<CaseStatement>(
std::move(lit), std::vector<std::unique_ptr<Statement>>()));
CaseStatementList body;
body.push_back(
std::make_unique<CaseStatement>(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<IdentifierExpression>("ident");
SwitchStatement stmt(Source{20, 2}, std::move(ident),
std::vector<std::unique_ptr<CaseStatement>>());
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<BoolLiteral>(&bool_type, true);
auto ident = std::make_unique<IdentifierExpression>("ident");
std::vector<std::unique_ptr<CaseStatement>> body;
body.push_back(std::make_unique<CaseStatement>(
std::move(lit), std::vector<std::unique_ptr<Statement>>()));
CaseStatementList body;
body.push_back(
std::make_unique<CaseStatement>(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<BoolLiteral>(&bool_type, true);
std::vector<std::unique_ptr<CaseStatement>> body;
body.push_back(std::make_unique<CaseStatement>(
std::move(lit), std::vector<std::unique_ptr<Statement>>()));
CaseStatementList body;
body.push_back(
std::make_unique<CaseStatement>(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<BoolLiteral>(&bool_type, true);
auto ident = std::make_unique<IdentifierExpression>("");
std::vector<std::unique_ptr<CaseStatement>> body;
body.push_back(std::make_unique<CaseStatement>(
std::move(lit), std::vector<std::unique_ptr<Statement>>()));
CaseStatementList body;
body.push_back(
std::make_unique<CaseStatement>(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<BoolLiteral>(&bool_type, true);
auto ident = std::make_unique<IdentifierExpression>("ident");
std::vector<std::unique_ptr<CaseStatement>> body;
body.push_back(std::make_unique<CaseStatement>(
std::move(lit), std::vector<std::unique_ptr<Statement>>()));
CaseStatementList body;
body.push_back(
std::make_unique<CaseStatement>(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<IdentifierExpression>("ident");
std::vector<std::unique_ptr<Statement>> case_body;
StatementList case_body;
case_body.push_back(nullptr);
std::vector<std::unique_ptr<CaseStatement>> body;
CaseStatementList body;
body.push_back(
std::make_unique<CaseStatement>(nullptr, std::move(case_body)));
@ -141,9 +140,9 @@ TEST_F(SwitchStatementTest, ToStr) {
ast::type::BoolType bool_type;
auto lit = std::make_unique<BoolLiteral>(&bool_type, true);
auto ident = std::make_unique<IdentifierExpression>("ident");
std::vector<std::unique_ptr<CaseStatement>> body;
body.push_back(std::make_unique<CaseStatement>(
std::move(lit), std::vector<std::unique_ptr<Statement>>()));
CaseStatementList body;
body.push_back(
std::make_unique<CaseStatement>(std::move(lit), StatementList()));
SwitchStatement stmt(std::move(ident), std::move(body));
std::ostringstream out;

View File

@ -20,15 +20,13 @@ namespace ast {
TypeConstructorExpression::TypeConstructorExpression()
: ConstructorExpression() {}
TypeConstructorExpression::TypeConstructorExpression(
type::Type* type,
std::vector<std::unique_ptr<Expression>> 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<std::unique_ptr<Expression>> values)
TypeConstructorExpression::TypeConstructorExpression(const Source& source,
type::Type* type,
ExpressionList values)
: ConstructorExpression(source), type_(type), values_(std::move(values)) {}
TypeConstructorExpression::~TypeConstructorExpression() = default;

View File

@ -17,7 +17,6 @@
#include <memory>
#include <utility>
#include <vector>
#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<std::unique_ptr<Expression>> 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<std::unique_ptr<Expression>> 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<std::unique_ptr<Expression>> values) {
values_ = std::move(values);
}
void set_values(ExpressionList values) { values_ = std::move(values); }
/// @returns the values
const std::vector<std::unique_ptr<Expression>>& 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<std::unique_ptr<Expression>> values_;
ExpressionList values_;
};
} // namespace ast

View File

@ -16,7 +16,6 @@
#include <memory>
#include <sstream>
#include <vector>
#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<std::unique_ptr<Expression>> expr;
ExpressionList expr;
expr.push_back(std::make_unique<IdentifierExpression>("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<std::unique_ptr<Expression>> expr;
ExpressionList expr;
expr.push_back(std::make_unique<IdentifierExpression>("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<std::unique_ptr<Expression>> expr;
ExpressionList expr;
expr.push_back(std::make_unique<IdentifierExpression>("expr"));
TypeConstructorExpression t(&f32, std::move(expr));
@ -68,7 +67,7 @@ TEST_F(TypeConstructorExpressionTest, IsValid) {
}
TEST_F(TypeConstructorExpressionTest, IsValid_NullType) {
std::vector<std::unique_ptr<Expression>> expr;
ExpressionList expr;
expr.push_back(std::make_unique<IdentifierExpression>("expr"));
TypeConstructorExpression t;
@ -78,7 +77,7 @@ TEST_F(TypeConstructorExpressionTest, IsValid_NullType) {
TEST_F(TypeConstructorExpressionTest, IsValid_NullValue) {
type::F32Type f32;
std::vector<std::unique_ptr<Expression>> expr;
ExpressionList expr;
expr.push_back(std::make_unique<IdentifierExpression>("expr"));
expr.push_back(nullptr);
@ -88,7 +87,7 @@ TEST_F(TypeConstructorExpressionTest, IsValid_NullValue) {
TEST_F(TypeConstructorExpressionTest, IsValid_InvalidValue) {
type::F32Type f32;
std::vector<std::unique_ptr<Expression>> expr;
ExpressionList expr;
expr.push_back(std::make_unique<IdentifierExpression>(""));
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<std::unique_ptr<Expression>> 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<std::unique_ptr<Expression>> expr;
ExpressionList expr;
expr.push_back(std::make_unique<IdentifierExpression>("expr_1"));
expr.push_back(std::make_unique<IdentifierExpression>("expr_2"));
expr.push_back(std::make_unique<IdentifierExpression>("expr_3"));

View File

@ -19,15 +19,13 @@ namespace ast {
UnaryMethodExpression::UnaryMethodExpression() : Expression() {}
UnaryMethodExpression::UnaryMethodExpression(
UnaryMethod op,
std::vector<std::unique_ptr<Expression>> params)
UnaryMethodExpression::UnaryMethodExpression(UnaryMethod op,
ExpressionList params)
: Expression(), op_(op), params_(std::move(params)) {}
UnaryMethodExpression::UnaryMethodExpression(
const Source& source,
UnaryMethod op,
std::vector<std::unique_ptr<Expression>> params)
UnaryMethodExpression::UnaryMethodExpression(const Source& source,
UnaryMethod op,
ExpressionList params)
: Expression(source), op_(op), params_(std::move(params)) {}
UnaryMethodExpression::~UnaryMethodExpression() = default;

View File

@ -15,9 +15,7 @@
#ifndef SRC_AST_UNARY_METHOD_EXPRESSION_H_
#define SRC_AST_UNARY_METHOD_EXPRESSION_H_
#include <memory>
#include <utility>
#include <vector>
#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<std::unique_ptr<Expression>> 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<std::unique_ptr<Expression>> 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<std::unique_ptr<Expression>> params) {
params_ = std::move(params);
}
void set_params(ExpressionList params) { params_ = std::move(params); }
/// @returns the params
const std::vector<std::unique_ptr<Expression>>& 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<std::unique_ptr<Expression>> params_;
ExpressionList params_;
};
} // namespace ast

View File

@ -14,6 +14,7 @@
#include "src/ast/unary_method_expression.h"
#include <memory>
#include <sstream>
#include "gtest/gtest.h"
@ -26,7 +27,7 @@ namespace {
using UnaryMethodExpressionTest = testing::Test;
TEST_F(UnaryMethodExpressionTest, Creation) {
std::vector<std::unique_ptr<Expression>> params;
ExpressionList params;
params.push_back(std::make_unique<IdentifierExpression>("ident"));
auto ident_ptr = params[0].get();
@ -38,7 +39,7 @@ TEST_F(UnaryMethodExpressionTest, Creation) {
}
TEST_F(UnaryMethodExpressionTest, Creation_WithSource) {
std::vector<std::unique_ptr<Expression>> params;
ExpressionList params;
params.push_back(std::make_unique<IdentifierExpression>("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<std::unique_ptr<Expression>> params;
ExpressionList params;
params.push_back(std::make_unique<IdentifierExpression>("ident"));
UnaryMethodExpression u(UnaryMethod::kAll, std::move(params));
@ -61,7 +62,7 @@ TEST_F(UnaryMethodExpressionTest, IsValid) {
}
TEST_F(UnaryMethodExpressionTest, IsValid_NullParam) {
std::vector<std::unique_ptr<Expression>> params;
ExpressionList params;
params.push_back(std::make_unique<IdentifierExpression>("ident"));
params.push_back(nullptr);
@ -70,7 +71,7 @@ TEST_F(UnaryMethodExpressionTest, IsValid_NullParam) {
}
TEST_F(UnaryMethodExpressionTest, IsValid_InvalidParam) {
std::vector<std::unique_ptr<Expression>> params;
ExpressionList params;
params.push_back(std::make_unique<IdentifierExpression>(""));
UnaryMethodExpression u(UnaryMethod::kAll, std::move(params));
@ -84,7 +85,7 @@ TEST_F(UnaryMethodExpressionTest, IsValid_EmptyParams) {
}
TEST_F(UnaryMethodExpressionTest, ToStr) {
std::vector<std::unique_ptr<Expression>> params;
ExpressionList params;
params.push_back(std::make_unique<IdentifierExpression>("ident"));
UnaryMethodExpression u(UnaryMethod::kAll, std::move(params));

View File

@ -20,12 +20,12 @@ namespace ast {
UnlessStatement::UnlessStatement() : Statement() {}
UnlessStatement::UnlessStatement(std::unique_ptr<Expression> condition,
std::vector<std::unique_ptr<Statement>> body)
StatementList body)
: Statement(), condition_(std::move(condition)), body_(std::move(body)) {}
UnlessStatement::UnlessStatement(const Source& source,
std::unique_ptr<Expression> condition,
std::vector<std::unique_ptr<Statement>> body)
StatementList body)
: Statement(source),
condition_(std::move(condition)),
body_(std::move(body)) {}

View File

@ -17,7 +17,6 @@
#include <memory>
#include <utility>
#include <vector>
#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<Expression> condition,
std::vector<std::unique_ptr<Statement>> body);
UnlessStatement(std::unique_ptr<Expression> 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<Expression> condition,
std::vector<std::unique_ptr<Statement>> 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<std::unique_ptr<Statement>> body) {
body_ = std::move(body);
}
void set_body(StatementList body) { body_ = std::move(body); }
/// @returns the body statements
const std::vector<std::unique_ptr<Statement>>& 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<Expression> condition_;
std::vector<std::unique_ptr<Statement>> body_;
StatementList body_;
};
} // namespace ast

View File

@ -27,7 +27,7 @@ using UnlessStatementTest = testing::Test;
TEST_F(UnlessStatementTest, Creation) {
auto ident = std::make_unique<IdentifierExpression>("ident");
std::vector<std::unique_ptr<Statement>> body;
StatementList body;
body.push_back(std::make_unique<NopStatement>());
auto ident_ptr = ident.get();
@ -41,7 +41,7 @@ TEST_F(UnlessStatementTest, Creation) {
TEST_F(UnlessStatementTest, Creation_WithSource) {
auto ident = std::make_unique<IdentifierExpression>("ident");
std::vector<std::unique_ptr<Statement>> body;
StatementList body;
body.push_back(std::make_unique<NopStatement>());
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<IdentifierExpression>("ident");
std::vector<std::unique_ptr<Statement>> body;
StatementList body;
body.push_back(std::make_unique<NopStatement>());
UnlessStatement u(std::move(ident), std::move(body));
@ -65,7 +65,7 @@ TEST_F(UnlessStatementTest, IsValid) {
}
TEST_F(UnlessStatementTest, IsValid_NullCondition) {
std::vector<std::unique_ptr<Statement>> body;
StatementList body;
body.push_back(std::make_unique<NopStatement>());
UnlessStatement u;
@ -75,7 +75,7 @@ TEST_F(UnlessStatementTest, IsValid_NullCondition) {
TEST_F(UnlessStatementTest, IsValid_InvalidCondition) {
auto ident = std::make_unique<IdentifierExpression>("");
std::vector<std::unique_ptr<Statement>> body;
StatementList body;
body.push_back(std::make_unique<NopStatement>());
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<IdentifierExpression>("ident");
std::vector<std::unique_ptr<Statement>> body;
StatementList body;
body.push_back(std::make_unique<NopStatement>());
body.push_back(nullptr);
@ -94,7 +94,7 @@ TEST_F(UnlessStatementTest, IsValid_NullBodyStatement) {
TEST_F(UnlessStatementTest, IsValid_InvalidBodyStatement) {
auto ident = std::make_unique<IdentifierExpression>("ident");
std::vector<std::unique_ptr<Statement>> body;
StatementList body;
body.push_back(std::make_unique<NopStatement>());
body.push_back(std::make_unique<IfStatement>());
@ -104,7 +104,7 @@ TEST_F(UnlessStatementTest, IsValid_InvalidBodyStatement) {
TEST_F(UnlessStatementTest, ToStr) {
auto ident = std::make_unique<IdentifierExpression>("ident");
std::vector<std::unique_ptr<Statement>> body;
StatementList body;
body.push_back(std::make_unique<NopStatement>());
UnlessStatement u(std::move(ident), std::move(body));

View File

@ -19,6 +19,7 @@
#include <ostream>
#include <string>
#include <utility>
#include <vector>
#include "src/ast/expression.h"
#include "src/ast/node.h"
@ -170,6 +171,9 @@ class Variable : public Node {
std::unique_ptr<Expression> constructor_;
};
/// A list of unique variables
using VariableList = std::vector<std::unique_ptr<Variable>>;
} // namespace ast
} // namespace tint

View File

@ -15,8 +15,10 @@
#ifndef SRC_AST_VARIABLE_DECORATION_H_
#define SRC_AST_VARIABLE_DECORATION_H_
#include <memory>
#include <ostream>
#include <string>
#include <vector>
namespace tint {
namespace ast {
@ -57,6 +59,9 @@ class VariableDecoration {
VariableDecoration();
};
/// A list of unique variable decorations
using VariableDecorationList = std::vector<std::unique_ptr<VariableDecoration>>;
} // namespace ast
} // namespace tint

View File

@ -549,7 +549,7 @@ ast::type::Type* ParserImpl::ConvertType(
}
// Compute members
std::vector<std::unique_ptr<ast::StructMember>> 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<std::unique_ptr<ast::StructMemberDecoration>>
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<ast::Variable> ParserImpl::MakeVariable(uint32_t id,
auto ast_var = std::make_unique<ast::Variable>(Name(id), sc, type);
std::vector<std::unique_ptr<ast::VariableDecoration>> 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<std::unique_ptr<ast::Variable>> 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) {

View File

@ -15,6 +15,7 @@
#include "src/reader/wgsl/parser_impl.h"
#include <memory>
#include <vector>
#include "src/ast/array_accessor_expression.h"
#include "src/ast/as_expression.h"
@ -396,9 +397,8 @@ std::unique_ptr<ast::Variable> ParserImpl::global_constant_decl() {
// variable_decoration_list
// : ATTR_LEFT variable_decoration (COMMA variable_decoration)* ATTR_RIGHT
std::vector<std::unique_ptr<ast::VariableDecoration>>
ParserImpl::variable_decoration_list() {
std::vector<std::unique_ptr<ast::VariableDecoration>> 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<std::unique_ptr<ast::StructMember>> ParserImpl::struct_body_decl() {
ast::StructMemberList ParserImpl::struct_body_decl() {
auto t = peek();
if (!t.IsBracketLeft())
return {};
@ -1056,7 +1056,7 @@ std::vector<std::unique_ptr<ast::StructMember>> ParserImpl::struct_body_decl() {
if (t.IsBracketRight())
return {};
std::vector<std::unique_ptr<ast::StructMember>> members;
ast::StructMemberList members;
for (;;) {
auto mem = struct_member();
if (has_error())
@ -1116,8 +1116,7 @@ std::unique_ptr<ast::StructMember> ParserImpl::struct_member() {
// :
// | ATTR_LEFT (struct_member_decoration COMMA)*
// struct_member_decoration ATTR_RIGHT
std::vector<std::unique_ptr<ast::StructMemberDecoration>>
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<std::unique_ptr<ast::StructMemberDecoration>> decos;
ast::StructMemberDecorationList decos;
bool found_offset = false;
for (;;) {
auto deco = struct_member_decoration();
@ -1266,11 +1265,11 @@ std::unique_ptr<ast::Function> ParserImpl::function_header() {
// param_list
// :
// | (variable_ident_decl COMMA)* variable_ident_decl
std::vector<std::unique_ptr<ast::Variable>> ParserImpl::param_list() {
ast::VariableList ParserImpl::param_list() {
auto t = peek();
auto source = t.source();
std::vector<std::unique_ptr<ast::Variable>> 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<std::unique_ptr<ast::Statement>> ParserImpl::body_stmt() {
ast::StatementList ParserImpl::body_stmt() {
auto t = peek();
if (!t.IsBracketLeft())
return {};
@ -1429,8 +1428,8 @@ std::unique_ptr<ast::Expression> ParserImpl::paren_rhs_stmt() {
// statements
// : statement*
std::vector<std::unique_ptr<ast::Statement>> ParserImpl::statements() {
std::vector<std::unique_ptr<ast::Statement>> ret;
ast::StatementList ParserImpl::statements() {
ast::StatementList ret;
for (;;) {
auto stmt = statement();
@ -1782,12 +1781,12 @@ std::unique_ptr<ast::IfStatement> ParserImpl::if_stmt() {
// elseif_stmt
// : ELSE_IF paren_rhs_stmt body_stmt elseif_stmt?
std::vector<std::unique_ptr<ast::ElseStatement>> ParserImpl::elseif_stmt() {
ast::ElseStatementList ParserImpl::elseif_stmt() {
auto t = peek();
if (!t.IsElseIf())
return {};
std::vector<std::unique_ptr<ast::ElseStatement>> ret;
ast::ElseStatementList ret;
for (;;) {
auto source = t.source();
next(); // Consume the peek
@ -1846,7 +1845,7 @@ std::unique_ptr<ast::ElseStatement> ParserImpl::else_stmt() {
// premerge_stmt
// : PREMERGE body_stmt
std::vector<std::unique_ptr<ast::Statement>> ParserImpl::premerge_stmt() {
ast::StatementList ParserImpl::premerge_stmt() {
auto t = peek();
if (!t.IsPremerge())
return {};
@ -1931,7 +1930,7 @@ std::unique_ptr<ast::SwitchStatement> ParserImpl::switch_stmt() {
return nullptr;
}
std::vector<std::unique_ptr<ast::CaseStatement>> body;
ast::CaseStatementList body;
for (;;) {
auto stmt = switch_body();
if (has_error())
@ -2006,8 +2005,8 @@ std::unique_ptr<ast::CaseStatement> ParserImpl::switch_body() {
// :
// | statement case_body
// | FALLTHROUGH SEMICOLON
std::vector<std::unique_ptr<ast::Statement>> ParserImpl::case_body() {
std::vector<std::unique_ptr<ast::Statement>> ret;
ast::StatementList ParserImpl::case_body() {
ast::StatementList ret;
for (;;) {
auto t = peek();
if (t.IsFallthrough()) {
@ -2072,7 +2071,7 @@ std::unique_ptr<ast::LoopStatement> ParserImpl::loop_stmt() {
// continuing_stmt
// : CONTINUING body_stmt
std::vector<std::unique_ptr<ast::Statement>> ParserImpl::continuing_stmt() {
ast::StatementList ParserImpl::continuing_stmt() {
auto t = peek();
if (!t.IsContinuing())
return {};
@ -2148,7 +2147,7 @@ std::unique_ptr<ast::ConstructorExpression> ParserImpl::const_expr() {
return nullptr;
}
std::vector<std::unique_ptr<ast::Expression>> params;
ast::ExpressionList params;
auto param = const_expr();
if (has_error())
return nullptr;
@ -2313,8 +2312,7 @@ std::unique_ptr<ast::Expression> ParserImpl::primary_expression() {
// argument_expression_list
// : (logical_or_expression COMMA)* logical_or_expression
std::vector<std::unique_ptr<ast::Expression>>
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<std::unique_ptr<ast::Expression>> ret;
ast::ExpressionList ret;
ret.push_back(std::move(arg));
for (;;) {
@ -2379,7 +2377,7 @@ std::unique_ptr<ast::Expression> ParserImpl::postfix_expr(
next(); // Consume the peek
t = peek();
std::vector<std::unique_ptr<ast::Expression>> params;
ast::ExpressionList params;
if (!t.IsParenRight() && !t.IsEof()) {
params = argument_expression_list();
if (has_error())
@ -2501,7 +2499,7 @@ std::unique_ptr<ast::Expression> ParserImpl::unary_expression() {
set_error(t, "missing identifier for method call");
return nullptr;
}
std::vector<std::unique_ptr<ast::Expression>> ident;
ast::ExpressionList ident;
ident.push_back(
std::make_unique<ast::IdentifierExpression>(source, t.to_str()));
@ -2531,7 +2529,7 @@ std::unique_ptr<ast::Expression> ParserImpl::unary_expression() {
set_error(t, "missing identifier for method call");
return nullptr;
}
std::vector<std::unique_ptr<ast::Expression>> ident;
ast::ExpressionList ident;
ident.push_back(
std::make_unique<ast::IdentifierExpression>(source, t.to_str()));

View File

@ -20,12 +20,12 @@
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#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<ast::Variable> global_constant_decl();
/// Parses a `variable_decoration_list` grammar element
/// @returns a vector of parsed variable decorations
std::vector<std::unique_ptr<ast::VariableDecoration>>
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<ast::VariableDecoration> 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<std::unique_ptr<ast::StructMember>> struct_body_decl();
ast::StructMemberList struct_body_decl();
/// Parses a `struct_member` grammar element
/// @returns the struct member or nullptr
std::unique_ptr<ast::StructMember> struct_member();
/// Parses a `struct_member_decoration_decl` grammar element
/// @returns the list of decorations
std::vector<std::unique_ptr<ast::StructMemberDecoration>>
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<ast::StructMemberDecoration> struct_member_decoration();
@ -174,7 +172,7 @@ class ParserImpl {
std::unique_ptr<ast::Function> function_header();
/// Parses a `param_list` grammar element
/// @returns the parsed variables
std::vector<std::unique_ptr<ast::Variable>> param_list();
ast::VariableList param_list();
/// Parses a `entry_point_decl` grammar element
/// @returns the EntryPoint or nullptr on error
std::unique_ptr<ast::EntryPoint> 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<std::unique_ptr<ast::Statement>> body_stmt();
ast::StatementList body_stmt();
/// Parses a `paren_rhs_stmt` grammar element
/// @returns the parsed element or nullptr
std::unique_ptr<ast::Expression> paren_rhs_stmt();
/// Parses a `statements` grammar element
/// @returns the statements parsed
std::vector<std::unique_ptr<ast::Statement>> statements();
ast::StatementList statements();
/// Parses a `statement` grammar element
/// @returns the parsed statement or nullptr
std::unique_ptr<ast::Statement> statement();
@ -207,13 +205,13 @@ class ParserImpl {
std::unique_ptr<ast::IfStatement> if_stmt();
/// Parses a `elseif_stmt` grammar element
/// @returns the parsed elements
std::vector<std::unique_ptr<ast::ElseStatement>> elseif_stmt();
ast::ElseStatementList elseif_stmt();
/// Parses a `else_stmt` grammar element
/// @returns the parsed statement or nullptr
std::unique_ptr<ast::ElseStatement> else_stmt();
/// Parses a `premerge_stmt` grammar element
/// @returns the parsed statements
std::vector<std::unique_ptr<ast::Statement>> premerge_stmt();
ast::StatementList premerge_stmt();
/// Parses a `unless_stmt` grammar element
/// @returns the parsed element or nullptr
std::unique_ptr<ast::UnlessStatement> unless_stmt();
@ -228,13 +226,13 @@ class ParserImpl {
std::unique_ptr<ast::CaseStatement> switch_body();
/// Parses a `case_body` grammar element
/// @returns the parsed statements
std::vector<std::unique_ptr<ast::Statement>> case_body();
ast::StatementList case_body();
/// Parses a `loop_stmt` grammar element
/// @returns the parsed loop or nullptr
std::unique_ptr<ast::LoopStatement> loop_stmt();
/// Parses a `continuing_stmt` grammar element
/// @returns the parsed statements
std::vector<std::unique_ptr<ast::Statement>> 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<ast::Literal> const_literal();
@ -246,7 +244,7 @@ class ParserImpl {
std::unique_ptr<ast::Expression> primary_expression();
/// Parses a `argument_expression_list` grammar element
/// @returns the list of arguments
std::vector<std::unique_ptr<ast::Expression>> 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

View File

@ -51,7 +51,7 @@ TEST_F(BuilderTest, Constructor_Type) {
ast::type::F32Type f32;
ast::type::VectorType vec(&f32, 3);
std::vector<std::unique_ptr<ast::Expression>> vals;
ast::ExpressionList vals;
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.0f)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
@ -77,7 +77,7 @@ TEST_F(BuilderTest, Constructor_Type_Dedups) {
ast::type::F32Type f32;
ast::type::VectorType vec(&f32, 3);
std::vector<std::unique_ptr<ast::Expression>> vals;
ast::ExpressionList vals;
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.0f)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
@ -103,7 +103,7 @@ TEST_F(BuilderTest, Constructor_NonConst_Type_Fails) {
std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 3.0f)));
std::vector<std::unique_ptr<ast::Expression>> vals;
ast::ExpressionList vals;
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.0f)));
vals.push_back(std::move(rel));

View File

@ -62,7 +62,7 @@ TEST_F(BuilderTest, FunctionVar_WithConstantConstructor) {
ast::type::F32Type f32;
ast::type::VectorType vec(&f32, 3);
std::vector<std::unique_ptr<ast::Expression>> vals;
ast::ExpressionList vals;
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.0f)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
@ -109,7 +109,7 @@ TEST_F(BuilderTest, DISABLED_FunctionVar_WithNonConstantConstructor) {
std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 3.0f)));
std::vector<std::unique_ptr<ast::Expression>> vals;
ast::ExpressionList vals;
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&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<std::unique_ptr<ast::Expression>> vals;
ast::ExpressionList vals;
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.0f)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(

View File

@ -71,7 +71,7 @@ TEST_F(BuilderTest, GlobalVar_WithConstructor) {
ast::type::F32Type f32;
ast::type::VectorType vec(&f32, 3);
std::vector<std::unique_ptr<ast::Expression>> vals;
ast::ExpressionList vals;
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.0f)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
@ -105,7 +105,7 @@ TEST_F(BuilderTest, GlobalVar_Const) {
ast::type::F32Type f32;
ast::type::VectorType vec(&f32, 3);
std::vector<std::unique_ptr<ast::Expression>> vals;
ast::ExpressionList vals;
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.0f)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
@ -136,7 +136,7 @@ TEST_F(BuilderTest, GlobalVar_WithLocation) {
ast::type::F32Type f32;
auto v =
std::make_unique<ast::Variable>("var", ast::StorageClass::kOutput, &f32);
std::vector<std::unique_ptr<ast::VariableDecoration>> decos;
ast::VariableDecorationList decos;
decos.push_back(std::make_unique<ast::LocationDecoration>(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<ast::Variable>("var", ast::StorageClass::kOutput, &f32);
std::vector<std::unique_ptr<ast::VariableDecoration>> decos;
ast::VariableDecorationList decos;
decos.push_back(std::make_unique<ast::BindingDecoration>(2));
decos.push_back(std::make_unique<ast::SetDecoration>(3));
@ -180,7 +180,7 @@ TEST_F(BuilderTest, GlobalVar_WithBuiltin) {
ast::type::F32Type f32;
auto v =
std::make_unique<ast::Variable>("var", ast::StorageClass::kOutput, &f32);
std::vector<std::unique_ptr<ast::VariableDecoration>> decos;
ast::VariableDecorationList decos;
decos.push_back(
std::make_unique<ast::BuiltinDecoration>(ast::Builtin::kPosition));

View File

@ -36,7 +36,7 @@ TEST_F(BuilderTest, IdentifierExpression_GlobalConst) {
ast::type::F32Type f32;
ast::type::VectorType vec(&f32, 3);
std::vector<std::unique_ptr<ast::Expression>> vals;
ast::ExpressionList vals;
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.0f)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
@ -87,7 +87,7 @@ TEST_F(BuilderTest, IdentifierExpression_FunctionConst) {
ast::type::F32Type f32;
ast::type::VectorType vec(&f32, 3);
std::vector<std::unique_ptr<ast::Expression>> vals;
ast::ExpressionList vals;
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.0f)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(

View File

@ -47,7 +47,7 @@ TEST_F(BuilderTest, Return_WithValue) {
ast::type::F32Type f32;
ast::type::VectorType vec(&f32, 3);
std::vector<std::unique_ptr<ast::Expression>> vals;
ast::ExpressionList vals;
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.0f)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(

View File

@ -277,8 +277,8 @@ TEST_F(BuilderTest_Type, GenerateStruct_Empty) {
TEST_F(BuilderTest_Type, GenerateStruct) {
ast::type::F32Type f32;
std::vector<std::unique_ptr<ast::StructMemberDecoration>> decos;
std::vector<std::unique_ptr<ast::StructMember>> members;
ast::StructMemberDecorationList decos;
ast::StructMemberList members;
members.push_back(
std::make_unique<ast::StructMember>("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<std::unique_ptr<ast::StructMemberDecoration>> decos;
std::vector<std::unique_ptr<ast::StructMember>> members;
ast::StructMemberDecorationList decos;
ast::StructMemberList members;
members.push_back(
std::make_unique<ast::StructMember>("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<std::unique_ptr<ast::StructMemberDecoration>> a_decos;
ast::StructMemberDecorationList a_decos;
a_decos.push_back(std::make_unique<ast::StructMemberOffsetDecoration>(0));
std::vector<std::unique_ptr<ast::StructMemberDecoration>> b_decos;
ast::StructMemberDecorationList b_decos;
b_decos.push_back(std::make_unique<ast::StructMemberOffsetDecoration>(8));
std::vector<std::unique_ptr<ast::StructMember>> members;
ast::StructMemberList members;
members.push_back(
std::make_unique<ast::StructMember>("a", &f32, std::move(a_decos)));
members.push_back(

View File

@ -690,8 +690,7 @@ bool GeneratorImpl::EmitUnaryOp(ast::UnaryOpExpression* expr) {
return true;
}
bool GeneratorImpl::EmitStatementBlock(
const std::vector<std::unique_ptr<ast::Statement>>& 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<std::unique_ptr<ast::Statement>>& statements) {
const ast::StatementList& statements) {
const bool result = EmitStatementBlock(statements);
if (result) {
out_ << std::endl;

View File

@ -15,10 +15,8 @@
#ifndef SRC_WRITER_WGSL_GENERATOR_IMPL_H_
#define SRC_WRITER_WGSL_GENERATOR_IMPL_H_
#include <memory>
#include <sstream>
#include <string>
#include <vector>
#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<std::unique_ptr<ast::Statement>>& 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<std::unique_ptr<ast::Statement>>& statements);
bool EmitStatementBlockAndNewline(const ast::StatementList& statements);
/// Handles statement
/// @param stmt the statement to emit
/// @returns true if the statement was emitted

View File

@ -43,11 +43,11 @@ TEST_F(GeneratorImplTest, EmitAliasType_Struct) {
ast::type::I32Type i32;
ast::type::F32Type f32;
std::vector<std::unique_ptr<ast::StructMember>> members;
ast::StructMemberList members;
members.push_back(std::make_unique<ast::StructMember>(
"a", &f32, std::vector<std::unique_ptr<ast::StructMemberDecoration>>{}));
"a", &f32, ast::StructMemberDecorationList{}));
std::vector<std::unique_ptr<ast::StructMemberDecoration>> b_deco;
ast::StructMemberDecorationList b_deco;
b_deco.push_back(std::make_unique<ast::StructMemberOffsetDecoration>(4));
members.push_back(
std::make_unique<ast::StructMember>("b", &i32, std::move(b_deco)));

View File

@ -37,7 +37,7 @@ TEST_F(GeneratorImplTest, EmitExpression_Call_WithoutParams) {
TEST_F(GeneratorImplTest, EmitExpression_Call_WithParams) {
auto id = std::make_unique<ast::IdentifierExpression>("my_func");
std::vector<std::unique_ptr<ast::Expression>> params;
ast::ExpressionList params;
params.push_back(std::make_unique<ast::IdentifierExpression>("param1"));
params.push_back(std::make_unique<ast::IdentifierExpression>("param2"));
ast::CallExpression call(std::move(id), std::move(params));

View File

@ -13,7 +13,6 @@
// limitations under the License.
#include <memory>
#include <vector>
#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<ast::IntLiteral>(&i32, 5);
std::vector<std::unique_ptr<ast::Statement>> body;
ast::StatementList body;
body.push_back(std::make_unique<ast::BreakStatement>());
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<std::unique_ptr<ast::Statement>> body;
ast::StatementList body;
body.push_back(std::make_unique<ast::BreakStatement>());
c.set_body(std::move(body));

View File

@ -12,9 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <memory>
#include <vector>
#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<ast::FloatLiteral>(&f32, -1.2e-5);
std::vector<std::unique_ptr<ast::Expression>> values;
ast::ExpressionList values;
values.push_back(
std::make_unique<ast::ScalarConstructorExpression>(std::move(lit)));
@ -96,7 +93,7 @@ TEST_F(GeneratorImplTest, EmitConstructor_Type_Bool) {
ast::type::BoolType b;
auto lit = std::make_unique<ast::BoolLiteral>(&b, true);
std::vector<std::unique_ptr<ast::Expression>> values;
ast::ExpressionList values;
values.push_back(
std::make_unique<ast::ScalarConstructorExpression>(std::move(lit)));
@ -111,7 +108,7 @@ TEST_F(GeneratorImplTest, EmitConstructor_Type_Int) {
ast::type::I32Type i32;
auto lit = std::make_unique<ast::IntLiteral>(&i32, -12345);
std::vector<std::unique_ptr<ast::Expression>> values;
ast::ExpressionList values;
values.push_back(
std::make_unique<ast::ScalarConstructorExpression>(std::move(lit)));
@ -126,7 +123,7 @@ TEST_F(GeneratorImplTest, EmitConstructor_Type_Uint) {
ast::type::U32Type u32;
auto lit = std::make_unique<ast::UintLiteral>(&u32, 12345);
std::vector<std::unique_ptr<ast::Expression>> values;
ast::ExpressionList values;
values.push_back(
std::make_unique<ast::ScalarConstructorExpression>(std::move(lit)));
@ -144,7 +141,7 @@ TEST_F(GeneratorImplTest, EmitConstructor_Type_Vec) {
auto lit1 = std::make_unique<ast::FloatLiteral>(&f32, 1.f);
auto lit2 = std::make_unique<ast::FloatLiteral>(&f32, 2.f);
auto lit3 = std::make_unique<ast::FloatLiteral>(&f32, 3.f);
std::vector<std::unique_ptr<ast::Expression>> values;
ast::ExpressionList values;
values.push_back(
std::make_unique<ast::ScalarConstructorExpression>(std::move(lit1)));
values.push_back(
@ -165,13 +162,13 @@ TEST_F(GeneratorImplTest, EmitConstructor_Type_Mat) {
ast::type::VectorType vec(&f32, 2);
std::vector<std::unique_ptr<ast::Expression>> mat_values;
ast::ExpressionList mat_values;
for (size_t i = 0; i < 3; i++) {
auto lit1 = std::make_unique<ast::FloatLiteral>(&f32, 1.f + (i * 2));
auto lit2 = std::make_unique<ast::FloatLiteral>(&f32, 2.f + (i * 2));
std::vector<std::unique_ptr<ast::Expression>> values;
ast::ExpressionList values;
values.push_back(
std::make_unique<ast::ScalarConstructorExpression>(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<std::unique_ptr<ast::Expression>> ary_values;
ast::ExpressionList ary_values;
for (size_t i = 0; i < 3; i++) {
auto lit1 = std::make_unique<ast::FloatLiteral>(&f32, 1.f + (i * 3));
auto lit2 = std::make_unique<ast::FloatLiteral>(&f32, 2.f + (i * 3));
auto lit3 = std::make_unique<ast::FloatLiteral>(&f32, 3.f + (i * 3));
std::vector<std::unique_ptr<ast::Expression>> values;
ast::ExpressionList values;
values.push_back(
std::make_unique<ast::ScalarConstructorExpression>(std::move(lit1)));
values.push_back(

View File

@ -13,7 +13,6 @@
// limitations under the License.
#include <memory>
#include <vector>
#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<std::unique_ptr<ast::Statement>> body;
ast::StatementList body;
body.push_back(std::make_unique<ast::KillStatement>());
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<ast::IdentifierExpression>("cond");
std::vector<std::unique_ptr<ast::Statement>> body;
ast::StatementList body;
body.push_back(std::make_unique<ast::KillStatement>());
ast::ElseStatement e(std::move(cond), std::move(body));

View File

@ -30,7 +30,7 @@ namespace {
using GeneratorImplTest = testing::Test;
TEST_F(GeneratorImplTest, Emit_Function) {
std::vector<std::unique_ptr<ast::Statement>> body;
ast::StatementList body;
body.push_back(std::make_unique<ast::KillStatement>());
body.push_back(std::make_unique<ast::ReturnStatement>());
@ -50,13 +50,13 @@ TEST_F(GeneratorImplTest, Emit_Function) {
}
TEST_F(GeneratorImplTest, Emit_Function_WithParams) {
std::vector<std::unique_ptr<ast::Statement>> body;
ast::StatementList body;
body.push_back(std::make_unique<ast::KillStatement>());
body.push_back(std::make_unique<ast::ReturnStatement>());
ast::type::F32Type f32;
ast::type::I32Type i32;
std::vector<std::unique_ptr<ast::Variable>> params;
ast::VariableList params;
params.push_back(
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &f32));
params.push_back(

View File

@ -12,9 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <memory>
#include <vector>
#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<ast::IdentifierExpression>("cond");
std::vector<std::unique_ptr<ast::Statement>> body;
ast::StatementList body;
body.push_back(std::make_unique<ast::KillStatement>());
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<ast::IdentifierExpression>("else_cond");
std::vector<std::unique_ptr<ast::Statement>> else_body;
ast::StatementList else_body;
else_body.push_back(std::make_unique<ast::KillStatement>());
std::vector<std::unique_ptr<ast::ElseStatement>> elses;
ast::ElseStatementList elses;
elses.push_back(std::make_unique<ast::ElseStatement>(std::move(else_cond),
std::move(else_body)));
auto cond = std::make_unique<ast::IdentifierExpression>("cond");
std::vector<std::unique_ptr<ast::Statement>> body;
ast::StatementList body;
body.push_back(std::make_unique<ast::KillStatement>());
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<std::unique_ptr<ast::Statement>> else_body;
ast::StatementList else_body;
else_body.push_back(std::make_unique<ast::KillStatement>());
std::vector<std::unique_ptr<ast::ElseStatement>> elses;
ast::ElseStatementList elses;
elses.push_back(std::make_unique<ast::ElseStatement>(std::move(else_body)));
auto cond = std::make_unique<ast::IdentifierExpression>("cond");
std::vector<std::unique_ptr<ast::Statement>> body;
ast::StatementList body;
body.push_back(std::make_unique<ast::KillStatement>());
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<ast::IdentifierExpression>("else_cond");
std::vector<std::unique_ptr<ast::Statement>> else_body;
ast::StatementList else_body;
else_body.push_back(std::make_unique<ast::KillStatement>());
std::vector<std::unique_ptr<ast::Statement>> else_body_2;
ast::StatementList else_body_2;
else_body_2.push_back(std::make_unique<ast::KillStatement>());
std::vector<std::unique_ptr<ast::ElseStatement>> elses;
ast::ElseStatementList elses;
elses.push_back(std::make_unique<ast::ElseStatement>(std::move(else_cond),
std::move(else_body)));
elses.push_back(std::make_unique<ast::ElseStatement>(std::move(else_body_2)));
auto cond = std::make_unique<ast::IdentifierExpression>("cond");
std::vector<std::unique_ptr<ast::Statement>> body;
ast::StatementList body;
body.push_back(std::make_unique<ast::KillStatement>());
ast::IfStatement i(std::move(cond), std::move(body));

View File

@ -13,7 +13,6 @@
// limitations under the License.
#include <memory>
#include <vector>
#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<std::unique_ptr<ast::Statement>> body;
ast::StatementList body;
body.push_back(std::make_unique<ast::KillStatement>());
ast::LoopStatement l(std::move(body), {});
@ -45,10 +44,10 @@ TEST_F(GeneratorImplTest, Emit_Loop) {
}
TEST_F(GeneratorImplTest, Emit_LoopWithContinuing) {
std::vector<std::unique_ptr<ast::Statement>> body;
ast::StatementList body;
body.push_back(std::make_unique<ast::KillStatement>());
std::vector<std::unique_ptr<ast::Statement>> continuing;
ast::StatementList continuing;
continuing.push_back(std::make_unique<ast::NopStatement>());
ast::LoopStatement l(std::move(body), std::move(continuing));

View File

@ -13,7 +13,6 @@
// limitations under the License.
#include <memory>
#include <vector>
#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<ast::IdentifierExpression>("cond");
std::vector<std::unique_ptr<ast::Statement>> body;
ast::StatementList body;
body.push_back(std::make_unique<ast::NopStatement>());
body.push_back(std::make_unique<ast::KillStatement>());

View File

@ -13,7 +13,6 @@
// limitations under the License.
#include <memory>
#include <vector>
#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<ast::CaseStatement>();
std::vector<std::unique_ptr<ast::Statement>> def_body;
ast::StatementList def_body;
def_body.push_back(std::make_unique<ast::BreakStatement>());
def->set_body(std::move(def_body));
ast::type::I32Type i32;
auto case_val = std::make_unique<ast::IntLiteral>(&i32, 5);
std::vector<std::unique_ptr<ast::Statement>> case_body;
ast::StatementList case_body;
case_body.push_back(std::make_unique<ast::BreakStatement>());
auto case_stmt = std::make_unique<ast::CaseStatement>(std::move(case_val),
std::move(case_body));
std::vector<std::unique_ptr<ast::CaseStatement>> body;
ast::CaseStatementList body;
body.push_back(std::move(case_stmt));
body.push_back(std::move(def));

View File

@ -110,11 +110,11 @@ TEST_F(GeneratorImplTest, EmitType_Struct) {
ast::type::I32Type i32;
ast::type::F32Type f32;
std::vector<std::unique_ptr<ast::StructMember>> members;
ast::StructMemberList members;
members.push_back(std::make_unique<ast::StructMember>(
"a", &i32, std::vector<std::unique_ptr<ast::StructMemberDecoration>>{}));
"a", &i32, ast::StructMemberDecorationList{}));
std::vector<std::unique_ptr<ast::StructMemberDecoration>> b_deco;
ast::StructMemberDecorationList b_deco;
b_deco.push_back(std::make_unique<ast::StructMemberOffsetDecoration>(4));
members.push_back(
std::make_unique<ast::StructMember>("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<std::unique_ptr<ast::StructMember>> members;
ast::StructMemberList members;
members.push_back(std::make_unique<ast::StructMember>(
"a", &i32, std::vector<std::unique_ptr<ast::StructMemberDecoration>>{}));
"a", &i32, ast::StructMemberDecorationList{}));
std::vector<std::unique_ptr<ast::StructMemberDecoration>> b_deco;
ast::StructMemberDecorationList b_deco;
b_deco.push_back(std::make_unique<ast::StructMemberOffsetDecoration>(4));
members.push_back(
std::make_unique<ast::StructMember>("b", &f32, std::move(b_deco)));

View File

@ -13,7 +13,6 @@
// limitations under the License.
#include <memory>
#include <vector>
#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<ast::IdentifierExpression>("expr");
std::vector<std::unique_ptr<ast::Expression>> 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<ast::IdentifierExpression>("expr1");
auto expr2 = std::make_unique<ast::IdentifierExpression>("expr2");
std::vector<std::unique_ptr<ast::Expression>> ops;
ast::ExpressionList ops;
ops.push_back(std::move(expr1));
ops.push_back(std::move(expr2));

View File

@ -13,7 +13,6 @@
// limitations under the License.
#include <memory>
#include <vector>
#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<ast::IdentifierExpression>("cond");
std::vector<std::unique_ptr<ast::Statement>> body;
ast::StatementList body;
body.push_back(std::make_unique<ast::NopStatement>());
body.push_back(std::make_unique<ast::KillStatement>());

View File

@ -13,7 +13,6 @@
// limitations under the License.
#include <memory>
#include <vector>
#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<std::unique_ptr<ast::VariableDecoration>> decos;
ast::VariableDecorationList decos;
decos.push_back(std::make_unique<ast::LocationDecoration>(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<std::unique_ptr<ast::VariableDecoration>> decos;
ast::VariableDecorationList decos;
decos.push_back(
std::make_unique<ast::BuiltinDecoration>(ast::Builtin::kPosition));
decos.push_back(std::make_unique<ast::BindingDecoration>(0));