| author | |
| committer | |
| log | 989e77153439666b1eb4ed463828960d8cc5930d |
| tree | 1e8f9b697a5817f5540cca8ad9841f9f6368056c |
| parent | e675af06984d0709d308e3faf60b33cadadf2bbf |
| parent | e6cab917e15a064f5247a742e028bcb628bfc014 |
| signature |
autodoc: added support for tuple structs2 files changed, 40 insertions(+), 11 deletions(-)
lib/docs/main.js+23-7| ... | ... | @@ -1772,9 +1772,17 @@ const NAV_MODES = { |
| 1772 | 1772 | let structObj = typeObj; |
| 1773 | 1773 | let name = ""; |
| 1774 | 1774 | if (opts.wantHtml) { |
| 1775 | name = "<span class='tok-kw'>struct</span> { "; | |
| 1775 | if (structObj.is_tuple) { | |
| 1776 | name = "<span class='tok-kw'>tuple</span> { "; | |
| 1777 | } else { | |
| 1778 | name = "<span class='tok-kw'>struct</span> { "; | |
| 1779 | } | |
| 1776 | 1780 | } else { |
| 1777 | name = "struct { "; | |
| 1781 | if (structObj.is_tuple) { | |
| 1782 | name = "tuple { "; | |
| 1783 | } else { | |
| 1784 | name = "struct { "; | |
| 1785 | } | |
| 1778 | 1786 | } |
| 1779 | 1787 | if (structObj.fields.length > 1 && opts.wantHtml) {name += "</br>";} |
| 1780 | 1788 | let indent = ""; |
| ... | ... | @@ -1795,10 +1803,15 @@ const NAV_MODES = { |
| 1795 | 1803 | for(let i = 0; i < structObj.fields.length; i += 1) { |
| 1796 | 1804 | let fieldNode = getAstNode(structNode.fields[i]); |
| 1797 | 1805 | let fieldName = fieldNode.name; |
| 1798 | let html = indent + escapeHtml(fieldName); | |
| 1806 | let html = indent; | |
| 1807 | if (!structObj.is_tuple) { | |
| 1808 | html += escapeHtml(fieldName); | |
| 1809 | } | |
| 1799 | 1810 | |
| 1800 | 1811 | let fieldTypeExpr = structObj.fields[i]; |
| 1801 | html += ": "; | |
| 1812 | if(!structObj.is_tuple) { | |
| 1813 | html += ": "; | |
| 1814 | } | |
| 1802 | 1815 | |
| 1803 | 1816 | html += exprName(fieldTypeExpr, {...opts, indent: indent}); |
| 1804 | 1817 | |
| ... | ... | @@ -2797,7 +2810,9 @@ const NAV_MODES = { |
| 2797 | 2810 | html += ' = <span class="tok-number">' + fieldName + "</span>"; |
| 2798 | 2811 | } else { |
| 2799 | 2812 | let fieldTypeExpr = container.fields[i]; |
| 2800 | html += ": "; | |
| 2813 | if(container.kind ==! typeKinds.Struct || !container.is_tuple) { | |
| 2814 | html += ": "; | |
| 2815 | } | |
| 2801 | 2816 | html += exprName(fieldTypeExpr, {wantHtml:true, wantLink:true}); |
| 2802 | 2817 | let tsn = typeShorthandName(fieldTypeExpr); |
| 2803 | 2818 | if (tsn) { |
| ... | ... | @@ -3945,8 +3960,9 @@ const NAV_MODES = { |
| 3945 | 3960 | privDecls: ty[3], |
| 3946 | 3961 | pubDecls: ty[4], |
| 3947 | 3962 | fields: ty[5], |
| 3948 | line_number: ty[6], | |
| 3949 | outer_decl: ty[7], | |
| 3963 | is_tuple: ty[6], | |
| 3964 | line_number: ty[7], | |
| 3965 | outer_decl: ty[8], | |
| 3950 | 3966 | }; |
| 3951 | 3967 | case 10: // ComptimeExpr |
| 3952 | 3968 | case 11: // ComptimeFloat |
src/Autodoc.zig+17-4| ... | ... | @@ -561,6 +561,7 @@ const DocData = struct { |
| 561 | 561 | privDecls: []usize = &.{}, // index into decls |
| 562 | 562 | pubDecls: []usize = &.{}, // index into decls |
| 563 | 563 | fields: ?[]Expr = null, // (use src->fields to find names) |
| 564 | is_tuple: bool, | |
| 564 | 565 | line_number: usize, |
| 565 | 566 | outer_decl: usize, |
| 566 | 567 | }, |
| ... | ... | @@ -2942,6 +2943,7 @@ fn walkInstruction( |
| 2942 | 2943 | &field_type_refs, |
| 2943 | 2944 | &field_name_indexes, |
| 2944 | 2945 | extra_index, |
| 2946 | small.is_tuple, | |
| 2945 | 2947 | ); |
| 2946 | 2948 | |
| 2947 | 2949 | self.ast_nodes.items[self_ast_node_index].fields = field_name_indexes.items; |
| ... | ... | @@ -2953,6 +2955,7 @@ fn walkInstruction( |
| 2953 | 2955 | .privDecls = priv_decl_indexes.items, |
| 2954 | 2956 | .pubDecls = decl_indexes.items, |
| 2955 | 2957 | .fields = field_type_refs.items, |
| 2958 | .is_tuple = small.is_tuple, | |
| 2956 | 2959 | .line_number = self.ast_nodes.items[self_ast_node_index].line, |
| 2957 | 2960 | .outer_decl = type_slot_index - 1, |
| 2958 | 2961 | }, |
| ... | ... | @@ -4116,6 +4119,7 @@ fn collectStructFieldInfo( |
| 4116 | 4119 | field_type_refs: *std.ArrayListUnmanaged(DocData.Expr), |
| 4117 | 4120 | field_name_indexes: *std.ArrayListUnmanaged(usize), |
| 4118 | 4121 | ei: usize, |
| 4122 | is_tuple: bool, | |
| 4119 | 4123 | ) !void { |
| 4120 | 4124 | if (fields_len == 0) return; |
| 4121 | 4125 | var extra_index = ei; |
| ... | ... | @@ -4125,7 +4129,7 @@ fn collectStructFieldInfo( |
| 4125 | 4129 | const bit_bags_count = std.math.divCeil(usize, fields_len, fields_per_u32) catch unreachable; |
| 4126 | 4130 | |
| 4127 | 4131 | const Field = struct { |
| 4128 | field_name: u32, | |
| 4132 | field_name: ?u32, | |
| 4129 | 4133 | doc_comment_index: u32, |
| 4130 | 4134 | type_body_len: u32 = 0, |
| 4131 | 4135 | align_body_len: u32 = 0, |
| ... | ... | @@ -4153,8 +4157,12 @@ fn collectStructFieldInfo( |
| 4153 | 4157 | const has_type_body = @truncate(u1, cur_bit_bag) != 0; |
| 4154 | 4158 | cur_bit_bag >>= 1; |
| 4155 | 4159 | |
| 4156 | const field_name = file.zir.extra[extra_index]; | |
| 4157 | extra_index += 1; | |
| 4160 | const field_name: ?u32 = if (!is_tuple) blk: { | |
| 4161 | const fname = file.zir.extra[extra_index]; | |
| 4162 | extra_index += 1; | |
| 4163 | break :blk fname; | |
| 4164 | } else null; | |
| 4165 | ||
| 4158 | 4166 | const doc_comment_index = file.zir.extra[extra_index]; |
| 4159 | 4167 | extra_index += 1; |
| 4160 | 4168 | |
| ... | ... | @@ -4217,8 +4225,13 @@ fn collectStructFieldInfo( |
| 4217 | 4225 | file.zir.nullTerminatedString(field.doc_comment_index) |
| 4218 | 4226 | else |
| 4219 | 4227 | null; |
| 4228 | const field_name: []const u8 = if (field.field_name) |f_name| | |
| 4229 | file.zir.nullTerminatedString(f_name) | |
| 4230 | else | |
| 4231 | ""; | |
| 4232 | ||
| 4220 | 4233 | try self.ast_nodes.append(self.arena, .{ |
| 4221 | .name = file.zir.nullTerminatedString(field.field_name), | |
| 4234 | .name = field_name, | |
| 4222 | 4235 | .docs = doc_comment, |
| 4223 | 4236 | }); |
| 4224 | 4237 | } |