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;...@@ -1161,13 +1161,25 @@ var zigAnalysis;
1161 }1161 }
1162 case "switchOp":{1162 case "switchOp":{
1163 let condExpr = zigAnalysis.exprs[expr.switchOp.cond_index];1163 let condExpr = zigAnalysis.exprs[expr.switchOp.cond_index];
1164 let node_name_ = expr.switchOp.node_name;1164 let ast = zigAnalysis.astNodes[expr.switchOp.ast];
1165 let file_name = expr.switchOp.file_name;1165 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;
1167 let payloadHtml = "";1178 let payloadHtml = "";
1168 let cond = exprName(condExpr, opts);1179 let cond = exprName(condExpr, opts);
1169 payloadHtml += "</br>" + "node_name: " + node_name_ + "</br>" + "file: " + file_name + "</br>" + "line_start: " + line_start + "</br>";1180
1170 payloadHtml += "switch(" + cond + ") {...}";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>}";
1171 return payloadHtml;1183 return payloadHtml;
1172 }1184 }
1173 case "switchIndex": {1185 case "switchIndex": {
src/Autodoc.zig+32-35
...@@ -501,6 +501,9 @@ const DocData = struct {...@@ -501,6 +501,9 @@ const DocData = struct {
501 privDecls: []usize = &.{}, // index into decls501 privDecls: []usize = &.{}, // index into decls
502 pubDecls: []usize = &.{}, // index into decls502 pubDecls: []usize = &.{}, // index into decls
503 fields: ?[]Expr = null, // (use src->fields to find names)503 fields: ?[]Expr = null, // (use src->fields to find names)
504 line_number: usize,
505 outer_decl: usize,
506 ast: usize,
504 },507 },
505 ComptimeExpr: struct { name: []const u8 },508 ComptimeExpr: struct { name: []const u8 },
506 ComptimeFloat: struct { name: []const u8 },509 ComptimeFloat: struct { name: []const u8 },
...@@ -523,6 +526,7 @@ const DocData = struct {...@@ -523,6 +526,7 @@ const DocData = struct {
523 src: usize, // index into astNodes526 src: usize, // index into astNodes
524 privDecls: []usize = &.{}, // index into decls527 privDecls: []usize = &.{}, // index into decls
525 pubDecls: []usize = &.{}, // index into decls528 pubDecls: []usize = &.{}, // index into decls
529 ast: usize,
526 // (use src->fields to find field names)530 // (use src->fields to find field names)
527 },531 },
528 Union: struct {532 Union: struct {
...@@ -531,6 +535,7 @@ const DocData = struct {...@@ -531,6 +535,7 @@ const DocData = struct {
531 privDecls: []usize = &.{}, // index into decls535 privDecls: []usize = &.{}, // index into decls
532 pubDecls: []usize = &.{}, // index into decls536 pubDecls: []usize = &.{}, // index into decls
533 fields: []Expr = &.{}, // (use src->fields to find names)537 fields: []Expr = &.{}, // (use src->fields to find names)
538 ast: usize,
534 },539 },
535 Fn: struct {540 Fn: struct {
536 name: []const u8,541 name: []const u8,
...@@ -750,9 +755,9 @@ const DocData = struct {...@@ -750,9 +755,9 @@ const DocData = struct {
750 };755 };
751 const SwitchOp = struct {756 const SwitchOp = struct {
752 cond_index: usize,757 cond_index: usize,
753 node_name: []const u8,
754 file_name: []const u8,758 file_name: []const u8,
755 line_start: usize,759 ast: usize,
760 outer_decl: usize, // index in `types`
756 };761 };
757 const BuiltinBin = struct {762 const BuiltinBin = struct {
758 name: []const u8 = "", // fn name763 name: []const u8 = "", // fn name
...@@ -1029,8 +1034,8 @@ fn walkInstruction(...@@ -1029,8 +1034,8 @@ fn walkInstruction(
1029 // are already loaded at this point1034 // are already loaded at this point
1030 if (file.pkg.table.get(path)) |other_package| {1035 if (file.pkg.table.get(path)) |other_package| {
1031 const result = try self.packages.getOrPut(self.arena, other_package);1036 const result = try self.packages.getOrPut(self.arena, other_package);
1032 1037
1033 // Immediately add this package to the import table of our 1038 // Immediately add this package to the import table of our
1034 // current package, regardless of wether it's new or not.1039 // current package, regardless of wether it's new or not.
1035 if (self.packages.getPtr(file.pkg)) |current_package| {1040 if (self.packages.getPtr(file.pkg)) |current_package| {
1036 // TODO: apparently, in the stdlib a file gets analized before1041 // TODO: apparently, in the stdlib a file gets analized before
...@@ -1062,7 +1067,6 @@ fn walkInstruction(...@@ -1062,7 +1067,6 @@ fn walkInstruction(
1062 },1067 },
1063 };1068 };
10641069
1065
1066 // TODO: Add this package as a dependency to the current pakcage1070 // TODO: Add this package as a dependency to the current pakcage
1067 // TODO: this seems something that could be done in bulk1071 // TODO: this seems something that could be done in bulk
1068 // at the beginning or the end, or something.1072 // at the beginning or the end, or something.
...@@ -2043,19 +2047,21 @@ fn walkInstruction(...@@ -2043,19 +2047,21 @@ fn walkInstruction(
2043 const cond_index = self.exprs.items.len;2047 const cond_index = self.exprs.items.len;
2044 _ = try self.walkRef(file, parent_scope, extra.data.operand, false);2048 _ = try self.walkRef(file, parent_scope, extra.data.operand, false);
20452049
2046 const ast_index = self.ast_nodes.items.len - 1;2050 const ast_index = self.ast_nodes.items.len;
2047 const ast = self.ast_nodes.items[ast_index];2051 const type_index = self.types.items.len - 1;
20482052
2049 // const sep = "=" ** 200;2053 const ast_line = self.ast_nodes.items[ast_index - 1];
2050 // std.debug.print("{s}\n", .{sep});2054
2051 // std.debug.print("SWITCH BLOCK\n", .{});2055 const sep = "=" ** 200;
2052 // std.debug.print("file path = {any}\n", .{file.sub_file_path});2056 std.debug.print("{s}\n", .{sep});
2053 // std.debug.print("lazysrcloc = {any}\n", .{pl_node.src()});2057 std.debug.print("SWITCH BLOCK\n", .{});
2054 // std.debug.print("ast = {any}\n", .{ast});2058 std.debug.print("extra = {any}\n", .{extra});
2055 // std.debug.print("{s}\n", .{sep});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
2057 const switch_index = self.exprs.items.len;2063 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
2060 return DocData.WalkResult{2066 return DocData.WalkResult{
2061 .typeRef = .{ .type = @enumToInt(Ref.type_type) },2067 .typeRef = .{ .type = @enumToInt(Ref.type_type) },
...@@ -2073,6 +2079,14 @@ fn walkInstruction(...@@ -2073,6 +2079,14 @@ fn walkInstruction(
2073 const operand_index = self.exprs.items.len;2079 const operand_index = self.exprs.items.len;
2074 try self.exprs.append(self.arena, operand.expr);2080 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
2076 return DocData.WalkResult{2090 return DocData.WalkResult{
2077 .typeRef = operand.typeRef,2091 .typeRef = operand.typeRef,
2078 .expr = .{ .typeOf = operand_index },2092 .expr = .{ .typeOf = operand_index },
...@@ -2633,13 +2647,7 @@ fn walkInstruction(...@@ -2633,13 +2647,7 @@ fn walkInstruction(
2633 self.ast_nodes.items[self_ast_node_index].fields = field_name_indexes.items;2647 self.ast_nodes.items[self_ast_node_index].fields = field_name_indexes.items;
26342648
2635 self.types.items[type_slot_index] = .{2649 self.types.items[type_slot_index] = .{
2636 .Union = .{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 },
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 },
2643 };2651 };
26442652
2645 if (self.ref_paths_pending_on_types.get(type_slot_index)) |paths| {2653 if (self.ref_paths_pending_on_types.get(type_slot_index)) |paths| {
...@@ -2786,12 +2794,7 @@ fn walkInstruction(...@@ -2786,12 +2794,7 @@ fn walkInstruction(
2786 self.ast_nodes.items[self_ast_node_index].fields = field_name_indexes.items;2794 self.ast_nodes.items[self_ast_node_index].fields = field_name_indexes.items;
27872795
2788 self.types.items[type_slot_index] = .{2796 self.types.items[type_slot_index] = .{
2789 .Enum = .{2797 .Enum = .{ .name = "todo_name", .src = self_ast_node_index, .privDecls = priv_decl_indexes.items, .pubDecls = decl_indexes.items, .ast = self_ast_node_index },
2790 .name = "todo_name",
2791 .src = self_ast_node_index,
2792 .privDecls = priv_decl_indexes.items,
2793 .pubDecls = decl_indexes.items,
2794 },
2795 };2798 };
2796 if (self.ref_paths_pending_on_types.get(type_slot_index)) |paths| {2799 if (self.ref_paths_pending_on_types.get(type_slot_index)) |paths| {
2797 for (paths.items) |resume_info| {2800 for (paths.items) |resume_info| {
...@@ -2897,13 +2900,7 @@ fn walkInstruction(...@@ -2897,13 +2900,7 @@ fn walkInstruction(
2897 self.ast_nodes.items[self_ast_node_index].fields = field_name_indexes.items;2900 self.ast_nodes.items[self_ast_node_index].fields = field_name_indexes.items;
28982901
2899 self.types.items[type_slot_index] = .{2902 self.types.items[type_slot_index] = .{
2900 .Struct = .{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 },
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 },
2907 };2904 };
2908 if (self.ref_paths_pending_on_types.get(type_slot_index)) |paths| {2905 if (self.ref_paths_pending_on_types.get(type_slot_index)) |paths| {
2909 for (paths.items) |resume_info| {2906 for (paths.items) |resume_info| {