| ... | ... | @@ -328,6 +328,7 @@ const DocData = struct { |
| 328 | 328 | name: ?[]const u8 = null, |
| 329 | 329 | docs: ?[]const u8 = null, |
| 330 | 330 | fields: ?[]usize = null, // index into astNodes |
| 331 | @"comptime": bool = false, |
| 331 | 332 | }; |
| 332 | 333 | |
| 333 | 334 | const Type = union(DocTypeKinds) { |
| ... | ... | @@ -709,7 +710,7 @@ fn walkInstruction( |
| 709 | 710 | path[0] = decls_slot_index; |
| 710 | 711 | return DocData.WalkResult{ .declPath = path }; |
| 711 | 712 | }, |
| 712 | | .field_val => { |
| 713 | .field_val, .field_call_bind, .field_ptr => { |
| 713 | 714 | const pl_node = data[inst_index].pl_node; |
| 714 | 715 | const extra = file.zir.extraData(Zir.Inst.Field, pl_node.payload_index); |
| 715 | 716 | |
| ... | ... | @@ -719,7 +720,10 @@ fn walkInstruction( |
| 719 | 720 | try path.append(self.arena, extra.data.field_name_start); |
| 720 | 721 | // Put inside path the starting index of each decl name |
| 721 | 722 | // that we encounter as we navigate through all the field_vals |
| 722 | | while (tags[lhs] == .field_val) { |
| 723 | while (tags[lhs] == .field_val or |
| 724 | tags[lhs] == .field_call_bind or |
| 725 | tags[lhs] == .field_ptr) |
| 726 | { |
| 723 | 727 | const lhs_extra = file.zir.extraData( |
| 724 | 728 | Zir.Inst.Field, |
| 725 | 729 | data[lhs].pl_node.payload_index, |
| ... | ... | @@ -729,8 +733,11 @@ fn walkInstruction( |
| 729 | 733 | lhs = @enumToInt(lhs_extra.data.lhs) - Ref.typed_value_map.len; // underflow = need to handle Refs |
| 730 | 734 | } |
| 731 | 735 | |
| 732 | | if (tags[lhs] != .decl_val) { |
| 733 | | @panic("TODO: handle non-decl_val endings in walkInstruction.field_val"); |
| 736 | if (tags[lhs] != .decl_val and tags[lhs] != .decl_ref) { |
| 737 | std.debug.panic( |
| 738 | "TODO: handle `{s}` endings in walkInstruction.field_val", |
| 739 | .{@tagName(tags[lhs])}, |
| 740 | ); |
| 734 | 741 | } |
| 735 | 742 | const str_tok = data[lhs].str_tok; |
| 736 | 743 | const decls_slot_index = parent_scope.resolveDeclName(str_tok.start); |
| ... | ... | @@ -770,7 +777,6 @@ fn walkInstruction( |
| 770 | 777 | const pl_node = data[inst_index].pl_node; |
| 771 | 778 | const extra = file.zir.extraData(Zir.Inst.Call, pl_node.payload_index); |
| 772 | 779 | |
| 773 | | // TODO: handle the way scoping works with fn args |
| 774 | 780 | const callee = DocData.TypeRef.fromWalkResult( |
| 775 | 781 | try self.walkRef(file, parent_scope, extra.data.callee), |
| 776 | 782 | ); |
| ... | ... | @@ -794,9 +800,7 @@ fn walkInstruction( |
| 794 | 800 | .func => { |
| 795 | 801 | const fn_info = file.zir.getFnInfo(@intCast(u32, inst_index)); |
| 796 | 802 | |
| 797 | | // TODO: change this to a resize and change the appends accordingly |
| 798 | 803 | try self.ast_nodes.ensureUnusedCapacity(self.arena, fn_info.total_params_len); |
| 799 | | try self.types.ensureUnusedCapacity(self.arena, fn_info.total_params_len); |
| 800 | 804 | var param_type_refs = try std.ArrayListUnmanaged(DocData.TypeRef).initCapacity( |
| 801 | 805 | self.arena, |
| 802 | 806 | fn_info.total_params_len, |
| ... | ... | @@ -805,28 +809,39 @@ fn walkInstruction( |
| 805 | 809 | self.arena, |
| 806 | 810 | fn_info.total_params_len, |
| 807 | 811 | ); |
| 812 | // TODO: handle scope rules for fn parameters |
| 808 | 813 | for (fn_info.param_body[0..fn_info.total_params_len]) |param_index| { |
| 809 | | if (tags[param_index] != .param) unreachable; // TODO: handle more param types |
| 810 | | const pl_tok = data[param_index].pl_tok; |
| 811 | | const extra = file.zir.extraData(Zir.Inst.Param, pl_tok.payload_index); |
| 812 | | const doc_comment = if (extra.data.doc_comment != 0) |
| 813 | | file.zir.nullTerminatedString(extra.data.doc_comment) |
| 814 | | else |
| 815 | | ""; |
| 816 | | |
| 817 | | param_ast_indexes.appendAssumeCapacity(self.ast_nodes.items.len); |
| 818 | | try self.ast_nodes.append(self.arena, .{ |
| 819 | | .name = file.zir.nullTerminatedString(extra.data.name), |
| 820 | | .docs = doc_comment, |
| 821 | | }); |
| 822 | | |
| 823 | | const break_index = file.zir.extra[extra.end..][extra.data.body_len - 1]; |
| 824 | | const break_operand = data[break_index].@"break".operand; |
| 825 | | const param_type_ref = try self.walkRef(file, parent_scope, break_operand); |
| 826 | | |
| 827 | | param_type_refs.appendAssumeCapacity( |
| 828 | | DocData.TypeRef.fromWalkResult(param_type_ref), |
| 829 | | ); |
| 814 | switch (tags[param_index]) { |
| 815 | else => { |
| 816 | std.debug.panic( |
| 817 | "TODO: handle `{s}` in walkInstruction.func\n", |
| 818 | .{@tagName(tags[param_index])}, |
| 819 | ); |
| 820 | }, |
| 821 | .param, .param_comptime => { |
| 822 | const pl_tok = data[param_index].pl_tok; |
| 823 | const extra = file.zir.extraData(Zir.Inst.Param, pl_tok.payload_index); |
| 824 | const doc_comment = if (extra.data.doc_comment != 0) |
| 825 | file.zir.nullTerminatedString(extra.data.doc_comment) |
| 826 | else |
| 827 | ""; |
| 828 | |
| 829 | param_ast_indexes.appendAssumeCapacity(self.ast_nodes.items.len); |
| 830 | self.ast_nodes.appendAssumeCapacity(.{ |
| 831 | .name = file.zir.nullTerminatedString(extra.data.name), |
| 832 | .docs = doc_comment, |
| 833 | .@"comptime" = tags[param_index] == .param_comptime, |
| 834 | }); |
| 835 | |
| 836 | const break_index = file.zir.extra[extra.end..][extra.data.body_len - 1]; |
| 837 | const break_operand = data[break_index].@"break".operand; |
| 838 | const param_type_ref = try self.walkRef(file, parent_scope, break_operand); |
| 839 | |
| 840 | param_type_refs.appendAssumeCapacity( |
| 841 | DocData.TypeRef.fromWalkResult(param_type_ref), |
| 842 | ); |
| 843 | }, |
| 844 | } |
| 830 | 845 | } |
| 831 | 846 | |
| 832 | 847 | // ret |