authorgravatar for vallahor91@gmail.comVallahor <vallahor91@gmail.com> 2022-05-31 19:48:00-03:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-07-19 19:10:12-07:00
loga0ec87be717094b080a98595cfd4ceb0aec38cdf
tree2ec7801b3de8c175c9c5ae7402809bcd1eeb96c0
parentd858f261396fa6b9b3097b5b4d377f6465ec5909

add: merge_error_sets and @alignOf() need a checkin to confirm it's fully work


2 files changed, 150 insertions(+), 32 deletions(-)

lib/docs/main.js+28-3
...@@ -1093,16 +1093,16 @@ var zigAnalysis;...@@ -1093,16 +1093,16 @@ var zigAnalysis;
1093 console.log(caseIndex);1093 console.log(caseIndex);
1094 console.log(item);1094 console.log(item);
1095 if (item['enumLiteral']) {1095 if (item['enumLiteral']) {
1096 payloadHtml += " " + " ." + exprName(item, opts) + " = " + "</br>";1096 payloadHtml += " " + " ." + exprName(item, opts) + " => {} " + "</br>";
1097 continue;1097 continue;
1098 }1098 }
1099 payloadHtml += " " + exprName(item, opts) + " = " + "</br>";1099 payloadHtml += " " + exprName(item, opts) + " => {} " + "</br>";
1100 }1100 }
1101 if (expr.switchOp.else_index !== 0) {1101 if (expr.switchOp.else_index !== 0) {
1102 const else_index = expr.switchOp.else_index;1102 const else_index = expr.switchOp.else_index;
1103 const item = zigAnalysis.exprs[else_index];1103 const item = zigAnalysis.exprs[else_index];
1104 console.log(item);1104 console.log(item);
1105 payloadHtml += " " + "else" + " = " + "</br>";1105 payloadHtml += " " + "else" + " => {} " + "</br>";
1106 }1106 }
1107 payloadHtml += "}";1107 payloadHtml += "}";
1108 return payloadHtml;1108 return payloadHtml;
...@@ -1239,6 +1239,13 @@ var zigAnalysis;...@@ -1239,6 +1239,13 @@ var zigAnalysis;
1239 }1239 }
1240 return print_lhs + " " + operator + " " + print_rhs;1240 return print_lhs + " " + operator + " " + print_rhs;
12411241
1242 }
1243 case "errorSets": {
1244 const errUnionObj = zigAnalysis.types[expr.errorSets];
1245 let lhs = exprName(errUnionObj.lhs, opts);
1246 let rhs = exprName(errUnionObj.rhs, opts);
1247 return lhs + " || " + rhs;
1248
1242 }1249 }
1243 case "errorUnion": {1250 case "errorUnion": {
1244 const errUnionObj = zigAnalysis.types[expr.errorUnion];1251 const errUnionObj = zigAnalysis.types[expr.errorUnion];
...@@ -1281,6 +1288,11 @@ var zigAnalysis;...@@ -1281,6 +1288,11 @@ var zigAnalysis;
1281 return payloadHtml;1288 return payloadHtml;
12821289
1283 }1290 }
1291 case "alignOf": {
1292 const alignRefArg = zigAnalysis.exprs[expr.alignOf];
1293 let payloadHtml = "@alignOf(" + exprName(alignRefArg, {wantHtml: true, wantLink:true}) + ")";
1294 return payloadHtml;
1295 }
1284 case "typeOf": {1296 case "typeOf": {
1285 const typeRefArg = zigAnalysis.exprs[expr.typeOf];1297 const typeRefArg = zigAnalysis.exprs[expr.typeOf];
1286 let payloadHtml = "@TypeOf(" + exprName(typeRefArg, {wantHtml: true, wantLink:true}) + ")";1298 let payloadHtml = "@TypeOf(" + exprName(typeRefArg, {wantHtml: true, wantLink:true}) + ")";
...@@ -1634,6 +1646,18 @@ var zigAnalysis;...@@ -1634,6 +1646,18 @@ var zigAnalysis;
1634 if (isVarArgs && i === fnObj.params.length - 1) {1646 if (isVarArgs && i === fnObj.params.length - 1) {
1635 payloadHtml += '...';1647 payloadHtml += '...';
1636 }1648 }
1649 else if ("alignOf" in value) {
1650 if (opts.wantHtml) {
1651 payloadHtml += '<a href="">';
1652 payloadHtml +=
1653 '<span class="tok-kw" style="color:lightblue;">'
1654 + exprName(value, opts) + '</span>';
1655 payloadHtml += '</a>';
1656 } else {
1657 payloadHtml += exprName(value, opts);
1658 }
1659
1660 }
1637 else if ("typeOf" in value) {1661 else if ("typeOf" in value) {
1638 if (opts.wantHtml) {1662 if (opts.wantHtml) {
1639 payloadHtml += '<a href="">';1663 payloadHtml += '<a href="">';
...@@ -1728,6 +1752,7 @@ var zigAnalysis;...@@ -1728,6 +1752,7 @@ var zigAnalysis;
1728 }1752 }
17291753
1730 if (fnObj.is_inferred_error) {1754 if (fnObj.is_inferred_error) {
1755 console.log(fnObj)
1731 payloadHtml += "!";1756 payloadHtml += "!";
1732 }1757 }
1733 if (fnObj.ret != null) {1758 if (fnObj.ret != null) {
src/Autodoc.zig+122-29
...@@ -657,6 +657,7 @@ const DocData = struct {...@@ -657,6 +657,7 @@ const DocData = struct {
657 array: []usize, // index in `exprs`657 array: []usize, // index in `exprs`
658 call: usize, // index in `calls`658 call: usize, // index in `calls`
659 enumLiteral: []const u8, // direct value659 enumLiteral: []const u8, // direct value
660 alignOf: usize, // index in `exprs`
660 typeOf: usize, // index in `exprs`661 typeOf: usize, // index in `exprs`
661 typeOf_peer: []usize,662 typeOf_peer: []usize,
662 errorUnion: usize, // index in `exprs`663 errorUnion: usize, // index in `exprs`
...@@ -665,6 +666,7 @@ const DocData = struct {...@@ -665,6 +666,7 @@ const DocData = struct {
665 bitSizeOf: usize, // index in `exprs`666 bitSizeOf: usize, // index in `exprs`
666 enumToInt: usize, // index in `exprs`667 enumToInt: usize, // index in `exprs`
667 compileError: []const u8,668 compileError: []const u8,
669 errorSets: usize,
668 string: []const u8, // direct value670 string: []const u8, // direct value
669 switchIndex: usize, // index in `exprs`671 switchIndex: usize, // index in `exprs`
670 switchOp: SwitchOp,672 switchOp: SwitchOp,
...@@ -693,9 +695,6 @@ const DocData = struct {...@@ -693,9 +695,6 @@ const DocData = struct {
693 const SwitchOp = struct {695 const SwitchOp = struct {
694 cases: []usize,696 cases: []usize,
695 else_index: ?usize,697 else_index: ?usize,
696 // body_cases: ?[]usize,
697
698 // const Case = struct { lhs: Expr, rhs: Expr };
699 };698 };
700 const As = struct {699 const As = struct {
701 typeRefArg: ?usize, // index in `exprs`700 typeRefArg: ?usize, // index in `exprs`
...@@ -722,7 +721,7 @@ const DocData = struct {...@@ -722,7 +721,7 @@ const DocData = struct {
722 \\{{ "{s}":{{}} }}721 \\{{ "{s}":{{}} }}
723 , .{@tagName(self)});722 , .{@tagName(self)});
724 },723 },
725 .type, .comptimeExpr, .call, .this, .declRef, .typeOf, .errorUnion => |v| {724 .type, .comptimeExpr, .call, .this, .declRef, .typeOf, .errorUnion, .errorSets, .alignOf => |v| {
726 try w.print(725 try w.print(
727 \\{{ "{s}":{} }}726 \\{{ "{s}":{} }}
728 , .{ @tagName(self), v });727 , .{ @tagName(self), v });
...@@ -1792,6 +1791,33 @@ fn walkInstruction(...@@ -1792,6 +1791,33 @@ fn walkInstruction(
1792 .expr = .{ .errorUnion = type_slot_index },1791 .expr = .{ .errorUnion = type_slot_index },
1793 };1792 };
1794 },1793 },
1794 .merge_error_sets => {
1795 const pl_node = data[inst_index].pl_node;
1796 const extra = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index);
1797
1798 var lhs: DocData.WalkResult = try self.walkRef(
1799 file,
1800 parent_scope,
1801 extra.data.lhs,
1802 false,
1803 );
1804 var rhs: DocData.WalkResult = try self.walkRef(
1805 file,
1806 parent_scope,
1807 extra.data.rhs,
1808 false,
1809 );
1810 const type_slot_index = self.types.items.len;
1811 try self.types.append(self.arena, .{ .ErrorUnion = .{
1812 .lhs = lhs.expr,
1813 .rhs = rhs.expr,
1814 } });
1815
1816 return DocData.WalkResult{
1817 .typeRef = .{ .type = @enumToInt(Ref.type_type) },
1818 .expr = .{ .errorSets = type_slot_index },
1819 };
1820 },
1795 .elem_type => {1821 .elem_type => {
1796 const un_node = data[inst_index].un_node;1822 const un_node = data[inst_index].un_node;
17971823
...@@ -2228,15 +2254,17 @@ fn walkInstruction(...@@ -2228,15 +2254,17 @@ fn walkInstruction(
2228 };2254 };
2229 },2255 },
2230 .switch_block => {2256 .switch_block => {
2257 // WIP
2231 const pl_node = data[inst_index].pl_node;2258 const pl_node = data[inst_index].pl_node;
2232 const extra = file.zir.extraData(Zir.Inst.SwitchBlock, pl_node.payload_index);2259 const extra = file.zir.extraData(Zir.Inst.SwitchBlock, pl_node.payload_index);
2233 const array_data = try self.arena.alloc(usize, extra.data.bits.scalar_cases_len);2260 const array_data = try self.arena.alloc(usize, extra.data.bits.scalar_cases_len);
2234 var extra_index = extra.end;2261 var extra_index = extra.end;
22352262
2236 const sep = "=" ** 200;2263 // const sep = "=" ** 200;
2237 std.debug.print("{s}\n", .{sep});2264 // std.debug.print("{s}\n", .{sep});
2238 std.debug.print("pl_node = {any}\n", .{pl_node});2265 // std.debug.print("pl_node = {any}\n", .{pl_node});
2239 std.debug.print("extra = {any}\n", .{extra});2266 // std.debug.print("extra = {any}\n", .{extra});
2267 // std.debug.print("{s}\n", .{sep});
22402268
2241 const multi_cases_len = if (extra.data.bits.has_multi_cases) blk: {2269 const multi_cases_len = if (extra.data.bits.has_multi_cases) blk: {
2242 const multi_cases_len = file.zir.extra[extra_index];2270 const multi_cases_len = file.zir.extra[extra_index];
...@@ -2251,12 +2279,12 @@ fn walkInstruction(...@@ -2251,12 +2279,12 @@ fn walkInstruction(
2251 extra_index += 1;2279 extra_index += 1;
2252 const body = file.zir.extra[extra_index..][0..body_len];2280 const body = file.zir.extra[extra_index..][0..body_len];
2253 extra_index += body.len;2281 extra_index += body.len;
2254 for (body) |body_member| {2282 for (body) |_| {
2255 const item_ref = @intToEnum(Ref, file.zir.extra[extra_index]);2283 const item_ref = @intToEnum(Ref, file.zir.extra[extra_index]);
2256 const item = try self.walkRef(file, parent_scope, item_ref, false);2284 const item = try self.walkRef(file, parent_scope, item_ref, false);
2257 std.debug.print("prong item_ref = {any}\n", .{item_ref});2285 // std.debug.print("prong item_ref = {any}\n", .{item_ref});
2258 std.debug.print("prong item = {any}\n", .{item});2286 // std.debug.print("prong item = {any}\n", .{item});
2259 std.debug.print("body member = {any}\n", .{body_member});2287 // std.debug.print("body member = {any}\n", .{body_member});
2260 const item_index = self.exprs.items.len;2288 const item_index = self.exprs.items.len;
2261 try self.exprs.append(self.arena, item.expr);2289 try self.exprs.append(self.arena, item.expr);
2262 else_index = item_index;2290 else_index = item_index;
...@@ -2279,15 +2307,16 @@ fn walkInstruction(...@@ -2279,15 +2307,16 @@ fn walkInstruction(
2279 array_data[scalar_i] = item.expr.as.exprArg;2307 array_data[scalar_i] = item.expr.as.exprArg;
22802308
2281 const body_ref = @intToEnum(Ref, file.zir.extra[extra_index]);2309 const body_ref = @intToEnum(Ref, file.zir.extra[extra_index]);
2282 const body_item = try self.walkRef(file, parent_scope, item_ref, false);2310 const body_item = try self.walkRef(file, parent_scope, body_ref, false);
2311 _ = body_item;
22832312
2284 array_data[scalar_i] = item.expr.as.exprArg;2313 array_data[scalar_i] = item.expr.as.exprArg;
2285 std.debug.print("{s}\n", .{sep});2314 // std.debug.print("{s}\n", .{sep});
2286 std.debug.print("body item_ref = {any}\n", .{item_ref});2315 // std.debug.print("body item_ref = {any}\n", .{item_ref});
2287 std.debug.print("body item = {any}\n", .{item});2316 // std.debug.print("body item = {any}\n", .{item});
2288 std.debug.print("body_len scalar cases = {any}\n", .{body_ref});2317 // std.debug.print("body_len scalar cases = {any}\n", .{body_ref});
2289 std.debug.print("body scalar cases = {any}\n", .{body_item});2318 // std.debug.print("body scalar cases = {any}\n", .{body_item});
2290 std.debug.print("{s}\n", .{sep});2319 // std.debug.print("{s}\n", .{sep});
2291 }2320 }
2292 }2321 }
2293 {2322 {
...@@ -2311,14 +2340,15 @@ fn walkInstruction(...@@ -2311,14 +2340,15 @@ fn walkInstruction(
23112340
2312 const body = file.zir.extra[extra_index..][0..body_len];2341 const body = file.zir.extra[extra_index..][0..body_len];
2313 extra_index += body_len;2342 extra_index += body_len;
2343 _ = body;
23142344
2315 std.debug.print("body multi_i = {any}\n", .{body});2345 // std.debug.print("body multi_i = {any}\n", .{body});
2316 std.debug.print("items = {any}\n", .{items});2346 // std.debug.print("items = {any}\n", .{items});
2317 }2347 }
2318 }2348 }
23192349
2320 // std.debug.print("multi_cases_len = {}\n", .{multi_cases_len});2350 // std.debug.print("multi_cases_len = {}\n", .{multi_cases_len});
2321 std.debug.print("{s}\n", .{sep});2351 // std.debug.print("{s}\n", .{sep});
23222352
2323 const switch_index = self.exprs.items.len;2353 const switch_index = self.exprs.items.len;
2324 try self.exprs.append(self.arena, .{ .switchOp = .{ .cases = array_data, .else_index = else_index } });2354 try self.exprs.append(self.arena, .{ .switchOp = .{ .cases = array_data, .else_index = else_index } });
...@@ -2368,6 +2398,26 @@ fn walkInstruction(...@@ -2368,6 +2398,26 @@ fn walkInstruction(
2368 .expr = .{ .typeOf = operand_index },2398 .expr = .{ .typeOf = operand_index },
2369 };2399 };
2370 },2400 },
2401 .align_of => {
2402 // WIP
2403 // not fully working
2404 // @alignOf() with some pointer type it's not even called in js
2405 // @alignOf([*]u8) are being rendered as [*]u8
2406 const un_node = data[inst_index].un_node;
2407 const operand = try self.walkRef(
2408 file,
2409 parent_scope,
2410 un_node.operand,
2411 need_type,
2412 );
2413 const operand_index = self.exprs.items.len;
2414 try self.exprs.append(self.arena, operand.expr);
2415
2416 return DocData.WalkResult{
2417 .typeRef = operand.typeRef,
2418 .expr = .{ .alignOf = operand_index },
2419 };
2420 },
2371 .typeof_builtin => {2421 .typeof_builtin => {
2372 const pl_node = data[inst_index].pl_node;2422 const pl_node = data[inst_index].pl_node;
2373 const extra = file.zir.extraData(Zir.Inst.Block, pl_node.payload_index);2423 const extra = file.zir.extraData(Zir.Inst.Block, pl_node.payload_index);
...@@ -2388,6 +2438,31 @@ fn walkInstruction(...@@ -2388,6 +2438,31 @@ fn walkInstruction(
2388 .expr = .{ .typeOf = operand_index },2438 .expr = .{ .typeOf = operand_index },
2389 };2439 };
2390 },2440 },
2441 .typeof_log2_int_type => {
2442 // @check
2443 const un_node = data[inst_index].un_node;
2444 const operand = try self.walkRef(
2445 file,
2446 parent_scope,
2447 un_node.operand,
2448 need_type,
2449 );
2450
2451 // WIP
2452 // const sep = "=" ** 200;
2453 // std.debug.print("{s}\n", .{sep});
2454 // std.debug.print("un_node = {any}\n", .{un_node});
2455 // std.debug.print("operand = {any}\n", .{operand});
2456 // std.debug.print("{s}\n", .{sep});
2457
2458 const operand_index = self.exprs.items.len;
2459 try self.exprs.append(self.arena, operand.expr);
2460
2461 return DocData.WalkResult{
2462 .typeRef = operand.typeRef,
2463 .expr = .{ .typeOf = operand_index },
2464 };
2465 },
2391 .type_info => {2466 .type_info => {
2392 // @check2467 // @check
2393 const un_node = data[inst_index].un_node;2468 const un_node = data[inst_index].un_node;
...@@ -2536,6 +2611,23 @@ fn walkInstruction(...@@ -2536,6 +2611,23 @@ fn walkInstruction(
2536 .expr = .{ .type = self.types.items.len - 1 },2611 .expr = .{ .type = self.types.items.len - 1 },
2537 };2612 };
2538 },2613 },
2614 .float128 => {
2615 const pl_node = data[inst_index].pl_node;
2616 const extra = file.zir.extraData(Zir.Inst.Float128, pl_node.payload_index);
2617 _ = extra;
2618 // const sep = "=" ** 200;
2619 // std.debug.print("{s}\n", .{sep});
2620 // std.debug.print("pl_node = {any}\n", .{pl_node});
2621 // std.debug.print("extra = {any}\n", .{extra});
2622 // std.debug.print("{s}\n", .{sep});
2623 // printWithContext(
2624 // file,
2625 // inst_index,
2626 // "TODO: implement `{s}` for walkInstruction\n\n",
2627 // .{@tagName(tags[inst_index])},
2628 // );
2629 return self.cteTodo(@tagName(tags[inst_index]));
2630 },
2539 .block => {2631 .block => {
2540 const res = DocData.WalkResult{ .expr = .{2632 const res = DocData.WalkResult{ .expr = .{
2541 .comptimeExpr = self.comptime_exprs.items.len,2633 .comptimeExpr = self.comptime_exprs.items.len,
...@@ -3746,14 +3838,15 @@ fn tryResolveRefPath(...@@ -3746,14 +3838,15 @@ fn tryResolveRefPath(
3746 }3838 }
37473839
3748 // if we got here, our search failed3840 // if we got here, our search failed
3749 printWithContext(3841 // printWithContext(
3750 file,3842 // file,
3751 inst_index,3843 // inst_index,
3752 "failed to match `{s}` in struct",3844 // "failed to match `{s}` in struct",
3753 .{child_string},3845 // .{child_string},
3754 );3846 // );
3755 // path[i + 1] = (try self.cteTodo("match failure")).expr;3847 // path[i + 1] = (try self.cteTodo("match failure")).expr;
3756 // this are working, check c.zig3848 //
3849 // that's working
3757 path[i + 1] = (try self.cteTodo(child_string)).expr;3850 path[i + 1] = (try self.cteTodo(child_string)).expr;
3758 continue :outer;3851 continue :outer;
3759 },3852 },