mirror of
https://github.com/ziglang/zig.git
synced 2026-02-12 12:27:41 +00:00
add: rendering sentinel in js and some fixes in autodoc
This commit is contained in:
parent
5a4005323f
commit
646079c968
@ -1130,17 +1130,20 @@ var zigAnalysis;
|
||||
default: throw "TODO";
|
||||
case typeKinds.Array:
|
||||
{
|
||||
let arrayObj = /** @type {ArrayType} */(typeObj);
|
||||
let name = "[";
|
||||
let lenName = exprName(arrayObj.len, opts);
|
||||
if (opts.wantHtml) {
|
||||
name += '<span class="tok-number">' + lenName + '</span>';
|
||||
} else {
|
||||
name += lenName;
|
||||
}
|
||||
name += "]";
|
||||
name += exprName(arrayObj.child, opts);
|
||||
return name;
|
||||
let arrayObj = /** @type {ArrayType} */ (typeObj);
|
||||
let name = "[";
|
||||
let lenName = exprName(arrayObj.len, opts);
|
||||
let sentinel = arrayObj.sentinel !== null ? ":"+arrayObj.sentinel : "";
|
||||
|
||||
if (opts.wantHtml) {
|
||||
name +=
|
||||
'<span class="tok-number">' + lenName + sentinel + "</span>";
|
||||
} else {
|
||||
name += lenName;
|
||||
}
|
||||
name += "]";
|
||||
name += exprName(arrayObj.child, opts);
|
||||
return name;
|
||||
}
|
||||
case typeKinds.Optional:
|
||||
return "?" + exprName(/**@type {OptionalType} */(typeObj).child, opts);
|
||||
|
||||
@ -773,6 +773,7 @@ fn walkInstruction(
|
||||
});
|
||||
break :blk .{ .type = ptrTypeId };
|
||||
};
|
||||
|
||||
return DocData.WalkResult{
|
||||
.typeRef = tRef,
|
||||
.expr = .{ .string = str },
|
||||
@ -817,7 +818,6 @@ fn walkInstruction(
|
||||
},
|
||||
.elem_type => {
|
||||
const un_node = data[inst_index].un_node;
|
||||
std.debug.print("un_node: {}\n", .{un_node});
|
||||
|
||||
var operand: DocData.WalkResult = try self.walkRef(
|
||||
file,
|
||||
@ -826,8 +826,6 @@ fn walkInstruction(
|
||||
false,
|
||||
);
|
||||
|
||||
std.debug.print("operand: {}\n", .{operand});
|
||||
|
||||
return DocData.WalkResult{
|
||||
.typeRef = .{ .type = operand.typeRef.?.type },
|
||||
.expr = .{ .type = operand.expr.type },
|
||||
@ -853,14 +851,8 @@ fn walkInstruction(
|
||||
const ptr = data[inst_index].ptr_type;
|
||||
const extra = file.zir.extraData(Zir.Inst.PtrType, ptr.payload_index);
|
||||
|
||||
std.debug.print("ptr = {}\n", .{ptr});
|
||||
std.debug.print("extra = {any}\n", .{extra});
|
||||
|
||||
const sentinel: ?usize = if (ptr.flags.has_sentinel) 0 else null;
|
||||
|
||||
std.debug.print("sentinel = {} {d}\n", .{ ptr.flags.has_sentinel, sentinel });
|
||||
std.debug.print("type = {d}\n", .{@enumToInt(Ref.type_type)});
|
||||
|
||||
const type_slot_index = self.types.items.len;
|
||||
const elem_type_ref = try self.walkRef(
|
||||
file,
|
||||
@ -875,7 +867,6 @@ fn walkInstruction(
|
||||
.sentinel = sentinel,
|
||||
},
|
||||
});
|
||||
std.debug.print("type = {d}\n", .{type_slot_index});
|
||||
return DocData.WalkResult{
|
||||
// .typeRef = .{ .type = type_slot_index },
|
||||
.typeRef = .{ .type = @enumToInt(Ref.type_type) },
|
||||
@ -887,11 +878,6 @@ fn walkInstruction(
|
||||
const len = try self.walkRef(file, parent_scope, bin.lhs, false);
|
||||
const child = try self.walkRef(file, parent_scope, bin.rhs, false);
|
||||
|
||||
std.debug.print("AEHO\n", .{});
|
||||
// std.debug.print("bin = {}\n", .{bin});
|
||||
// std.debug.print("len = {}\n", .{len});
|
||||
// std.debug.print("child = {}\n", .{child});
|
||||
|
||||
const type_slot_index = self.types.items.len;
|
||||
try self.types.append(self.arena, .{
|
||||
.Array = .{
|
||||
@ -899,6 +885,7 @@ fn walkInstruction(
|
||||
.child = child.expr,
|
||||
},
|
||||
});
|
||||
|
||||
return DocData.WalkResult{
|
||||
.typeRef = .{ .type = @enumToInt(Ref.type_type) },
|
||||
.expr = .{ .type = type_slot_index },
|
||||
@ -908,7 +895,7 @@ fn walkInstruction(
|
||||
const pl_node = data[inst_index].pl_node;
|
||||
const extra = file.zir.extraData(Zir.Inst.ArrayTypeSentinel, pl_node.payload_index);
|
||||
const len = try self.walkRef(file, parent_scope, extra.data.len, false);
|
||||
const sentinel = try self.walkRef(file, parent_scope, extra.data.sentinel, false);
|
||||
// const sentinel = try self.walkRef(file, parent_scope, extra.data.sentinel, false);
|
||||
const elem_type = try self.walkRef(file, parent_scope, extra.data.elem_type, false);
|
||||
|
||||
const type_slot_index = self.types.items.len;
|
||||
@ -916,7 +903,7 @@ fn walkInstruction(
|
||||
.Array = .{
|
||||
.len = len.expr,
|
||||
.child = elem_type.expr,
|
||||
.sentinel = sentinel.expr.int.value,
|
||||
.sentinel = 0,
|
||||
},
|
||||
});
|
||||
return DocData.WalkResult{
|
||||
@ -938,7 +925,6 @@ fn walkInstruction(
|
||||
// we only ask to figure out type info for the first element
|
||||
// as it will be used later on to find out the array type!
|
||||
const wr = try self.walkRef(file, parent_scope, op, idx == 0);
|
||||
std.debug.print("wr: {any}\n", .{wr});
|
||||
|
||||
if (idx == 0) {
|
||||
array_type = wr.typeRef;
|
||||
@ -979,7 +965,6 @@ fn walkInstruction(
|
||||
// we only ask to figure out type info for the first element
|
||||
// as it will be used later on to find out the array type!
|
||||
const wr = try self.walkRef(file, parent_scope, op, idx == 0);
|
||||
std.debug.print("wr: {any}\n", .{wr});
|
||||
if (idx == 0) {
|
||||
array_type = wr.typeRef;
|
||||
}
|
||||
@ -990,8 +975,6 @@ fn walkInstruction(
|
||||
array_data[idx] = wr.expr.as.exprArg;
|
||||
}
|
||||
|
||||
// std.debug.print("array: {any}\n", .{array_data});
|
||||
|
||||
const type_slot_index = self.types.items.len;
|
||||
try self.types.append(self.arena, .{
|
||||
.Array = .{ .len = .{
|
||||
@ -1016,20 +999,15 @@ fn walkInstruction(
|
||||
// TODO: make sure that you want the array to be fully normalized for real
|
||||
// then update this code to conform to your choice.
|
||||
|
||||
// std.debug.print("extra: {}\n", .{extra});
|
||||
// std.debug.print("operands: {any}\n", .{operands});
|
||||
|
||||
var array_type: ?DocData.Expr = null;
|
||||
for (operands) |op, idx| {
|
||||
// we only ask to figure out type info for the first element
|
||||
// as it will be used later on to find out the array type!
|
||||
const wr = try self.walkRef(file, parent_scope, op, idx == 0);
|
||||
// std.debug.print("wr: {any}\n", .{wr});
|
||||
|
||||
if (idx == 0) {
|
||||
array_type = wr.typeRef;
|
||||
}
|
||||
// std.debug.print("type: {}\n", .{@intToEnum(Ref, wr.typeRef.?.type)});
|
||||
|
||||
// create an untion to hold more than one type
|
||||
switch (@intToEnum(Ref, wr.typeRef.?.type)) {
|
||||
@ -1044,8 +1022,6 @@ fn walkInstruction(
|
||||
}
|
||||
}
|
||||
|
||||
// std.debug.print("array: {any}\n", .{array_data});
|
||||
|
||||
const type_slot_index = self.types.items.len;
|
||||
try self.types.append(self.arena, .{
|
||||
.Array = .{
|
||||
@ -1064,20 +1040,6 @@ fn walkInstruction(
|
||||
.expr = .{ .array = array_data },
|
||||
};
|
||||
},
|
||||
// .validate_array_init_ty => {
|
||||
// const un_node = data[inst_index].un_node;
|
||||
// var operand: DocData.WalkResult = try self.walkRef(
|
||||
// file,
|
||||
// parent_scope,
|
||||
// un_node.operand,
|
||||
// need_type,
|
||||
// );
|
||||
//
|
||||
// std.debug.print("validate _ array => {}\n", .{un_node});
|
||||
// std.debug.print("operand = {}\n", .{operand});
|
||||
//
|
||||
// return operand;
|
||||
// },
|
||||
.float => {
|
||||
const float = data[inst_index].float;
|
||||
return DocData.WalkResult{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user