| ... | ... | @@ -586,7 +586,8 @@ const DocData = struct { |
| 586 | 586 | src: usize, // index into astNodes |
| 587 | 587 | privDecls: []usize = &.{}, // index into decls |
| 588 | 588 | pubDecls: []usize = &.{}, // index into decls |
| 589 | | fields: ?[]Expr = null, // (use src->fields to find names) |
| 589 | field_types: []Expr = &.{}, // (use src->fields to find names) |
| 590 | field_defaults: []?Expr = &.{}, // default values is specified |
| 590 | 591 | is_tuple: bool, |
| 591 | 592 | line_number: usize, |
| 592 | 593 | outer_decl: usize, |
| ... | ... | @@ -614,6 +615,7 @@ const DocData = struct { |
| 614 | 615 | pubDecls: []usize = &.{}, // index into decls |
| 615 | 616 | // (use src->fields to find field names) |
| 616 | 617 | tag: ?Expr = null, // tag type if specified |
| 618 | values: []?Expr = &.{}, // tag values if specified |
| 617 | 619 | nonexhaustive: bool, |
| 618 | 620 | }, |
| 619 | 621 | Union: struct { |
| ... | ... | @@ -2705,6 +2707,7 @@ fn walkInstruction( |
| 2705 | 2707 | extra_index += body_len; |
| 2706 | 2708 | |
| 2707 | 2709 | var field_name_indexes: std.ArrayListUnmanaged(usize) = .{}; |
| 2710 | var field_values: std.ArrayListUnmanaged(?DocData.Expr) = .{}; |
| 2708 | 2711 | { |
| 2709 | 2712 | var bit_bag_idx = extra_index; |
| 2710 | 2713 | var cur_bit_bag: u32 = undefined; |
| ... | ... | @@ -2726,12 +2729,13 @@ fn walkInstruction( |
| 2726 | 2729 | const doc_comment_index = file.zir.extra[extra_index]; |
| 2727 | 2730 | extra_index += 1; |
| 2728 | 2731 | |
| 2729 | | const value_ref: ?Ref = if (has_value) blk: { |
| 2732 | const value_expr: ?DocData.Expr = if (has_value) blk: { |
| 2730 | 2733 | const value_ref = file.zir.extra[extra_index]; |
| 2731 | 2734 | extra_index += 1; |
| 2732 | | break :blk @intToEnum(Ref, value_ref); |
| 2735 | const value = try self.walkRef(file, &scope, src_info, @intToEnum(Ref, value_ref), false); |
| 2736 | break :blk value.expr; |
| 2733 | 2737 | } else null; |
| 2734 | | _ = value_ref; |
| 2738 | try field_values.append(self.arena, value_expr); |
| 2735 | 2739 | |
| 2736 | 2740 | const field_name = file.zir.nullTerminatedString(field_name_index); |
| 2737 | 2741 | |
| ... | ... | @@ -2756,6 +2760,7 @@ fn walkInstruction( |
| 2756 | 2760 | .privDecls = priv_decl_indexes.items, |
| 2757 | 2761 | .pubDecls = decl_indexes.items, |
| 2758 | 2762 | .tag = tag_type, |
| 2763 | .values = field_values.items, |
| 2759 | 2764 | .nonexhaustive = small.nonexhaustive, |
| 2760 | 2765 | }, |
| 2761 | 2766 | }; |
| ... | ... | @@ -2831,6 +2836,7 @@ fn walkInstruction( |
| 2831 | 2836 | ); |
| 2832 | 2837 | |
| 2833 | 2838 | var field_type_refs: std.ArrayListUnmanaged(DocData.Expr) = .{}; |
| 2839 | var field_default_refs: std.ArrayListUnmanaged(?DocData.Expr) = .{}; |
| 2834 | 2840 | var field_name_indexes: std.ArrayListUnmanaged(usize) = .{}; |
| 2835 | 2841 | try self.collectStructFieldInfo( |
| 2836 | 2842 | file, |
| ... | ... | @@ -2838,6 +2844,7 @@ fn walkInstruction( |
| 2838 | 2844 | src_info, |
| 2839 | 2845 | fields_len, |
| 2840 | 2846 | &field_type_refs, |
| 2847 | &field_default_refs, |
| 2841 | 2848 | &field_name_indexes, |
| 2842 | 2849 | extra_index, |
| 2843 | 2850 | small.is_tuple, |
| ... | ... | @@ -2851,7 +2858,8 @@ fn walkInstruction( |
| 2851 | 2858 | .src = self_ast_node_index, |
| 2852 | 2859 | .privDecls = priv_decl_indexes.items, |
| 2853 | 2860 | .pubDecls = decl_indexes.items, |
| 2854 | | .fields = field_type_refs.items, |
| 2861 | .field_types = field_type_refs.items, |
| 2862 | .field_defaults = field_default_refs.items, |
| 2855 | 2863 | .is_tuple = small.is_tuple, |
| 2856 | 2864 | .line_number = self.ast_nodes.items[self_ast_node_index].line, |
| 2857 | 2865 | .outer_decl = type_slot_index - 1, |
| ... | ... | @@ -4309,6 +4317,7 @@ fn collectStructFieldInfo( |
| 4309 | 4317 | parent_src: SrcLocInfo, |
| 4310 | 4318 | fields_len: usize, |
| 4311 | 4319 | field_type_refs: *std.ArrayListUnmanaged(DocData.Expr), |
| 4320 | field_default_refs: *std.ArrayListUnmanaged(?DocData.Expr), |
| 4312 | 4321 | field_name_indexes: *std.ArrayListUnmanaged(usize), |
| 4313 | 4322 | ei: usize, |
| 4314 | 4323 | is_tuple: bool, |
| ... | ... | @@ -4406,9 +4415,23 @@ fn collectStructFieldInfo( |
| 4406 | 4415 | }; |
| 4407 | 4416 | |
| 4408 | 4417 | extra_index += field.align_body_len; |
| 4409 | | extra_index += field.init_body_len; |
| 4418 | |
| 4419 | const default_expr: ?DocData.Expr = def: { |
| 4420 | if (field.init_body_len == 0) { |
| 4421 | break :def null; |
| 4422 | } |
| 4423 | |
| 4424 | const body = file.zir.extra[extra_index..][0..field.init_body_len]; |
| 4425 | extra_index += body.len; |
| 4426 | |
| 4427 | const break_inst = body[body.len - 1]; |
| 4428 | const operand = data[break_inst].@"break".operand; |
| 4429 | const walk_result = try self.walkRef(file, scope, parent_src, operand, false); |
| 4430 | break :def walk_result.expr; |
| 4431 | }; |
| 4410 | 4432 | |
| 4411 | 4433 | try field_type_refs.append(self.arena, type_expr); |
| 4434 | try field_default_refs.append(self.arena, default_expr); |
| 4412 | 4435 | |
| 4413 | 4436 | // ast node |
| 4414 | 4437 | { |