| ... | @@ -586,7 +586,8 @@ const DocData = struct { | ... | @@ -586,7 +586,8 @@ const DocData = struct { |
| 586 | src: usize, // index into astNodes | 586 | src: usize, // index into astNodes |
| 587 | privDecls: []usize = &.{}, // index into decls | 587 | privDecls: []usize = &.{}, // index into decls |
| 588 | pubDecls: []usize = &.{}, // index into decls | 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 | is_tuple: bool, | 591 | is_tuple: bool, |
| 591 | line_number: usize, | 592 | line_number: usize, |
| 592 | outer_decl: usize, | 593 | outer_decl: usize, |
| ... | @@ -614,6 +615,7 @@ const DocData = struct { | ... | @@ -614,6 +615,7 @@ const DocData = struct { |
| 614 | pubDecls: []usize = &.{}, // index into decls | 615 | pubDecls: []usize = &.{}, // index into decls |
| 615 | // (use src->fields to find field names) | 616 | // (use src->fields to find field names) |
| 616 | tag: ?Expr = null, // tag type if specified | 617 | tag: ?Expr = null, // tag type if specified |
| | 618 | values: []?Expr = &.{}, // tag values if specified |
| 617 | nonexhaustive: bool, | 619 | nonexhaustive: bool, |
| 618 | }, | 620 | }, |
| 619 | Union: struct { | 621 | Union: struct { |
| ... | @@ -2705,6 +2707,7 @@ fn walkInstruction( | ... | @@ -2705,6 +2707,7 @@ fn walkInstruction( |
| 2705 | extra_index += body_len; | 2707 | extra_index += body_len; |
| 2706 | | 2708 | |
| 2707 | var field_name_indexes: std.ArrayListUnmanaged(usize) = .{}; | 2709 | var field_name_indexes: std.ArrayListUnmanaged(usize) = .{}; |
| | 2710 | var field_values: std.ArrayListUnmanaged(?DocData.Expr) = .{}; |
| 2708 | { | 2711 | { |
| 2709 | var bit_bag_idx = extra_index; | 2712 | var bit_bag_idx = extra_index; |
| 2710 | var cur_bit_bag: u32 = undefined; | 2713 | var cur_bit_bag: u32 = undefined; |
| ... | @@ -2726,12 +2729,13 @@ fn walkInstruction( | ... | @@ -2726,12 +2729,13 @@ fn walkInstruction( |
| 2726 | const doc_comment_index = file.zir.extra[extra_index]; | 2729 | const doc_comment_index = file.zir.extra[extra_index]; |
| 2727 | extra_index += 1; | 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 | const value_ref = file.zir.extra[extra_index]; | 2733 | const value_ref = file.zir.extra[extra_index]; |
| 2731 | extra_index += 1; | 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 | } else null; | 2737 | } else null; |
| 2734 | _ = value_ref; | 2738 | try field_values.append(self.arena, value_expr); |
| 2735 | | 2739 | |
| 2736 | const field_name = file.zir.nullTerminatedString(field_name_index); | 2740 | const field_name = file.zir.nullTerminatedString(field_name_index); |
| 2737 | | 2741 | |
| ... | @@ -2756,6 +2760,7 @@ fn walkInstruction( | ... | @@ -2756,6 +2760,7 @@ fn walkInstruction( |
| 2756 | .privDecls = priv_decl_indexes.items, | 2760 | .privDecls = priv_decl_indexes.items, |
| 2757 | .pubDecls = decl_indexes.items, | 2761 | .pubDecls = decl_indexes.items, |
| 2758 | .tag = tag_type, | 2762 | .tag = tag_type, |
| | 2763 | .values = field_values.items, |
| 2759 | .nonexhaustive = small.nonexhaustive, | 2764 | .nonexhaustive = small.nonexhaustive, |
| 2760 | }, | 2765 | }, |
| 2761 | }; | 2766 | }; |
| ... | @@ -2831,6 +2836,7 @@ fn walkInstruction( | ... | @@ -2831,6 +2836,7 @@ fn walkInstruction( |
| 2831 | ); | 2836 | ); |
| 2832 | | 2837 | |
| 2833 | var field_type_refs: std.ArrayListUnmanaged(DocData.Expr) = .{}; | 2838 | var field_type_refs: std.ArrayListUnmanaged(DocData.Expr) = .{}; |
| | 2839 | var field_default_refs: std.ArrayListUnmanaged(?DocData.Expr) = .{}; |
| 2834 | var field_name_indexes: std.ArrayListUnmanaged(usize) = .{}; | 2840 | var field_name_indexes: std.ArrayListUnmanaged(usize) = .{}; |
| 2835 | try self.collectStructFieldInfo( | 2841 | try self.collectStructFieldInfo( |
| 2836 | file, | 2842 | file, |
| ... | @@ -2838,6 +2844,7 @@ fn walkInstruction( | ... | @@ -2838,6 +2844,7 @@ fn walkInstruction( |
| 2838 | src_info, | 2844 | src_info, |
| 2839 | fields_len, | 2845 | fields_len, |
| 2840 | &field_type_refs, | 2846 | &field_type_refs, |
| | 2847 | &field_default_refs, |
| 2841 | &field_name_indexes, | 2848 | &field_name_indexes, |
| 2842 | extra_index, | 2849 | extra_index, |
| 2843 | small.is_tuple, | 2850 | small.is_tuple, |
| ... | @@ -2851,7 +2858,8 @@ fn walkInstruction( | ... | @@ -2851,7 +2858,8 @@ fn walkInstruction( |
| 2851 | .src = self_ast_node_index, | 2858 | .src = self_ast_node_index, |
| 2852 | .privDecls = priv_decl_indexes.items, | 2859 | .privDecls = priv_decl_indexes.items, |
| 2853 | .pubDecls = decl_indexes.items, | 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 | .is_tuple = small.is_tuple, | 2863 | .is_tuple = small.is_tuple, |
| 2856 | .line_number = self.ast_nodes.items[self_ast_node_index].line, | 2864 | .line_number = self.ast_nodes.items[self_ast_node_index].line, |
| 2857 | .outer_decl = type_slot_index - 1, | 2865 | .outer_decl = type_slot_index - 1, |
| ... | @@ -4309,6 +4317,7 @@ fn collectStructFieldInfo( | ... | @@ -4309,6 +4317,7 @@ fn collectStructFieldInfo( |
| 4309 | parent_src: SrcLocInfo, | 4317 | parent_src: SrcLocInfo, |
| 4310 | fields_len: usize, | 4318 | fields_len: usize, |
| 4311 | field_type_refs: *std.ArrayListUnmanaged(DocData.Expr), | 4319 | field_type_refs: *std.ArrayListUnmanaged(DocData.Expr), |
| | 4320 | field_default_refs: *std.ArrayListUnmanaged(?DocData.Expr), |
| 4312 | field_name_indexes: *std.ArrayListUnmanaged(usize), | 4321 | field_name_indexes: *std.ArrayListUnmanaged(usize), |
| 4313 | ei: usize, | 4322 | ei: usize, |
| 4314 | is_tuple: bool, | 4323 | is_tuple: bool, |
| ... | @@ -4406,9 +4415,23 @@ fn collectStructFieldInfo( | ... | @@ -4406,9 +4415,23 @@ fn collectStructFieldInfo( |
| 4406 | }; | 4415 | }; |
| 4407 | | 4416 | |
| 4408 | extra_index += field.align_body_len; | 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 | try field_type_refs.append(self.arena, type_expr); | 4433 | try field_type_refs.append(self.arena, type_expr); |
| | 4434 | try field_default_refs.append(self.arena, default_expr); |
| 4412 | | 4435 | |
| 4413 | // ast node | 4436 | // ast node |
| 4414 | { | 4437 | { |