authorgravatar for kappaloris@gmail.comLoris Cro <kappaloris@gmail.com> 2023-04-22 19:07:28+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-04-22 19:07:28+02:00
logad634bca9f12a9de641270478a6abf9495b9846f
tree8ef3ba9aeeae1fc71273e800fca92afd3598e76f
parentc4a63389e4eefb78c1ee2028047447094bb864dc
parent7e18bd7f7108dd3b1d018212d2c1aa6222fe99bd
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #15385 from der-teufel-programming/autodoc-cc-inline

autodoc: Handle calling conventions better

2 files changed, 47 insertions(+), 24 deletions(-)

lib/docs/main.js+21-6
......@@ -2198,13 +2198,26 @@ const NAV_MODES = {
21982198 if (opts.addParensIfFnSignature && fnObj.src == 0) {
21992199 payloadHtml += "(";
22002200 }
2201 if (opts.wantHtml) {
2202 if (fnObj.is_extern) {
2203 payloadHtml += "pub extern ";
2201 if (fnObj.is_extern) {
2202 if (opts.wantHtml) {
2203 payloadHtml += '<span class="tok-kw">extern </span>';
2204 } else {
2205 payloadHtml += "extern ";
22042206 }
2205 if (fnObj.has_lib_name) {
2206 payloadHtml += '"' + fnObj.lib_name + '" ';
2207 } else if (fnObj.has_cc) {
2208 let cc_expr = zigAnalysis.exprs[fnObj.cc];
2209 if (cc_expr.enumLiteral === "Inline") {
2210 if(opts.wantHtml) {
2211 payloadHtml += '<span class="tok-kw">inline </span>'
2212 } else {
2213 payloadHtml += "inline "
2214 }
22072215 }
2216 }
2217 if (fnObj.has_lib_name) {
2218 payloadHtml += '"' + fnObj.lib_name + '" ';
2219 }
2220 if (opts.wantHtml) {
22082221 payloadHtml += '<span class="tok-kw">fn </span>';
22092222 if (fnDecl) {
22102223 payloadHtml += '<span class="tok-fn">';
......@@ -2324,7 +2337,9 @@ const NAV_MODES = {
23242337 if (fnObj.has_cc) {
23252338 let cc = zigAnalysis.exprs[fnObj.cc];
23262339 if (cc) {
2327 payloadHtml += "callconv(." + cc.enumLiteral + ") ";
2340 if (cc.enumLiteral !== "Inline") {
2341 payloadHtml += "callconv(" + exprName(cc, opts) + ") ";
2342 }
23282343 }
23292344 }
23302345
src/Autodoc.zig+26-18
......@@ -112,7 +112,7 @@ pub fn generateZirData(self: *Autodoc) !void {
112112 .ComptimeExpr = .{ .name = "ComptimeExpr" },
113113 });
114114
115 // this skipts Ref.none but it's ok becuse we replaced it with ComptimeExpr
115 // this skips Ref.none but it's ok becuse we replaced it with ComptimeExpr
116116 var i: u32 = 1;
117117 while (i <= @enumToInt(Ref.anyerror_void_error_union_type)) : (i += 1) {
118118 var tmpbuf = std.ArrayList(u8).init(self.arena);
......@@ -196,8 +196,10 @@ pub fn generateZirData(self: *Autodoc) !void {
196196 .anyerror_type => .{
197197 .ErrorSet = .{ .name = try tmpbuf.toOwnedSlice() },
198198 },
199 .calling_convention_inline, .calling_convention_c, .calling_convention_type => .{
200 .EnumLiteral = .{ .name = try tmpbuf.toOwnedSlice() },
199 // should be an Enum but if we don't analyze std we don't get the ast node
200 // since it's std.builtin.CallingConvention
201 .calling_convention_type => .{
202 .Type = .{ .name = try tmpbuf.toOwnedSlice() },
201203 },
202204 },
203205 );
......@@ -4009,17 +4011,27 @@ fn analyzeFancyFunction(
40094011 }
40104012
40114013 var cc_index: ?usize = null;
4012 if (extra.data.bits.has_cc_ref) {
4014 if (extra.data.bits.has_cc_ref and !extra.data.bits.has_cc_body) {
40134015 const cc_ref = @intToEnum(Zir.Inst.Ref, file.zir.extra[extra_index]);
4016 const cc_expr = try self.walkRef(file, scope, parent_src, cc_ref, false);
4017
40144018 cc_index = self.exprs.items.len;
4015 _ = try self.walkRef(file, scope, parent_src, cc_ref, false);
4019 try self.exprs.append(self.arena, cc_expr.expr);
4020
40164021 extra_index += 1;
40174022 } else if (extra.data.bits.has_cc_body) {
40184023 const cc_body_len = file.zir.extra[extra_index];
40194024 extra_index += 1;
4020 const cc_body = file.zir.extra[extra_index .. extra_index + cc_body_len];
4021 _ = cc_body;
4022 // TODO: analyze the block (or bail with a comptimeExpr)
4025 const cc_body = file.zir.extra[extra_index..][0..cc_body_len];
4026
4027 // We assume the body ends with a break_inline
4028 const break_index = cc_body[cc_body.len - 1];
4029 const break_operand = data[break_index].@"break".operand;
4030 const cc_expr = try self.walkRef(file, scope, parent_src, break_operand, false);
4031
4032 cc_index = self.exprs.items.len;
4033 try self.exprs.append(self.arena, cc_expr.expr);
4034
40234035 extra_index += cc_body_len;
40244036 } else {
40254037 // auto calling convention
......@@ -4564,26 +4576,22 @@ fn walkRef(
45644576 .expr = .{ .int = .{ .value = 1 } },
45654577 };
45664578 },
4567 // TODO: dunno what to do with those
45684579 .calling_convention_type => {
45694580 return DocData.WalkResult{
4570 .typeRef = .{ .type = @enumToInt(Ref.calling_convention_type) },
4571 // .typeRef = .{ .type = @enumToInt(Ref.comptime_int_type) },
4572 .expr = .{ .int = .{ .value = 1 } },
4581 .typeRef = .{ .type = @enumToInt(Ref.type_type) },
4582 .expr = .{ .type = @enumToInt(Ref.calling_convention_type) },
45734583 };
45744584 },
45754585 .calling_convention_c => {
45764586 return DocData.WalkResult{
4577 .typeRef = .{ .type = @enumToInt(Ref.calling_convention_c) },
4578 // .typeRef = .{ .type = @enumToInt(Ref.comptime_int_type) },
4579 .expr = .{ .int = .{ .value = 1 } },
4587 .typeRef = .{ .type = @enumToInt(Ref.calling_convention_type) },
4588 .expr = .{ .enumLiteral = "C" },
45804589 };
45814590 },
45824591 .calling_convention_inline => {
45834592 return DocData.WalkResult{
4584 .typeRef = .{ .type = @enumToInt(Ref.calling_convention_inline) },
4585 // .typeRef = .{ .type = @enumToInt(Ref.comptime_int_type) },
4586 .expr = .{ .int = .{ .value = 1 } },
4593 .typeRef = .{ .type = @enumToInt(Ref.calling_convention_type) },
4594 .expr = .{ .enumLiteral = "Inline" },
45874595 };
45884596 },
45894597 // .generic_poison => {