feature. See also
. The project being documented here (as the example) is the Zig library itself.
Translator.transAssignExpr
fn transAssignExpr(t: *Translator, scope: *Scope, bin: Node.Binary, used: ResultUsed) !ZigNode
File
Code
fn transAssignExpr(t: *Translator, scope: *Scope, bin: Node.Binary, used: ResultUsed) !ZigNode {
if (used == .unused) {
const lhs = try t.transExpr(scope, bin.lhs, .used);
const rhs = try t.transExprCoercing(scope, bin.rhs, .used);
const lhs_qt = bin.lhs.qt(t.tree);
return t.createBinOpNode(.assign, lhs, try t.toNonBool(rhs, lhs_qt));
}
var block_scope = try Scope.Block.init(t, scope, true);
defer block_scope.deinit();
const tmp = try block_scope.reserveMangledName("tmp");
const rhs = try t.transExpr(&block_scope.base, bin.rhs, .used);
const lhs_qt = bin.lhs.qt(t.tree);
const tmp_decl = try ZigTag.var_simple.create(t.arena, .{
.name = tmp,
.init = try t.toNonBool(rhs, lhs_qt),
});
try block_scope.statements.append(t.gpa, tmp_decl);
const lhs = try t.transExprCoercing(&block_scope.base, bin.lhs, .used);
const tmp_ident = try ZigTag.identifier.create(t.arena, tmp);
const assign = try t.createBinOpNode(.assign, lhs, tmp_ident);
try block_scope.statements.append(t.gpa, assign);
const break_node = try ZigTag.break_val.create(t.arena, .{
.label = block_scope.label,
.val = tmp_ident,
});
try block_scope.statements.append(t.gpa, break_node);
return try block_scope.complete();
}