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;...@@ -1130,17 +1130,20 @@ var zigAnalysis;
1130 default: throw "TODO";1130 default: throw "TODO";
1131 case typeKinds.Array:1131 case typeKinds.Array:
1132 {1132 {
1133 let arrayObj = /** @type {ArrayType} */(typeObj);1133 let arrayObj = /** @type {ArrayType} */ (typeObj);
1134 let name = "[";1134 let name = "[";
1135 let lenName = exprName(arrayObj.len, opts);1135 let lenName = exprName(arrayObj.len, opts);
1136 if (opts.wantHtml) {1136 let sentinel = arrayObj.sentinel !== null ? ":"+arrayObj.sentinel : "";
1137 name += '<span class="tok-number">' + lenName + '</span>';1137
1138 } else {1138 if (opts.wantHtml) {
1139 name += lenName;1139 name +=
1140 }1140 '<span class="tok-number">' + lenName + sentinel + "</span>";
1141 name += "]";1141 } else {
1142 name += exprName(arrayObj.child, opts);1142 name += lenName;
1143 return name;1143 }
1144 name += "]";
1145 name += exprName(arrayObj.child, opts);
1146 return name;
1144 }1147 }
1145 case typeKinds.Optional:1148 case typeKinds.Optional:
1146 return "?" + exprName(/**@type {OptionalType} */(typeObj).child, opts);1149 return "?" + exprName(/**@type {OptionalType} */(typeObj).child, opts);
src/Autodoc.zig+4-42
...@@ -773,6 +773,7 @@ fn walkInstruction(...@@ -773,6 +773,7 @@ fn walkInstruction(
773 });773 });
774 break :blk .{ .type = ptrTypeId };774 break :blk .{ .type = ptrTypeId };
775 };775 };
776
776 return DocData.WalkResult{777 return DocData.WalkResult{
777 .typeRef = tRef,778 .typeRef = tRef,
778 .expr = .{ .string = str },779 .expr = .{ .string = str },
...@@ -817,7 +818,6 @@ fn walkInstruction(...@@ -817,7 +818,6 @@ fn walkInstruction(
817 },818 },
818 .elem_type => {819 .elem_type => {
819 const un_node = data[inst_index].un_node;820 const un_node = data[inst_index].un_node;
820 std.debug.print("un_node: {}\n", .{un_node});
821821
822 var operand: DocData.WalkResult = try self.walkRef(822 var operand: DocData.WalkResult = try self.walkRef(
823 file,823 file,
...@@ -826,8 +826,6 @@ fn walkInstruction(...@@ -826,8 +826,6 @@ fn walkInstruction(
826 false,826 false,
827 );827 );
828828
829 std.debug.print("operand: {}\n", .{operand});
830
831 return DocData.WalkResult{829 return DocData.WalkResult{
832 .typeRef = .{ .type = operand.typeRef.?.type },830 .typeRef = .{ .type = operand.typeRef.?.type },
833 .expr = .{ .type = operand.expr.type },831 .expr = .{ .type = operand.expr.type },
...@@ -853,14 +851,8 @@ fn walkInstruction(...@@ -853,14 +851,8 @@ fn walkInstruction(
853 const ptr = data[inst_index].ptr_type;851 const ptr = data[inst_index].ptr_type;
854 const extra = file.zir.extraData(Zir.Inst.PtrType, ptr.payload_index);852 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
859 const sentinel: ?usize = if (ptr.flags.has_sentinel) 0 else null;854 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
864 const type_slot_index = self.types.items.len;856 const type_slot_index = self.types.items.len;
865 const elem_type_ref = try self.walkRef(857 const elem_type_ref = try self.walkRef(
866 file,858 file,
...@@ -875,7 +867,6 @@ fn walkInstruction(...@@ -875,7 +867,6 @@ fn walkInstruction(
875 .sentinel = sentinel,867 .sentinel = sentinel,
876 },868 },
877 });869 });
878 std.debug.print("type = {d}\n", .{type_slot_index});
879 return DocData.WalkResult{870 return DocData.WalkResult{
880 // .typeRef = .{ .type = type_slot_index },871 // .typeRef = .{ .type = type_slot_index },
881 .typeRef = .{ .type = @enumToInt(Ref.type_type) },872 .typeRef = .{ .type = @enumToInt(Ref.type_type) },
...@@ -887,11 +878,6 @@ fn walkInstruction(...@@ -887,11 +878,6 @@ fn walkInstruction(
887 const len = try self.walkRef(file, parent_scope, bin.lhs, false);878 const len = try self.walkRef(file, parent_scope, bin.lhs, false);
888 const child = try self.walkRef(file, parent_scope, bin.rhs, false);879 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
895 const type_slot_index = self.types.items.len;881 const type_slot_index = self.types.items.len;
896 try self.types.append(self.arena, .{882 try self.types.append(self.arena, .{
897 .Array = .{883 .Array = .{
...@@ -899,6 +885,7 @@ fn walkInstruction(...@@ -899,6 +885,7 @@ fn walkInstruction(
899 .child = child.expr,885 .child = child.expr,
900 },886 },
901 });887 });
888
902 return DocData.WalkResult{889 return DocData.WalkResult{
903 .typeRef = .{ .type = @enumToInt(Ref.type_type) },890 .typeRef = .{ .type = @enumToInt(Ref.type_type) },
904 .expr = .{ .type = type_slot_index },891 .expr = .{ .type = type_slot_index },
...@@ -908,7 +895,7 @@ fn walkInstruction(...@@ -908,7 +895,7 @@ fn walkInstruction(
908 const pl_node = data[inst_index].pl_node;895 const pl_node = data[inst_index].pl_node;
909 const extra = file.zir.extraData(Zir.Inst.ArrayTypeSentinel, pl_node.payload_index);896 const extra = file.zir.extraData(Zir.Inst.ArrayTypeSentinel, pl_node.payload_index);
910 const len = try self.walkRef(file, parent_scope, extra.data.len, false);897 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);
912 const elem_type = try self.walkRef(file, parent_scope, extra.data.elem_type, false);899 const elem_type = try self.walkRef(file, parent_scope, extra.data.elem_type, false);
913900
914 const type_slot_index = self.types.items.len;901 const type_slot_index = self.types.items.len;
...@@ -916,7 +903,7 @@ fn walkInstruction(...@@ -916,7 +903,7 @@ fn walkInstruction(
916 .Array = .{903 .Array = .{
917 .len = len.expr,904 .len = len.expr,
918 .child = elem_type.expr,905 .child = elem_type.expr,
919 .sentinel = sentinel.expr.int.value,906 .sentinel = 0,
920 },907 },
921 });908 });
922 return DocData.WalkResult{909 return DocData.WalkResult{
...@@ -938,7 +925,6 @@ fn walkInstruction(...@@ -938,7 +925,6 @@ fn walkInstruction(
938 // we only ask to figure out type info for the first element925 // we only ask to figure out type info for the first element
939 // as it will be used later on to find out the array type!926 // as it will be used later on to find out the array type!
940 const wr = try self.walkRef(file, parent_scope, op, idx == 0);927 const wr = try self.walkRef(file, parent_scope, op, idx == 0);
941 std.debug.print("wr: {any}\n", .{wr});
942928
943 if (idx == 0) {929 if (idx == 0) {
944 array_type = wr.typeRef;930 array_type = wr.typeRef;
...@@ -979,7 +965,6 @@ fn walkInstruction(...@@ -979,7 +965,6 @@ fn walkInstruction(
979 // we only ask to figure out type info for the first element965 // we only ask to figure out type info for the first element
980 // as it will be used later on to find out the array type!966 // as it will be used later on to find out the array type!
981 const wr = try self.walkRef(file, parent_scope, op, idx == 0);967 const wr = try self.walkRef(file, parent_scope, op, idx == 0);
982 std.debug.print("wr: {any}\n", .{wr});
983 if (idx == 0) {968 if (idx == 0) {
984 array_type = wr.typeRef;969 array_type = wr.typeRef;
985 }970 }
...@@ -990,8 +975,6 @@ fn walkInstruction(...@@ -990,8 +975,6 @@ fn walkInstruction(
990 array_data[idx] = wr.expr.as.exprArg;975 array_data[idx] = wr.expr.as.exprArg;
991 }976 }
992977
993 // std.debug.print("array: {any}\n", .{array_data});
994
995 const type_slot_index = self.types.items.len;978 const type_slot_index = self.types.items.len;
996 try self.types.append(self.arena, .{979 try self.types.append(self.arena, .{
997 .Array = .{ .len = .{980 .Array = .{ .len = .{
...@@ -1016,20 +999,15 @@ fn walkInstruction(...@@ -1016,20 +999,15 @@ fn walkInstruction(
1016 // TODO: make sure that you want the array to be fully normalized for real999 // TODO: make sure that you want the array to be fully normalized for real
1017 // then update this code to conform to your choice.1000 // 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
1022 var array_type: ?DocData.Expr = null;1002 var array_type: ?DocData.Expr = null;
1023 for (operands) |op, idx| {1003 for (operands) |op, idx| {
1024 // we only ask to figure out type info for the first element1004 // we only ask to figure out type info for the first element
1025 // as it will be used later on to find out the array type!1005 // as it will be used later on to find out the array type!
1026 const wr = try self.walkRef(file, parent_scope, op, idx == 0);1006 const wr = try self.walkRef(file, parent_scope, op, idx == 0);
1027 // std.debug.print("wr: {any}\n", .{wr});
10281007
1029 if (idx == 0) {1008 if (idx == 0) {
1030 array_type = wr.typeRef;1009 array_type = wr.typeRef;
1031 }1010 }
1032 // std.debug.print("type: {}\n", .{@intToEnum(Ref, wr.typeRef.?.type)});
10331011
1034 // create an untion to hold more than one type1012 // create an untion to hold more than one type
1035 switch (@intToEnum(Ref, wr.typeRef.?.type)) {1013 switch (@intToEnum(Ref, wr.typeRef.?.type)) {
...@@ -1044,8 +1022,6 @@ fn walkInstruction(...@@ -1044,8 +1022,6 @@ fn walkInstruction(
1044 }1022 }
1045 }1023 }
10461024
1047 // std.debug.print("array: {any}\n", .{array_data});
1048
1049 const type_slot_index = self.types.items.len;1025 const type_slot_index = self.types.items.len;
1050 try self.types.append(self.arena, .{1026 try self.types.append(self.arena, .{
1051 .Array = .{1027 .Array = .{
...@@ -1064,20 +1040,6 @@ fn walkInstruction(...@@ -1064,20 +1040,6 @@ fn walkInstruction(
1064 .expr = .{ .array = array_data },1040 .expr = .{ .array = array_data },
1065 };1041 };
1066 },1042 },
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 // },
1081 .float => {1043 .float => {
1082 const float = data[inst_index].float;1044 const float = data[inst_index].float;
1083 return DocData.WalkResult{1045 return DocData.WalkResult{