authorgravatar for der.teufel.mail@gmail.comKrzysztof Wolicki <der.teufel.mail@gmail.com> 2023-06-27 19:40:08+00:00
committergravatar for kappaloris@gmail.comLoris Cro <kappaloris@gmail.com> 2023-06-28 19:03:24+02:00
log2984a758046a307c0dae7f8f664b7e34828ea59f
treed4bfb2704837664e585bb9d48cef26a7c1f7c6b3
parent4dacaa1e129a3991cd805f5a602bcc329e5794d2

autodoc: Try to handle all InternPool.Index types good enough


1 files changed, 97 insertions(+), 18 deletions(-)

src/Autodoc.zig+97-18
......@@ -121,21 +121,6 @@ pub fn generateZirData(self: *Autodoc) !void {
121121 try self.types.append(
122122 self.arena,
123123 switch (ip_index) {
124 else => blk: {
125 // TODO: map the remaining refs to a correct type
126 // instead of just assinging "array" to them.
127 break :blk .{
128 .Array = .{
129 .len = .{
130 .int = .{
131 .value = 1,
132 .negated = false,
133 },
134 },
135 .child = .{ .type = 0 },
136 },
137 };
138 },
139124 .u0_type,
140125 .i0_type,
141126 .u1_type,
......@@ -153,6 +138,7 @@ pub fn generateZirData(self: *Autodoc) !void {
153138 .i128_type,
154139 .usize_type,
155140 .isize_type,
141 .c_char_type,
156142 .c_short_type,
157143 .c_ushort_type,
158144 .c_int_type,
......@@ -183,10 +169,10 @@ pub fn generateZirData(self: *Autodoc) !void {
183169 .anyopaque_type => .{
184170 .ComptimeExpr = .{ .name = try tmpbuf.toOwnedSlice() },
185171 },
172
186173 .bool_type => .{
187174 .Bool = .{ .name = try tmpbuf.toOwnedSlice() },
188175 },
189
190176 .noreturn_type => .{
191177 .NoReturn = .{ .name = try tmpbuf.toOwnedSlice() },
192178 },
......@@ -203,10 +189,103 @@ pub fn generateZirData(self: *Autodoc) !void {
203189 .ErrorSet = .{ .name = try tmpbuf.toOwnedSlice() },
204190 },
205191 // should be an Enum but if we don't analyze std we don't get the ast node
206 // since it's std.builtin.CallingConvention
207 .calling_convention_type => .{
192 // since it's defined in std.builtin
193 .calling_convention_type,
194 .atomic_order_type,
195 .atomic_rmw_op_type,
196 .address_space_type,
197 .float_mode_type,
198 .reduce_op_type,
199 .call_modifier_type,
200 .prefetch_options_type,
201 .export_options_type,
202 .extern_options_type,
203 => .{
204 .Type = .{ .name = try tmpbuf.toOwnedSlice() },
205 },
206 .manyptr_u8_type => .{
207 .Pointer = .{
208 .size = .Many,
209 .child = .{ .type = @intFromEnum(InternPool.Index.u8_type) },
210 .is_mutable = true,
211 },
212 },
213 .manyptr_const_u8_type => .{
214 .Pointer = .{
215 .size = .Many,
216 .child = .{ .type = @intFromEnum(InternPool.Index.u8_type) },
217 },
218 },
219 .manyptr_const_u8_sentinel_0_type => .{
220 .Pointer = .{
221 .size = .Many,
222 .child = .{ .type = @intFromEnum(InternPool.Index.u8_type) },
223 .sentinel = .{ .int = .{ .value = 0 } },
224 },
225 },
226 .single_const_pointer_to_comptime_int_type => .{
227 .Pointer = .{
228 .size = .One,
229 .child = .{ .type = @intFromEnum(InternPool.Index.comptime_int_type) },
230 },
231 },
232 .slice_const_u8_type => .{
233 .Pointer = .{
234 .size = .Slice,
235 .child = .{ .type = @intFromEnum(InternPool.Index.u8_type) },
236 },
237 },
238 .slice_const_u8_sentinel_0_type => .{
239 .Pointer = .{
240 .size = .Slice,
241 .child = .{ .type = @intFromEnum(InternPool.Index.u8_type) },
242 .sentinel = .{ .int = .{ .value = 0 } },
243 },
244 },
245 // Not fully correct
246 // since it actually has no src or line_number
247 .empty_struct_type => .{
248 .Struct = .{
249 .name = "",
250 .src = 0,
251 .is_tuple = false,
252 .line_number = 0,
253 .parent_container = null,
254 .layout = null,
255 },
256 },
257 .anyerror_void_error_union_type => .{
258 .ErrorUnion = .{
259 .lhs = .{ .type = @intFromEnum(InternPool.Index.anyerror_type) },
260 .rhs = .{ .type = @intFromEnum(InternPool.Index.void_type) },
261 },
262 },
263 .anyframe_type => .{
264 .AnyFrame = .{ .name = try tmpbuf.toOwnedSlice() },
265 },
266 .enum_literal_type => .{
267 .EnumLiteral = .{ .name = try tmpbuf.toOwnedSlice() },
268 },
269 .undefined_type => .{
270 .Undefined = .{ .name = try tmpbuf.toOwnedSlice() },
271 },
272 .null_type => .{
273 .Null = .{ .name = try tmpbuf.toOwnedSlice() },
274 },
275 .optional_noreturn_type => .{
276 .Optional = .{
277 .name = try tmpbuf.toOwnedSlice(),
278 .child = .{ .type = @intFromEnum(InternPool.Index.noreturn_type) },
279 },
280 },
281 // Poison and special tag
282 .generic_poison_type,
283 .var_args_param_type,
284 => .{
208285 .Type = .{ .name = try tmpbuf.toOwnedSlice() },
209286 },
287 // We want to catch new types added to InternPool.Index
288 else => unreachable,
210289 },
211290 );
212291 }