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;...@@ -1193,7 +1193,7 @@ var zigAnalysis;
1193 let name = "[";1193 let name = "[";
1194 let lenName = exprName(arrayObj.len, opts);1194 let lenName = exprName(arrayObj.len, opts);
1195 let sentinel = arrayObj.sentinel ? ":"+exprName(arrayObj.sentinel, opts) : "";1195 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
1198 if (opts.wantHtml) {1198 if (opts.wantHtml) {
1199 name +=1199 name +=
...@@ -1202,7 +1202,7 @@ var zigAnalysis;...@@ -1202,7 +1202,7 @@ var zigAnalysis;
1202 name += lenName + sentinel;1202 name += lenName + sentinel;
1203 }1203 }
1204 name += "]";1204 name += "]";
1205 name += is_mutable;1205 // name += is_mutable;
1206 name += exprName(arrayObj.child, opts);1206 name += exprName(arrayObj.child, opts);
1207 return name;1207 return name;
1208 }1208 }
...@@ -1240,13 +1240,14 @@ var zigAnalysis;...@@ -1240,13 +1240,14 @@ var zigAnalysis;
1240 name += is_mutable;1240 name += is_mutable;
1241 break;1241 break;
1242 }1242 }
1243 if (!ptrObj.is_mutable) {1243 // @check: after the major changes in arrays the consts are came from switch above
1244 if (opts.wantHtml) {1244 // if (!ptrObj.is_mutable) {
1245 name += '<span class="tok-kw">const</span> ';1245 // if (opts.wantHtml) {
1246 } else {1246 // name += '<span class="tok-kw">const</span> ';
1247 name += "const ";1247 // } else {
1248 }1248 // name += "const ";
1249 }1249 // }
1250 // }
1250 if (ptrObj.is_allowzero) {1251 if (ptrObj.is_allowzero) {
1251 name += "allowzero ";1252 name += "allowzero ";
1252 }1253 }
src/Autodoc.zig+27-65
...@@ -536,9 +536,9 @@ const DocData = struct {...@@ -536,9 +536,9 @@ const DocData = struct {
536 \\536 \\
537 , .{ v.is_allowzero, v.is_mutable, v.is_volatile, v.has_sentinel, v.has_align, v.has_addrspace, v.has_bit_range });537 , .{ v.is_allowzero, v.is_mutable, v.is_volatile, v.has_sentinel, v.has_align, v.has_addrspace, v.has_bit_range });
538 if (options.whitespace) |ws| try ws.outputIndent(w);538 if (options.whitespace) |ws| try ws.outputIndent(w);
539 try w.print(539 // try w.print(
540 \\"child":540 // \\"child":
541 , .{});541 // , .{});
542542
543 if (options.whitespace) |*ws| ws.indent_level += 1;543 if (options.whitespace) |*ws| ws.indent_level += 1;
544 try v.child.jsonStringify(options, w);544 try v.child.jsonStringify(options, w);
...@@ -924,8 +924,8 @@ fn walkInstruction(...@@ -924,8 +924,8 @@ fn walkInstruction(
924 },924 },
925 .ptr_type_simple => {925 .ptr_type_simple => {
926 const ptr = data[inst_index].ptr_type_simple;926 const ptr = data[inst_index].ptr_type_simple;
927 const type_slot_index = self.types.items.len;
928 const elem_type_ref = try self.walkRef(file, parent_scope, ptr.elem_type, false);927 const elem_type_ref = try self.walkRef(file, parent_scope, ptr.elem_type, false);
928 const type_slot_index = self.types.items.len;
929 try self.types.append(self.arena, .{929 try self.types.append(self.arena, .{
930 .Pointer = .{ .size = ptr.size, .child = elem_type_ref.expr, .is_mutable = ptr.is_mutable, .is_volatile = ptr.is_volatile, .is_allowzero = ptr.is_allowzero },930 .Pointer = .{ .size = ptr.size, .child = elem_type_ref.expr, .is_mutable = ptr.is_mutable, .is_volatile = ptr.is_volatile, .is_allowzero = ptr.is_allowzero },
931 });931 });
...@@ -948,7 +948,6 @@ fn walkInstruction(...@@ -948,7 +948,6 @@ fn walkInstruction(
948 );948 );
949949
950 const sentinel: ?DocData.Expr = if (ptr.flags.has_sentinel) DocData.Expr{ .int = .{ .value = 0, .negated = false } } else null;950 const sentinel: ?DocData.Expr = if (ptr.flags.has_sentinel) DocData.Expr{ .int = .{ .value = 0, .negated = false } } else null;
951
952 try self.types.append(self.arena, .{951 try self.types.append(self.arena, .{
953 .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 },952 .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 },
954 });953 });
...@@ -1021,14 +1020,11 @@ fn walkInstruction(...@@ -1021,14 +1020,11 @@ fn walkInstruction(
1021 }1020 }
10221021
1023 const type_slot_index = self.types.items.len;1022 const type_slot_index = self.types.items.len;
1024 try self.types.append(self.arena, .{1023 try self.types.append(self.arena, .{ .Pointer = .{
1025 .Array = .{ .len = .{1024 .size = .Slice,
1026 .int = .{1025 .child = array_type.?,
1027 .value = operands.len,1026 .is_mutable = true,
1028 .negated = false,1027 } });
1029 },
1030 }, .child = array_type.? },
1031 });
10321028
1033 return DocData.WalkResult{1029 return DocData.WalkResult{
1034 .typeRef = .{ .type = type_slot_index },1030 .typeRef = .{ .type = type_slot_index },
...@@ -1061,14 +1057,7 @@ fn walkInstruction(...@@ -1061,14 +1057,7 @@ fn walkInstruction(
1061 }1057 }
10621058
1063 const type_slot_index = self.types.items.len;1059 const type_slot_index = self.types.items.len;
1064 try self.types.append(self.arena, .{1060 try self.types.append(self.arena, .{ .Pointer = .{ .size = .Slice, .child = array_type.?, .is_mutable = true, .sentinel = sentinel } });
1065 .Array = .{ .len = .{
1066 .int = .{
1067 .value = operands.len - 1,
1068 .negated = false,
1069 },
1070 }, .child = array_type.?, .sentinel = sentinel },
1071 });
10721061
1073 return DocData.WalkResult{1062 return DocData.WalkResult{
1074 .typeRef = .{ .type = type_slot_index },1063 .typeRef = .{ .type = type_slot_index },
...@@ -1180,14 +1169,7 @@ fn walkInstruction(...@@ -1180,14 +1169,7 @@ fn walkInstruction(
1180 }1169 }
11811170
1182 const type_slot_index = self.types.items.len;1171 const type_slot_index = self.types.items.len;
1183 try self.types.append(self.arena, .{1172 try self.types.append(self.arena, .{ .Pointer = .{ .size = .Slice, .child = array_type.?, .is_mutable = true, .sentinel = sentinel } });
1184 .Array = .{ .len = .{
1185 .int = .{
1186 .value = operands.len - 1,
1187 .negated = false,
1188 },
1189 }, .child = array_type.?, .sentinel = sentinel },
1190 });
11911173
1192 return DocData.WalkResult{1174 return DocData.WalkResult{
1193 .typeRef = .{ .type = type_slot_index },1175 .typeRef = .{ .type = type_slot_index },
...@@ -1198,9 +1180,7 @@ fn walkInstruction(...@@ -1198,9 +1180,7 @@ fn walkInstruction(
1198 const pl_node = data[inst_index].pl_node;1180 const pl_node = data[inst_index].pl_node;
1199 const extra = file.zir.extraData(Zir.Inst.MultiOp, pl_node.payload_index);1181 const extra = file.zir.extraData(Zir.Inst.MultiOp, pl_node.payload_index);
1200 const operands = file.zir.refSlice(extra.end, extra.data.operands_len);1182 const operands = file.zir.refSlice(extra.end, extra.data.operands_len);
1201 const array_data = try self.arena.alloc(usize, operands.len - 1);1183 const array_data = try self.arena.alloc(usize, operands.len);
1202
1203 var sentinel: ?DocData.Expr = null;
12041184
1205 var array_type: ?DocData.Expr = null;1185 var array_type: ?DocData.Expr = null;
1206 for (operands) |op, idx| {1186 for (operands) |op, idx| {
...@@ -1209,22 +1189,22 @@ fn walkInstruction(...@@ -1209,22 +1189,22 @@ fn walkInstruction(
1209 array_type = wr.typeRef;1189 array_type = wr.typeRef;
1210 }1190 }
12111191
1212 if (idx == extra.data.operands_len - 1) {1192 const expr_index = self.exprs.items.len;
1213 sentinel = wr.expr;1193 try self.exprs.append(self.arena, wr.expr);
1214 const expr_index = self.exprs.items.len;1194 array_data[idx] = expr_index;
1215 try self.exprs.append(self.arena, wr.expr);
1216 array_data[idx] = expr_index;
1217 }
1218 }1195 }
12191196
1220 const type_slot_index = self.types.items.len;1197 const type_slot_index = self.types.items.len;
1221 try self.types.append(self.arena, .{1198 try self.types.append(self.arena, .{
1222 .Array = .{ .len = .{1199 .Array = .{
1223 .int = .{1200 .len = .{
1224 .value = operands.len - 1,1201 .int = .{
1225 .negated = false,1202 .value = operands.len - 1,
1203 .negated = false,
1204 },
1226 },1205 },
1227 }, .child = array_type.?, .sentinel = sentinel },1206 .child = array_type.?,
1207 },
1228 });1208 });
12291209
1230 return DocData.WalkResult{1210 return DocData.WalkResult{
...@@ -1239,20 +1219,6 @@ fn walkInstruction(...@@ -1239,20 +1219,6 @@ fn walkInstruction(
1239 .expr = .{ .float = float },1219 .expr = .{ .float = float },
1240 };1220 };
1241 },1221 },
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 },
1256 .negate => {1222 .negate => {
1257 const un_node = data[inst_index].un_node;1223 const un_node = data[inst_index].un_node;
1258 var operand: DocData.WalkResult = try self.walkRef(1224 var operand: DocData.WalkResult = try self.walkRef(
...@@ -2793,13 +2759,13 @@ fn analyzeFunction(...@@ -2793,13 +2759,13 @@ fn analyzeFunction(
2793 .func_extended => blk: {2759 .func_extended => blk: {
2794 const inst_data = data[inst_index].pl_node;2760 const inst_data = data[inst_index].pl_node;
2795 const extra = file.zir.extraData(Zir.Inst.ExtendedFunc, inst_data.payload_index);2761 const extra = file.zir.extraData(Zir.Inst.ExtendedFunc, inst_data.payload_index);
2796
2797 var cc_index: ?usize = null;2762 var cc_index: ?usize = null;
2798 if (extra.data.bits.has_cc) {2763 if (extra.data.bits.has_cc) {
2799 const cc_ref = @intToEnum(Zir.Inst.Ref, file.zir.extra[extra.end]);2764 const cc_ref = @intToEnum(Zir.Inst.Ref, file.zir.extra[extra.end]);
2800 _ = try self.walkRef(file, scope, cc_ref, false);2765 _ = try self.walkRef(file, scope, cc_ref, false);
2801 cc_index = self.types.items.len - 1;2766 cc_index = self.types.items.len - 1;
2802 }2767 }
2768
2803 break :blk .{2769 break :blk .{
2804 .Fn = .{2770 .Fn = .{
2805 .name = "todo_name func",2771 .name = "todo_name func",
...@@ -3043,25 +3009,21 @@ fn walkRef(...@@ -3043,25 +3009,21 @@ fn walkRef(
3043 // TODO: dunno what to do with those3009 // TODO: dunno what to do with those
3044 // .calling_convention_type => {3010 // .calling_convention_type => {
3045 // return DocData.WalkResult{3011 // return DocData.WalkResult{
3046 // .typeRef = .{ .type = @enumToInt(Ref.comptime_int_type) },3012 // .typeRef = .{ .type = @enumToInt(Ref.calling_convention_type) },
3047 // .expr = .{ .int = .{ .value = 1 } },3013 // .expr = .{ .int = .{ .value = 1 } },
3048 // };3014 // };
3049 // },3015 // },
3050 // .calling_convention_c => {3016 // .calling_convention_c => {
3051 // return DocData.WalkResult{3017 // return DocData.WalkResult{
3052 // .typeRef = .{ .type = @enumToInt(Ref.comptime_int_type) },3018 // .typeRef = .{ .type = @enumToInt(Ref.calling_convention_c) },
3053 // .expr = .{ .int = .{ .value = 1 } },3019 // .expr = .{ .int = .{ .value = 1 } },
3054 // };3020 // };
3055 // },3021 // },
3056 // .calling_convention_inline => {3022 // .calling_convention_inline => {
3057 // return DocData.WalkResult{3023 // return DocData.WalkResult{
3058 // .typeRef = .{ .type = @enumToInt(Ref.comptime_int_type) },3024 // .typeRef = .{ .type = @enumToInt(Ref.calling_convention_inline) },
3059 // .expr = .{ .int = .{ .value = 1 } },3025 // .expr = .{ .int = .{ .value = 1 } },
3060 // };3026 // };
3061 // // return DocData.WalkResult{ .int = .{
3062 // // .type = @enumToInt(Ref.comptime_int_type),
3063 // // .value = 1,
3064 // // } };
3065 // },3027 // },
3066 // .generic_poison => {3028 // .generic_poison => {
3067 // return DocData.WalkResult{ .int = .{3029 // return DocData.WalkResult{ .int = .{