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 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']) {

View File

@ -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 },