authorgravatar for vallahor91@gmail.comVallahor <vallahor91@gmail.com> 2022-05-23 14:28:49-03:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-07-19 19:10:11-07:00
log5b20b1f2a71392ccac0afd582bbcbc974846bac3
tree1667e9c0b6ef27c7b8b999b25e44c6c69538cfb2
parent646079c968dcc847806fceacefaf894f97dacfe4

add: array init refs


1 files changed, 90 insertions(+), 1 deletions(-)

src/Autodoc.zig+90-1
......@@ -843,7 +843,7 @@ fn walkInstruction(
843843 });
844844
845845 return DocData.WalkResult{
846 .typeRef = .{ .type = @enumToInt(Ref.type_type) },
846 .typeRef = .{ .type = elem_type_ref.expr.type },
847847 .expr = .{ .type = type_slot_index },
848848 };
849849 },
......@@ -1040,6 +1040,94 @@ fn walkInstruction(
10401040 .expr = .{ .array = array_data },
10411041 };
10421042 },
1043 .array_init_ref => {
1044 const pl_node = data[inst_index].pl_node;
1045 const extra = file.zir.extraData(Zir.Inst.MultiOp, pl_node.payload_index);
1046 const operands = file.zir.refSlice(extra.end, extra.data.operands_len);
1047 const array_data = try self.arena.alloc(usize, operands.len);
1048
1049 var array_type: ?DocData.Expr = null;
1050 for (operands) |op, idx| {
1051 const wr = try self.walkRef(file, parent_scope, op, idx == 0);
1052 if (idx == 0) {
1053 array_type = wr.typeRef;
1054 }
1055 array_data[idx] = wr.expr.as.exprArg;
1056 }
1057
1058 const type_slot_index = self.types.items.len;
1059 try self.types.append(self.arena, .{ .Pointer = .{
1060 .size = .One,
1061 .child = array_type.?,
1062 } });
1063
1064 return DocData.WalkResult{
1065 .typeRef = .{ .type = type_slot_index },
1066 .expr = .{ .array = array_data },
1067 };
1068 },
1069 .array_init_sent_ref => {
1070 const pl_node = data[inst_index].pl_node;
1071 const extra = file.zir.extraData(Zir.Inst.MultiOp, pl_node.payload_index);
1072 // the sentinel terminator are calculated at compile time
1073 // (extra.data.operands_len - 1) is to not account for that
1074 const operands = file.zir.refSlice(extra.end, extra.data.operands_len - 1);
1075 const array_data = try self.arena.alloc(usize, operands.len);
1076
1077 var array_type: ?DocData.Expr = null;
1078 for (operands) |op, idx| {
1079 const wr = try self.walkRef(file, parent_scope, op, idx == 0);
1080 if (idx == 0) {
1081 array_type = wr.typeRef;
1082 }
1083 array_data[idx] = wr.expr.as.exprArg;
1084 }
1085
1086 const type_slot_index = self.types.items.len;
1087 try self.types.append(self.arena, .{
1088 .Array = .{ .len = .{
1089 .int = .{
1090 .value = operands.len,
1091 .negated = false,
1092 },
1093 }, .child = array_type.?, .sentinel = 0 },
1094 });
1095
1096 return DocData.WalkResult{
1097 .typeRef = .{ .type = type_slot_index },
1098 .expr = .{ .array = array_data },
1099 };
1100 },
1101 .array_init_anon_ref => {
1102 const pl_node = data[inst_index].pl_node;
1103 const extra = file.zir.extraData(Zir.Inst.MultiOp, pl_node.payload_index);
1104 const operands = file.zir.refSlice(extra.end, extra.data.operands_len);
1105 const array_data = try self.arena.alloc(usize, operands.len);
1106
1107 var array_type: ?DocData.Expr = null;
1108 for (operands) |op, idx| {
1109 const wr = try self.walkRef(file, parent_scope, op, idx == 0);
1110 if (idx == 0) {
1111 array_type = wr.typeRef;
1112 }
1113 array_data[idx] = wr.expr.int.value;
1114 }
1115
1116 const type_slot_index = self.types.items.len;
1117 try self.types.append(self.arena, .{
1118 .Array = .{ .len = .{
1119 .int = .{
1120 .value = operands.len,
1121 .negated = false,
1122 },
1123 }, .child = array_type.? },
1124 });
1125
1126 return DocData.WalkResult{
1127 .typeRef = .{ .type = type_slot_index },
1128 .expr = .{ .array = array_data },
1129 };
1130 },
10431131 .float => {
10441132 const float = data[inst_index].float;
10451133 return DocData.WalkResult{
......@@ -1116,6 +1204,7 @@ fn walkInstruction(
11161204 extra.data.operand,
11171205 false,
11181206 );
1207
11191208 const operand_idx = self.exprs.items.len;
11201209 try self.exprs.append(self.arena, operand.expr);
11211210