mirror of
https://github.com/ziglang/zig.git
synced 2024-11-27 07:32:44 +00:00
autodoc: added support for tuple structs
This commit is contained in:
parent
e675af0698
commit
e6cab917e1
@ -1772,9 +1772,17 @@ const NAV_MODES = {
|
||||
let structObj = typeObj;
|
||||
let name = "";
|
||||
if (opts.wantHtml) {
|
||||
name = "<span class='tok-kw'>struct</span> { ";
|
||||
if (structObj.is_tuple) {
|
||||
name = "<span class='tok-kw'>tuple</span> { ";
|
||||
} else {
|
||||
name = "<span class='tok-kw'>struct</span> { ";
|
||||
}
|
||||
} else {
|
||||
name = "struct { ";
|
||||
if (structObj.is_tuple) {
|
||||
name = "tuple { ";
|
||||
} else {
|
||||
name = "struct { ";
|
||||
}
|
||||
}
|
||||
if (structObj.fields.length > 1 && opts.wantHtml) {name += "</br>";}
|
||||
let indent = "";
|
||||
@ -1795,10 +1803,15 @@ const NAV_MODES = {
|
||||
for(let i = 0; i < structObj.fields.length; i += 1) {
|
||||
let fieldNode = getAstNode(structNode.fields[i]);
|
||||
let fieldName = fieldNode.name;
|
||||
let html = indent + escapeHtml(fieldName);
|
||||
let html = indent;
|
||||
if (!structObj.is_tuple) {
|
||||
html += escapeHtml(fieldName);
|
||||
}
|
||||
|
||||
let fieldTypeExpr = structObj.fields[i];
|
||||
html += ": ";
|
||||
if(!structObj.is_tuple) {
|
||||
html += ": ";
|
||||
}
|
||||
|
||||
html += exprName(fieldTypeExpr, {...opts, indent: indent});
|
||||
|
||||
@ -2797,7 +2810,9 @@ const NAV_MODES = {
|
||||
html += ' = <span class="tok-number">' + fieldName + "</span>";
|
||||
} else {
|
||||
let fieldTypeExpr = container.fields[i];
|
||||
html += ": ";
|
||||
if(container.kind ==! typeKinds.Struct || !container.is_tuple) {
|
||||
html += ": ";
|
||||
}
|
||||
html += exprName(fieldTypeExpr, {wantHtml:true, wantLink:true});
|
||||
let tsn = typeShorthandName(fieldTypeExpr);
|
||||
if (tsn) {
|
||||
@ -3945,8 +3960,9 @@ const NAV_MODES = {
|
||||
privDecls: ty[3],
|
||||
pubDecls: ty[4],
|
||||
fields: ty[5],
|
||||
line_number: ty[6],
|
||||
outer_decl: ty[7],
|
||||
is_tuple: ty[6],
|
||||
line_number: ty[7],
|
||||
outer_decl: ty[8],
|
||||
};
|
||||
case 10: // ComptimeExpr
|
||||
case 11: // ComptimeFloat
|
||||
|
@ -561,6 +561,7 @@ const DocData = struct {
|
||||
privDecls: []usize = &.{}, // index into decls
|
||||
pubDecls: []usize = &.{}, // index into decls
|
||||
fields: ?[]Expr = null, // (use src->fields to find names)
|
||||
is_tuple: bool,
|
||||
line_number: usize,
|
||||
outer_decl: usize,
|
||||
},
|
||||
@ -2942,6 +2943,7 @@ fn walkInstruction(
|
||||
&field_type_refs,
|
||||
&field_name_indexes,
|
||||
extra_index,
|
||||
small.is_tuple,
|
||||
);
|
||||
|
||||
self.ast_nodes.items[self_ast_node_index].fields = field_name_indexes.items;
|
||||
@ -2953,6 +2955,7 @@ fn walkInstruction(
|
||||
.privDecls = priv_decl_indexes.items,
|
||||
.pubDecls = decl_indexes.items,
|
||||
.fields = field_type_refs.items,
|
||||
.is_tuple = small.is_tuple,
|
||||
.line_number = self.ast_nodes.items[self_ast_node_index].line,
|
||||
.outer_decl = type_slot_index - 1,
|
||||
},
|
||||
@ -4116,6 +4119,7 @@ fn collectStructFieldInfo(
|
||||
field_type_refs: *std.ArrayListUnmanaged(DocData.Expr),
|
||||
field_name_indexes: *std.ArrayListUnmanaged(usize),
|
||||
ei: usize,
|
||||
is_tuple: bool,
|
||||
) !void {
|
||||
if (fields_len == 0) return;
|
||||
var extra_index = ei;
|
||||
@ -4125,7 +4129,7 @@ fn collectStructFieldInfo(
|
||||
const bit_bags_count = std.math.divCeil(usize, fields_len, fields_per_u32) catch unreachable;
|
||||
|
||||
const Field = struct {
|
||||
field_name: u32,
|
||||
field_name: ?u32,
|
||||
doc_comment_index: u32,
|
||||
type_body_len: u32 = 0,
|
||||
align_body_len: u32 = 0,
|
||||
@ -4153,8 +4157,12 @@ fn collectStructFieldInfo(
|
||||
const has_type_body = @truncate(u1, cur_bit_bag) != 0;
|
||||
cur_bit_bag >>= 1;
|
||||
|
||||
const field_name = file.zir.extra[extra_index];
|
||||
extra_index += 1;
|
||||
const field_name: ?u32 = if (!is_tuple) blk: {
|
||||
const fname = file.zir.extra[extra_index];
|
||||
extra_index += 1;
|
||||
break :blk fname;
|
||||
} else null;
|
||||
|
||||
const doc_comment_index = file.zir.extra[extra_index];
|
||||
extra_index += 1;
|
||||
|
||||
@ -4217,8 +4225,13 @@ fn collectStructFieldInfo(
|
||||
file.zir.nullTerminatedString(field.doc_comment_index)
|
||||
else
|
||||
null;
|
||||
const field_name: []const u8 = if (field.field_name) |f_name|
|
||||
file.zir.nullTerminatedString(f_name)
|
||||
else
|
||||
"";
|
||||
|
||||
try self.ast_nodes.append(self.arena, .{
|
||||
.name = file.zir.nullTerminatedString(field.field_name),
|
||||
.name = field_name,
|
||||
.docs = doc_comment,
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user