fix: sentinel working with types and in fn decls

This commit is contained in:
Vallahor 2022-05-23 18:58:51 -03:00 committed by Andrew Kelley
parent 5b20b1f2a7
commit 019fd45617
2 changed files with 20 additions and 12 deletions

View File

@ -1133,13 +1133,13 @@ var zigAnalysis;
let arrayObj = /** @type {ArrayType} */ (typeObj); let arrayObj = /** @type {ArrayType} */ (typeObj);
let name = "["; let name = "[";
let lenName = exprName(arrayObj.len, opts); let lenName = exprName(arrayObj.len, opts);
let sentinel = arrayObj.sentinel !== null ? ":"+arrayObj.sentinel : ""; let sentinel = arrayObj.sentinel ? ":0" : "";
if (opts.wantHtml) { if (opts.wantHtml) {
name += name +=
'<span class="tok-number">' + lenName + sentinel + "</span>"; '<span class="tok-number">' + lenName + sentinel + "</span>";
} else { } else {
name += lenName; name += lenName + sentinel;
} }
name += "]"; name += "]";
name += exprName(arrayObj.child, opts); name += exprName(arrayObj.child, opts);
@ -1150,6 +1150,7 @@ var zigAnalysis;
case typeKinds.Pointer: case typeKinds.Pointer:
{ {
let ptrObj = /** @type {PointerType} */(typeObj); let ptrObj = /** @type {PointerType} */(typeObj);
let sentinel = ptrObj.sentinel ? ":0" : "";
let name = ""; let name = "";
switch (ptrObj.size) { switch (ptrObj.size) {
default: default:
@ -1158,13 +1159,19 @@ var zigAnalysis;
name += "*"; name += "*";
break; break;
case pointerSizeEnum.Many: case pointerSizeEnum.Many:
name += "[*]"; name += "[*";
name += sentinel;
name += "]";
break; break;
case pointerSizeEnum.Slice: case pointerSizeEnum.Slice:
name += "[]"; name += "[";
name += sentinel;
name += "]";
break; break;
case pointerSizeEnum.C: case pointerSizeEnum.C:
name += "[*c]"; name += "[*c";
name += sentinel;
name += "]";
break; break;
} }
if (ptrObj['const']) { if (ptrObj['const']) {

View File

@ -383,12 +383,12 @@ const DocData = struct {
Pointer: struct { Pointer: struct {
size: std.builtin.TypeInfo.Pointer.Size, size: std.builtin.TypeInfo.Pointer.Size,
child: Expr, child: Expr,
sentinel: ?usize = null, sentinel: bool = false,
}, },
Array: struct { Array: struct {
len: Expr, len: Expr,
child: Expr, child: Expr,
sentinel: ?usize = null, sentinel: bool = false,
}, },
Struct: struct { Struct: struct {
name: []const u8, name: []const u8,
@ -767,7 +767,7 @@ fn walkInstruction(
.Pointer = .{ .Pointer = .{
.size = .One, .size = .One,
.child = .{ .type = arrTypeId }, .child = .{ .type = arrTypeId },
.sentinel = 0, .sentinel = true,
// TODO: add sentinel! // TODO: add sentinel!
}, },
}); });
@ -851,7 +851,7 @@ fn walkInstruction(
const ptr = data[inst_index].ptr_type; const ptr = data[inst_index].ptr_type;
const extra = file.zir.extraData(Zir.Inst.PtrType, ptr.payload_index); 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 type_slot_index = self.types.items.len;
const elem_type_ref = try self.walkRef( const elem_type_ref = try self.walkRef(
@ -903,7 +903,7 @@ fn walkInstruction(
.Array = .{ .Array = .{
.len = len.expr, .len = len.expr,
.child = elem_type.expr, .child = elem_type.expr,
.sentinel = 0, .sentinel = true,
}, },
}); });
return DocData.WalkResult{ return DocData.WalkResult{
@ -982,7 +982,7 @@ fn walkInstruction(
.value = operands.len, .value = operands.len,
.negated = false, .negated = false,
}, },
}, .child = array_type.?, .sentinel = 0 }, }, .child = array_type.?, .sentinel = true },
}); });
return DocData.WalkResult{ return DocData.WalkResult{
@ -1090,7 +1090,7 @@ fn walkInstruction(
.value = operands.len, .value = operands.len,
.negated = false, .negated = false,
}, },
}, .child = array_type.?, .sentinel = 0 }, }, .child = array_type.?, .sentinel = true },
}); });
return DocData.WalkResult{ return DocData.WalkResult{
@ -1312,6 +1312,7 @@ fn walkInstruction(
try self.types.append(self.arena, .{ try self.types.append(self.arena, .{
.Int = .{ .name = name }, .Int = .{ .name = name },
}); });
return DocData.WalkResult{ return DocData.WalkResult{
.typeRef = .{ .type = @enumToInt(Ref.type_type) }, .typeRef = .{ .type = @enumToInt(Ref.type_type) },
.expr = .{ .type = self.types.items.len - 1 }, .expr = .{ .type = self.types.items.len - 1 },