authorgravatar for vallahor91@gmail.comVallahor <vallahor91@gmail.com> 2022-05-23 00:13:32-03:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-07-19 19:10:11-07:00
log646079c968dcc847806fceacefaf894f97dacfe4
treeb824ef9883937b419d44c88ffde2ad2af63ec47b
parent5a4005323f0e234532fc81ca7f1e917754e02f11

add: rendering sentinel in js and some fixes in autodoc


2 files changed, 18 insertions(+), 53 deletions(-)

lib/docs/main.js+14-11
......@@ -1130,17 +1130,20 @@ var zigAnalysis;
11301130 default: throw "TODO";
11311131 case typeKinds.Array:
11321132 {
1133 let arrayObj = /** @type {ArrayType} */(typeObj);
1134 let name = "[";
1135 let lenName = exprName(arrayObj.len, opts);
1136 if (opts.wantHtml) {
1137 name += '<span class="tok-number">' + lenName + '</span>';
1138 } else {
1139 name += lenName;
1140 }
1141 name += "]";
1142 name += exprName(arrayObj.child, opts);
1143 return name;
1133 let arrayObj = /** @type {ArrayType} */ (typeObj);
1134 let name = "[";
1135 let lenName = exprName(arrayObj.len, opts);
1136 let sentinel = arrayObj.sentinel !== null ? ":"+arrayObj.sentinel : "";
1137
1138 if (opts.wantHtml) {
1139 name +=
1140 '<span class="tok-number">' + lenName + sentinel + "</span>";
1141 } else {
1142 name += lenName;
1143 }
1144 name += "]";
1145 name += exprName(arrayObj.child, opts);
1146 return name;
11441147 }
11451148 case typeKinds.Optional:
11461149 return "?" + exprName(/**@type {OptionalType} */(typeObj).child, opts);
src/Autodoc.zig+4-42
......@@ -773,6 +773,7 @@ fn walkInstruction(
773773 });
774774 break :blk .{ .type = ptrTypeId };
775775 };
776
776777 return DocData.WalkResult{
777778 .typeRef = tRef,
778779 .expr = .{ .string = str },
......@@ -817,7 +818,6 @@ fn walkInstruction(
817818 },
818819 .elem_type => {
819820 const un_node = data[inst_index].un_node;
820 std.debug.print("un_node: {}\n", .{un_node});
821821
822822 var operand: DocData.WalkResult = try self.walkRef(
823823 file,
......@@ -826,8 +826,6 @@ fn walkInstruction(
826826 false,
827827 );
828828
829 std.debug.print("operand: {}\n", .{operand});
830
831829 return DocData.WalkResult{
832830 .typeRef = .{ .type = operand.typeRef.?.type },
833831 .expr = .{ .type = operand.expr.type },
......@@ -853,14 +851,8 @@ fn walkInstruction(
853851 const ptr = data[inst_index].ptr_type;
854852 const extra = file.zir.extraData(Zir.Inst.PtrType, ptr.payload_index);
855853
856 std.debug.print("ptr = {}\n", .{ptr});
857 std.debug.print("extra = {any}\n", .{extra});
858
859854 const sentinel: ?usize = if (ptr.flags.has_sentinel) 0 else null;
860855
861 std.debug.print("sentinel = {} {d}\n", .{ ptr.flags.has_sentinel, sentinel });
862 std.debug.print("type = {d}\n", .{@enumToInt(Ref.type_type)});
863
864856 const type_slot_index = self.types.items.len;
865857 const elem_type_ref = try self.walkRef(
866858 file,
......@@ -875,7 +867,6 @@ fn walkInstruction(
875867 .sentinel = sentinel,
876868 },
877869 });
878 std.debug.print("type = {d}\n", .{type_slot_index});
879870 return DocData.WalkResult{
880871 // .typeRef = .{ .type = type_slot_index },
881872 .typeRef = .{ .type = @enumToInt(Ref.type_type) },
......@@ -887,11 +878,6 @@ fn walkInstruction(
887878 const len = try self.walkRef(file, parent_scope, bin.lhs, false);
888879 const child = try self.walkRef(file, parent_scope, bin.rhs, false);
889880
890 std.debug.print("AEHO\n", .{});
891 // std.debug.print("bin = {}\n", .{bin});
892 // std.debug.print("len = {}\n", .{len});
893 // std.debug.print("child = {}\n", .{child});
894
895881 const type_slot_index = self.types.items.len;
896882 try self.types.append(self.arena, .{
897883 .Array = .{
......@@ -899,6 +885,7 @@ fn walkInstruction(
899885 .child = child.expr,
900886 },
901887 });
888
902889 return DocData.WalkResult{
903890 .typeRef = .{ .type = @enumToInt(Ref.type_type) },
904891 .expr = .{ .type = type_slot_index },
......@@ -908,7 +895,7 @@ fn walkInstruction(
908895 const pl_node = data[inst_index].pl_node;
909896 const extra = file.zir.extraData(Zir.Inst.ArrayTypeSentinel, pl_node.payload_index);
910897 const len = try self.walkRef(file, parent_scope, extra.data.len, false);
911 const sentinel = try self.walkRef(file, parent_scope, extra.data.sentinel, false);
898 // const sentinel = try self.walkRef(file, parent_scope, extra.data.sentinel, false);
912899 const elem_type = try self.walkRef(file, parent_scope, extra.data.elem_type, false);
913900
914901 const type_slot_index = self.types.items.len;
......@@ -916,7 +903,7 @@ fn walkInstruction(
916903 .Array = .{
917904 .len = len.expr,
918905 .child = elem_type.expr,
919 .sentinel = sentinel.expr.int.value,
906 .sentinel = 0,
920907 },
921908 });
922909 return DocData.WalkResult{
......@@ -938,7 +925,6 @@ fn walkInstruction(
938925 // we only ask to figure out type info for the first element
939926 // as it will be used later on to find out the array type!
940927 const wr = try self.walkRef(file, parent_scope, op, idx == 0);
941 std.debug.print("wr: {any}\n", .{wr});
942928
943929 if (idx == 0) {
944930 array_type = wr.typeRef;
......@@ -979,7 +965,6 @@ fn walkInstruction(
979965 // we only ask to figure out type info for the first element
980966 // as it will be used later on to find out the array type!
981967 const wr = try self.walkRef(file, parent_scope, op, idx == 0);
982 std.debug.print("wr: {any}\n", .{wr});
983968 if (idx == 0) {
984969 array_type = wr.typeRef;
985970 }
......@@ -990,8 +975,6 @@ fn walkInstruction(
990975 array_data[idx] = wr.expr.as.exprArg;
991976 }
992977
993 // std.debug.print("array: {any}\n", .{array_data});
994
995978 const type_slot_index = self.types.items.len;
996979 try self.types.append(self.arena, .{
997980 .Array = .{ .len = .{
......@@ -1016,20 +999,15 @@ fn walkInstruction(
1016999 // TODO: make sure that you want the array to be fully normalized for real
10171000 // then update this code to conform to your choice.
10181001
1019 // std.debug.print("extra: {}\n", .{extra});
1020 // std.debug.print("operands: {any}\n", .{operands});
1021
10221002 var array_type: ?DocData.Expr = null;
10231003 for (operands) |op, idx| {
10241004 // we only ask to figure out type info for the first element
10251005 // as it will be used later on to find out the array type!
10261006 const wr = try self.walkRef(file, parent_scope, op, idx == 0);
1027 // std.debug.print("wr: {any}\n", .{wr});
10281007
10291008 if (idx == 0) {
10301009 array_type = wr.typeRef;
10311010 }
1032 // std.debug.print("type: {}\n", .{@intToEnum(Ref, wr.typeRef.?.type)});
10331011
10341012 // create an untion to hold more than one type
10351013 switch (@intToEnum(Ref, wr.typeRef.?.type)) {
......@@ -1044,8 +1022,6 @@ fn walkInstruction(
10441022 }
10451023 }
10461024
1047 // std.debug.print("array: {any}\n", .{array_data});
1048
10491025 const type_slot_index = self.types.items.len;
10501026 try self.types.append(self.arena, .{
10511027 .Array = .{
......@@ -1064,20 +1040,6 @@ fn walkInstruction(
10641040 .expr = .{ .array = array_data },
10651041 };
10661042 },
1067 // .validate_array_init_ty => {
1068 // const un_node = data[inst_index].un_node;
1069 // var operand: DocData.WalkResult = try self.walkRef(
1070 // file,
1071 // parent_scope,
1072 // un_node.operand,
1073 // need_type,
1074 // );
1075 //
1076 // std.debug.print("validate _ array => {}\n", .{un_node});
1077 // std.debug.print("operand = {}\n", .{operand});
1078 //
1079 // return operand;
1080 // },
10811043 .float => {
10821044 const float = data[inst_index].float;
10831045 return DocData.WalkResult{