authorgravatar for vallahor91@gmail.comVallahor <vallahor91@gmail.com> 2022-06-09 16:28:12-03:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-07-19 19:10:12-07:00
log02bd5fe93a08fa778ce0adb0a82b26becbfdc7e7
treef249487af23d33cc0a7f91154ef69c3fcbacd920
parentcd357fc7676a86b11a3593d63bd530add91cfd6e

autodoc: experiment get line info


2 files changed, 48 insertions(+), 39 deletions(-)

lib/docs/main.js+16-4
......@@ -1161,13 +1161,25 @@ var zigAnalysis;
11611161 }
11621162 case "switchOp":{
11631163 let condExpr = zigAnalysis.exprs[expr.switchOp.cond_index];
1164 let node_name_ = expr.switchOp.node_name;
1164 let ast = zigAnalysis.astNodes[expr.switchOp.ast];
11651165 let file_name = expr.switchOp.file_name;
1166 let line_start = expr.switchOp.line_start;
1166 let outer_decl_index = expr.switchOp.outer_decl;
1167 let outer_decl = zigAnalysis.types[outer_decl_index];
1168 let line = 0;
1169 console.log(expr.switchOp)
1170 console.log(outer_decl)
1171 while (outer_decl_index !== 0 && outer_decl.line_number > 0) {
1172 line += outer_decl.line_number;
1173 outer_decl_index = outer_decl.outer_decl;
1174 outer_decl = zigAnalysis.types[outer_decl_index];
1175 console.log(outer_decl)
1176 }
1177 line += ast.line + 1;
11671178 let payloadHtml = "";
11681179 let cond = exprName(condExpr, opts);
1169 payloadHtml += "</br>" + "node_name: " + node_name_ + "</br>" + "file: " + file_name + "</br>" + "line_start: " + line_start + "</br>";
1170 payloadHtml += "switch(" + cond + ") {...}";
1180
1181 payloadHtml += "</br>" + "node_name: " + ast.name + "</br>" + "file: " + file_name + "</br>" + "line: " + line + "</br>";
1182 payloadHtml += "switch(" + cond + ") {" + "<a href=\"https://github.com/ziglang/zig/tree/master/lib/std/" + file_name + "#L" + line + "\">" +"..." + "</a>}";
11711183 return payloadHtml;
11721184 }
11731185 case "switchIndex": {
src/Autodoc.zig+32-35
......@@ -501,6 +501,9 @@ const DocData = struct {
501501 privDecls: []usize = &.{}, // index into decls
502502 pubDecls: []usize = &.{}, // index into decls
503503 fields: ?[]Expr = null, // (use src->fields to find names)
504 line_number: usize,
505 outer_decl: usize,
506 ast: usize,
504507 },
505508 ComptimeExpr: struct { name: []const u8 },
506509 ComptimeFloat: struct { name: []const u8 },
......@@ -523,6 +526,7 @@ const DocData = struct {
523526 src: usize, // index into astNodes
524527 privDecls: []usize = &.{}, // index into decls
525528 pubDecls: []usize = &.{}, // index into decls
529 ast: usize,
526530 // (use src->fields to find field names)
527531 },
528532 Union: struct {
......@@ -531,6 +535,7 @@ const DocData = struct {
531535 privDecls: []usize = &.{}, // index into decls
532536 pubDecls: []usize = &.{}, // index into decls
533537 fields: []Expr = &.{}, // (use src->fields to find names)
538 ast: usize,
534539 },
535540 Fn: struct {
536541 name: []const u8,
......@@ -750,9 +755,9 @@ const DocData = struct {
750755 };
751756 const SwitchOp = struct {
752757 cond_index: usize,
753 node_name: []const u8,
754758 file_name: []const u8,
755 line_start: usize,
759 ast: usize,
760 outer_decl: usize, // index in `types`
756761 };
757762 const BuiltinBin = struct {
758763 name: []const u8 = "", // fn name
......@@ -1029,8 +1034,8 @@ fn walkInstruction(
10291034 // are already loaded at this point
10301035 if (file.pkg.table.get(path)) |other_package| {
10311036 const result = try self.packages.getOrPut(self.arena, other_package);
1032
1033 // Immediately add this package to the import table of our
1037
1038 // Immediately add this package to the import table of our
10341039 // current package, regardless of wether it's new or not.
10351040 if (self.packages.getPtr(file.pkg)) |current_package| {
10361041 // TODO: apparently, in the stdlib a file gets analized before
......@@ -1062,7 +1067,6 @@ fn walkInstruction(
10621067 },
10631068 };
10641069
1065
10661070 // TODO: Add this package as a dependency to the current pakcage
10671071 // TODO: this seems something that could be done in bulk
10681072 // at the beginning or the end, or something.
......@@ -2043,19 +2047,21 @@ fn walkInstruction(
20432047 const cond_index = self.exprs.items.len;
20442048 _ = try self.walkRef(file, parent_scope, extra.data.operand, false);
20452049
2046 const ast_index = self.ast_nodes.items.len - 1;
2047 const ast = self.ast_nodes.items[ast_index];
2050 const ast_index = self.ast_nodes.items.len;
2051 const type_index = self.types.items.len - 1;
20482052
2049 // const sep = "=" ** 200;
2050 // std.debug.print("{s}\n", .{sep});
2051 // std.debug.print("SWITCH BLOCK\n", .{});
2052 // std.debug.print("file path = {any}\n", .{file.sub_file_path});
2053 // std.debug.print("lazysrcloc = {any}\n", .{pl_node.src()});
2054 // std.debug.print("ast = {any}\n", .{ast});
2055 // std.debug.print("{s}\n", .{sep});
2053 const ast_line = self.ast_nodes.items[ast_index - 1];
2054
2055 const sep = "=" ** 200;
2056 std.debug.print("{s}\n", .{sep});
2057 std.debug.print("SWITCH BLOCK\n", .{});
2058 std.debug.print("extra = {any}\n", .{extra});
2059 std.debug.print("outer_decl = {any}\n", .{self.types.items[type_index]});
2060 std.debug.print("ast_lines = {}\n", .{ast_line});
2061 std.debug.print("{s}\n", .{sep});
20562062
20572063 const switch_index = self.exprs.items.len;
2058 try self.exprs.append(self.arena, .{ .switchOp = .{ .cond_index = cond_index, .node_name = ast.name orelse "", .file_name = file.sub_file_path, .line_start = ast.line } });
2064 try self.exprs.append(self.arena, .{ .switchOp = .{ .cond_index = cond_index, .file_name = file.sub_file_path, .ast = ast_index, .outer_decl = type_index } });
20592065
20602066 return DocData.WalkResult{
20612067 .typeRef = .{ .type = @enumToInt(Ref.type_type) },
......@@ -2073,6 +2079,14 @@ fn walkInstruction(
20732079 const operand_index = self.exprs.items.len;
20742080 try self.exprs.append(self.arena, operand.expr);
20752081
2082 const ast_index = self.ast_nodes.items.len;
2083 const sep = "=" ** 200;
2084 std.debug.print("{s}\n", .{sep});
2085 std.debug.print("SWITCH COND\n", .{});
2086 std.debug.print("ast index = {}\n", .{ast_index});
2087 std.debug.print("ast previous = {}\n", .{self.ast_nodes.items[ast_index - 1]});
2088 std.debug.print("{s}\n", .{sep});
2089
20762090 return DocData.WalkResult{
20772091 .typeRef = operand.typeRef,
20782092 .expr = .{ .typeOf = operand_index },
......@@ -2633,13 +2647,7 @@ fn walkInstruction(
26332647 self.ast_nodes.items[self_ast_node_index].fields = field_name_indexes.items;
26342648
26352649 self.types.items[type_slot_index] = .{
2636 .Union = .{
2637 .name = "todo_name",
2638 .src = self_ast_node_index,
2639 .privDecls = priv_decl_indexes.items,
2640 .pubDecls = decl_indexes.items,
2641 .fields = field_type_refs.items,
2642 },
2650 .Union = .{ .name = "todo_name", .src = self_ast_node_index, .privDecls = priv_decl_indexes.items, .pubDecls = decl_indexes.items, .fields = field_type_refs.items, .ast = self_ast_node_index },
26432651 };
26442652
26452653 if (self.ref_paths_pending_on_types.get(type_slot_index)) |paths| {
......@@ -2786,12 +2794,7 @@ fn walkInstruction(
27862794 self.ast_nodes.items[self_ast_node_index].fields = field_name_indexes.items;
27872795
27882796 self.types.items[type_slot_index] = .{
2789 .Enum = .{
2790 .name = "todo_name",
2791 .src = self_ast_node_index,
2792 .privDecls = priv_decl_indexes.items,
2793 .pubDecls = decl_indexes.items,
2794 },
2797 .Enum = .{ .name = "todo_name", .src = self_ast_node_index, .privDecls = priv_decl_indexes.items, .pubDecls = decl_indexes.items, .ast = self_ast_node_index },
27952798 };
27962799 if (self.ref_paths_pending_on_types.get(type_slot_index)) |paths| {
27972800 for (paths.items) |resume_info| {
......@@ -2897,13 +2900,7 @@ fn walkInstruction(
28972900 self.ast_nodes.items[self_ast_node_index].fields = field_name_indexes.items;
28982901
28992902 self.types.items[type_slot_index] = .{
2900 .Struct = .{
2901 .name = "todo_name",
2902 .src = self_ast_node_index,
2903 .privDecls = priv_decl_indexes.items,
2904 .pubDecls = decl_indexes.items,
2905 .fields = field_type_refs.items,
2906 },
2903 .Struct = .{ .name = "todo_name", .src = self_ast_node_index, .privDecls = priv_decl_indexes.items, .pubDecls = decl_indexes.items, .fields = field_type_refs.items, .line_number = self.ast_nodes.items[self_ast_node_index].line, .outer_decl = type_slot_index - 1, .ast = self_ast_node_index },
29072904 };
29082905 if (self.ref_paths_pending_on_types.get(type_slot_index)) |paths| {
29092906 for (paths.items) |resume_info| {