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;
11331133 let arrayObj = /** @type {ArrayType} */ (typeObj);
11341134 let name = "[";
11351135 let lenName = exprName(arrayObj.len, opts);
1136 let sentinel = arrayObj.sentinel !== null ? ":"+arrayObj.sentinel : "";
1136 let sentinel = arrayObj.sentinel ? ":0" : "";
11371137
11381138 if (opts.wantHtml) {
11391139 name +=
11401140 '<span class="tok-number">' + lenName + sentinel + "</span>";
11411141 } else {
1142 name += lenName;
1142 name += lenName + sentinel;
11431143 }
11441144 name += "]";
11451145 name += exprName(arrayObj.child, opts);
......@@ -1150,6 +1150,7 @@ var zigAnalysis;
11501150 case typeKinds.Pointer:
11511151 {
11521152 let ptrObj = /** @type {PointerType} */(typeObj);
1153 let sentinel = ptrObj.sentinel ? ":0" : "";
11531154 let name = "";
11541155 switch (ptrObj.size) {
11551156 default:
......@@ -1158,13 +1159,19 @@ var zigAnalysis;
11581159 name += "*";
11591160 break;
11601161 case pointerSizeEnum.Many:
1161 name += "[*]";
1162 name += "[*";
1163 name += sentinel;
1164 name += "]";
11621165 break;
11631166 case pointerSizeEnum.Slice:
1164 name += "[]";
1167 name += "[";
1168 name += sentinel;
1169 name += "]";
11651170 break;
11661171 case pointerSizeEnum.C:
1167 name += "[*c]";
1172 name += "[*c";
1173 name += sentinel;
1174 name += "]";
11681175 break;
11691176 }
11701177 if (ptrObj['const']) {
src/Autodoc.zig+8-7
......@@ -383,12 +383,12 @@ const DocData = struct {
383383 Pointer: struct {
384384 size: std.builtin.TypeInfo.Pointer.Size,
385385 child: Expr,
386 sentinel: ?usize = null,
386 sentinel: bool = false,
387387 },
388388 Array: struct {
389389 len: Expr,
390390 child: Expr,
391 sentinel: ?usize = null,
391 sentinel: bool = false,
392392 },
393393 Struct: struct {
394394 name: []const u8,
......@@ -767,7 +767,7 @@ fn walkInstruction(
767767 .Pointer = .{
768768 .size = .One,
769769 .child = .{ .type = arrTypeId },
770 .sentinel = 0,
770 .sentinel = true,
771771 // TODO: add sentinel!
772772 },
773773 });
......@@ -851,7 +851,7 @@ fn walkInstruction(
851851 const ptr = data[inst_index].ptr_type;
852852 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
856856 const type_slot_index = self.types.items.len;
857857 const elem_type_ref = try self.walkRef(
......@@ -903,7 +903,7 @@ fn walkInstruction(
903903 .Array = .{
904904 .len = len.expr,
905905 .child = elem_type.expr,
906 .sentinel = 0,
906 .sentinel = true,
907907 },
908908 });
909909 return DocData.WalkResult{
......@@ -982,7 +982,7 @@ fn walkInstruction(
982982 .value = operands.len,
983983 .negated = false,
984984 },
985 }, .child = array_type.?, .sentinel = 0 },
985 }, .child = array_type.?, .sentinel = true },
986986 });
987987
988988 return DocData.WalkResult{
......@@ -1090,7 +1090,7 @@ fn walkInstruction(
10901090 .value = operands.len,
10911091 .negated = false,
10921092 },
1093 }, .child = array_type.?, .sentinel = 0 },
1093 }, .child = array_type.?, .sentinel = true },
10941094 });
10951095
10961096 return DocData.WalkResult{
......@@ -1312,6 +1312,7 @@ fn walkInstruction(
13121312 try self.types.append(self.arena, .{
13131313 .Int = .{ .name = name },
13141314 });
1315
13151316 return DocData.WalkResult{
13161317 .typeRef = .{ .type = @enumToInt(Ref.type_type) },
13171318 .expr = .{ .type = self.types.items.len - 1 },