authorgravatar for MyvarHD@gmail.comEmile Badenhorst <MyvarHD@gmail.com> 2023-07-01 16:43:17+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-07-01 16:43:17+02:00
log35a8e8a06c0cb0a5a0c6ddcca3b70be05dc4d035
treec43865cf9e619f2fa7aaec7e7be1a4876fa4cb93
parentf571438fc0010c0c45f79a2f709161a324c5a164
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Fixed Autodoc rendering of @truncate builtin (#16263)

* fixed autodoc rendering of @trucate builtin * Changed to LHS for typeRef * autodoc: fix typeref for `truncate` --------- Co-authored-by: Loris Cro <kappaloris@gmail.com>

2 files changed, 38 insertions(+), 2 deletions(-)

lib/docs/main.js+3-1
......@@ -1419,6 +1419,9 @@ const NAV_MODES = {
14191419 case "bit_reverse": {
14201420 return "@bitReverse(T" + ", " + param + ")";
14211421 }
1422 case "truncate": {
1423 return "@truncate(" + param + ")";
1424 }
14221425 default:
14231426 console.log("builtin function not handled yet or doesn't exist!");
14241427 }
......@@ -2622,7 +2625,6 @@ const NAV_MODES = {
26222625
26232626 function renderValue(decl) {
26242627 let resolvedValue = resolveValue(decl.value);
2625
26262628 if (resolvedValue.expr.fieldRef) {
26272629 const declRef = decl.value.expr.refPath[0].declRef;
26282630 const type = getDecl(declRef);
src/Autodoc.zig+35-1
......@@ -1601,7 +1601,42 @@ fn walkInstruction(
16011601 .expr = .{ .builtinIndex = bin_index },
16021602 };
16031603 },
1604 .truncate => {
1605 // in the ZIR this node is a builtin `bin` but we want send it as a `un` builtin
1606 const pl_node = data[inst_index].pl_node;
1607 const extra = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index);
16041608
1609 var rhs: DocData.WalkResult = try self.walkRef(
1610 file,
1611 parent_scope,
1612 parent_src,
1613 extra.data.rhs,
1614 false,
1615 );
1616
1617 const bin_index = self.exprs.items.len;
1618 try self.exprs.append(self.arena, .{ .builtin = .{ .param = 0 } });
1619
1620 const rhs_index = self.exprs.items.len;
1621 try self.exprs.append(self.arena, rhs.expr);
1622
1623 var lhs: DocData.WalkResult = try self.walkRef(
1624 file,
1625 parent_scope,
1626 parent_src,
1627 extra.data.lhs,
1628 false,
1629 );
1630
1631 self.exprs.items[bin_index] = .{ .builtin = .{ .name = @tagName(tags[inst_index]), .param = rhs_index } };
1632
1633 std.debug.print("lhs: {any}\n\n", .{lhs});
1634 std.debug.print("lhs typeref: {any}\n\n", .{lhs.typeRef});
1635 return DocData.WalkResult{
1636 .typeRef = lhs.expr,
1637 .expr = .{ .builtinIndex = bin_index },
1638 };
1639 },
16051640 .int_from_float,
16061641 .float_from_int,
16071642 .ptr_from_int,
......@@ -1609,7 +1644,6 @@ fn walkInstruction(
16091644 .float_cast,
16101645 .int_cast,
16111646 .ptr_cast,
1612 .truncate,
16131647 .has_decl,
16141648 .has_field,
16151649 .div_exact,