authorgravatar for jacoblevgw@gmail.comJacob G-W <jacoblevgw@gmail.com> 2022-01-28 17:54:02-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-07-19 19:10:10-07:00
log66a46888bbf8636c4ba9e59544fc3679d39a32f6
treec6bcc6a5f7e0d6f3c6d45b3a6f9ccd0444ac99ea
parent025337a78d1f213183050079f79065b0a6c454de

autodoc: generate WalkResults for ref types


1 files changed, 22 insertions(+), 2 deletions(-)

src/Autodoc.zig+22-2
...@@ -47,6 +47,19 @@ pub fn generateZirData(self: Autodoc) !void {...@@ -47,6 +47,19 @@ pub fn generateZirData(self: Autodoc) !void {
47 .kind = 0,47 .kind = 0,
48 .name = "type",48 .name = "type",
49 });49 });
50 // append all the types in Zir.Inst.Ref
51 {
52 // we don't count .none
53 var i: u32 = 1;
54 while (i <= @enumToInt(Zir.Inst.Ref.anyerror_void_error_union_type)) : (i += 1) {
55 var tmpbuf = std.ArrayList(u8).init(gpa);
56 try Zir.Inst.Ref.typed_value_map[i].val.format("", .{}, tmpbuf.writer());
57 try types.append(.{
58 .kind = 0,
59 .name = tmpbuf.toOwnedSlice(),
60 });
61 }
62 }
5063
51 var root_scope: Scope = .{ .parent = null };64 var root_scope: Scope = .{ .parent = null };
52 try ast_nodes.append(.{ .name = "(root)" });65 try ast_nodes.append(.{ .name = "(root)" });
...@@ -233,8 +246,15 @@ fn walkInstruction(...@@ -233,8 +246,15 @@ fn walkInstruction(
233246
234 std.debug.print("body len: {}\n", .{body_len});247 std.debug.print("body len: {}\n", .{body_len});
235248
236 const result_index = inst_index + body_len - 1;249 const break_index = inst_index + body_len;
237 return walkInstruction(zir, gpa, parent_scope, types, decls, ast_nodes, result_index);250 const break_operand = data[break_index].@"break".operand;
251 return if (Zir.refToIndex(break_operand)) |bi|
252 walkInstruction(zir, gpa, parent_scope, types, decls, ast_nodes, bi)
253 else if (@enumToInt(break_operand) <= @enumToInt(Zir.Inst.Ref.anyerror_void_error_union_type))
254 // we append all the types in ref first, so we can just do this if we encounter a ref that is a type
255 return DocData.WalkResult{ .type = @enumToInt(break_operand) }
256 else
257 std.debug.todo("generate WalkResults for refs that are not types");
238 },258 },
239 .extended => {259 .extended => {
240 const extended = data[inst_index].extended;260 const extended = data[inst_index].extended;