add: handling binOp div

This commit is contained in:
Vallahor 2022-05-29 06:27:03 -03:00 committed by Andrew Kelley
parent d5d27f245b
commit 8e835fd3a2
2 changed files with 35 additions and 0 deletions

View File

@ -1110,6 +1110,10 @@ var zigAnalysis;
break;
}
case 3: {
if (!expr.binOp.extact && !expr.binOp.floor && !expr.binOp.trunv) {
operator += "/";
break;
}
let print_div = "";
if (expr.binOp.exact) {
print_div = "@divExact(";

View File

@ -1251,6 +1251,37 @@ fn walkInstruction(
};
},
.div => {
const pl_node = data[inst_index].pl_node;
const extra = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index);
const binop_index = self.exprs.items.len;
try self.exprs.append(self.arena, .{ .binOp = .{ .lhs = 0, .rhs = 0 } });
var lhs: DocData.WalkResult = try self.walkRef(
file,
parent_scope,
extra.data.lhs,
false,
);
var rhs: DocData.WalkResult = try self.walkRef(
file,
parent_scope,
extra.data.rhs,
false,
);
const lhs_index = self.exprs.items.len;
try self.exprs.append(self.arena, lhs.expr);
const rhs_index = self.exprs.items.len;
try self.exprs.append(self.arena, rhs.expr);
self.exprs.items[binop_index] = .{ .binOp = .{ .lhs = lhs_index, .rhs = rhs_index, .opKind = 3 } };
return DocData.WalkResult{
.typeRef = .{ .type = @enumToInt(Ref.type_type) },
.expr = .{ .binOpIndex = binop_index },
};
},
.div_exact => {
const pl_node = data[inst_index].pl_node;
const extra = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index);