| ... | ... | @@ -162,9 +162,9 @@ pub fn generateZirData(self: *Autodoc) !void { |
| 162 | 162 | .anyerror_type => .{ |
| 163 | 163 | .ErrorSet = .{ .name = tmpbuf.toOwnedSlice() }, |
| 164 | 164 | }, |
| 165 | | // .calling_convention_inline, .calling_convention_c, .calling_convention_type => .{ |
| 166 | | // .EnumLiteral = .{ .name = tmpbuf.toOwnedSlice() }, |
| 167 | | // }, |
| 165 | .calling_convention_inline, .calling_convention_c, .calling_convention_type => .{ |
| 166 | .EnumLiteral = .{ .name = tmpbuf.toOwnedSlice() }, |
| 167 | }, |
| 168 | 168 | }, |
| 169 | 169 | ); |
| 170 | 170 | } |
| ... | ... | @@ -520,13 +520,6 @@ const DocData = struct { |
| 520 | 520 | .Type => |v| try printTypeBody(v, options, w), |
| 521 | 521 | .NoReturn => |v| try printTypeBody(v, options, w), |
| 522 | 522 | .EnumLiteral => |v| try printTypeBody(v, options, w), |
| 523 | | .Unanalyzed => |_| { |
| 524 | | if (options.whitespace) |ws| try ws.outputIndent(w); |
| 525 | | try w.print( |
| 526 | | \\"Unanalyzed": "Unanalyzed" |
| 527 | | \\ |
| 528 | | , .{}); |
| 529 | | }, |
| 530 | 523 | .Pointer => |v| { |
| 531 | 524 | if (options.whitespace) |ws| try ws.outputIndent(w); |
| 532 | 525 | try w.print( |
| ... | ... | @@ -885,7 +878,7 @@ fn walkInstruction( |
| 885 | 878 | const literal = file.zir.nullTerminatedString(str_tok.start); |
| 886 | 879 | const type_index = self.types.items.len; |
| 887 | 880 | try self.types.append(self.arena, .{ |
| 888 | | .EnumLiteral = .{ .name = literal }, |
| 881 | .EnumLiteral = .{ .name = "todo enum literal" }, |
| 889 | 882 | }); |
| 890 | 883 | |
| 891 | 884 | return DocData.WalkResult{ |
| ... | ... | @@ -1643,17 +1636,33 @@ fn walkInstruction( |
| 1643 | 1636 | .expr = .{ .call = call_slot_index }, |
| 1644 | 1637 | }; |
| 1645 | 1638 | }, |
| 1646 | | .func, .func_inferred, .func_extended => { |
| 1639 | .func, .func_inferred => { |
| 1640 | const type_slot_index = self.types.items.len; |
| 1641 | try self.types.append(self.arena, .{ .Unanalyzed = {} }); |
| 1642 | |
| 1643 | const result = self.analyzeFunction( |
| 1644 | file, |
| 1645 | parent_scope, |
| 1646 | inst_index, |
| 1647 | self_ast_node_index, |
| 1648 | type_slot_index, |
| 1649 | ); |
| 1650 | |
| 1651 | return result; |
| 1652 | }, |
| 1653 | .func_extended => { |
| 1647 | 1654 | const type_slot_index = self.types.items.len; |
| 1648 | 1655 | try self.types.append(self.arena, .{ .Unanalyzed = {} }); |
| 1649 | 1656 | |
| 1650 | | return self.analyzeFunction( |
| 1657 | const result = self.analyzeFunctionExtended( |
| 1651 | 1658 | file, |
| 1652 | 1659 | parent_scope, |
| 1653 | 1660 | inst_index, |
| 1654 | 1661 | self_ast_node_index, |
| 1655 | 1662 | type_slot_index, |
| 1656 | 1663 | ); |
| 1664 | |
| 1665 | return result; |
| 1657 | 1666 | }, |
| 1658 | 1667 | .extended => { |
| 1659 | 1668 | const extended = data[inst_index].extended; |
| ... | ... | @@ -2677,7 +2686,119 @@ fn tryResolveRefPath( |
| 2677 | 2686 | // that said, we might want to store it elsewhere and reclaim memory asap |
| 2678 | 2687 | } |
| 2679 | 2688 | } |
| 2689 | fn analyzeFunctionExtended( |
| 2690 | self: *Autodoc, |
| 2691 | file: *File, |
| 2692 | scope: *Scope, |
| 2693 | inst_index: usize, |
| 2694 | self_ast_node_index: usize, |
| 2695 | type_slot_index: usize, |
| 2696 | ) error{OutOfMemory}!DocData.WalkResult { |
| 2697 | const tags = file.zir.instructions.items(.tag); |
| 2698 | const data = file.zir.instructions.items(.data); |
| 2699 | const fn_info = file.zir.getFnInfo(@intCast(u32, inst_index)); |
| 2700 | |
| 2701 | try self.ast_nodes.ensureUnusedCapacity(self.arena, fn_info.total_params_len); |
| 2702 | var param_type_refs = try std.ArrayListUnmanaged(DocData.Expr).initCapacity( |
| 2703 | self.arena, |
| 2704 | fn_info.total_params_len, |
| 2705 | ); |
| 2706 | var param_ast_indexes = try std.ArrayListUnmanaged(usize).initCapacity( |
| 2707 | self.arena, |
| 2708 | fn_info.total_params_len, |
| 2709 | ); |
| 2710 | |
| 2711 | // TODO: handle scope rules for fn parameters |
| 2712 | for (fn_info.param_body[0..fn_info.total_params_len]) |param_index| { |
| 2713 | switch (tags[param_index]) { |
| 2714 | else => { |
| 2715 | panicWithContext( |
| 2716 | file, |
| 2717 | param_index, |
| 2718 | "TODO: handle `{s}` in walkInstruction.func\n", |
| 2719 | .{@tagName(tags[param_index])}, |
| 2720 | ); |
| 2721 | }, |
| 2722 | .param_anytype, .param_anytype_comptime => { |
| 2723 | // TODO: where are the doc comments? |
| 2724 | const str_tok = data[param_index].str_tok; |
| 2680 | 2725 | |
| 2726 | const name = str_tok.get(file.zir); |
| 2727 | |
| 2728 | param_ast_indexes.appendAssumeCapacity(self.ast_nodes.items.len); |
| 2729 | self.ast_nodes.appendAssumeCapacity(.{ |
| 2730 | .name = name, |
| 2731 | .docs = "", |
| 2732 | .@"comptime" = tags[param_index] == .param_anytype_comptime, |
| 2733 | }); |
| 2734 | |
| 2735 | param_type_refs.appendAssumeCapacity( |
| 2736 | DocData.Expr{ .@"anytype" = {} }, |
| 2737 | ); |
| 2738 | }, |
| 2739 | .param, .param_comptime => { |
| 2740 | const pl_tok = data[param_index].pl_tok; |
| 2741 | const extra = file.zir.extraData(Zir.Inst.Param, pl_tok.payload_index); |
| 2742 | const doc_comment = if (extra.data.doc_comment != 0) |
| 2743 | file.zir.nullTerminatedString(extra.data.doc_comment) |
| 2744 | else |
| 2745 | ""; |
| 2746 | const name = file.zir.nullTerminatedString(extra.data.name); |
| 2747 | |
| 2748 | param_ast_indexes.appendAssumeCapacity(self.ast_nodes.items.len); |
| 2749 | try self.ast_nodes.append(self.arena, .{ |
| 2750 | .name = name, |
| 2751 | .docs = doc_comment, |
| 2752 | .@"comptime" = tags[param_index] == .param_comptime, |
| 2753 | }); |
| 2754 | |
| 2755 | const break_index = file.zir.extra[extra.end..][extra.data.body_len - 1]; |
| 2756 | const break_operand = data[break_index].@"break".operand; |
| 2757 | const param_type_ref = try self.walkRef(file, scope, break_operand, false); |
| 2758 | |
| 2759 | param_type_refs.appendAssumeCapacity(param_type_ref.expr); |
| 2760 | }, |
| 2761 | } |
| 2762 | } |
| 2763 | |
| 2764 | // ret |
| 2765 | const ret_type_ref = blk: { |
| 2766 | const last_instr_index = fn_info.ret_ty_body[fn_info.ret_ty_body.len - 1]; |
| 2767 | const break_operand = data[last_instr_index].@"break".operand; |
| 2768 | const wr = try self.walkRef(file, scope, break_operand, false); |
| 2769 | |
| 2770 | break :blk wr; |
| 2771 | }; |
| 2772 | |
| 2773 | self.ast_nodes.items[self_ast_node_index].fields = param_ast_indexes.items; |
| 2774 | const inst_data = data[inst_index].pl_node; |
| 2775 | |
| 2776 | const extra = file.zir.extraData(Zir.Inst.ExtendedFunc, inst_data.payload_index); |
| 2777 | var cc_index: ?usize = null; |
| 2778 | if (extra.data.bits.has_cc) { |
| 2779 | const cc_ref = @intToEnum(Zir.Inst.Ref, file.zir.extra[extra.end]); |
| 2780 | cc_index = self.exprs.items.len; |
| 2781 | _ = try self.walkRef(file, scope, cc_ref, false); |
| 2782 | } |
| 2783 | |
| 2784 | self.types.items[type_slot_index] = .{ |
| 2785 | .Fn = .{ |
| 2786 | .name = "todo_name func", |
| 2787 | .src = self_ast_node_index, |
| 2788 | .params = param_type_refs.items, |
| 2789 | .ret = ret_type_ref.expr, |
| 2790 | .is_extern = extra.data.bits.is_extern, |
| 2791 | .has_cc = extra.data.bits.has_cc, |
| 2792 | .is_inferred_error = extra.data.bits.is_inferred_error, |
| 2793 | .cc = cc_index, |
| 2794 | }, |
| 2795 | }; |
| 2796 | |
| 2797 | return DocData.WalkResult{ |
| 2798 | .typeRef = .{ .type = @enumToInt(Ref.type_type) }, |
| 2799 | .expr = .{ .type = type_slot_index }, |
| 2800 | }; |
| 2801 | } |
| 2681 | 2802 | fn analyzeFunction( |
| 2682 | 2803 | self: *Autodoc, |
| 2683 | 2804 | file: *File, |
| ... | ... | @@ -2763,46 +2884,13 @@ fn analyzeFunction( |
| 2763 | 2884 | }; |
| 2764 | 2885 | |
| 2765 | 2886 | self.ast_nodes.items[self_ast_node_index].fields = param_ast_indexes.items; |
| 2766 | | self.types.items[type_slot_index] = switch (tags[inst_index]) { |
| 2767 | | .func, .func_inferred => blk: { |
| 2768 | | break :blk .{ |
| 2769 | | .Fn = .{ |
| 2770 | | .name = "todo_name func", |
| 2771 | | .src = self_ast_node_index, |
| 2772 | | .params = param_type_refs.items, |
| 2773 | | .ret = ret_type_ref.expr, |
| 2774 | | }, |
| 2775 | | }; |
| 2776 | | }, |
| 2777 | | .func_extended => blk: { |
| 2778 | | const inst_data = data[inst_index].pl_node; |
| 2779 | | const extra = file.zir.extraData(Zir.Inst.ExtendedFunc, inst_data.payload_index); |
| 2780 | | var cc_index: ?usize = null; |
| 2781 | | cc_index = self.types.items.len - 1; |
| 2782 | | // if (extra.data.bits.has_cc) { |
| 2783 | | // const cc = file.zir.extra[extra.end]; |
| 2784 | | // const cc_ref = @intToEnum(Zir.Inst.Ref, cc); |
| 2785 | | // _ = try self.walkRef(file, scope, cc_ref, false); |
| 2786 | | // cc_index = self.types.items.len - 1; |
| 2787 | | // std.debug.print("DONE\n", .{}); |
| 2788 | | // std.debug.print("cc_ref = {any}\n", .{cc_ref}); |
| 2789 | | // std.debug.print("index = {}\n", .{cc_index}); |
| 2790 | | // } |
| 2791 | | |
| 2792 | | break :blk .{ |
| 2793 | | .Fn = .{ |
| 2794 | | .name = "todo_name func", |
| 2795 | | .src = self_ast_node_index, |
| 2796 | | .params = param_type_refs.items, |
| 2797 | | .ret = ret_type_ref.expr, |
| 2798 | | .is_extern = extra.data.bits.is_extern, |
| 2799 | | .has_cc = extra.data.bits.has_cc, |
| 2800 | | .is_inferred_error = extra.data.bits.is_inferred_error, |
| 2801 | | .cc = cc_index, |
| 2802 | | }, |
| 2803 | | }; |
| 2887 | self.types.items[type_slot_index] = .{ |
| 2888 | .Fn = .{ |
| 2889 | .name = "todo_name func", |
| 2890 | .src = self_ast_node_index, |
| 2891 | .params = param_type_refs.items, |
| 2892 | .ret = ret_type_ref.expr, |
| 2804 | 2893 | }, |
| 2805 | | else => unreachable, |
| 2806 | 2894 | }; |
| 2807 | 2895 | |
| 2808 | 2896 | return DocData.WalkResult{ |
| ... | ... | @@ -3032,22 +3120,22 @@ fn walkRef( |
| 3032 | 3120 | // TODO: dunno what to do with those |
| 3033 | 3121 | .calling_convention_type => { |
| 3034 | 3122 | return DocData.WalkResult{ |
| 3035 | | // .typeRef = .{ .type = @enumToInt(Ref.calling_convention_type) }, |
| 3036 | | .typeRef = .{ .type = @enumToInt(Ref.comptime_int_type) }, |
| 3123 | .typeRef = .{ .type = @enumToInt(Ref.calling_convention_type) }, |
| 3124 | // .typeRef = .{ .type = @enumToInt(Ref.comptime_int_type) }, |
| 3037 | 3125 | .expr = .{ .int = .{ .value = 1 } }, |
| 3038 | 3126 | }; |
| 3039 | 3127 | }, |
| 3040 | 3128 | .calling_convention_c => { |
| 3041 | 3129 | return DocData.WalkResult{ |
| 3042 | | // .typeRef = .{ .type = @enumToInt(Ref.calling_convention_c) }, |
| 3043 | | .typeRef = .{ .type = @enumToInt(Ref.comptime_int_type) }, |
| 3130 | .typeRef = .{ .type = @enumToInt(Ref.calling_convention_c) }, |
| 3131 | // .typeRef = .{ .type = @enumToInt(Ref.comptime_int_type) }, |
| 3044 | 3132 | .expr = .{ .int = .{ .value = 1 } }, |
| 3045 | 3133 | }; |
| 3046 | 3134 | }, |
| 3047 | 3135 | .calling_convention_inline => { |
| 3048 | 3136 | return DocData.WalkResult{ |
| 3049 | | // .typeRef = .{ .type = @enumToInt(Ref.calling_convention_inline) }, |
| 3050 | | .typeRef = .{ .type = @enumToInt(Ref.comptime_int_type) }, |
| 3137 | .typeRef = .{ .type = @enumToInt(Ref.calling_convention_inline) }, |
| 3138 | // .typeRef = .{ .type = @enumToInt(Ref.comptime_int_type) }, |
| 3051 | 3139 | .expr = .{ .int = .{ .value = 1 } }, |
| 3052 | 3140 | }; |
| 3053 | 3141 | }, |