Big cleanup now that AST nodes are raw pointers

Remove all redundant std::move()s. I've also removed calls to
std::move() in tests, even if they act as an optimization. This is for
two reasons:
(a) Performance is not important for testing, and this helps with
    readability.
(b) A whole bunch tests were relying on std::move() clearing vectors so
    they can be repopulated and used again. This is undefined behavior:

> Objects of types defined in the C++ standard library may be moved from
> (12.8). Move operations may be explicitly specified or implicitly
> generated. Unless otherwise specified, such moved-from objects shall
> be placed in a valid but unspecified state.

All of these UB cases have been fixed.

Removed all duplicate variables left over from:
  `auto* foo_ptr = foo.get()`
which became:
  `auto* foo_ptr = foo`

Bug: tint:322
Change-Id: Ibd08a2379671382320fd4d8da296ccc6a378b8af
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32900
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton
2020-11-16 16:41:47 +00:00
committed by Commit Bot service account
parent b053acf796
commit 4bfe461646
130 changed files with 3078 additions and 3708 deletions

View File

@@ -517,11 +517,10 @@ void FunctionEmitter::PushGuard(const std::string& guard_name,
auto* cond = create<ast::IdentifierExpression>(guard_name);
auto* body = create<ast::BlockStatement>();
auto* const guard_stmt =
AddStatement(create<ast::IfStatement>(std::move(cond), std::move(body)))
->AsIf();
AddStatement(create<ast::IfStatement>(cond, body))->AsIf();
PushNewStatementBlock(top.construct_, end_id,
[guard_stmt](StatementBlock* s) {
guard_stmt->set_body(std::move(s->statements_));
guard_stmt->set_body(s->statements_);
});
}
@@ -531,12 +530,11 @@ void FunctionEmitter::PushTrueGuard(uint32_t end_id) {
auto* cond = MakeTrue();
auto* body = create<ast::BlockStatement>();
auto* const guard_stmt =
AddStatement(create<ast::IfStatement>(std::move(cond), std::move(body)))
->AsIf();
AddStatement(create<ast::IfStatement>(cond, body))->AsIf();
guard_stmt->set_condition(MakeTrue());
PushNewStatementBlock(top.construct_, end_id,
[guard_stmt](StatementBlock* s) {
guard_stmt->set_body(std::move(s->statements_));
guard_stmt->set_body(s->statements_);
});
}
@@ -549,7 +547,7 @@ ast::Statement* FunctionEmitter::AddStatement(ast::Statement* statement) {
assert(!statements_stack_.empty());
auto* result = statement;
if (result != nullptr) {
statements_stack_.back().statements_->append(std::move(statement));
statements_stack_.back().statements_->append(statement);
}
return result;
}
@@ -557,7 +555,7 @@ ast::Statement* FunctionEmitter::AddStatement(ast::Statement* statement) {
ast::Statement* FunctionEmitter::AddStatementForInstruction(
ast::Statement* statement,
const spvtools::opt::Instruction& inst) {
auto* node = AddStatement(std::move(statement));
auto* node = AddStatement(statement);
ApplySourceForInstruction(node, inst);
return node;
}
@@ -592,8 +590,8 @@ bool FunctionEmitter::Emit() {
"element but has "
<< statements_stack_.size();
}
auto* body = std::move(statements_stack_[0].statements_);
parser_impl_.get_module().functions().back()->set_body(std::move(body));
auto* body = statements_stack_[0].statements_;
parser_impl_.get_module().functions().back()->set_body(body);
// Maintain the invariant by repopulating the one and only element.
statements_stack_.clear();
PushNewStatementBlock(constructs_[0].get(), 0, nullptr);
@@ -635,7 +633,7 @@ bool FunctionEmitter::EmitFunctionDeclaration() {
param->result_id(), ast::StorageClass::kNone, ast_type);
// Parameters are treated as const declarations.
ast_param->set_is_const(true);
ast_params.emplace_back(std::move(ast_param));
ast_params.emplace_back(ast_param);
// The value is accessible by name.
identifier_values_.insert(param->result_id());
} else {
@@ -655,7 +653,7 @@ bool FunctionEmitter::EmitFunctionDeclaration() {
create<ast::StageDecoration>(ep_info_->stage, Source{}));
}
ast_module_.AddFunction(std::move(ast_fn));
ast_module_.AddFunction(ast_fn);
return success();
}
@@ -1704,8 +1702,8 @@ bool FunctionEmitter::EmitFunctionVariables() {
parser_impl_.MakeConstantExpression(inst.GetSingleWordInOperand(1))
.expr);
}
auto* var_decl_stmt = create<ast::VariableDeclStatement>(std::move(var));
AddStatementForInstruction(std::move(var_decl_stmt), inst);
auto* var_decl_stmt = create<ast::VariableDeclStatement>(var);
AddStatementForInstruction(var_decl_stmt, inst);
// Save this as an already-named value.
identifier_values_.insert(inst.result_id());
}
@@ -1972,8 +1970,8 @@ bool FunctionEmitter::EmitIfStart(const BlockInfo& block_info) {
auto* guard_var = create<ast::Variable>(
guard_name, ast::StorageClass::kFunction, parser_impl_.BoolType());
guard_var->set_constructor(MakeTrue());
auto* guard_decl = create<ast::VariableDeclStatement>(std::move(guard_var));
AddStatement(std::move(guard_decl));
auto* guard_decl = create<ast::VariableDeclStatement>(guard_var);
AddStatement(guard_decl);
}
const auto condition_id =
@@ -1981,8 +1979,7 @@ bool FunctionEmitter::EmitIfStart(const BlockInfo& block_info) {
auto* cond = MakeExpression(condition_id).expr;
auto* body = create<ast::BlockStatement>();
auto* const if_stmt =
AddStatement(create<ast::IfStatement>(std::move(cond), std::move(body)))
->AsIf();
AddStatement(create<ast::IfStatement>(cond, body))->AsIf();
// Generate the code for the condition.
@@ -2029,7 +2026,7 @@ bool FunctionEmitter::EmitIfStart(const BlockInfo& block_info) {
// The "then" consists of the statement list
// from the top of statments stack, without an
// elseif condition.
if_stmt->set_body(std::move(s->statements_));
if_stmt->set_body(s->statements_);
});
};
@@ -2043,8 +2040,8 @@ bool FunctionEmitter::EmitIfStart(const BlockInfo& block_info) {
// statments stack, without an elseif condition.
ast::ElseStatementList else_stmts;
else_stmts.emplace_back(
create<ast::ElseStatement>(nullptr, std::move(s->statements_)));
if_stmt->set_else_statements(std::move(else_stmts));
create<ast::ElseStatement>(nullptr, s->statements_));
if_stmt->set_else_statements(else_stmts);
}
});
};
@@ -2099,7 +2096,7 @@ bool FunctionEmitter::EmitSwitchStart(const BlockInfo& block_info) {
const auto selector_id = branch->GetSingleWordInOperand(0);
// Generate the code for the selector.
auto selector = MakeExpression(selector_id);
switch_stmt->set_condition(std::move(selector.expr));
switch_stmt->set_condition(selector.expr);
// First, push the statement block for the entire switch. All the actual
// work is done by completion actions of the case/default clauses.
@@ -2177,7 +2174,7 @@ bool FunctionEmitter::EmitSwitchStart(const BlockInfo& block_info) {
create<ast::SintLiteral>(selector.type, value32));
}
}
clause->set_selectors(std::move(selectors));
clause->set_selectors(selectors);
}
// Where does this clause end?
@@ -2185,7 +2182,7 @@ bool FunctionEmitter::EmitSwitchStart(const BlockInfo& block_info) {
: construct->end_id;
PushNewStatementBlock(construct, end_id, [clause](StatementBlock* s) {
clause->set_body(std::move(s->statements_));
clause->set_body(s->statements_);
});
if ((default_info == clause_heads[i]) && has_selectors &&
@@ -2193,8 +2190,8 @@ bool FunctionEmitter::EmitSwitchStart(const BlockInfo& block_info) {
// Generate a default clause with a just fallthrough.
auto* stmts = create<ast::BlockStatement>();
stmts->append(create<ast::FallthroughStatement>());
auto* case_stmt = create<ast::CaseStatement>(std::move(stmts));
cases->emplace_back(std::move(case_stmt));
auto* case_stmt = create<ast::CaseStatement>(stmts);
cases->emplace_back(case_stmt);
}
if (i == 0) {
@@ -2216,7 +2213,7 @@ bool FunctionEmitter::EmitLoopStart(const Construct* construct) {
->AsLoop();
PushNewStatementBlock(
construct, construct->end_id,
[loop](StatementBlock* s) { loop->set_body(std::move(s->statements_)); });
[loop](StatementBlock* s) { loop->set_body(s->statements_); });
return success();
}
@@ -2229,10 +2226,9 @@ bool FunctionEmitter::EmitContinuingStart(const Construct* construct) {
"expected loop on top of stack";
}
auto* loop = loop_candidate->AsLoop();
PushNewStatementBlock(construct, construct->end_id,
[loop](StatementBlock* s) {
loop->set_continuing(std::move(s->statements_));
});
PushNewStatementBlock(
construct, construct->end_id,
[loop](StatementBlock* s) { loop->set_continuing(s->statements_); });
return success();
}
@@ -2244,7 +2240,7 @@ bool FunctionEmitter::EmitNormalTerminator(const BlockInfo& block_info) {
return true;
case SpvOpReturnValue: {
auto value = MakeExpression(terminator.GetSingleWordInOperand(0));
AddStatement(create<ast::ReturnStatement>(std::move(value.expr)));
AddStatement(create<ast::ReturnStatement>(value.expr));
}
return true;
case SpvOpKill:
@@ -2296,11 +2292,11 @@ bool FunctionEmitter::EmitNormalTerminator(const BlockInfo& block_info) {
// The fallthrough case is special because WGSL requires the fallthrough
// statement to be last in the case clause.
if (true_kind == EdgeKind::kCaseFallThrough) {
return EmitConditionalCaseFallThrough(block_info, std::move(cond),
false_kind, *false_info, true);
return EmitConditionalCaseFallThrough(block_info, cond, false_kind,
*false_info, true);
} else if (false_kind == EdgeKind::kCaseFallThrough) {
return EmitConditionalCaseFallThrough(block_info, std::move(cond),
true_kind, *true_info, false);
return EmitConditionalCaseFallThrough(block_info, cond, true_kind,
*true_info, false);
}
// At this point, at most one edge is kForward or kIfBreak.
@@ -2317,8 +2313,7 @@ bool FunctionEmitter::EmitNormalTerminator(const BlockInfo& block_info) {
auto* false_branch =
MakeBranchDetailed(block_info, *false_info, false, &flow_guard);
AddStatement(MakeSimpleIf(std::move(cond), std::move(true_branch),
std::move(false_branch)));
AddStatement(MakeSimpleIf(cond, true_branch, false_branch));
if (!flow_guard.empty()) {
PushGuard(flow_guard, statements_stack_.back().end_id_);
}
@@ -2413,20 +2408,19 @@ ast::Statement* FunctionEmitter::MakeSimpleIf(ast::Expression* condition,
if ((then_stmt == nullptr) && (else_stmt == nullptr)) {
return nullptr;
}
auto* if_stmt = create<ast::IfStatement>(std::move(condition),
create<ast::BlockStatement>());
auto* if_stmt =
create<ast::IfStatement>(condition, create<ast::BlockStatement>());
if (then_stmt != nullptr) {
auto* stmts = create<ast::BlockStatement>();
stmts->append(std::move(then_stmt));
if_stmt->set_body(std::move(stmts));
stmts->append(then_stmt);
if_stmt->set_body(stmts);
}
if (else_stmt != nullptr) {
auto* stmts = create<ast::BlockStatement>();
stmts->append(std::move(else_stmt));
stmts->append(else_stmt);
ast::ElseStatementList else_stmts;
else_stmts.emplace_back(
create<ast::ElseStatement>(nullptr, std::move(stmts)));
if_stmt->set_else_statements(std::move(else_stmts));
else_stmts.emplace_back(create<ast::ElseStatement>(nullptr, stmts));
if_stmt->set_else_statements(else_stmts);
}
return if_stmt;
}
@@ -2466,11 +2460,9 @@ bool FunctionEmitter::EmitConditionalCaseFallThrough(
<< int(other_edge_kind);
}
if (fall_through_is_true_branch) {
AddStatement(
MakeSimpleIf(std::move(cond), nullptr, std::move(other_branch)));
AddStatement(MakeSimpleIf(cond, nullptr, other_branch));
} else {
AddStatement(
MakeSimpleIf(std::move(cond), std::move(other_branch), nullptr));
AddStatement(MakeSimpleIf(cond, other_branch, nullptr));
}
AddStatement(create<ast::FallthroughStatement>());
@@ -2513,7 +2505,7 @@ bool FunctionEmitter::EmitStatementsInBasicBlock(const BlockInfo& block_info,
auto* var =
create<ast::Variable>(phi_var_name, ast::StorageClass::kFunction,
parser_impl_.ConvertType(def_inst->type_id()));
AddStatement(create<ast::VariableDeclStatement>(std::move(var)));
AddStatement(create<ast::VariableDeclStatement>(var));
}
// Emit regular statements.
@@ -2544,7 +2536,7 @@ bool FunctionEmitter::EmitStatementsInBasicBlock(const BlockInfo& block_info,
const auto var_name = GetDefInfo(assignment.phi_id)->phi_var;
auto expr = MakeExpression(assignment.value);
AddStatement(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(var_name), std::move(expr.expr)));
create<ast::IdentifierExpression>(var_name), expr.expr));
}
}
@@ -2563,10 +2555,10 @@ bool FunctionEmitter::EmitConstDefinition(
if (!ast_const) {
return false;
}
ast_const->set_constructor(std::move(ast_expr.expr));
ast_const->set_constructor(ast_expr.expr);
ast_const->set_is_const(true);
AddStatementForInstruction(
create<ast::VariableDeclStatement>(std::move(ast_const)), inst);
AddStatementForInstruction(create<ast::VariableDeclStatement>(ast_const),
inst);
// Save this as an already-named value.
identifier_values_.insert(inst.result_id());
return success();
@@ -2582,11 +2574,11 @@ bool FunctionEmitter::EmitConstDefOrWriteToHoistedVar(
AddStatementForInstruction(
create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(namer_.Name(result_id)),
std::move(ast_expr.expr)),
ast_expr.expr),
inst);
return true;
}
return EmitConstDefinition(inst, std::move(ast_expr));
return EmitConstDefinition(inst, ast_expr);
}
bool FunctionEmitter::EmitStatement(const spvtools::opt::Instruction& inst) {
@@ -2615,13 +2607,11 @@ bool FunctionEmitter::EmitStatement(const spvtools::opt::Instruction& inst) {
def_info->num_uses != 1) {
// Generate a const definition or an assignment to a hoisted definition
// now and later use the const or variable name at the uses of this value.
return EmitConstDefOrWriteToHoistedVar(inst,
std::move(combinatorial_expr));
return EmitConstDefOrWriteToHoistedVar(inst, combinatorial_expr);
}
// It is harmless to defer emitting the expression until it's used.
// Any supporting statements have already been emitted.
singly_used_values_.insert(
std::make_pair(result_id, std::move(combinatorial_expr)));
singly_used_values_.insert(std::make_pair(result_id, combinatorial_expr));
return success();
}
if (failed()) {
@@ -2646,9 +2636,8 @@ bool FunctionEmitter::EmitStatement(const spvtools::opt::Instruction& inst) {
// TODO(dneto): Order of evaluation?
auto lhs = MakeExpression(ptr_id);
auto rhs = MakeExpression(value_id);
AddStatementForInstruction(create<ast::AssignmentStatement>(
std::move(lhs.expr), std::move(rhs.expr)),
inst);
AddStatementForInstruction(
create<ast::AssignmentStatement>(lhs.expr, rhs.expr), inst);
return success();
}
case SpvOpLoad: {
@@ -2658,7 +2647,7 @@ bool FunctionEmitter::EmitStatement(const spvtools::opt::Instruction& inst) {
// The load result type is the pointee type of its operand.
assert(expr.type->IsPointer());
expr.type = expr.type->AsPointer()->type();
return EmitConstDefOrWriteToHoistedVar(inst, std::move(expr));
return EmitConstDefOrWriteToHoistedVar(inst, expr);
}
case SpvOpCopyObject: {
// Arguably, OpCopyObject is purely combinatorial. On the other hand,
@@ -2666,14 +2655,14 @@ bool FunctionEmitter::EmitStatement(const spvtools::opt::Instruction& inst) {
// a new named constant definition.
auto expr = MakeExpression(inst.GetSingleWordInOperand(0));
expr.type = RemapStorageClass(expr.type, result_id);
return EmitConstDefOrWriteToHoistedVar(inst, std::move(expr));
return EmitConstDefOrWriteToHoistedVar(inst, expr);
}
case SpvOpPhi: {
// Emit a read from the associated state variable.
TypedExpression expr{
parser_impl_.ConvertType(inst.type_id()),
create<ast::IdentifierExpression>(def_info->phi_var)};
return EmitConstDefOrWriteToHoistedVar(inst, std::move(expr));
return EmitConstDefOrWriteToHoistedVar(inst, expr);
}
case SpvOpFunctionCall:
return EmitFunctionCall(inst);
@@ -2706,21 +2695,18 @@ TypedExpression FunctionEmitter::MaybeEmitCombinatorialValue(
if (binary_op != ast::BinaryOp::kNone) {
auto arg0 = MakeOperand(inst, 0);
auto arg1 = MakeOperand(inst, 1);
auto* binary_expr = create<ast::BinaryExpression>(
binary_op, std::move(arg0.expr), std::move(arg1.expr));
TypedExpression result{ast_type, std::move(binary_expr)};
return parser_impl_.RectifyForcedResultType(std::move(result), opcode,
arg0.type);
auto* binary_expr =
create<ast::BinaryExpression>(binary_op, arg0.expr, arg1.expr);
TypedExpression result{ast_type, binary_expr};
return parser_impl_.RectifyForcedResultType(result, opcode, arg0.type);
}
auto unary_op = ast::UnaryOp::kNegation;
if (GetUnaryOp(opcode, &unary_op)) {
auto arg0 = MakeOperand(inst, 0);
auto* unary_expr =
create<ast::UnaryOpExpression>(unary_op, std::move(arg0.expr));
TypedExpression result{ast_type, std::move(unary_expr)};
return parser_impl_.RectifyForcedResultType(std::move(result), opcode,
arg0.type);
auto* unary_expr = create<ast::UnaryOpExpression>(unary_op, arg0.expr);
TypedExpression result{ast_type, unary_expr};
return parser_impl_.RectifyForcedResultType(result, opcode, arg0.type);
}
const char* unary_builtin_name = GetUnaryBuiltInFunctionName(opcode);
@@ -2750,11 +2736,11 @@ TypedExpression FunctionEmitter::MaybeEmitCombinatorialValue(
if (negated_op != ast::BinaryOp::kNone) {
auto arg0 = MakeOperand(inst, 0);
auto arg1 = MakeOperand(inst, 1);
auto* binary_expr = create<ast::BinaryExpression>(
negated_op, std::move(arg0.expr), std::move(arg1.expr));
auto* negated_expr = create<ast::UnaryOpExpression>(ast::UnaryOp::kNot,
std::move(binary_expr));
return {ast_type, std::move(negated_expr)};
auto* binary_expr =
create<ast::BinaryExpression>(negated_op, arg0.expr, arg1.expr);
auto* negated_expr =
create<ast::UnaryOpExpression>(ast::UnaryOp::kNot, binary_expr);
return {ast_type, negated_expr};
}
if (opcode == SpvOpExtInst) {
@@ -2836,9 +2822,8 @@ TypedExpression FunctionEmitter::EmitGlslStd450ExtInst(
operands.emplace_back(MakeOperand(inst, iarg).expr);
}
auto* ast_type = parser_impl_.ConvertType(inst.type_id());
auto* call =
create<ast::CallExpression>(std::move(func), std::move(operands));
return {ast_type, std::move(call)};
auto* call = create<ast::CallExpression>(func, std::move(operands));
return {ast_type, call};
}
TypedExpression FunctionEmitter::MakeAccessChain(
@@ -2956,13 +2941,12 @@ TypedExpression FunctionEmitter::MakeAccessChain(
}
auto* letter_index =
create<ast::IdentifierExpression>(swizzles[index_const_val]);
next_expr = create<ast::MemberAccessorExpression>(
std::move(current_expr.expr), std::move(letter_index));
next_expr = create<ast::MemberAccessorExpression>(current_expr.expr,
letter_index);
} else {
// Non-constant index. Use array syntax
next_expr = create<ast::ArrayAccessorExpression>(
std::move(current_expr.expr),
std::move(MakeOperand(inst, index).expr));
current_expr.expr, MakeOperand(inst, index).expr);
}
// All vector components are the same type.
pointee_type_id = pointee_type_inst->GetSingleWordInOperand(0);
@@ -2970,21 +2954,18 @@ TypedExpression FunctionEmitter::MakeAccessChain(
case SpvOpTypeMatrix:
// Use array syntax.
next_expr = create<ast::ArrayAccessorExpression>(
std::move(current_expr.expr),
std::move(MakeOperand(inst, index).expr));
current_expr.expr, MakeOperand(inst, index).expr);
// All matrix components are the same type.
pointee_type_id = pointee_type_inst->GetSingleWordInOperand(0);
break;
case SpvOpTypeArray:
next_expr = create<ast::ArrayAccessorExpression>(
std::move(current_expr.expr),
std::move(MakeOperand(inst, index).expr));
current_expr.expr, MakeOperand(inst, index).expr);
pointee_type_id = pointee_type_inst->GetSingleWordInOperand(0);
break;
case SpvOpTypeRuntimeArray:
next_expr = create<ast::ArrayAccessorExpression>(
std::move(current_expr.expr),
std::move(MakeOperand(inst, index).expr));
current_expr.expr, MakeOperand(inst, index).expr);
pointee_type_id = pointee_type_inst->GetSingleWordInOperand(0);
break;
case SpvOpTypeStruct: {
@@ -3005,8 +2986,8 @@ TypedExpression FunctionEmitter::MakeAccessChain(
auto* member_access = create<ast::IdentifierExpression>(
namer_.GetMemberName(pointee_type_id, uint32_t(index_const_val)));
next_expr = create<ast::MemberAccessorExpression>(
std::move(current_expr.expr), std::move(member_access));
next_expr = create<ast::MemberAccessorExpression>(current_expr.expr,
member_access);
pointee_type_id = pointee_type_inst->GetSingleWordInOperand(
static_cast<uint32_t>(index_const_val));
break;
@@ -3021,7 +3002,7 @@ TypedExpression FunctionEmitter::MakeAccessChain(
auto* ast_pointer_type = parser_impl_.ConvertType(pointer_type_id);
assert(ast_pointer_type);
assert(ast_pointer_type->IsPointer());
current_expr = TypedExpression{ast_pointer_type, std::move(next_expr)};
current_expr = TypedExpression{ast_pointer_type, next_expr};
}
return current_expr;
}
@@ -3080,8 +3061,8 @@ TypedExpression FunctionEmitter::MakeCompositeExtract(
}
auto* letter_index =
create<ast::IdentifierExpression>(swizzles[index_val]);
next_expr = create<ast::MemberAccessorExpression>(
std::move(current_expr.expr), std::move(letter_index));
next_expr = create<ast::MemberAccessorExpression>(current_expr.expr,
letter_index);
// All vector components are the same type.
current_type_id = current_type_inst->GetSingleWordInOperand(0);
break;
@@ -3101,8 +3082,8 @@ TypedExpression FunctionEmitter::MakeCompositeExtract(
<< ((sizeof(swizzles) / sizeof(swizzles[0])) - 1);
}
// Use array syntax.
next_expr = create<ast::ArrayAccessorExpression>(
std::move(current_expr.expr), make_index(index_val));
next_expr = create<ast::ArrayAccessorExpression>(current_expr.expr,
make_index(index_val));
// All matrix components are the same type.
current_type_id = current_type_inst->GetSingleWordInOperand(0);
break;
@@ -3111,8 +3092,8 @@ TypedExpression FunctionEmitter::MakeCompositeExtract(
// The array size could be a spec constant, and so it's not always
// statically checkable. Instead, rely on a runtime index clamp
// or runtime check to keep this safe.
next_expr = create<ast::ArrayAccessorExpression>(
std::move(current_expr.expr), make_index(index_val));
next_expr = create<ast::ArrayAccessorExpression>(current_expr.expr,
make_index(index_val));
current_type_id = current_type_inst->GetSingleWordInOperand(0);
break;
case SpvOpTypeRuntimeArray:
@@ -3129,8 +3110,8 @@ TypedExpression FunctionEmitter::MakeCompositeExtract(
auto* member_access = create<ast::IdentifierExpression>(
namer_.GetMemberName(current_type_id, uint32_t(index_val)));
next_expr = create<ast::MemberAccessorExpression>(
std::move(current_expr.expr), std::move(member_access));
next_expr = create<ast::MemberAccessorExpression>(current_expr.expr,
member_access);
current_type_id = current_type_inst->GetSingleWordInOperand(index_val);
break;
}
@@ -3139,8 +3120,8 @@ TypedExpression FunctionEmitter::MakeCompositeExtract(
<< current_type_inst->PrettyPrint();
return {};
}
current_expr = TypedExpression{parser_impl_.ConvertType(current_type_id),
std::move(next_expr)};
current_expr =
TypedExpression{parser_impl_.ConvertType(current_type_id), next_expr};
}
return current_expr;
}
@@ -3197,8 +3178,8 @@ TypedExpression FunctionEmitter::MakeVectorShuffle(
return {};
}
}
return {result_type, create<ast::TypeConstructorExpression>(
result_type, std::move(values))};
return {result_type,
create<ast::TypeConstructorExpression>(result_type, values)};
}
bool FunctionEmitter::RegisterLocallyDefinedValues() {
@@ -3487,15 +3468,15 @@ TypedExpression FunctionEmitter::MakeNumericConversion(
}
ast::ExpressionList params;
params.push_back(std::move(arg_expr.expr));
params.push_back(arg_expr.expr);
TypedExpression result{expr_type, create<ast::TypeConstructorExpression>(
expr_type, std::move(params))};
if (requested_type == expr_type) {
return result;
}
return {requested_type, create<ast::BitcastExpression>(
requested_type, std::move(result.expr))};
return {requested_type,
create<ast::BitcastExpression>(requested_type, result.expr)};
}
bool FunctionEmitter::EmitFunctionCall(const spvtools::opt::Instruction& inst) {
@@ -3507,8 +3488,7 @@ bool FunctionEmitter::EmitFunctionCall(const spvtools::opt::Instruction& inst) {
for (uint32_t iarg = 1; iarg < inst.NumInOperands(); ++iarg) {
params.emplace_back(MakeOperand(inst, iarg).expr);
}
auto* call_expr =
create<ast::CallExpression>(std::move(function), std::move(params));
auto* call_expr = create<ast::CallExpression>(function, std::move(params));
auto* result_type = parser_impl_.ConvertType(inst.type_id());
if (!result_type) {
return Fail() << "internal error: no mapped type result of call: "
@@ -3516,13 +3496,11 @@ bool FunctionEmitter::EmitFunctionCall(const spvtools::opt::Instruction& inst) {
}
if (result_type->IsVoid()) {
return nullptr !=
AddStatementForInstruction(
create<ast::CallStatement>(std::move(call_expr)), inst);
return nullptr != AddStatementForInstruction(
create<ast::CallStatement>(call_expr), inst);
}
return EmitConstDefOrWriteToHoistedVar(inst,
{result_type, std::move(call_expr)});
return EmitConstDefOrWriteToHoistedVar(inst, {result_type, call_expr});
}
TypedExpression FunctionEmitter::MakeIntrinsicCall(
@@ -3537,15 +3515,14 @@ TypedExpression FunctionEmitter::MakeIntrinsicCall(
for (uint32_t iarg = 0; iarg < inst.NumInOperands(); ++iarg) {
params.emplace_back(MakeOperand(inst, iarg).expr);
}
auto* call_expr =
create<ast::CallExpression>(std::move(ident), std::move(params));
auto* call_expr = create<ast::CallExpression>(ident, std::move(params));
auto* result_type = parser_impl_.ConvertType(inst.type_id());
if (!result_type) {
Fail() << "internal error: no mapped type result of call: "
<< inst.PrettyPrint();
return {};
}
return {result_type, std::move(call_expr)};
return {result_type, call_expr};
}
TypedExpression FunctionEmitter::MakeSimpleSelect(
@@ -3563,10 +3540,10 @@ TypedExpression FunctionEmitter::MakeSimpleSelect(
if (op_ty->IsVector() || op_ty->is_float_scalar() ||
op_ty->is_integer_scalar() || op_ty->IsBool()) {
ast::ExpressionList params;
params.push_back(std::move(operand1.expr));
params.push_back(std::move(operand2.expr));
params.push_back(operand1.expr);
params.push_back(operand2.expr);
// The condition goes last.
params.push_back(std::move(condition.expr));
params.push_back(condition.expr);
return {operand1.type, create<ast::CallExpression>(
create<ast::IdentifierExpression>("select"),
std::move(params))};

View File

@@ -851,7 +851,7 @@ ast::type::Type* ParserImpl::ConvertType(
return nullptr;
}
if (ast_member_decoration) {
ast_member_decorations.push_back(std::move(ast_member_decoration));
ast_member_decorations.push_back(ast_member_decoration);
}
}
}
@@ -863,7 +863,7 @@ ast::type::Type* ParserImpl::ConvertType(
const auto member_name = namer_.GetMemberName(type_id, member_index);
auto* ast_struct_member = create<ast::StructMember>(
member_name, ast_member_ty, std::move(ast_member_decorations));
ast_members.push_back(std::move(ast_struct_member));
ast_members.push_back(ast_struct_member);
}
// Now make the struct.
@@ -872,7 +872,7 @@ ast::type::Type* ParserImpl::ConvertType(
namer_.SuggestSanitizedName(type_id, "S");
auto ast_struct_type = std::make_unique<ast::type::StructType>(
namer_.GetName(type_id), std::move(ast_struct));
namer_.GetName(type_id), ast_struct);
auto* result = ctx_.type_mgr().Get(std::move(ast_struct_type));
id_to_type_[type_id] = result;
@@ -991,21 +991,21 @@ bool ParserImpl::EmitScalarSpecConstants() {
for (const auto& deco : GetDecorationsFor(inst.result_id())) {
if ((deco.size() == 2) && (deco[0] == SpvDecorationSpecId)) {
auto* cid = create<ast::ConstantIdDecoration>(deco[1], Source{});
spec_id_decos.push_back(std::move(cid));
spec_id_decos.push_back(cid);
break;
}
}
if (spec_id_decos.empty()) {
// Register it as a named constant, without specialization id.
ast_var->set_is_const(true);
ast_var->set_constructor(std::move(ast_expr));
ast_module_.AddGlobalVariable(std::move(ast_var));
ast_var->set_constructor(ast_expr);
ast_module_.AddGlobalVariable(ast_var);
} else {
auto* ast_deco_var = create<ast::DecoratedVariable>(std::move(ast_var));
auto* ast_deco_var = create<ast::DecoratedVariable>(ast_var);
ast_deco_var->set_is_const(true);
ast_deco_var->set_constructor(std::move(ast_expr));
ast_deco_var->set_constructor(ast_expr);
ast_deco_var->set_decorations(std::move(spec_id_decos));
ast_module_.AddGlobalVariable(std::move(ast_deco_var));
ast_module_.AddGlobalVariable(ast_deco_var);
}
scalar_spec_constants_.insert(inst.result_id());
}
@@ -1112,7 +1112,7 @@ bool ParserImpl::EmitModuleScopeVariables() {
MakeConstantExpression(var.GetSingleWordInOperand(1)).expr);
}
// TODO(dneto): initializers (a.k.a. constructor expression)
ast_module_.AddGlobalVariable(std::move(ast_var));
ast_module_.AddGlobalVariable(ast_var);
}
// Emit gl_Position instead of gl_PerVertex
@@ -1129,7 +1129,7 @@ bool ParserImpl::EmitModuleScopeVariables() {
create<ast::BuiltinDecoration>(ast::Builtin::kPosition, Source{}));
var->set_decorations(std::move(decos));
ast_module_.AddGlobalVariable(std::move(var));
ast_module_.AddGlobalVariable(var);
}
return success_;
}
@@ -1202,7 +1202,7 @@ ast::Variable* ParserImpl::MakeVariable(uint32_t id,
}
}
if (!ast_decorations.empty()) {
auto* decorated_var = create<ast::DecoratedVariable>(std::move(ast_var));
auto* decorated_var = create<ast::DecoratedVariable>(ast_var);
decorated_var->set_decorations(std::move(ast_decorations));
ast_var = std::move(decorated_var);
}
@@ -1284,7 +1284,7 @@ TypedExpression ParserImpl::MakeConstantExpression(uint32_t id) {
// We've already emitted a diagnostic.
return {};
}
ast_components.emplace_back(std::move(ast_component.expr));
ast_components.emplace_back(ast_component.expr);
}
return {original_ast_type,
create<ast::TypeConstructorExpression>(original_ast_type,
@@ -1394,15 +1394,14 @@ TypedExpression ParserImpl::RectifyOperandSignedness(SpvOp op,
auto* unsigned_ty = unsigned_type_for_[type];
if (unsigned_ty != nullptr) {
// Conversion is required.
return {unsigned_ty, create<ast::BitcastExpression>(
unsigned_ty, std::move(expr.expr))};
return {unsigned_ty,
create<ast::BitcastExpression>(unsigned_ty, expr.expr)};
}
} else if (requires_signed) {
auto* signed_ty = signed_type_for_[type];
if (signed_ty != nullptr) {
// Conversion is required.
return {signed_ty,
create<ast::BitcastExpression>(signed_ty, std::move(expr.expr))};
return {signed_ty, create<ast::BitcastExpression>(signed_ty, expr.expr)};
}
}
// We should not reach here.
@@ -1465,8 +1464,7 @@ TypedExpression ParserImpl::RectifyForcedResultType(
if ((forced_result_ty == nullptr) || (forced_result_ty == expr.type)) {
return expr;
}
return {expr.type,
create<ast::BitcastExpression>(expr.type, std::move(expr.expr))};
return {expr.type, create<ast::BitcastExpression>(expr.type, expr.expr)};
}
bool ParserImpl::EmitFunctions() {

View File

@@ -268,7 +268,7 @@ Expect<bool> ParserImpl::expect_global_decl() {
if (!expect("variable declaration", Token::Type::kSemicolon))
return Failure::kErrored;
module_.AddGlobalVariable(std::move(gv.value));
module_.AddGlobalVariable(gv.value);
return true;
}
@@ -280,7 +280,7 @@ Expect<bool> ParserImpl::expect_global_decl() {
if (!expect("constant declaration", Token::Type::kSemicolon))
return Failure::kErrored;
module_.AddGlobalVariable(std::move(gc.value));
module_.AddGlobalVariable(gc.value);
return true;
}
@@ -322,7 +322,7 @@ Expect<bool> ParserImpl::expect_global_decl() {
if (func.errored)
errored = true;
if (func.matched) {
module_.AddFunction(std::move(func.value));
module_.AddFunction(func.value);
return true;
}
@@ -348,23 +348,23 @@ Maybe<ast::Variable*> ParserImpl::global_variable_decl(
if (!decl.matched)
return Failure::kNoMatch;
auto* var = std::move(decl.value);
auto* var = decl.value;
auto var_decos = cast_decorations<ast::VariableDecoration>(decos);
if (var_decos.errored)
return Failure::kErrored;
if (var_decos.value.size() > 0) {
auto* dv = create<ast::DecoratedVariable>(std::move(var));
dv->set_decorations(std::move(var_decos.value));
var = std::move(dv);
auto* dv = create<ast::DecoratedVariable>(var);
dv->set_decorations(var_decos.value);
var = dv;
}
if (match(Token::Type::kEqual)) {
auto expr = expect_const_expr();
if (expr.errored)
return Failure::kErrored;
var->set_constructor(std::move(expr.value));
var->set_constructor(expr.value);
}
return var;
}
@@ -392,7 +392,7 @@ Maybe<ast::Variable*> ParserImpl::global_constant_decl() {
if (init.errored)
return Failure::kErrored;
var->set_constructor(std::move(init.value));
var->set_constructor(init.value);
return var;
}
@@ -1113,7 +1113,7 @@ Expect<ast::StructMemberList> ParserImpl::expect_struct_body_decl() {
if (member.errored) {
errored = true;
} else {
members.push_back(std::move(member.value));
members.push_back(member.value);
}
}
@@ -1177,8 +1177,8 @@ Maybe<ast::Function*> ParserImpl::function_decl(ast::DecorationList& decos) {
if (errored)
return Failure::kErrored;
f->set_body(std::move(body.value));
return std::move(f.value);
f->set_body(body.value);
return f.value;
}
// function_type_decl
@@ -1252,7 +1252,7 @@ Expect<ast::VariableList> ParserImpl::expect_param_list() {
// that it's not updatable after intially set. This is unlike C or GLSL
// which treat formal parameters like local variables that can be updated.
var->set_is_const(true);
ret.push_back(std::move(var));
ret.push_back(var);
if (!match(Token::Type::kComma))
break;
@@ -1311,7 +1311,7 @@ Expect<ast::Expression*> ParserImpl::expect_paren_rhs_stmt() {
if (!expr.matched)
return add_error(peek(), "unable to parse expression");
return std::move(expr.value);
return expr.value;
});
}
@@ -1326,7 +1326,7 @@ Expect<ast::BlockStatement*> ParserImpl::expect_statements() {
if (stmt.errored) {
errored = true;
} else if (stmt.matched) {
ret->append(std::move(stmt.value));
ret->append(stmt.value);
} else {
break;
}
@@ -1371,31 +1371,31 @@ Maybe<ast::Statement*> ParserImpl::statement() {
if (stmt_if.errored)
return Failure::kErrored;
if (stmt_if.matched)
return std::move(stmt_if.value);
return stmt_if.value;
auto sw = switch_stmt();
if (sw.errored)
return Failure::kErrored;
if (sw.matched)
return std::move(sw.value);
return sw.value;
auto loop = loop_stmt();
if (loop.errored)
return Failure::kErrored;
if (loop.matched)
return std::move(loop.value);
return loop.value;
auto stmt_for = for_stmt();
if (stmt_for.errored)
return Failure::kErrored;
if (stmt_for.matched)
return std::move(stmt_for.value);
return stmt_for.value;
if (peek().IsBraceLeft()) {
auto body = expect_body_stmt();
if (body.errored)
return Failure::kErrored;
return std::move(body.value);
return body.value;
}
return Failure::kNoMatch;
@@ -1415,37 +1415,37 @@ Maybe<ast::Statement*> ParserImpl::non_block_statement() {
if (ret_stmt.errored)
return Failure::kErrored;
if (ret_stmt.matched)
return std::move(ret_stmt.value);
return ret_stmt.value;
auto func = func_call_stmt();
if (func.errored)
return Failure::kErrored;
if (func.matched)
return std::move(func.value);
return func.value;
auto var = variable_stmt();
if (var.errored)
return Failure::kErrored;
if (var.matched)
return std::move(var.value);
return var.value;
auto b = break_stmt();
if (b.errored)
return Failure::kErrored;
if (b.matched)
return std::move(b.value);
return b.value;
auto cont = continue_stmt();
if (cont.errored)
return Failure::kErrored;
if (cont.matched)
return std::move(cont.value);
return cont.value;
auto assign = assignment_stmt();
if (assign.errored)
return Failure::kErrored;
if (assign.matched)
return std::move(assign.value);
return assign.value;
Source source;
if (match(Token::Type::kDiscard, &source))
@@ -1475,7 +1475,7 @@ Maybe<ast::ReturnStatement*> ParserImpl::return_stmt() {
return Failure::kErrored;
// TODO(bclayton): Check matched?
return create<ast::ReturnStatement>(source, std::move(expr.value));
return create<ast::ReturnStatement>(source, expr.value);
}
// variable_stmt
@@ -1500,9 +1500,9 @@ Maybe<ast::VariableDeclStatement*> ParserImpl::variable_stmt() {
auto* var = create<ast::Variable>(decl->source, decl->name,
ast::StorageClass::kNone, decl->type);
var->set_is_const(true);
var->set_constructor(std::move(constructor.value));
var->set_constructor(constructor.value);
return create<ast::VariableDeclStatement>(decl->source, std::move(var));
return create<ast::VariableDeclStatement>(decl->source, var);
}
auto var = variable_decl();
@@ -1518,11 +1518,10 @@ Maybe<ast::VariableDeclStatement*> ParserImpl::variable_stmt() {
if (!constructor.matched)
return add_error(peek(), "missing constructor for variable declaration");
var->set_constructor(std::move(constructor.value));
var->set_constructor(constructor.value);
}
return create<ast::VariableDeclStatement>(var->source(),
std::move(var.value));
return create<ast::VariableDeclStatement>(var->source(), var.value);
}
// if_stmt
@@ -1548,12 +1547,11 @@ Maybe<ast::IfStatement*> ParserImpl::if_stmt() {
if (el.errored)
return Failure::kErrored;
auto* stmt = create<ast::IfStatement>(source, std::move(condition.value),
std::move(body.value));
auto* stmt = create<ast::IfStatement>(source, condition.value, body.value);
if (el.matched) {
elseif.value.push_back(std::move(el.value));
elseif.value.push_back(el.value);
}
stmt->set_else_statements(std::move(elseif.value));
stmt->set_else_statements(elseif.value);
return stmt;
}
@@ -1575,8 +1573,8 @@ Maybe<ast::ElseStatementList> ParserImpl::elseif_stmt() {
if (body.errored)
return Failure::kErrored;
ret.push_back(create<ast::ElseStatement>(source, std::move(condition.value),
std::move(body.value)));
ret.push_back(
create<ast::ElseStatement>(source, condition.value, body.value));
if (!match(Token::Type::kElseIf, &source))
break;
@@ -1596,7 +1594,7 @@ Maybe<ast::ElseStatement*> ParserImpl::else_stmt() {
if (body.errored)
return Failure::kErrored;
return create<ast::ElseStatement>(source, std::move(body.value));
return create<ast::ElseStatement>(source, body.value);
}
// switch_stmt
@@ -1622,7 +1620,7 @@ Maybe<ast::SwitchStatement*> ParserImpl::switch_stmt() {
}
if (!stmt.matched)
break;
list.push_back(std::move(stmt.value));
list.push_back(stmt.value);
}
if (errored)
return Failure::kErrored;
@@ -1632,8 +1630,7 @@ Maybe<ast::SwitchStatement*> ParserImpl::switch_stmt() {
if (body.errored)
return Failure::kErrored;
return create<ast::SwitchStatement>(source, std::move(condition.value),
std::move(body.value));
return create<ast::SwitchStatement>(source, condition.value, body.value);
}
// switch_body
@@ -1669,7 +1666,7 @@ Maybe<ast::CaseStatement*> ParserImpl::switch_body() {
if (!body.matched)
return add_error(body.source, "expected case body");
stmt->set_body(std::move(body.value));
stmt->set_body(body.value);
return stmt;
}
@@ -1720,7 +1717,7 @@ Maybe<ast::BlockStatement*> ParserImpl::case_body() {
if (!stmt.matched)
break;
ret->append(std::move(stmt.value));
ret->append(stmt.value);
}
return ret;
@@ -1742,17 +1739,14 @@ Maybe<ast::LoopStatement*> ParserImpl::loop_stmt() {
if (continuing.errored)
return Failure::kErrored;
return create<ast::LoopStatement>(source, std::move(body.value),
std::move(continuing.value));
return create<ast::LoopStatement>(source, body.value, continuing.value);
});
}
ForHeader::ForHeader(ast::Statement* init,
ast::Expression* cond,
ast::Statement* cont)
: initializer(std::move(init)),
condition(std::move(cond)),
continuing(std::move(cont)) {}
: initializer(init), condition(cond), continuing(cont) {}
ForHeader::~ForHeader() = default;
@@ -1762,19 +1756,19 @@ Maybe<ast::Statement*> ParserImpl::for_header_initializer() {
if (call.errored)
return Failure::kErrored;
if (call.matched)
return std::move(call.value);
return call.value;
auto var = variable_stmt();
if (var.errored)
return Failure::kErrored;
if (var.matched)
return std::move(var.value);
return var.value;
auto assign = assignment_stmt();
if (assign.errored)
return Failure::kErrored;
if (assign.matched)
return std::move(assign.value);
return assign.value;
return Failure::kNoMatch;
}
@@ -1785,13 +1779,13 @@ Maybe<ast::Statement*> ParserImpl::for_header_continuing() {
if (call_stmt.errored)
return Failure::kErrored;
if (call_stmt.matched)
return std::move(call_stmt.value);
return call_stmt.value;
auto assign = assignment_stmt();
if (assign.errored)
return Failure::kErrored;
if (assign.matched)
return std::move(assign.value);
return assign.value;
return Failure::kNoMatch;
}
@@ -1820,9 +1814,8 @@ Expect<std::unique_ptr<ForHeader>> ParserImpl::expect_for_header() {
if (continuing.errored)
return Failure::kErrored;
return std::make_unique<ForHeader>(std::move(initializer.value),
std::move(condition.value),
std::move(continuing.value));
return std::make_unique<ForHeader>(initializer.value, condition.value,
continuing.value);
}
// for_statement
@@ -1848,32 +1841,29 @@ Maybe<ast::Statement*> ParserImpl::for_stmt() {
if (header->condition != nullptr) {
// !condition
auto* not_condition = create<ast::UnaryOpExpression>(
header->condition->source(), ast::UnaryOp::kNot,
std::move(header->condition));
header->condition->source(), ast::UnaryOp::kNot, header->condition);
// { break; }
auto* break_stmt = create<ast::BreakStatement>(not_condition->source());
auto* break_body = create<ast::BlockStatement>(not_condition->source());
break_body->append(std::move(break_stmt));
break_body->append(break_stmt);
// if (!condition) { break; }
auto* break_if_not_condition = create<ast::IfStatement>(
not_condition->source(), std::move(not_condition),
std::move(break_body));
body->insert(0, std::move(break_if_not_condition));
not_condition->source(), not_condition, break_body);
body->insert(0, break_if_not_condition);
}
ast::BlockStatement* continuing_body = nullptr;
if (header->continuing != nullptr) {
continuing_body = create<ast::BlockStatement>(header->continuing->source());
continuing_body->append(std::move(header->continuing));
continuing_body->append(header->continuing);
}
auto* loop = create<ast::LoopStatement>(source, std::move(body.value),
std::move(continuing_body));
auto* loop = create<ast::LoopStatement>(source, body.value, continuing_body);
if (header->initializer != nullptr) {
auto* result = create<ast::BlockStatement>(source);
result->append(std::move(header->initializer));
result->append(std::move(loop));
result->append(header->initializer);
result->append(loop);
return result;
}
@@ -1955,15 +1945,14 @@ Maybe<ast::Expression*> ParserImpl::primary_expression() {
if (lit.errored)
return Failure::kErrored;
if (lit.matched)
return create<ast::ScalarConstructorExpression>(source,
std::move(lit.value));
return create<ast::ScalarConstructorExpression>(source, lit.value);
if (t.IsParenLeft()) {
auto paren = expect_paren_rhs_stmt();
if (paren.errored)
return Failure::kErrored;
return std::move(paren.value);
return paren.value;
}
if (match(Token::Type::kBitcast)) {
@@ -1977,8 +1966,7 @@ Maybe<ast::Expression*> ParserImpl::primary_expression() {
if (params.errored)
return Failure::kErrored;
return create<ast::BitcastExpression>(source, type.value,
std::move(params.value));
return create<ast::BitcastExpression>(source, type.value, params.value);
}
if (match(Token::Type::kIdentifier))
@@ -1999,14 +1987,14 @@ Maybe<ast::Expression*> ParserImpl::primary_expression() {
if (params.errored)
return Failure::kErrored;
return create<ast::TypeConstructorExpression>(
source, type.value, std::move(params.value));
return create<ast::TypeConstructorExpression>(source, type.value,
params.value);
});
if (expr.errored)
return Failure::kErrored;
return std::move(expr.value);
return expr.value;
}
return Failure::kNoMatch;
@@ -2029,8 +2017,8 @@ Maybe<ast::Expression*> ParserImpl::postfix_expr(ast::Expression* prefix) {
if (!expect("array accessor", Token::Type::kBracketRight))
return Failure::kErrored;
return postfix_expr(create<ast::ArrayAccessorExpression>(
source, std::move(prefix), std::move(param.value)));
return postfix_expr(
create<ast::ArrayAccessorExpression>(source, prefix, param.value));
}
if (match(Token::Type::kParenLeft, &source)) {
@@ -2041,14 +2029,13 @@ Maybe<ast::Expression*> ParserImpl::postfix_expr(ast::Expression* prefix) {
auto list = expect_argument_expression_list();
if (list.errored)
return Failure::kErrored;
params = std::move(list.value);
params = list.value;
}
if (!expect("call expression", Token::Type::kParenRight))
return Failure::kErrored;
return postfix_expr(create<ast::CallExpression>(source, std::move(prefix),
std::move(params)));
return postfix_expr(create<ast::CallExpression>(source, prefix, params));
}
if (match(Token::Type::kPeriod)) {
@@ -2057,7 +2044,7 @@ Maybe<ast::Expression*> ParserImpl::postfix_expr(ast::Expression* prefix) {
return Failure::kErrored;
return postfix_expr(create<ast::MemberAccessorExpression>(
ident.source, std::move(prefix),
ident.source, prefix,
create<ast::IdentifierExpression>(ident.source, ident.value)));
}
@@ -2073,7 +2060,7 @@ Maybe<ast::Expression*> ParserImpl::postfix_expression() {
if (!prefix.matched)
return Failure::kNoMatch;
return postfix_expr(std::move(prefix.value));
return postfix_expr(prefix.value);
}
// argument_expression_list
@@ -2086,7 +2073,7 @@ Expect<ast::ExpressionList> ParserImpl::expect_argument_expression_list() {
return add_error(peek(), "unable to parse argument expression");
ast::ExpressionList ret;
ret.push_back(std::move(arg.value));
ret.push_back(arg.value);
while (match(Token::Type::kComma)) {
arg = logical_or_expression();
@@ -2096,7 +2083,7 @@ Expect<ast::ExpressionList> ParserImpl::expect_argument_expression_list() {
return add_error(peek(),
"unable to parse argument expression after comma");
}
ret.push_back(std::move(arg.value));
ret.push_back(arg.value);
}
return ret;
}
@@ -2124,7 +2111,7 @@ Maybe<ast::Expression*> ParserImpl::unary_expression() {
return add_error(peek(),
"unable to parse right side of " + name + " expression");
return create<ast::UnaryOpExpression>(source, op, std::move(expr.value));
return create<ast::UnaryOpExpression>(source, op, expr.value);
}
return postfix_expression();
}
@@ -2160,8 +2147,8 @@ Expect<ast::Expression*> ParserImpl::expect_multiplicative_expr(
"unable to parse right side of " + name + " expression");
}
return expect_multiplicative_expr(create<ast::BinaryExpression>(
source, op, std::move(lhs), std::move(rhs.value)));
return expect_multiplicative_expr(
create<ast::BinaryExpression>(source, op, lhs, rhs.value));
}
// multiplicative_expression
@@ -2173,7 +2160,7 @@ Maybe<ast::Expression*> ParserImpl::multiplicative_expression() {
if (!lhs.matched)
return Failure::kNoMatch;
return expect_multiplicative_expr(std::move(lhs.value));
return expect_multiplicative_expr(lhs.value);
}
// additive_expr
@@ -2201,8 +2188,8 @@ Expect<ast::Expression*> ParserImpl::expect_additive_expr(
if (!rhs.matched)
return add_error(peek(), "unable to parse right side of + expression");
return expect_additive_expr(create<ast::BinaryExpression>(
source, op, std::move(lhs), std::move(rhs.value)));
return expect_additive_expr(
create<ast::BinaryExpression>(source, op, lhs, rhs.value));
}
// additive_expression
@@ -2214,7 +2201,7 @@ Maybe<ast::Expression*> ParserImpl::additive_expression() {
if (!lhs.matched)
return Failure::kNoMatch;
return expect_additive_expr(std::move(lhs.value));
return expect_additive_expr(lhs.value);
}
// shift_expr
@@ -2249,8 +2236,8 @@ Expect<ast::Expression*> ParserImpl::expect_shift_expr(ast::Expression* lhs) {
return add_error(peek(), std::string("unable to parse right side of ") +
name + " expression");
}
return expect_shift_expr(create<ast::BinaryExpression>(
source, op, std::move(lhs), std::move(rhs.value)));
return expect_shift_expr(
create<ast::BinaryExpression>(source, op, lhs, rhs.value));
} // namespace wgsl
// shift_expression
@@ -2262,7 +2249,7 @@ Maybe<ast::Expression*> ParserImpl::shift_expression() {
if (!lhs.matched)
return Failure::kNoMatch;
return expect_shift_expr(std::move(lhs.value));
return expect_shift_expr(lhs.value);
}
// relational_expr
@@ -2298,8 +2285,8 @@ Expect<ast::Expression*> ParserImpl::expect_relational_expr(
"unable to parse right side of " + name + " expression");
}
return expect_relational_expr(create<ast::BinaryExpression>(
source, op, std::move(lhs), std::move(rhs.value)));
return expect_relational_expr(
create<ast::BinaryExpression>(source, op, lhs, rhs.value));
}
// relational_expression
@@ -2311,7 +2298,7 @@ Maybe<ast::Expression*> ParserImpl::relational_expression() {
if (!lhs.matched)
return Failure::kNoMatch;
return expect_relational_expr(std::move(lhs.value));
return expect_relational_expr(lhs.value);
}
// equality_expr
@@ -2341,8 +2328,8 @@ Expect<ast::Expression*> ParserImpl::expect_equality_expr(
"unable to parse right side of " + name + " expression");
}
return expect_equality_expr(create<ast::BinaryExpression>(
source, op, std::move(lhs), std::move(rhs.value)));
return expect_equality_expr(
create<ast::BinaryExpression>(source, op, lhs, rhs.value));
}
// equality_expression
@@ -2354,7 +2341,7 @@ Maybe<ast::Expression*> ParserImpl::equality_expression() {
if (!lhs.matched)
return Failure::kNoMatch;
return expect_equality_expr(std::move(lhs.value));
return expect_equality_expr(lhs.value);
}
// and_expr
@@ -2375,7 +2362,7 @@ Expect<ast::Expression*> ParserImpl::expect_and_expr(ast::Expression* lhs) {
return add_error(peek(), "unable to parse right side of & expression");
return expect_and_expr(create<ast::BinaryExpression>(
source, ast::BinaryOp::kAnd, std::move(lhs), std::move(rhs.value)));
source, ast::BinaryOp::kAnd, lhs, rhs.value));
}
// and_expression
@@ -2387,7 +2374,7 @@ Maybe<ast::Expression*> ParserImpl::and_expression() {
if (!lhs.matched)
return Failure::kNoMatch;
return expect_and_expr(std::move(lhs.value));
return expect_and_expr(lhs.value);
}
// exclusive_or_expr
@@ -2406,7 +2393,7 @@ Expect<ast::Expression*> ParserImpl::expect_exclusive_or_expr(
return add_error(peek(), "unable to parse right side of ^ expression");
return expect_exclusive_or_expr(create<ast::BinaryExpression>(
source, ast::BinaryOp::kXor, std::move(lhs), std::move(rhs.value)));
source, ast::BinaryOp::kXor, lhs, rhs.value));
}
// exclusive_or_expression
@@ -2418,7 +2405,7 @@ Maybe<ast::Expression*> ParserImpl::exclusive_or_expression() {
if (!lhs.matched)
return Failure::kNoMatch;
return expect_exclusive_or_expr(std::move(lhs.value));
return expect_exclusive_or_expr(lhs.value);
}
// inclusive_or_expr
@@ -2437,7 +2424,7 @@ Expect<ast::Expression*> ParserImpl::expect_inclusive_or_expr(
return add_error(peek(), "unable to parse right side of | expression");
return expect_inclusive_or_expr(create<ast::BinaryExpression>(
source, ast::BinaryOp::kOr, std::move(lhs), std::move(rhs.value)));
source, ast::BinaryOp::kOr, lhs, rhs.value));
}
// inclusive_or_expression
@@ -2449,7 +2436,7 @@ Maybe<ast::Expression*> ParserImpl::inclusive_or_expression() {
if (!lhs.matched)
return Failure::kNoMatch;
return expect_inclusive_or_expr(std::move(lhs.value));
return expect_inclusive_or_expr(lhs.value);
}
// logical_and_expr
@@ -2470,9 +2457,8 @@ Expect<ast::Expression*> ParserImpl::expect_logical_and_expr(
if (!rhs.matched)
return add_error(peek(), "unable to parse right side of && expression");
return expect_logical_and_expr(
create<ast::BinaryExpression>(source, ast::BinaryOp::kLogicalAnd,
std::move(lhs), std::move(rhs.value)));
return expect_logical_and_expr(create<ast::BinaryExpression>(
source, ast::BinaryOp::kLogicalAnd, lhs, rhs.value));
}
// logical_and_expression
@@ -2484,7 +2470,7 @@ Maybe<ast::Expression*> ParserImpl::logical_and_expression() {
if (!lhs.matched)
return Failure::kNoMatch;
return expect_logical_and_expr(std::move(lhs.value));
return expect_logical_and_expr(lhs.value);
}
// logical_or_expr
@@ -2503,7 +2489,7 @@ Expect<ast::Expression*> ParserImpl::expect_logical_or_expr(
return add_error(peek(), "unable to parse right side of || expression");
return expect_logical_or_expr(create<ast::BinaryExpression>(
source, ast::BinaryOp::kLogicalOr, std::move(lhs), std::move(rhs.value)));
source, ast::BinaryOp::kLogicalOr, lhs, rhs.value));
}
// logical_or_expression
@@ -2515,7 +2501,7 @@ Maybe<ast::Expression*> ParserImpl::logical_or_expression() {
if (!lhs.matched)
return Failure::kNoMatch;
return expect_logical_or_expr(std::move(lhs.value));
return expect_logical_or_expr(lhs.value);
}
// assignment_stmt
@@ -2539,8 +2525,7 @@ Maybe<ast::AssignmentStatement*> ParserImpl::assignment_stmt() {
if (!rhs.matched)
return add_error(peek(), "unable to parse right side of assignment");
return create<ast::AssignmentStatement>(source, std::move(lhs.value),
std::move(rhs.value));
return create<ast::AssignmentStatement>(source, lhs.value, rhs.value);
}
// const_literal
@@ -2601,12 +2586,12 @@ Expect<ast::ConstructorExpression*> ParserImpl::expect_const_expr_internal(
auto param = expect_const_expr_internal(depth + 1);
if (param.errored)
return Failure::kErrored;
list.emplace_back(std::move(param.value));
list.emplace_back(param.value);
while (match(Token::Type::kComma)) {
param = expect_const_expr_internal(depth + 1);
if (param.errored)
return Failure::kErrored;
list.emplace_back(std::move(param.value));
list.emplace_back(param.value);
}
return list;
});
@@ -2615,7 +2600,7 @@ Expect<ast::ConstructorExpression*> ParserImpl::expect_const_expr_internal(
return Failure::kErrored;
return create<ast::TypeConstructorExpression>(source, type.value,
std::move(params.value));
params.value);
}
auto lit = const_literal();
@@ -2624,7 +2609,7 @@ Expect<ast::ConstructorExpression*> ParserImpl::expect_const_expr_internal(
if (!lit.matched)
return add_error(peek(), "unable to parse const literal");
return create<ast::ScalarConstructorExpression>(source, std::move(lit.value));
return create<ast::ScalarConstructorExpression>(source, lit.value);
}
Maybe<ast::DecorationList> ParserImpl::decoration_list() {
@@ -2669,7 +2654,7 @@ Maybe<bool> ParserImpl::decoration_bracketed_list(ast::DecorationList& decos) {
auto deco = expect_decoration();
if (deco.errored)
errored = true;
decos.emplace_back(std::move(deco.value));
decos.emplace_back(deco.value);
if (match(Token::Type::kComma))
continue;
@@ -2701,7 +2686,7 @@ Expect<ast::Decoration*> ParserImpl::expect_decoration() {
if (deco.errored)
return Failure::kErrored;
if (deco.matched)
return std::move(deco.value);
return deco.value;
return add_error(t, "expected decoration");
}
@@ -2824,7 +2809,7 @@ Expect<std::vector<T*>> ParserImpl::cast_decorations(ast::DecorationList& in) {
ok = false;
continue;
}
out.emplace_back(ast::As<T>(std::move(deco)));
out.emplace_back(ast::As<T>(deco));
}
// clear in so that we can verify decorations were consumed with
// expect_decorations_consumed()

View File

@@ -30,8 +30,8 @@ TEST_F(ParserImplTest, FunctionDecorationList_Parses) {
EXPECT_TRUE(decos.matched);
ASSERT_EQ(decos.value.size(), 2u);
auto* deco_0 = ast::As<ast::FunctionDecoration>(std::move(decos.value[0]));
auto* deco_1 = ast::As<ast::FunctionDecoration>(std::move(decos.value[1]));
auto* deco_0 = ast::As<ast::FunctionDecoration>(decos.value[0]);
auto* deco_1 = ast::As<ast::FunctionDecoration>(decos.value[1]);
ASSERT_NE(deco_0, nullptr);
ASSERT_NE(deco_1, nullptr);

View File

@@ -30,7 +30,7 @@ TEST_F(ParserImplTest, FunctionDecoration_Workgroup) {
EXPECT_FALSE(deco.errored);
ASSERT_NE(deco.value, nullptr) << p->error();
ASSERT_FALSE(p->has_error());
auto* func_deco = ast::As<ast::FunctionDecoration>(std::move(deco.value));
auto* func_deco = ast::As<ast::FunctionDecoration>(deco.value);
ASSERT_NE(func_deco, nullptr);
ASSERT_TRUE(func_deco->IsWorkgroup());
@@ -50,7 +50,7 @@ TEST_F(ParserImplTest, FunctionDecoration_Workgroup_2Param) {
EXPECT_FALSE(deco.errored);
ASSERT_NE(deco.value, nullptr) << p->error();
ASSERT_FALSE(p->has_error());
auto* func_deco = ast::As<ast::FunctionDecoration>(std::move(deco.value));
auto* func_deco = ast::As<ast::FunctionDecoration>(deco.value);
ASSERT_NE(func_deco, nullptr) << p->error();
ASSERT_TRUE(func_deco->IsWorkgroup());
@@ -70,7 +70,7 @@ TEST_F(ParserImplTest, FunctionDecoration_Workgroup_3Param) {
EXPECT_FALSE(deco.errored);
ASSERT_NE(deco.value, nullptr) << p->error();
ASSERT_FALSE(p->has_error());
auto* func_deco = ast::As<ast::FunctionDecoration>(std::move(deco.value));
auto* func_deco = ast::As<ast::FunctionDecoration>(deco.value);
ASSERT_NE(func_deco, nullptr);
ASSERT_TRUE(func_deco->IsWorkgroup());
@@ -257,7 +257,7 @@ TEST_F(ParserImplTest, FunctionDecoration_Stage) {
EXPECT_FALSE(deco.errored);
ASSERT_NE(deco.value, nullptr) << p->error();
ASSERT_FALSE(p->has_error());
auto* func_deco = ast::As<ast::FunctionDecoration>(std::move(deco.value));
auto* func_deco = ast::As<ast::FunctionDecoration>(deco.value);
ASSERT_NE(func_deco, nullptr);
ASSERT_TRUE(func_deco->IsStage());
EXPECT_EQ(func_deco->AsStage()->value(), ast::PipelineStage::kCompute);

View File

@@ -28,7 +28,7 @@ TEST_F(ParserImplTest, StructDecorationDecl_Parses) {
EXPECT_FALSE(decos.errored);
EXPECT_TRUE(decos.matched);
ASSERT_EQ(decos.value.size(), 1u);
auto* struct_deco = ast::As<ast::StructDecoration>(std::move(decos.value[0]));
auto* struct_deco = ast::As<ast::StructDecoration>(decos.value[0]);
EXPECT_TRUE(struct_deco->IsBlock());
}

View File

@@ -43,7 +43,7 @@ TEST_P(StructDecorationTest, Parses) {
EXPECT_TRUE(deco.matched);
EXPECT_FALSE(deco.errored);
ASSERT_NE(deco.value, nullptr);
auto* struct_deco = ast::As<ast::StructDecoration>(std::move(deco.value));
auto* struct_deco = ast::As<ast::StructDecoration>(deco.value);
ASSERT_NE(struct_deco, nullptr);
EXPECT_EQ(struct_deco->IsBlock(), params.is_block);
}

View File

@@ -48,7 +48,7 @@ TEST_F(ParserImplTest, StructMemberDecorationDecl_Single) {
EXPECT_FALSE(decos.errored);
EXPECT_TRUE(decos.matched);
ASSERT_EQ(decos.value.size(), 1u);
auto* deco = ast::As<ast::StructMemberDecoration>(std::move(decos.value[0]));
auto* deco = ast::As<ast::StructMemberDecoration>(decos.value[0]);
ASSERT_NE(deco, nullptr);
EXPECT_TRUE(deco->IsOffset());
}

View File

@@ -30,8 +30,7 @@ TEST_F(ParserImplTest, StructMemberDecoration_Offset) {
ASSERT_NE(deco.value, nullptr);
ASSERT_FALSE(p->has_error());
auto* member_deco =
ast::As<ast::StructMemberDecoration>(std::move(deco.value));
auto* member_deco = ast::As<ast::StructMemberDecoration>(deco.value);
ASSERT_NE(member_deco, nullptr);
ASSERT_TRUE(member_deco->IsOffset());

View File

@@ -31,8 +31,8 @@ TEST_F(ParserImplTest, VariableDecorationList_Parses) {
ASSERT_TRUE(decos.matched);
ASSERT_EQ(decos.value.size(), 2u);
auto* deco_0 = ast::As<ast::VariableDecoration>(std::move(decos.value[0]));
auto* deco_1 = ast::As<ast::VariableDecoration>(std::move(decos.value[1]));
auto* deco_0 = ast::As<ast::VariableDecoration>(decos.value[0]);
auto* deco_1 = ast::As<ast::VariableDecoration>(decos.value[1]);
ASSERT_NE(deco_0, nullptr);
ASSERT_NE(deco_1, nullptr);

View File

@@ -31,7 +31,7 @@ TEST_F(ParserImplTest, VariableDecoration_Location) {
EXPECT_TRUE(deco.matched);
EXPECT_FALSE(deco.errored);
ASSERT_NE(deco.value, nullptr);
auto* var_deco = ast::As<ast::VariableDecoration>(std::move(deco.value));
auto* var_deco = ast::As<ast::VariableDecoration>(deco.value);
ASSERT_NE(var_deco, nullptr);
ASSERT_FALSE(p->has_error());
ASSERT_TRUE(var_deco->IsLocation());
@@ -101,7 +101,7 @@ TEST_P(BuiltinTest, VariableDecoration_Builtin) {
EXPECT_TRUE(deco.matched);
EXPECT_FALSE(deco.errored);
ASSERT_NE(deco.value, nullptr);
auto* var_deco = ast::As<ast::VariableDecoration>(std::move(deco.value));
auto* var_deco = ast::As<ast::VariableDecoration>(deco.value);
ASSERT_FALSE(p->has_error()) << p->error();
ASSERT_NE(var_deco, nullptr);
ASSERT_TRUE(var_deco->IsBuiltin());
@@ -180,7 +180,7 @@ TEST_F(ParserImplTest, VariableDecoration_Binding) {
EXPECT_TRUE(deco.matched);
EXPECT_FALSE(deco.errored);
ASSERT_NE(deco.value, nullptr);
auto* var_deco = ast::As<ast::VariableDecoration>(std::move(deco.value));
auto* var_deco = ast::As<ast::VariableDecoration>(deco.value);
ASSERT_NE(var_deco, nullptr);
ASSERT_FALSE(p->has_error());
ASSERT_TRUE(var_deco->IsBinding());
@@ -237,7 +237,7 @@ TEST_F(ParserImplTest, VariableDecoration_set) {
EXPECT_TRUE(deco.matched);
EXPECT_FALSE(deco.errored);
ASSERT_NE(deco.value, nullptr);
auto* var_deco = ast::As<ast::VariableDecoration>(std::move(deco.value));
auto* var_deco = ast::As<ast::VariableDecoration>(deco.value);
ASSERT_FALSE(p->has_error());
ASSERT_NE(var_deco, nullptr);
ASSERT_TRUE(var_deco->IsSet());