authorgravatar for vallahor91@gmail.comVallahor <vallahor91@gmail.com> 2022-05-26 05:26:10-03:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-07-19 19:10:11-07:00
loge1d55385ff3916f2a522225c41a239068972fdf4
treebeb79c91769191969f316bbac5cab6c9ab02890d
parent1a4d00d832ea0c23ce053387fdc7b5976828a295

add: typeof_builtin (not fully implemented)


1 files changed, 64 insertions(+), 17 deletions(-)

src/Autodoc.zig+64-17
......@@ -297,8 +297,7 @@ const DocData = struct {
297297 try w.print("\"", .{});
298298 for (kv.key_ptr.*.sub_file_path) |c| {
299299 if (c == '\\') {
300 try w.print("\\", .{});
301 try w.print("\\", .{});
300 try w.print("\\\\", .{});
302301 } else {
303302 try w.print("{c}", .{c});
304303 }
......@@ -1242,6 +1241,42 @@ fn walkInstruction(
12421241 .expr = .{ .typeOf = operand_index },
12431242 };
12441243 },
1244 .typeof_builtin => {
1245 // @check: @TypeOf(T)
1246 // right now it's only showing the T
1247 // a way to solve it could be creating a .call
1248 // another way is with a flag to handle it on Frontend
1249 const pl_node = data[inst_index].pl_node;
1250 const extra = file.zir.extraData(Zir.Inst.Block, pl_node.payload_index);
1251 const body = file.zir.extra[extra.end..][extra.data.body_len - 1];
1252
1253 var operand: DocData.WalkResult = try self.walkRef(
1254 file,
1255 parent_scope,
1256 data[body].@"break".operand,
1257 false,
1258 );
1259
1260 return operand;
1261 },
1262 .type_info => {
1263 // @check
1264 const un_node = data[inst_index].un_node;
1265 const operand = try self.walkRef(
1266 file,
1267 parent_scope,
1268 un_node.operand,
1269 need_type,
1270 );
1271
1272 const operand_index = self.exprs.items.len;
1273 try self.exprs.append(self.arena, operand.expr);
1274
1275 return DocData.WalkResult{
1276 .typeRef = operand.typeRef,
1277 .expr = .{ .typeOf = operand_index },
1278 };
1279 },
12451280 .as_node => {
12461281 const pl_node = data[inst_index].pl_node;
12471282 const extra = file.zir.extraData(Zir.Inst.As, pl_node.payload_index);
......@@ -1534,7 +1569,7 @@ fn walkInstruction(
15341569 .expr = .{ .call = call_slot_index },
15351570 };
15361571 },
1537 .func, .func_inferred => {
1572 .func, .func_inferred, .func_extended => {
15381573 const type_slot_index = self.types.items.len;
15391574 try self.types.append(self.arena, .{ .Unanalyzed = {} });
15401575
......@@ -2558,12 +2593,14 @@ fn analyzeFunction(
25582593 // TODO: handle scope rules for fn parameters
25592594 for (fn_info.param_body[0..fn_info.total_params_len]) |param_index| {
25602595 switch (tags[param_index]) {
2561 else => panicWithContext(
2562 file,
2563 param_index,
2564 "TODO: handle `{s}` in walkInstruction.func\n",
2565 .{@tagName(tags[param_index])},
2566 ),
2596 else => {
2597 panicWithContext(
2598 file,
2599 param_index,
2600 "TODO: handle `{s}` in walkInstruction.func\n",
2601 .{@tagName(tags[param_index])},
2602 );
2603 },
25672604 .param_anytype, .param_anytype_comptime => {
25682605 // TODO: where are the doc comments?
25692606 const str_tok = data[param_index].str_tok;
......@@ -2848,17 +2885,27 @@ fn walkRef(
28482885 };
28492886 },
28502887 // TODO: dunno what to do with those
2888 // .calling_convention_type => {
2889 // return DocData.WalkResult{
2890 // .typeRef = .{ .type = @enumToInt(Ref.comptime_int_type) },
2891 // .expr = .{ .int = .{ .value = 1 } },
2892 // };
2893 // },
28512894 // .calling_convention_c => {
2852 // return DocData.WalkResult{ .int = .{
2853 // .type = @enumToInt(Ref.comptime_int_type),
2854 // .value = 1,
2855 // } };
2895 // return DocData.WalkResult{
2896 // .typeRef = .{ .type = @enumToInt(Ref.comptime_int_type) },
2897 // .expr = .{ .int = .{ .value = 1 } },
2898 // };
28562899 // },
28572900 // .calling_convention_inline => {
2858 // return DocData.WalkResult{ .int = .{
2859 // .type = @enumToInt(Ref.comptime_int_type),
2860 // .value = 1,
2861 // } };
2901 // return DocData.WalkResult{
2902 // .typeRef = .{ .type = @enumToInt(Ref.comptime_int_type) },
2903 // .expr = .{ .int = .{ .value = 1 } },
2904 // };
2905 // // return DocData.WalkResult{ .int = .{
2906 // // .type = @enumToInt(Ref.comptime_int_type),
2907 // // .value = 1,
2908 // // } };
28622909 // },
28632910 // .generic_poison => {
28642911 // return DocData.WalkResult{ .int = .{