From 35a8e8a06c0cb0a5a0c6ddcca3b70be05dc4d035 Mon Sep 17 00:00:00 2001 From: Emile Badenhorst Date: Sat, 1 Jul 2023 16:43:17 +0200 Subject: [PATCH] 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 --- lib/docs/main.js | 4 +++- src/Autodoc.zig | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/lib/docs/main.js b/lib/docs/main.js index 168a9b3a6c..b43a289e48 100644 --- a/lib/docs/main.js +++ b/lib/docs/main.js @@ -1419,6 +1419,9 @@ const NAV_MODES = { case "bit_reverse": { return "@bitReverse(T" + ", " + param + ")"; } + case "truncate": { + return "@truncate(" + param + ")"; + } default: console.log("builtin function not handled yet or doesn't exist!"); } @@ -2622,7 +2625,6 @@ const NAV_MODES = { function renderValue(decl) { let resolvedValue = resolveValue(decl.value); - if (resolvedValue.expr.fieldRef) { const declRef = decl.value.expr.refPath[0].declRef; const type = getDecl(declRef); diff --git a/src/Autodoc.zig b/src/Autodoc.zig index ad90ae4c14..60c266e887 100644 --- a/src/Autodoc.zig +++ b/src/Autodoc.zig @@ -1601,7 +1601,42 @@ fn walkInstruction( .expr = .{ .builtinIndex = bin_index }, }; }, + .truncate => { + // in the ZIR this node is a builtin `bin` but we want send it as a `un` builtin + const pl_node = data[inst_index].pl_node; + const extra = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index); + var rhs: DocData.WalkResult = try self.walkRef( + file, + parent_scope, + parent_src, + extra.data.rhs, + false, + ); + + const bin_index = self.exprs.items.len; + try self.exprs.append(self.arena, .{ .builtin = .{ .param = 0 } }); + + const rhs_index = self.exprs.items.len; + try self.exprs.append(self.arena, rhs.expr); + + var lhs: DocData.WalkResult = try self.walkRef( + file, + parent_scope, + parent_src, + extra.data.lhs, + false, + ); + + self.exprs.items[bin_index] = .{ .builtin = .{ .name = @tagName(tags[inst_index]), .param = rhs_index } }; + + std.debug.print("lhs: {any}\n\n", .{lhs}); + std.debug.print("lhs typeref: {any}\n\n", .{lhs.typeRef}); + return DocData.WalkResult{ + .typeRef = lhs.expr, + .expr = .{ .builtinIndex = bin_index }, + }; + }, .int_from_float, .float_from_int, .ptr_from_int, @@ -1609,7 +1644,6 @@ fn walkInstruction( .float_cast, .int_cast, .ptr_cast, - .truncate, .has_decl, .has_field, .div_exact,