mirror of
https://github.com/ziglang/zig.git
synced 2026-01-20 22:35:24 +00:00
Merge pull request #15637 from der-teufel-programming/autodoc-layouts
autodoc: Add layout to Struct and Union to handle packed and extern
This commit is contained in:
commit
5512455974
@ -1848,18 +1848,26 @@ const NAV_MODES = {
|
||||
case typeKinds.Struct: {
|
||||
let structObj = typeObj;
|
||||
let name = "";
|
||||
let layout = "";
|
||||
if (structObj.layout !== null) {
|
||||
switch (structObj.layout.enumLiteral) {
|
||||
case "Packed": {
|
||||
layout = "packed ";
|
||||
break;
|
||||
}
|
||||
case "Extern": {
|
||||
layout = "extern ";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (opts.wantHtml) {
|
||||
name = "<span class='tok-kw'>struct</span>";
|
||||
name = "<span class='tok-kw'>" + layout + "struct</span>";
|
||||
} else {
|
||||
name = "struct";
|
||||
name = layout + "struct";
|
||||
}
|
||||
if (structObj.backing_int !== null) {
|
||||
if (opts.wantHtml) {
|
||||
name = "<span class='tok-kw'>packed</span> " + name;
|
||||
} else {
|
||||
name = "packed " + name;
|
||||
}
|
||||
name += " (" + exprName(structObj.backing_int, opts) + ")";
|
||||
name += "(" + exprName(structObj.backing_int, opts) + ")";
|
||||
}
|
||||
name += " { ";
|
||||
if (structObj.field_types.length > 1 && opts.wantHtml) { name += "</br>"; }
|
||||
@ -1916,7 +1924,7 @@ const NAV_MODES = {
|
||||
name = "enum";
|
||||
}
|
||||
if (enumObj.tag) {
|
||||
name += " (" + exprName(enumObj.tag, opts) + ")";
|
||||
name += "(" + exprName(enumObj.tag, opts) + ")";
|
||||
}
|
||||
name += " { ";
|
||||
let enumNode = getAstNode(enumObj.src);
|
||||
@ -1967,16 +1975,29 @@ const NAV_MODES = {
|
||||
case typeKinds.Union: {
|
||||
let unionObj = typeObj;
|
||||
let name = "";
|
||||
let layout = "";
|
||||
if (unionObj.layout !== null) {
|
||||
switch (unionObj.layout.enumLiteral) {
|
||||
case "Packed": {
|
||||
layout = "packed ";
|
||||
break;
|
||||
}
|
||||
case "Extern": {
|
||||
layout = "extern ";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (opts.wantHtml) {
|
||||
name = "<span class='tok-kw'>union</span>";
|
||||
name = "<span class='tok-kw'>" + layout + "union</span>";
|
||||
} else {
|
||||
name = "union";
|
||||
name = layout + "union";
|
||||
}
|
||||
if (unionObj.auto_tag) {
|
||||
if (opts.wantHtml) {
|
||||
name += " (<span class='tok-kw'>enum</span>";
|
||||
name += "(<span class='tok-kw'>enum</span>";
|
||||
} else {
|
||||
name += " (enum";
|
||||
name += "(enum";
|
||||
}
|
||||
if (unionObj.tag) {
|
||||
name += "(" + exprName(unionObj.tag, opts) + "))";
|
||||
@ -1984,7 +2005,7 @@ const NAV_MODES = {
|
||||
name += ")";
|
||||
}
|
||||
} else if (unionObj.tag) {
|
||||
name += " (" + exprName(unionObj.tag, opts) + ")";
|
||||
name += "(" + exprName(unionObj.tag, opts) + ")";
|
||||
}
|
||||
name += " { ";
|
||||
if (unionObj.field_types.length > 1 && opts.wantHtml) {
|
||||
@ -4510,6 +4531,7 @@ function addDeclToSearchResults(decl, declIndex, modNames, item, list, stack) {
|
||||
is_tuple: ty[8],
|
||||
line_number: ty[9],
|
||||
parent_container: ty[10],
|
||||
layout: ty[11],
|
||||
};
|
||||
case 10: // ComptimeExpr
|
||||
case 11: // ComptimeFloat
|
||||
@ -4563,6 +4585,7 @@ function addDeclToSearchResults(decl, declIndex, modNames, item, list, stack) {
|
||||
tag: ty[6],
|
||||
auto_tag: ty[7],
|
||||
parent_container: ty[8],
|
||||
layout: ty[9],
|
||||
};
|
||||
case 21: // Fn
|
||||
return {
|
||||
|
||||
@ -608,6 +608,7 @@ const DocData = struct {
|
||||
is_tuple: bool,
|
||||
line_number: usize,
|
||||
parent_container: ?usize, // index into `types`
|
||||
layout: ?Expr, // if different than Auto
|
||||
},
|
||||
ComptimeExpr: struct { name: []const u8 },
|
||||
ComptimeFloat: struct { name: []const u8 },
|
||||
@ -645,6 +646,7 @@ const DocData = struct {
|
||||
tag: ?Expr, // tag type if specified
|
||||
auto_enum: bool, // tag is an auto enum
|
||||
parent_container: ?usize, // index into `types`
|
||||
layout: ?Expr, // if different than Auto
|
||||
},
|
||||
Fn: struct {
|
||||
name: []const u8,
|
||||
@ -2625,6 +2627,11 @@ fn walkInstruction(
|
||||
break :blk fields_len;
|
||||
} else 0;
|
||||
|
||||
const layout_expr: ?DocData.Expr = switch (small.layout) {
|
||||
.Auto => null,
|
||||
else => .{ .enumLiteral = @tagName(small.layout) },
|
||||
};
|
||||
|
||||
var decl_indexes: std.ArrayListUnmanaged(usize) = .{};
|
||||
var priv_decl_indexes: std.ArrayListUnmanaged(usize) = .{};
|
||||
|
||||
@ -2679,6 +2686,7 @@ fn walkInstruction(
|
||||
.tag = tag_type,
|
||||
.auto_enum = small.auto_enum_tag,
|
||||
.parent_container = parent_scope.enclosing_type,
|
||||
.layout = layout_expr,
|
||||
},
|
||||
};
|
||||
|
||||
@ -2889,6 +2897,11 @@ fn walkInstruction(
|
||||
}
|
||||
}
|
||||
|
||||
const layout_expr: ?DocData.Expr = switch (small.layout) {
|
||||
.Auto => null,
|
||||
else => .{ .enumLiteral = @tagName(small.layout) },
|
||||
};
|
||||
|
||||
var decl_indexes: std.ArrayListUnmanaged(usize) = .{};
|
||||
var priv_decl_indexes: std.ArrayListUnmanaged(usize) = .{};
|
||||
|
||||
@ -2930,6 +2943,7 @@ fn walkInstruction(
|
||||
.backing_int = backing_int,
|
||||
.line_number = self.ast_nodes.items[self_ast_node_index].line,
|
||||
.parent_container = parent_scope.enclosing_type,
|
||||
.layout = layout_expr,
|
||||
},
|
||||
};
|
||||
if (self.ref_paths_pending_on_types.get(type_slot_index)) |paths| {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user