authorgravatar for vallahor91@gmail.comVallahor <vallahor91@gmail.com> 2022-05-28 06:37:25-03:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-07-19 19:10:11-07:00
log11eb11d7d6b54ac56aa9a5560f21140220bbe487
tree4a1403652b4ac366558b232cdc95b284887804be
parentf04f23a3aaeb0e0b3b17395fdc7ee0742a3f983e

fix: slices


2 files changed, 37 insertions(+), 74 deletions(-)

lib/docs/main.js+10-9
......@@ -1193,7 +1193,7 @@ var zigAnalysis;
11931193 let name = "[";
11941194 let lenName = exprName(arrayObj.len, opts);
11951195 let sentinel = arrayObj.sentinel ? ":"+exprName(arrayObj.sentinel, opts) : "";
1196 let is_mutable = arrayObj.is_multable ? "const " : "";
1196 // let is_mutable = arrayObj.is_multable ? "const " : "";
11971197
11981198 if (opts.wantHtml) {
11991199 name +=
......@@ -1202,7 +1202,7 @@ var zigAnalysis;
12021202 name += lenName + sentinel;
12031203 }
12041204 name += "]";
1205 name += is_mutable;
1205 // name += is_mutable;
12061206 name += exprName(arrayObj.child, opts);
12071207 return name;
12081208 }
......@@ -1240,13 +1240,14 @@ var zigAnalysis;
12401240 name += is_mutable;
12411241 break;
12421242 }
1243 if (!ptrObj.is_mutable) {
1244 if (opts.wantHtml) {
1245 name += '<span class="tok-kw">const</span> ';
1246 } else {
1247 name += "const ";
1248 }
1249 }
1243 // @check: after the major changes in arrays the consts are came from switch above
1244 // if (!ptrObj.is_mutable) {
1245 // if (opts.wantHtml) {
1246 // name += '<span class="tok-kw">const</span> ';
1247 // } else {
1248 // name += "const ";
1249 // }
1250 // }
12501251 if (ptrObj.is_allowzero) {
12511252 name += "allowzero ";
12521253 }
src/Autodoc.zig+27-65
......@@ -536,9 +536,9 @@ const DocData = struct {
536536 \\
537537 , .{ v.is_allowzero, v.is_mutable, v.is_volatile, v.has_sentinel, v.has_align, v.has_addrspace, v.has_bit_range });
538538 if (options.whitespace) |ws| try ws.outputIndent(w);
539 try w.print(
540 \\"child":
541 , .{});
539 // try w.print(
540 // \\"child":
541 // , .{});
542542
543543 if (options.whitespace) |*ws| ws.indent_level += 1;
544544 try v.child.jsonStringify(options, w);
......@@ -924,8 +924,8 @@ fn walkInstruction(
924924 },
925925 .ptr_type_simple => {
926926 const ptr = data[inst_index].ptr_type_simple;
927 const type_slot_index = self.types.items.len;
928927 const elem_type_ref = try self.walkRef(file, parent_scope, ptr.elem_type, false);
928 const type_slot_index = self.types.items.len;
929929 try self.types.append(self.arena, .{
930930 .Pointer = .{ .size = ptr.size, .child = elem_type_ref.expr, .is_mutable = ptr.is_mutable, .is_volatile = ptr.is_volatile, .is_allowzero = ptr.is_allowzero },
931931 });
......@@ -948,7 +948,6 @@ fn walkInstruction(
948948 );
949949
950950 const sentinel: ?DocData.Expr = if (ptr.flags.has_sentinel) DocData.Expr{ .int = .{ .value = 0, .negated = false } } else null;
951
952951 try self.types.append(self.arena, .{
953952 .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 },
954953 });
......@@ -1021,14 +1020,11 @@ fn walkInstruction(
10211020 }
10221021
10231022 const type_slot_index = self.types.items.len;
1024 try self.types.append(self.arena, .{
1025 .Array = .{ .len = .{
1026 .int = .{
1027 .value = operands.len,
1028 .negated = false,
1029 },
1030 }, .child = array_type.? },
1031 });
1023 try self.types.append(self.arena, .{ .Pointer = .{
1024 .size = .Slice,
1025 .child = array_type.?,
1026 .is_mutable = true,
1027 } });
10321028
10331029 return DocData.WalkResult{
10341030 .typeRef = .{ .type = type_slot_index },
......@@ -1061,14 +1057,7 @@ fn walkInstruction(
10611057 }
10621058
10631059 const type_slot_index = self.types.items.len;
1064 try self.types.append(self.arena, .{
1065 .Array = .{ .len = .{
1066 .int = .{
1067 .value = operands.len - 1,
1068 .negated = false,
1069 },
1070 }, .child = array_type.?, .sentinel = sentinel },
1071 });
1060 try self.types.append(self.arena, .{ .Pointer = .{ .size = .Slice, .child = array_type.?, .is_mutable = true, .sentinel = sentinel } });
10721061
10731062 return DocData.WalkResult{
10741063 .typeRef = .{ .type = type_slot_index },
......@@ -1180,14 +1169,7 @@ fn walkInstruction(
11801169 }
11811170
11821171 const type_slot_index = self.types.items.len;
1183 try self.types.append(self.arena, .{
1184 .Array = .{ .len = .{
1185 .int = .{
1186 .value = operands.len - 1,
1187 .negated = false,
1188 },
1189 }, .child = array_type.?, .sentinel = sentinel },
1190 });
1172 try self.types.append(self.arena, .{ .Pointer = .{ .size = .Slice, .child = array_type.?, .is_mutable = true, .sentinel = sentinel } });
11911173
11921174 return DocData.WalkResult{
11931175 .typeRef = .{ .type = type_slot_index },
......@@ -1198,9 +1180,7 @@ fn walkInstruction(
11981180 const pl_node = data[inst_index].pl_node;
11991181 const extra = file.zir.extraData(Zir.Inst.MultiOp, pl_node.payload_index);
12001182 const operands = file.zir.refSlice(extra.end, extra.data.operands_len);
1201 const array_data = try self.arena.alloc(usize, operands.len - 1);
1202
1203 var sentinel: ?DocData.Expr = null;
1183 const array_data = try self.arena.alloc(usize, operands.len);
12041184
12051185 var array_type: ?DocData.Expr = null;
12061186 for (operands) |op, idx| {
......@@ -1209,22 +1189,22 @@ fn walkInstruction(
12091189 array_type = wr.typeRef;
12101190 }
12111191
1212 if (idx == extra.data.operands_len - 1) {
1213 sentinel = wr.expr;
1214 const expr_index = self.exprs.items.len;
1215 try self.exprs.append(self.arena, wr.expr);
1216 array_data[idx] = expr_index;
1217 }
1192 const expr_index = self.exprs.items.len;
1193 try self.exprs.append(self.arena, wr.expr);
1194 array_data[idx] = expr_index;
12181195 }
12191196
12201197 const type_slot_index = self.types.items.len;
12211198 try self.types.append(self.arena, .{
1222 .Array = .{ .len = .{
1223 .int = .{
1224 .value = operands.len - 1,
1225 .negated = false,
1199 .Array = .{
1200 .len = .{
1201 .int = .{
1202 .value = operands.len - 1,
1203 .negated = false,
1204 },
12261205 },
1227 }, .child = array_type.?, .sentinel = sentinel },
1206 .child = array_type.?,
1207 },
12281208 });
12291209
12301210 return DocData.WalkResult{
......@@ -1239,20 +1219,6 @@ fn walkInstruction(
12391219 .expr = .{ .float = float },
12401220 };
12411221 },
1242 .float128 => {
1243 const pl_node = data[inst_index].pl_node;
1244 const extra = file.zir.extraData(Zir.Inst.Float128, pl_node.payload_index);
1245 _ = pl_node;
1246 _ = extra;
1247
1248 // printWithContext(
1249 // file,
1250 // inst_index,
1251 // "TODO: implement `{s}` for walkInstruction\n\n",
1252 // .{@tagName(tags[inst_index])},
1253 // );
1254 return self.cteTodo(@tagName(tags[inst_index]));
1255 },
12561222 .negate => {
12571223 const un_node = data[inst_index].un_node;
12581224 var operand: DocData.WalkResult = try self.walkRef(
......@@ -2793,13 +2759,13 @@ fn analyzeFunction(
27932759 .func_extended => blk: {
27942760 const inst_data = data[inst_index].pl_node;
27952761 const extra = file.zir.extraData(Zir.Inst.ExtendedFunc, inst_data.payload_index);
2796
27972762 var cc_index: ?usize = null;
27982763 if (extra.data.bits.has_cc) {
27992764 const cc_ref = @intToEnum(Zir.Inst.Ref, file.zir.extra[extra.end]);
28002765 _ = try self.walkRef(file, scope, cc_ref, false);
28012766 cc_index = self.types.items.len - 1;
28022767 }
2768
28032769 break :blk .{
28042770 .Fn = .{
28052771 .name = "todo_name func",
......@@ -3043,25 +3009,21 @@ fn walkRef(
30433009 // TODO: dunno what to do with those
30443010 // .calling_convention_type => {
30453011 // return DocData.WalkResult{
3046 // .typeRef = .{ .type = @enumToInt(Ref.comptime_int_type) },
3012 // .typeRef = .{ .type = @enumToInt(Ref.calling_convention_type) },
30473013 // .expr = .{ .int = .{ .value = 1 } },
30483014 // };
30493015 // },
30503016 // .calling_convention_c => {
30513017 // return DocData.WalkResult{
3052 // .typeRef = .{ .type = @enumToInt(Ref.comptime_int_type) },
3018 // .typeRef = .{ .type = @enumToInt(Ref.calling_convention_c) },
30533019 // .expr = .{ .int = .{ .value = 1 } },
30543020 // };
30553021 // },
30563022 // .calling_convention_inline => {
30573023 // return DocData.WalkResult{
3058 // .typeRef = .{ .type = @enumToInt(Ref.comptime_int_type) },
3024 // .typeRef = .{ .type = @enumToInt(Ref.calling_convention_inline) },
30593025 // .expr = .{ .int = .{ .value = 1 } },
30603026 // };
3061 // // return DocData.WalkResult{ .int = .{
3062 // // .type = @enumToInt(Ref.comptime_int_type),
3063 // // .value = 1,
3064 // // } };
30653027 // },
30663028 // .generic_poison => {
30673029 // return DocData.WalkResult{ .int = .{