autodoc: improve frontend rendering

This commit is contained in:
Loris Cro 2022-05-22 16:21:49 +02:00 committed by Andrew Kelley
parent cf685c1132
commit aa545dbd1e
2 changed files with 327 additions and 407 deletions

File diff suppressed because it is too large Load Diff

View File

@ -542,13 +542,14 @@ const DocData = struct {
call: usize, // index in `calls` call: usize, // index in `calls`
enumLiteral: []const u8, // direct value enumLiteral: []const u8, // direct value
typeOf: usize, // index in `exprs` typeOf: usize, // index in `exprs`
as: struct { as: As,
typeRefArg: ?usize, // index in `exprs`
exprArg: usize, // index in `exprs`
},
sizeOf: usize, // index in `exprs` sizeOf: usize, // index in `exprs`
compileError: []const u8, compileError: []const u8,
string: []const u8, // direct value string: []const u8, // direct value
const As = struct {
typeRefArg: ?usize, // index in `exprs`
exprArg: usize, // index in `exprs`
};
const FieldRef = struct { const FieldRef = struct {
type: usize, // index in `types` type: usize, // index in `types`
index: usize, // index in type.fields index: usize, // index in type.fields
@ -592,12 +593,16 @@ const DocData = struct {
, .{v}); , .{v});
}, },
.sizeOf => |v| try std.json.stringify(v, options, w), .sizeOf => |v| try std.json.stringify(v, options, w),
.as => |v| try std.json.stringify(v, options, w),
.fieldRef => |v| try std.json.stringify( .fieldRef => |v| try std.json.stringify(
struct { fieldRef: FieldRef }{ .fieldRef = v }, struct { fieldRef: FieldRef }{ .fieldRef = v },
options, options,
w, w,
), ),
.as => |v| try std.json.stringify(
struct { as: As }{ .as = v },
options,
w,
),
.@"struct" => |v| try std.json.stringify( .@"struct" => |v| try std.json.stringify(
struct { @"struct": []FieldVal }{ .@"struct" = v }, struct { @"struct": []FieldVal }{ .@"struct" = v },
options, options,
@ -774,7 +779,12 @@ fn walkInstruction(
); );
return DocData.WalkResult{ return DocData.WalkResult{
.expr = .{ .compileError = operand.expr.string }, .expr = .{
.compileError = switch (operand.expr) {
.string => |s| s,
else => "TODO: non-string @compileError arguments",
},
},
}; };
}, },
.enum_literal => { .enum_literal => {
@ -1010,6 +1020,9 @@ fn walkInstruction(
.decl_val, .decl_ref => { .decl_val, .decl_ref => {
const str_tok = data[inst_index].str_tok; const str_tok = data[inst_index].str_tok;
const decls_slot_index = parent_scope.resolveDeclName(str_tok.start); const decls_slot_index = parent_scope.resolveDeclName(str_tok.start);
// While it would make sense to grab the original decl's typeRef info,
// that decl might not have been analyzed yet! The frontend will have
// to navigate through all declRefs to find the underlying type.
return DocData.WalkResult{ .expr = .{ .declRef = decls_slot_index } }; return DocData.WalkResult{ .expr = .{ .declRef = decls_slot_index } };
}, },
.field_val, .field_call_bind, .field_ptr, .field_type => { .field_val, .field_call_bind, .field_ptr, .field_type => {