authorgravatar for vallahor91@gmail.comVallahor <vallahor91@gmail.com> 2022-05-23 18:58:51-03:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-07-19 19:10:11-07:00
log019fd456175daf6111dcb6cb265dbb9dc50aebfc
tree5ab75fb2192788900129f6704a0c3e824efae3ac
parent5b20b1f2a71392ccac0afd582bbcbc974846bac3

fix: sentinel working with types and in fn decls


2 files changed, 20 insertions(+), 12 deletions(-)

lib/docs/main.js+12-5
...@@ -1133,13 +1133,13 @@ var zigAnalysis;...@@ -1133,13 +1133,13 @@ var zigAnalysis;
1133 let arrayObj = /** @type {ArrayType} */ (typeObj);1133 let arrayObj = /** @type {ArrayType} */ (typeObj);
1134 let name = "[";1134 let name = "[";
1135 let lenName = exprName(arrayObj.len, opts);1135 let lenName = exprName(arrayObj.len, opts);
1136 let sentinel = arrayObj.sentinel !== null ? ":"+arrayObj.sentinel : "";1136 let sentinel = arrayObj.sentinel ? ":0" : "";
11371137
1138 if (opts.wantHtml) {1138 if (opts.wantHtml) {
1139 name +=1139 name +=
1140 '<span class="tok-number">' + lenName + sentinel + "</span>";1140 '<span class="tok-number">' + lenName + sentinel + "</span>";
1141 } else {1141 } else {
1142 name += lenName;1142 name += lenName + sentinel;
1143 }1143 }
1144 name += "]";1144 name += "]";
1145 name += exprName(arrayObj.child, opts);1145 name += exprName(arrayObj.child, opts);
...@@ -1150,6 +1150,7 @@ var zigAnalysis;...@@ -1150,6 +1150,7 @@ var zigAnalysis;
1150 case typeKinds.Pointer:1150 case typeKinds.Pointer:
1151 {1151 {
1152 let ptrObj = /** @type {PointerType} */(typeObj);1152 let ptrObj = /** @type {PointerType} */(typeObj);
1153 let sentinel = ptrObj.sentinel ? ":0" : "";
1153 let name = "";1154 let name = "";
1154 switch (ptrObj.size) {1155 switch (ptrObj.size) {
1155 default:1156 default:
...@@ -1158,13 +1159,19 @@ var zigAnalysis;...@@ -1158,13 +1159,19 @@ var zigAnalysis;
1158 name += "*";1159 name += "*";
1159 break;1160 break;
1160 case pointerSizeEnum.Many:1161 case pointerSizeEnum.Many:
1161 name += "[*]";1162 name += "[*";
1163 name += sentinel;
1164 name += "]";
1162 break;1165 break;
1163 case pointerSizeEnum.Slice:1166 case pointerSizeEnum.Slice:
1164 name += "[]";1167 name += "[";
1168 name += sentinel;
1169 name += "]";
1165 break;1170 break;
1166 case pointerSizeEnum.C:1171 case pointerSizeEnum.C:
1167 name += "[*c]";1172 name += "[*c";
1173 name += sentinel;
1174 name += "]";
1168 break;1175 break;
1169 }1176 }
1170 if (ptrObj['const']) {1177 if (ptrObj['const']) {
src/Autodoc.zig+8-7
...@@ -383,12 +383,12 @@ const DocData = struct {...@@ -383,12 +383,12 @@ const DocData = struct {
383 Pointer: struct {383 Pointer: struct {
384 size: std.builtin.TypeInfo.Pointer.Size,384 size: std.builtin.TypeInfo.Pointer.Size,
385 child: Expr,385 child: Expr,
386 sentinel: ?usize = null,386 sentinel: bool = false,
387 },387 },
388 Array: struct {388 Array: struct {
389 len: Expr,389 len: Expr,
390 child: Expr,390 child: Expr,
391 sentinel: ?usize = null,391 sentinel: bool = false,
392 },392 },
393 Struct: struct {393 Struct: struct {
394 name: []const u8,394 name: []const u8,
...@@ -767,7 +767,7 @@ fn walkInstruction(...@@ -767,7 +767,7 @@ fn walkInstruction(
767 .Pointer = .{767 .Pointer = .{
768 .size = .One,768 .size = .One,
769 .child = .{ .type = arrTypeId },769 .child = .{ .type = arrTypeId },
770 .sentinel = 0,770 .sentinel = true,
771 // TODO: add sentinel!771 // TODO: add sentinel!
772 },772 },
773 });773 });
...@@ -851,7 +851,7 @@ fn walkInstruction(...@@ -851,7 +851,7 @@ fn walkInstruction(
851 const ptr = data[inst_index].ptr_type;851 const ptr = data[inst_index].ptr_type;
852 const extra = file.zir.extraData(Zir.Inst.PtrType, ptr.payload_index);852 const extra = file.zir.extraData(Zir.Inst.PtrType, ptr.payload_index);
853853
854 const sentinel: ?usize = if (ptr.flags.has_sentinel) 0 else null;854 const sentinel: bool = if (ptr.flags.has_sentinel) true else false;
855855
856 const type_slot_index = self.types.items.len;856 const type_slot_index = self.types.items.len;
857 const elem_type_ref = try self.walkRef(857 const elem_type_ref = try self.walkRef(
...@@ -903,7 +903,7 @@ fn walkInstruction(...@@ -903,7 +903,7 @@ fn walkInstruction(
903 .Array = .{903 .Array = .{
904 .len = len.expr,904 .len = len.expr,
905 .child = elem_type.expr,905 .child = elem_type.expr,
906 .sentinel = 0,906 .sentinel = true,
907 },907 },
908 });908 });
909 return DocData.WalkResult{909 return DocData.WalkResult{
...@@ -982,7 +982,7 @@ fn walkInstruction(...@@ -982,7 +982,7 @@ fn walkInstruction(
982 .value = operands.len,982 .value = operands.len,
983 .negated = false,983 .negated = false,
984 },984 },
985 }, .child = array_type.?, .sentinel = 0 },985 }, .child = array_type.?, .sentinel = true },
986 });986 });
987987
988 return DocData.WalkResult{988 return DocData.WalkResult{
...@@ -1090,7 +1090,7 @@ fn walkInstruction(...@@ -1090,7 +1090,7 @@ fn walkInstruction(
1090 .value = operands.len,1090 .value = operands.len,
1091 .negated = false,1091 .negated = false,
1092 },1092 },
1093 }, .child = array_type.?, .sentinel = 0 },1093 }, .child = array_type.?, .sentinel = true },
1094 });1094 });
10951095
1096 return DocData.WalkResult{1096 return DocData.WalkResult{
...@@ -1312,6 +1312,7 @@ fn walkInstruction(...@@ -1312,6 +1312,7 @@ fn walkInstruction(
1312 try self.types.append(self.arena, .{1312 try self.types.append(self.arena, .{
1313 .Int = .{ .name = name },1313 .Int = .{ .name = name },
1314 });1314 });
1315
1315 return DocData.WalkResult{1316 return DocData.WalkResult{
1316 .typeRef = .{ .type = @enumToInt(Ref.type_type) },1317 .typeRef = .{ .type = @enumToInt(Ref.type_type) },
1317 .expr = .{ .type = self.types.items.len - 1 },1318 .expr = .{ .type = self.types.items.len - 1 },