authorgravatar for vallahor91@gmail.comVallahor <vallahor91@gmail.com> 2022-05-27 03:39:12-03:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-07-19 19:10:11-07:00
log76e934dba802fb7f0fdc7ed9f3d8d1561078132a
tree2866337ab3301388dc8934d036fe6245ea6df073
parentc449788b11d0184b356c6258fad33cc20813fd7d

fix: comptime not showing in all anytype params anymore. add: pointer flags


2 files changed, 67 insertions(+), 17 deletions(-)

lib/docs/main.js+12-7
...@@ -1210,6 +1210,7 @@ var zigAnalysis;...@@ -1210,6 +1210,7 @@ var zigAnalysis;
1210 let sentinel = ptrObj.sentinel ? ":"+exprName(ptrObj.sentinel, opts) : "";1210 let sentinel = ptrObj.sentinel ? ":"+exprName(ptrObj.sentinel, opts) : "";
1211 let is_mutable = !ptrObj.is_mutable ? "const " : "";1211 let is_mutable = !ptrObj.is_mutable ? "const " : "";
1212 let name = "";1212 let name = "";
1213 console.log(ptrObj);
1213 switch (ptrObj.size) {1214 switch (ptrObj.size) {
1214 default:1215 default:
1215 console.log("TODO: implement unhandled pointer size case");1216 console.log("TODO: implement unhandled pointer size case");
...@@ -1236,21 +1237,25 @@ var zigAnalysis;...@@ -1236,21 +1237,25 @@ var zigAnalysis;
1236 name += is_mutable;1237 name += is_mutable;
1237 break;1238 break;
1238 }1239 }
1239 if (ptrObj['const']) {1240 if (!ptrObj.is_mutable) {
1240 if (opts.wantHtml) {1241 if (opts.wantHtml) {
1241 name += '<span class="tok-kw">const</span> ';1242 name += '<span class="tok-kw">const</span> ';
1242 } else {1243 } else {
1243 name += "const ";1244 name += "const ";
1244 }1245 }
1245 }1246 }
1246 if (ptrObj['volatile']) {1247 if (ptrObj.is_allowzero) {
1247 if (opts.wantHtml) {1248 name += "allowzero ";
1248 name += '<span class="tok-kw">volatile</span> ';1249 }
1249 } else {1250 if (ptrObj.is_volatile) {
1250 name += "volatile ";1251 name += "volatile ";
1251 }
1252 }1252 }
1253 if (ptrObj.align != null) {1253 if (ptrObj.has_addrspace) {
1254 name += "addrspace(";
1255 name += "." + "";
1256 name += ") ";
1257 }
1258 if (ptrObj.has_align) {
1254 if (opts.wantHtml) {1259 if (opts.wantHtml) {
1255 name += '<span class="tok-kw">align</span>(';1260 name += '<span class="tok-kw">align</span>(';
1256 } else {1261 } else {
src/Autodoc.zig+55-10
...@@ -400,7 +400,13 @@ const DocData = struct {...@@ -400,7 +400,13 @@ const DocData = struct {
400 size: std.builtin.TypeInfo.Pointer.Size,400 size: std.builtin.TypeInfo.Pointer.Size,
401 child: Expr,401 child: Expr,
402 sentinel: ?Expr = null,402 sentinel: ?Expr = null,
403 is_mutable: bool = true,403 is_allowzero: bool = false,
404 is_mutable: bool = false,
405 is_volatile: bool = false,
406 has_sentinel: bool = false,
407 has_align: bool = false,
408 has_addrspace: bool = false,
409 has_bit_range: bool = false,
404 },410 },
405 Array: struct {411 Array: struct {
406 len: Expr,412 len: Expr,
...@@ -507,9 +513,15 @@ const DocData = struct {...@@ -507,9 +513,15 @@ const DocData = struct {
507 try w.print(",", .{});513 try w.print(",", .{});
508 }514 }
509 try w.print(515 try w.print(
516 \\"is_allowzero": {},
510 \\"is_mutable": {},517 \\"is_mutable": {},
518 \\"is_volatile": {},
519 \\"has_sentinel": {},
520 \\"has_align": {},
521 \\"has_addrspace": {},
522 \\"has_bit_range": {},
511 \\523 \\
512 , .{v.is_mutable});524 , .{ v.is_allowzero, v.is_mutable, v.is_volatile, v.has_sentinel, v.has_align, v.has_addrspace, v.has_bit_range });
513 if (options.whitespace) |ws| try ws.outputIndent(w);525 if (options.whitespace) |ws| try ws.outputIndent(w);
514 try w.print(526 try w.print(
515 \\"child":527 \\"child":
...@@ -880,11 +892,7 @@ fn walkInstruction(...@@ -880,11 +892,7 @@ fn walkInstruction(
880 const type_slot_index = self.types.items.len;892 const type_slot_index = self.types.items.len;
881 const elem_type_ref = try self.walkRef(file, parent_scope, ptr.elem_type, false);893 const elem_type_ref = try self.walkRef(file, parent_scope, ptr.elem_type, false);
882 try self.types.append(self.arena, .{894 try self.types.append(self.arena, .{
883 .Pointer = .{895 .Pointer = .{ .size = ptr.size, .child = elem_type_ref.expr, .is_mutable = ptr.is_mutable, .is_volatile = ptr.is_volatile, .is_allowzero = ptr.is_allowzero },
884 .size = ptr.size,
885 .child = elem_type_ref.expr,
886 .is_mutable = ptr.is_mutable,
887 },
888 });896 });
889897
890 return DocData.WalkResult{898 return DocData.WalkResult{
...@@ -904,8 +912,10 @@ fn walkInstruction(...@@ -904,8 +912,10 @@ fn walkInstruction(
904 false,912 false,
905 );913 );
906914
915 const sentinel: ?DocData.Expr = if (ptr.flags.has_sentinel) DocData.Expr{ .int = .{ .value = 0, .negated = false } } else null;
916
907 try self.types.append(self.arena, .{917 try self.types.append(self.arena, .{
908 .Pointer = .{ .size = ptr.size, .child = elem_type_ref.expr, .sentinel = .{ .int = .{ .value = 0, .negated = false } }, .is_mutable = ptr.flags.is_mutable },918 .Pointer = .{ .size = ptr.size, .child = elem_type_ref.expr, .sentinel = sentinel, .is_mutable = ptr.flags.is_mutable, .has_align = ptr.flags.has_align, .has_sentinel = ptr.flags.has_sentinel, .is_volatile = ptr.flags.is_volatile, .has_addrspace = ptr.flags.has_addrspace, .has_bit_range = ptr.flags.has_bit_range },
909 });919 });
910 return DocData.WalkResult{920 return DocData.WalkResult{
911 .typeRef = .{ .type = @enumToInt(Ref.type_type) },921 .typeRef = .{ .type = @enumToInt(Ref.type_type) },
...@@ -1194,6 +1204,20 @@ fn walkInstruction(...@@ -1194,6 +1204,20 @@ fn walkInstruction(
1194 .expr = .{ .float = float },1204 .expr = .{ .float = float },
1195 };1205 };
1196 },1206 },
1207 .float128 => {
1208 const pl_node = data[inst_index].pl_node;
1209 const extra = file.zir.extraData(Zir.Inst.Float128, pl_node.payload_index);
1210 _ = pl_node;
1211 _ = extra;
1212
1213 // printWithContext(
1214 // file,
1215 // inst_index,
1216 // "TODO: implement `{s}` for walkInstruction\n\n",
1217 // .{@tagName(tags[inst_index])},
1218 // );
1219 return self.cteTodo(@tagName(tags[inst_index]));
1220 },
1197 .negate => {1221 .negate => {
1198 const un_node = data[inst_index].un_node;1222 const un_node = data[inst_index].un_node;
1199 var operand: DocData.WalkResult = try self.walkRef(1223 var operand: DocData.WalkResult = try self.walkRef(
...@@ -1481,6 +1505,27 @@ fn walkInstruction(...@@ -1481,6 +1505,27 @@ fn walkInstruction(
1481 .expr = .{ .@"struct" = field_vals },1505 .expr = .{ .@"struct" = field_vals },
1482 };1506 };
1483 },1507 },
1508 .struct_init_empty => {
1509 const un_node = data[inst_index].un_node;
1510 var operand: DocData.WalkResult = try self.walkRef(
1511 file,
1512 parent_scope,
1513 un_node.operand,
1514 false,
1515 );
1516
1517 _ = operand;
1518
1519 // WIP
1520
1521 printWithContext(
1522 file,
1523 inst_index,
1524 "TODO: implement `{s}` for walkInstruction\n\n",
1525 .{@tagName(tags[inst_index])},
1526 );
1527 return self.cteTodo(@tagName(tags[inst_index]));
1528 },
1484 .error_set_decl => {1529 .error_set_decl => {
1485 const pl_node = data[inst_index].pl_node;1530 const pl_node = data[inst_index].pl_node;
1486 const extra = file.zir.extraData(Zir.Inst.ErrorSetDecl, pl_node.payload_index);1531 const extra = file.zir.extraData(Zir.Inst.ErrorSetDecl, pl_node.payload_index);
...@@ -1630,7 +1675,7 @@ fn walkInstruction(...@@ -1630,7 +1675,7 @@ fn walkInstruction(
1630 .negated = false,1675 .negated = false,
1631 },1676 },
1632 },1677 },
1633 .child = array_type.?,1678 .child = .{ .type = 0 },
1634 },1679 },
1635 });1680 });
1636 const result = DocData.WalkResult{1681 const result = DocData.WalkResult{
...@@ -2657,7 +2702,7 @@ fn analyzeFunction(...@@ -2657,7 +2702,7 @@ fn analyzeFunction(
2657 self.ast_nodes.appendAssumeCapacity(.{2702 self.ast_nodes.appendAssumeCapacity(.{
2658 .name = name,2703 .name = name,
2659 .docs = "",2704 .docs = "",
2660 .@"comptime" = true,2705 .@"comptime" = tags[param_index] == .param_anytype_comptime,
2661 });2706 });
26622707
2663 param_type_refs.appendAssumeCapacity(2708 param_type_refs.appendAssumeCapacity(