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