| ... | ... | @@ -10,6 +10,7 @@ module: *Module, |
| 10 | 10 | doc_location: Compilation.EmitLoc, |
| 11 | 11 | arena: std.mem.Allocator, |
| 12 | 12 | files: std.AutoHashMapUnmanaged(*File, usize) = .{}, |
| 13 | calls: std.ArrayListUnmanaged(DocData.Call) = .{}, |
| 13 | 14 | types: std.ArrayListUnmanaged(DocData.Type) = .{}, |
| 14 | 15 | decls: std.ArrayListUnmanaged(DocData.Decl) = .{}, |
| 15 | 16 | ast_nodes: std.ArrayListUnmanaged(DocData.AstNode) = .{}, |
| ... | ... | @@ -155,6 +156,7 @@ pub fn generateZirData(self: *Autodoc) !void { |
| 155 | 156 | |
| 156 | 157 | var data = DocData{ |
| 157 | 158 | .files = .{ .data = self.files }, |
| 159 | .calls = self.calls.items, |
| 158 | 160 | .types = self.types.items, |
| 159 | 161 | .decls = self.decls.items, |
| 160 | 162 | .astNodes = self.ast_nodes.items, |
| ... | ... | @@ -240,10 +242,10 @@ const DocData = struct { |
| 240 | 242 | } = .{}, |
| 241 | 243 | packages: [1]Package = .{.{}}, |
| 242 | 244 | errors: []struct {} = &.{}, |
| 243 | | calls: []struct {} = &.{}, |
| 244 | 245 | |
| 245 | 246 | // non-hardcoded stuff |
| 246 | 247 | astNodes: []AstNode, |
| 248 | calls: []Call, |
| 247 | 249 | files: struct { |
| 248 | 250 | // this struct is a temporary hack to support json serialization |
| 249 | 251 | data: std.AutoHashMapUnmanaged(*File, usize), |
| ... | ... | @@ -274,7 +276,11 @@ const DocData = struct { |
| 274 | 276 | types: []Type, |
| 275 | 277 | decls: []Decl, |
| 276 | 278 | comptimeExprs: []ComptimeExpr, |
| 277 | | |
| 279 | const Call = struct { |
| 280 | func: TypeRef, |
| 281 | args: []WalkResult, |
| 282 | ret: WalkResult, |
| 283 | }; |
| 278 | 284 | const DocTypeKinds = blk: { |
| 279 | 285 | var info = @typeInfo(std.builtin.TypeId); |
| 280 | 286 | const original_len = info.Enum.fields.len; |
| ... | ... | @@ -344,8 +350,8 @@ const DocData = struct { |
| 344 | 350 | Struct: struct { |
| 345 | 351 | name: []const u8, |
| 346 | 352 | src: ?usize = null, // index into astNodes |
| 347 | | privDecls: ?[]usize = null, // index into decls |
| 348 | | pubDecls: []usize, // index into decls |
| 353 | privDecls: []usize = &.{}, // index into decls |
| 354 | pubDecls: []usize = &.{}, // index into decls |
| 349 | 355 | fields: ?[]TypeRef = null, // (use src->fields to find names) |
| 350 | 356 | }, |
| 351 | 357 | ComptimeExpr: struct { name: []const u8 }, |
| ... | ... | @@ -507,6 +513,7 @@ const DocData = struct { |
| 507 | 513 | value: f64, // direct value |
| 508 | 514 | negated: bool = false, |
| 509 | 515 | }, |
| 516 | call: usize, // index in `calls` |
| 510 | 517 | |
| 511 | 518 | const Struct = struct { |
| 512 | 519 | typeRef: TypeRef, |
| ... | ... | @@ -526,7 +533,7 @@ const DocData = struct { |
| 526 | 533 | \\{{ "{s}":{{}} }} |
| 527 | 534 | , .{@tagName(self)}); |
| 528 | 535 | }, |
| 529 | | .type, .comptimeExpr => |v| { |
| 536 | .type, .comptimeExpr, .call => |v| { |
| 530 | 537 | try w.print( |
| 531 | 538 | \\{{ "{s}":{} }} |
| 532 | 539 | , .{ @tagName(self), v }); |
| ... | ... | @@ -616,14 +623,7 @@ fn walkInstruction( |
| 616 | 623 | |
| 617 | 624 | return new_file_walk_result; |
| 618 | 625 | }, |
| 619 | | .block => { |
| 620 | | const res = DocData.WalkResult{ .comptimeExpr = self.comptime_exprs.items.len }; |
| 621 | | try self.comptime_exprs.append(self.arena, .{ |
| 622 | | .code = "if(banana) 1 else 0", |
| 623 | | .typeRef = .{ .type = 0 }, |
| 624 | | }); |
| 625 | | return res; |
| 626 | | }, |
| 626 | |
| 627 | 627 | .int => { |
| 628 | 628 | const int = data[inst_index].int; |
| 629 | 629 | return DocData.WalkResult{ |
| ... | ... | @@ -755,16 +755,42 @@ fn walkInstruction( |
| 755 | 755 | }); |
| 756 | 756 | return DocData.WalkResult{ .type = self.types.items.len - 1 }; |
| 757 | 757 | }, |
| 758 | | //.block => { |
| 759 | | //const pl_node = data[inst_index].pl_node; |
| 760 | | //const extra = file.zir.extraData(Zir.Inst.Block, pl_node.payload_index); |
| 761 | | //const last_instr_index = file.zir.extra[extra.end..][extra.data.body_len - 1]; |
| 762 | | //const break_operand = data[break_index].@"break".operand; |
| 763 | | //return self.walkRef(file, parent_scope, break_operand); |
| 764 | | //}, |
| 758 | .block => { |
| 759 | const res = DocData.WalkResult{ .comptimeExpr = self.comptime_exprs.items.len }; |
| 760 | try self.comptime_exprs.append(self.arena, .{ |
| 761 | .code = "if(banana) 1 else 0", |
| 762 | .typeRef = .{ .type = 0 }, |
| 763 | }); |
| 764 | return res; |
| 765 | }, |
| 765 | 766 | .block_inline => { |
| 766 | 767 | return self.walkRef(file, parent_scope, getBlockInlineBreak(file.zir, inst_index)); |
| 767 | 768 | }, |
| 769 | .call => { |
| 770 | const pl_node = data[inst_index].pl_node; |
| 771 | const extra = file.zir.extraData(Zir.Inst.Call, pl_node.payload_index); |
| 772 | |
| 773 | // TODO: handle the way scoping works with fn args |
| 774 | const callee = DocData.TypeRef.fromWalkResult( |
| 775 | try self.walkRef(file, parent_scope, extra.data.callee), |
| 776 | ); |
| 777 | |
| 778 | const args_len = extra.data.flags.args_len; |
| 779 | var args = try self.arena.alloc(DocData.WalkResult, args_len); |
| 780 | const arg_refs = file.zir.refSlice(extra.end, args_len); |
| 781 | for (arg_refs) |ref, idx| { |
| 782 | args[idx] = try self.walkRef(file, parent_scope, ref); |
| 783 | } |
| 784 | |
| 785 | const call_slot_index = self.calls.items.len; |
| 786 | try self.calls.append(self.arena, .{ |
| 787 | .func = callee, |
| 788 | .args = args, |
| 789 | .ret = .{ .void = {} }, // TODO: handle returns! |
| 790 | }); |
| 791 | |
| 792 | return DocData.WalkResult{ .call = call_slot_index }; |
| 793 | }, |
| 768 | 794 | .func => { |
| 769 | 795 | const fn_info = file.zir.getFnInfo(@intCast(u32, inst_index)); |
| 770 | 796 | |