| author | |
| committer | |
| log | 8bbf62c3b98da474dbbde907819a74133da9f430 |
| tree | 11969c11103cc3ce4fc687b048d52fa6661fdd1d |
| parent | 97b3b36c65faad1fa66df82e53e3f464b9cedb44 |
Fixes to frontend handling of structs2 files changed, 18 insertions(+), 9 deletions(-)
lib/docs/main.js+9-4| ... | @@ -623,7 +623,7 @@ const NAV_MODES = { | ... | @@ -623,7 +623,7 @@ const NAV_MODES = { |
| 623 | function typeIsStructWithNoFields(typeIndex) { | 623 | function typeIsStructWithNoFields(typeIndex) { |
| 624 | let typeObj = getType(typeIndex); | 624 | let typeObj = getType(typeIndex); |
| 625 | if (typeObj.kind !== typeKinds.Struct) return false; | 625 | if (typeObj.kind !== typeKinds.Struct) return false; |
| 626 | return typeObj.fields.length == 0; | 626 | return typeObj.field_types.length == 0; |
| 627 | } | 627 | } |
| 628 | 628 | ||
| 629 | function typeIsGenericFn(typeIndex) { | 629 | function typeIsGenericFn(typeIndex) { |
| ... | @@ -2705,6 +2705,7 @@ const NAV_MODES = { | ... | @@ -2705,6 +2705,7 @@ const NAV_MODES = { |
| 2705 | let declValue = resolveValue(uns.value); | 2705 | let declValue = resolveValue(uns.value); |
| 2706 | if (!("type" in declValue.expr)) continue; | 2706 | if (!("type" in declValue.expr)) continue; |
| 2707 | let uns_container = getType(declValue.expr.type); | 2707 | let uns_container = getType(declValue.expr.type); |
| 2708 | if (!isContainerType(uns_container)) continue; | ||
| 2708 | categorizeDecls( | 2709 | categorizeDecls( |
| 2709 | uns_container.pubDecls, | 2710 | uns_container.pubDecls, |
| 2710 | typesList, | 2711 | typesList, |
| ... | @@ -2858,7 +2859,10 @@ const NAV_MODES = { | ... | @@ -2858,7 +2859,10 @@ const NAV_MODES = { |
| 2858 | escapeHtml(fieldName); | 2859 | escapeHtml(fieldName); |
| 2859 | 2860 | ||
| 2860 | if (container.kind === typeKinds.Enum) { | 2861 | if (container.kind === typeKinds.Enum) { |
| 2861 | html += ' = <span class="tok-number">' + fieldName + "</span>"; | 2862 | let value = container.values[i]; |
| 2863 | if (value !== null) { | ||
| 2864 | html += " = " + exprName(value, { wantHtml: true, wantLink: true }); | ||
| 2865 | } | ||
| 2862 | } else { | 2866 | } else { |
| 2863 | let fieldTypeExpr = container.field_types[i]; | 2867 | let fieldTypeExpr = container.field_types[i]; |
| 2864 | if (container.kind !== typeKinds.Struct || !container.is_tuple) { | 2868 | if (container.kind !== typeKinds.Struct || !container.is_tuple) { |
| ... | @@ -4106,7 +4110,8 @@ function addDeclToSearchResults(decl, declIndex, pkgNames, item, list, stack) { | ... | @@ -4106,7 +4110,8 @@ function addDeclToSearchResults(decl, declIndex, pkgNames, item, list, stack) { |
| 4106 | privDecls: ty[3], | 4110 | privDecls: ty[3], |
| 4107 | pubDecls: ty[4], | 4111 | pubDecls: ty[4], |
| 4108 | tag: ty[5], | 4112 | tag: ty[5], |
| 4109 | nonexhaustive: ty[6], | 4113 | values: ty[6], |
| 4114 | nonexhaustive: ty[7], | ||
| 4110 | }; | 4115 | }; |
| 4111 | case 20: // Union | 4116 | case 20: // Union |
| 4112 | return { | 4117 | return { |
| ... | @@ -4115,7 +4120,7 @@ function addDeclToSearchResults(decl, declIndex, pkgNames, item, list, stack) { | ... | @@ -4115,7 +4120,7 @@ function addDeclToSearchResults(decl, declIndex, pkgNames, item, list, stack) { |
| 4115 | src: ty[2], | 4120 | src: ty[2], |
| 4116 | privDecls: ty[3], | 4121 | privDecls: ty[3], |
| 4117 | pubDecls: ty[4], | 4122 | pubDecls: ty[4], |
| 4118 | fields: ty[5], | 4123 | field_types: ty[5], |
| 4119 | tag: ty[6], | 4124 | tag: ty[6], |
| 4120 | auto_tag: ty[7], | 4125 | auto_tag: ty[7], |
| 4121 | }; | 4126 | }; |
src/Autodoc.zig+9-5| ... | @@ -586,8 +586,8 @@ const DocData = struct { | ... | @@ -586,8 +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 | field_types: ?[]Expr = null, // (use src->fields to find names) | 589 | field_types: []Expr = &.{}, // (use src->fields to find names) |
| 590 | field_defaults: ?[]?Expr = null, | 590 | field_defaults: []?Expr = &.{}, // default values is specified |
| 591 | is_tuple: bool, | 591 | is_tuple: bool, |
| 592 | line_number: usize, | 592 | line_number: usize, |
| 593 | outer_decl: usize, | 593 | outer_decl: usize, |
| ... | @@ -615,6 +615,7 @@ const DocData = struct { | ... | @@ -615,6 +615,7 @@ const DocData = struct { |
| 615 | pubDecls: []usize = &.{}, // index into decls | 615 | pubDecls: []usize = &.{}, // index into decls |
| 616 | // (use src->fields to find field names) | 616 | // (use src->fields to find field names) |
| 617 | tag: ?Expr = null, // tag type if specified | 617 | tag: ?Expr = null, // tag type if specified |
| 618 | values: []?Expr = &.{}, // tag values if specified | ||
| 618 | nonexhaustive: bool, | 619 | nonexhaustive: bool, |
| 619 | }, | 620 | }, |
| 620 | Union: struct { | 621 | Union: struct { |
| ... | @@ -2706,6 +2707,7 @@ fn walkInstruction( | ... | @@ -2706,6 +2707,7 @@ fn walkInstruction( |
| 2706 | extra_index += body_len; | 2707 | extra_index += body_len; |
| 2707 | 2708 | ||
| 2708 | var field_name_indexes: std.ArrayListUnmanaged(usize) = .{}; | 2709 | var field_name_indexes: std.ArrayListUnmanaged(usize) = .{}; |
| 2710 | var field_values: std.ArrayListUnmanaged(?DocData.Expr) = .{}; | ||
| 2709 | { | 2711 | { |
| 2710 | var bit_bag_idx = extra_index; | 2712 | var bit_bag_idx = extra_index; |
| 2711 | var cur_bit_bag: u32 = undefined; | 2713 | var cur_bit_bag: u32 = undefined; |
| ... | @@ -2727,12 +2729,13 @@ fn walkInstruction( | ... | @@ -2727,12 +2729,13 @@ fn walkInstruction( |
| 2727 | const doc_comment_index = file.zir.extra[extra_index]; | 2729 | const doc_comment_index = file.zir.extra[extra_index]; |
| 2728 | extra_index += 1; | 2730 | extra_index += 1; |
| 2729 | 2731 | ||
| 2730 | const value_ref: ?Ref = if (has_value) blk: { | 2732 | const value_expr: ?DocData.Expr = if (has_value) blk: { |
| 2731 | const value_ref = file.zir.extra[extra_index]; | 2733 | const value_ref = file.zir.extra[extra_index]; |
| 2732 | extra_index += 1; | 2734 | extra_index += 1; |
| 2733 | 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; | ||
| 2734 | } else null; | 2737 | } else null; |
| 2735 | _ = value_ref; | 2738 | try field_values.append(self.arena, value_expr); |
| 2736 | 2739 | ||
| 2737 | const field_name = file.zir.nullTerminatedString(field_name_index); | 2740 | const field_name = file.zir.nullTerminatedString(field_name_index); |
| 2738 | 2741 | ||
| ... | @@ -2757,6 +2760,7 @@ fn walkInstruction( | ... | @@ -2757,6 +2760,7 @@ fn walkInstruction( |
| 2757 | .privDecls = priv_decl_indexes.items, | 2760 | .privDecls = priv_decl_indexes.items, |
| 2758 | .pubDecls = decl_indexes.items, | 2761 | .pubDecls = decl_indexes.items, |
| 2759 | .tag = tag_type, | 2762 | .tag = tag_type, |
| 2763 | .values = field_values.items, | ||
| 2760 | .nonexhaustive = small.nonexhaustive, | 2764 | .nonexhaustive = small.nonexhaustive, |
| 2761 | }, | 2765 | }, |
| 2762 | }; | 2766 | }; |