zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 019fd456175daf6111dcb6cb265dbb9dc50aebfc (tree)
parent 5b20b1f2a71392ccac0afd582bbcbc974846bac3
Author: Vallahor <vallahor91@gmail.com>
Date:   Mon, 23 May 2022 18:58:51 -0300

fix: sentinel working with types and in fn decls

Diffstat:
Mlib/docs/main.js | 17++++++++++++-----
Msrc/Autodoc.zig | 15++++++++-------
2 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/lib/docs/main.js b/lib/docs/main.js @@ -1133,13 +1133,13 @@ var zigAnalysis; let arrayObj = /** @type {ArrayType} */ (typeObj); let name = "["; let lenName = exprName(arrayObj.len, opts); - let sentinel = arrayObj.sentinel !== null ? ":"+arrayObj.sentinel : ""; + let sentinel = arrayObj.sentinel ? ":0" : ""; if (opts.wantHtml) { name += '<span class="tok-number">' + lenName + sentinel + "</span>"; } else { - name += lenName; + name += lenName + sentinel; } name += "]"; name += exprName(arrayObj.child, opts); @@ -1150,6 +1150,7 @@ var zigAnalysis; case typeKinds.Pointer: { let ptrObj = /** @type {PointerType} */(typeObj); + let sentinel = ptrObj.sentinel ? ":0" : ""; let name = ""; switch (ptrObj.size) { default: @@ -1158,13 +1159,19 @@ var zigAnalysis; name += "*"; break; case pointerSizeEnum.Many: - name += "[*]"; + name += "[*"; + name += sentinel; + name += "]"; break; case pointerSizeEnum.Slice: - name += "[]"; + name += "["; + name += sentinel; + name += "]"; break; case pointerSizeEnum.C: - name += "[*c]"; + name += "[*c"; + name += sentinel; + name += "]"; break; } if (ptrObj['const']) { diff --git a/src/Autodoc.zig b/src/Autodoc.zig @@ -383,12 +383,12 @@ const DocData = struct { Pointer: struct { size: std.builtin.TypeInfo.Pointer.Size, child: Expr, - sentinel: ?usize = null, + sentinel: bool = false, }, Array: struct { len: Expr, child: Expr, - sentinel: ?usize = null, + sentinel: bool = false, }, Struct: struct { name: []const u8, @@ -767,7 +767,7 @@ fn walkInstruction( .Pointer = .{ .size = .One, .child = .{ .type = arrTypeId }, - .sentinel = 0, + .sentinel = true, // TODO: add sentinel! }, }); @@ -851,7 +851,7 @@ fn walkInstruction( const ptr = data[inst_index].ptr_type; const extra = file.zir.extraData(Zir.Inst.PtrType, ptr.payload_index); - const sentinel: ?usize = if (ptr.flags.has_sentinel) 0 else null; + const sentinel: bool = if (ptr.flags.has_sentinel) true else false; const type_slot_index = self.types.items.len; const elem_type_ref = try self.walkRef( @@ -903,7 +903,7 @@ fn walkInstruction( .Array = .{ .len = len.expr, .child = elem_type.expr, - .sentinel = 0, + .sentinel = true, }, }); return DocData.WalkResult{ @@ -982,7 +982,7 @@ fn walkInstruction( .value = operands.len, .negated = false, }, - }, .child = array_type.?, .sentinel = 0 }, + }, .child = array_type.?, .sentinel = true }, }); return DocData.WalkResult{ @@ -1090,7 +1090,7 @@ fn walkInstruction( .value = operands.len, .negated = false, }, - }, .child = array_type.?, .sentinel = 0 }, + }, .child = array_type.?, .sentinel = true }, }); return DocData.WalkResult{ @@ -1312,6 +1312,7 @@ fn walkInstruction( try self.types.append(self.arena, .{ .Int = .{ .name = name }, }); + return DocData.WalkResult{ .typeRef = .{ .type = @enumToInt(Ref.type_type) }, .expr = .{ .type = self.types.items.len - 1 },