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;
10931093 console.log(caseIndex);
10941094 console.log(item);
10951095 if (item['enumLiteral']) {
1096 payloadHtml += " " + " ." + exprName(item, opts) + " = " + "</br>";
1096 payloadHtml += " " + " ." + exprName(item, opts) + " => {} " + "</br>";
10971097 continue;
10981098 }
1099 payloadHtml += " " + exprName(item, opts) + " = " + "</br>";
1099 payloadHtml += " " + exprName(item, opts) + " => {} " + "</br>";
11001100 }
11011101 if (expr.switchOp.else_index !== 0) {
11021102 const else_index = expr.switchOp.else_index;
11031103 const item = zigAnalysis.exprs[else_index];
11041104 console.log(item);
1105 payloadHtml += " " + "else" + " = " + "</br>";
1105 payloadHtml += " " + "else" + " => {} " + "</br>";
11061106 }
11071107 payloadHtml += "}";
11081108 return payloadHtml;
......@@ -1239,6 +1239,13 @@ var zigAnalysis;
12391239 }
12401240 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
12421249 }
12431250 case "errorUnion": {
12441251 const errUnionObj = zigAnalysis.types[expr.errorUnion];
......@@ -1281,6 +1288,11 @@ var zigAnalysis;
12811288 return payloadHtml;
12821289
12831290 }
1291 case "alignOf": {
1292 const alignRefArg = zigAnalysis.exprs[expr.alignOf];
1293 let payloadHtml = "@alignOf(" + exprName(alignRefArg, {wantHtml: true, wantLink:true}) + ")";
1294 return payloadHtml;
1295 }
12841296 case "typeOf": {
12851297 const typeRefArg = zigAnalysis.exprs[expr.typeOf];
12861298 let payloadHtml = "@TypeOf(" + exprName(typeRefArg, {wantHtml: true, wantLink:true}) + ")";
......@@ -1634,6 +1646,18 @@ var zigAnalysis;
16341646 if (isVarArgs && i === fnObj.params.length - 1) {
16351647 payloadHtml += '...';
16361648 }
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 }
16371661 else if ("typeOf" in value) {
16381662 if (opts.wantHtml) {
16391663 payloadHtml += '<a href="">';
......@@ -1728,6 +1752,7 @@ var zigAnalysis;
17281752 }
17291753
17301754 if (fnObj.is_inferred_error) {
1755 console.log(fnObj)
17311756 payloadHtml += "!";
17321757 }
17331758 if (fnObj.ret != null) {
src/Autodoc.zig+122-29
......@@ -657,6 +657,7 @@ const DocData = struct {
657657 array: []usize, // index in `exprs`
658658 call: usize, // index in `calls`
659659 enumLiteral: []const u8, // direct value
660 alignOf: usize, // index in `exprs`
660661 typeOf: usize, // index in `exprs`
661662 typeOf_peer: []usize,
662663 errorUnion: usize, // index in `exprs`
......@@ -665,6 +666,7 @@ const DocData = struct {
665666 bitSizeOf: usize, // index in `exprs`
666667 enumToInt: usize, // index in `exprs`
667668 compileError: []const u8,
669 errorSets: usize,
668670 string: []const u8, // direct value
669671 switchIndex: usize, // index in `exprs`
670672 switchOp: SwitchOp,
......@@ -693,9 +695,6 @@ const DocData = struct {
693695 const SwitchOp = struct {
694696 cases: []usize,
695697 else_index: ?usize,
696 // body_cases: ?[]usize,
697
698 // const Case = struct { lhs: Expr, rhs: Expr };
699698 };
700699 const As = struct {
701700 typeRefArg: ?usize, // index in `exprs`
......@@ -722,7 +721,7 @@ const DocData = struct {
722721 \\{{ "{s}":{{}} }}
723722 , .{@tagName(self)});
724723 },
725 .type, .comptimeExpr, .call, .this, .declRef, .typeOf, .errorUnion => |v| {
724 .type, .comptimeExpr, .call, .this, .declRef, .typeOf, .errorUnion, .errorSets, .alignOf => |v| {
726725 try w.print(
727726 \\{{ "{s}":{} }}
728727 , .{ @tagName(self), v });
......@@ -1792,6 +1791,33 @@ fn walkInstruction(
17921791 .expr = .{ .errorUnion = type_slot_index },
17931792 };
17941793 },
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 },
17951821 .elem_type => {
17961822 const un_node = data[inst_index].un_node;
17971823
......@@ -2228,15 +2254,17 @@ fn walkInstruction(
22282254 };
22292255 },
22302256 .switch_block => {
2257 // WIP
22312258 const pl_node = data[inst_index].pl_node;
22322259 const extra = file.zir.extraData(Zir.Inst.SwitchBlock, pl_node.payload_index);
22332260 const array_data = try self.arena.alloc(usize, extra.data.bits.scalar_cases_len);
22342261 var extra_index = extra.end;
22352262
2236 const sep = "=" ** 200;
2237 std.debug.print("{s}\n", .{sep});
2238 std.debug.print("pl_node = {any}\n", .{pl_node});
2239 std.debug.print("extra = {any}\n", .{extra});
2263 // const sep = "=" ** 200;
2264 // std.debug.print("{s}\n", .{sep});
2265 // std.debug.print("pl_node = {any}\n", .{pl_node});
2266 // std.debug.print("extra = {any}\n", .{extra});
2267 // std.debug.print("{s}\n", .{sep});
22402268
22412269 const multi_cases_len = if (extra.data.bits.has_multi_cases) blk: {
22422270 const multi_cases_len = file.zir.extra[extra_index];
......@@ -2251,12 +2279,12 @@ fn walkInstruction(
22512279 extra_index += 1;
22522280 const body = file.zir.extra[extra_index..][0..body_len];
22532281 extra_index += body.len;
2254 for (body) |body_member| {
2282 for (body) |_| {
22552283 const item_ref = @intToEnum(Ref, file.zir.extra[extra_index]);
22562284 const item = try self.walkRef(file, parent_scope, item_ref, false);
2257 std.debug.print("prong item_ref = {any}\n", .{item_ref});
2258 std.debug.print("prong item = {any}\n", .{item});
2259 std.debug.print("body member = {any}\n", .{body_member});
2285 // std.debug.print("prong item_ref = {any}\n", .{item_ref});
2286 // std.debug.print("prong item = {any}\n", .{item});
2287 // std.debug.print("body member = {any}\n", .{body_member});
22602288 const item_index = self.exprs.items.len;
22612289 try self.exprs.append(self.arena, item.expr);
22622290 else_index = item_index;
......@@ -2279,15 +2307,16 @@ fn walkInstruction(
22792307 array_data[scalar_i] = item.expr.as.exprArg;
22802308
22812309 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
22842313 array_data[scalar_i] = item.expr.as.exprArg;
2285 std.debug.print("{s}\n", .{sep});
2286 std.debug.print("body item_ref = {any}\n", .{item_ref});
2287 std.debug.print("body item = {any}\n", .{item});
2288 std.debug.print("body_len scalar cases = {any}\n", .{body_ref});
2289 std.debug.print("body scalar cases = {any}\n", .{body_item});
2290 std.debug.print("{s}\n", .{sep});
2314 // std.debug.print("{s}\n", .{sep});
2315 // std.debug.print("body item_ref = {any}\n", .{item_ref});
2316 // std.debug.print("body item = {any}\n", .{item});
2317 // std.debug.print("body_len scalar cases = {any}\n", .{body_ref});
2318 // std.debug.print("body scalar cases = {any}\n", .{body_item});
2319 // std.debug.print("{s}\n", .{sep});
22912320 }
22922321 }
22932322 {
......@@ -2311,14 +2340,15 @@ fn walkInstruction(
23112340
23122341 const body = file.zir.extra[extra_index..][0..body_len];
23132342 extra_index += body_len;
2343 _ = body;
23142344
2315 std.debug.print("body multi_i = {any}\n", .{body});
2316 std.debug.print("items = {any}\n", .{items});
2345 // std.debug.print("body multi_i = {any}\n", .{body});
2346 // std.debug.print("items = {any}\n", .{items});
23172347 }
23182348 }
23192349
23202350 // 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
23232353 const switch_index = self.exprs.items.len;
23242354 try self.exprs.append(self.arena, .{ .switchOp = .{ .cases = array_data, .else_index = else_index } });
......@@ -2368,6 +2398,26 @@ fn walkInstruction(
23682398 .expr = .{ .typeOf = operand_index },
23692399 };
23702400 },
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 },
23712421 .typeof_builtin => {
23722422 const pl_node = data[inst_index].pl_node;
23732423 const extra = file.zir.extraData(Zir.Inst.Block, pl_node.payload_index);
......@@ -2388,6 +2438,31 @@ fn walkInstruction(
23882438 .expr = .{ .typeOf = operand_index },
23892439 };
23902440 },
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 },
23912466 .type_info => {
23922467 // @check
23932468 const un_node = data[inst_index].un_node;
......@@ -2536,6 +2611,23 @@ fn walkInstruction(
25362611 .expr = .{ .type = self.types.items.len - 1 },
25372612 };
25382613 },
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 },
25392631 .block => {
25402632 const res = DocData.WalkResult{ .expr = .{
25412633 .comptimeExpr = self.comptime_exprs.items.len,
......@@ -3746,14 +3838,15 @@ fn tryResolveRefPath(
37463838 }
37473839
37483840 // if we got here, our search failed
3749 printWithContext(
3750 file,
3751 inst_index,
3752 "failed to match `{s}` in struct",
3753 .{child_string},
3754 );
3841 // printWithContext(
3842 // file,
3843 // inst_index,
3844 // "failed to match `{s}` in struct",
3845 // .{child_string},
3846 // );
37553847 // path[i + 1] = (try self.cteTodo("match failure")).expr;
3756 // this are working, check c.zig
3848 //
3849 // that's working
37573850 path[i + 1] = (try self.cteTodo(child_string)).expr;
37583851 continue :outer;
37593852 },