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