| ... | ... | @@ -86,7 +86,6 @@ pub fn generateZirData(self: *Autodoc) !void { |
| 86 | 86 | break :blk .{ |
| 87 | 87 | .Array = .{ |
| 88 | 88 | .len = 1, |
| 89 | | .name = tmpbuf.toOwnedSlice(), |
| 90 | 89 | .child = .{ .type = 0 }, |
| 91 | 90 | }, |
| 92 | 91 | }; |
| ... | ... | @@ -352,7 +351,6 @@ const DocData = struct { |
| 352 | 351 | child: TypeRef, |
| 353 | 352 | }, |
| 354 | 353 | Array: struct { |
| 355 | | name: []const u8, |
| 356 | 354 | len: usize, |
| 357 | 355 | child: TypeRef, |
| 358 | 356 | }, |
| ... | ... | @@ -522,6 +520,7 @@ const DocData = struct { |
| 522 | 520 | value: f64, // direct value |
| 523 | 521 | negated: bool = false, |
| 524 | 522 | }, |
| 523 | array: Array, |
| 525 | 524 | call: usize, // index in `calls` |
| 526 | 525 | |
| 527 | 526 | const Struct = struct { |
| ... | ... | @@ -531,6 +530,11 @@ const DocData = struct { |
| 531 | 530 | val: WalkResult, |
| 532 | 531 | }, |
| 533 | 532 | }; |
| 533 | const Array = struct { |
| 534 | typeRef: TypeRef, |
| 535 | data: []WalkResult, |
| 536 | }; |
| 537 | |
| 534 | 538 | pub fn jsonStringify( |
| 535 | 539 | self: WalkResult, |
| 536 | 540 | options: std.json.StringifyOptions, |
| ... | ... | @@ -586,6 +590,24 @@ const DocData = struct { |
| 586 | 590 | try w.print("{d}{s}", .{ d, comma }); |
| 587 | 591 | } |
| 588 | 592 | }, |
| 593 | .array => |v| try std.json.stringify( |
| 594 | struct { @"array": Array }{ .@"array" = v }, |
| 595 | options, |
| 596 | w, |
| 597 | ), |
| 598 | |
| 599 | // try w.print("{ len: {},\n", .{v.len}); |
| 600 | |
| 601 | // if (options.whitespace) |ws| try ws.outputIndent(w); |
| 602 | // try w.print("typeRef: ", .{}); |
| 603 | // try v.typeRef.jsonStringify(options, w); |
| 604 | |
| 605 | // try w.print("{{ \"data\": [", .{}); |
| 606 | // for (v.data) |d, i| { |
| 607 | // const comma = if (i == v.len - 1) "]}" else ","; |
| 608 | // try w.print("{d}{s}", .{ d, comma }); |
| 609 | // } |
| 610 | |
| 589 | 611 | } |
| 590 | 612 | } |
| 591 | 613 | }; |
| ... | ... | @@ -615,6 +637,16 @@ fn walkInstruction( |
| 615 | 637 | const path = str_tok.get(file.zir); |
| 616 | 638 | // importFile cannot error out since all files |
| 617 | 639 | // are already loaded at this point |
| 640 | if (file.pkg.table.get(path) != null) { |
| 641 | const cte_slot_index = self.comptime_exprs.items.len; |
| 642 | try self.comptime_exprs.append(self.arena, .{ |
| 643 | .code = path, |
| 644 | .typeRef = .{ .type = @enumToInt(DocData.DocTypeKinds.Type) }, |
| 645 | }); |
| 646 | return DocData.WalkResult{ |
| 647 | .comptimeExpr = cte_slot_index, |
| 648 | }; |
| 649 | } |
| 618 | 650 | const new_file = self.module.importFile(file, path) catch unreachable; |
| 619 | 651 | const result = try self.files.getOrPut(self.arena, new_file.file); |
| 620 | 652 | if (result.found_existing) { |
| ... | ... | @@ -644,6 +676,28 @@ fn walkInstruction( |
| 644 | 676 | }, |
| 645 | 677 | }; |
| 646 | 678 | }, |
| 679 | .array_init => { |
| 680 | const pl_node = data[inst_index].pl_node; |
| 681 | const extra = file.zir.extraData(Zir.Inst.MultiOp, pl_node.payload_index); |
| 682 | const operands = file.zir.refSlice(extra.end, extra.data.operands_len); |
| 683 | const array_data = try self.arena.alloc(DocData.WalkResult, operands.len); |
| 684 | for (operands) |op, idx| { |
| 685 | array_data[idx] = try self.walkRef(file, parent_scope, op); |
| 686 | } |
| 687 | |
| 688 | const type_slot_index = self.types.items.len; |
| 689 | try self.types.append(self.arena, .{ |
| 690 | .Array = .{ |
| 691 | .len = operands.len, |
| 692 | .child = typeOfWalkResult(array_data[0]), |
| 693 | }, |
| 694 | }); |
| 695 | |
| 696 | return DocData.WalkResult{ .array = .{ |
| 697 | .typeRef = .{ .type = type_slot_index }, |
| 698 | .data = array_data, |
| 699 | } }; |
| 700 | }, |
| 647 | 701 | .float => { |
| 648 | 702 | const float = data[inst_index].float; |
| 649 | 703 | return DocData.WalkResult{ |
| ... | ... | @@ -1555,7 +1609,8 @@ fn tryResolveDeclPath( |
| 1555 | 1609 | // with the final decl in `dp`. |
| 1556 | 1610 | // We then write the original value back as soon as we're done with the |
| 1557 | 1611 | // recoursive call. This will work out correctly even if the path |
| 1558 | | // will not get fully resolved. |
| 1612 | // will not get fully resolved (also in the case that final_decl is |
| 1613 | // not resolved yet). |
| 1559 | 1614 | path[i] = final_decl_index; |
| 1560 | 1615 | try self.tryResolveDeclPath(file, path); |
| 1561 | 1616 | path[i] = decl_index; |
| ... | ... | @@ -1870,6 +1925,19 @@ fn walkResultToTypeRef(wr: DocData.WalkResult) DocData.TypeRef { |
| 1870 | 1925 | }; |
| 1871 | 1926 | } |
| 1872 | 1927 | |
| 1928 | fn typeOfWalkResult(wr: DocData.WalkResult) DocData.TypeRef { |
| 1929 | return switch (wr) { |
| 1930 | else => std.debug.panic( |
| 1931 | "TODO: handle `{s}` in typeOfWalkResult\n", |
| 1932 | .{@tagName(wr)}, |
| 1933 | ), |
| 1934 | .type => .{ .type = @enumToInt(DocData.DocTypeKinds.Type) }, |
| 1935 | .int => |v| v.typeRef, |
| 1936 | .float => |v| v.typeRef, |
| 1937 | .array => |v| v.typeRef, |
| 1938 | }; |
| 1939 | } |
| 1940 | |
| 1873 | 1941 | //fn collectParamInfo(self: *Autodoc, file: *File, scope: *Scope, inst_idx: Zir.Index) void { |
| 1874 | 1942 | |
| 1875 | 1943 | //} |