diff options
| author | Vallahor <vallahor91@gmail.com> | 2022-05-28 20:33:46 -0300 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-07-19 19:10:11 -0700 |
| commit | b96bd33f5558225f249ecee86156a2b7dd029064 (patch) | |
| tree | 73d0b9f1c32c35aee0c6ffc94a7c85710994dee9 /src | |
| parent | b823f011412fdb3e168c5c093bbb5c47983e74bf (diff) | |
| download | zig-b96bd33f5558225f249ecee86156a2b7dd029064.tar.gz zig-b96bd33f5558225f249ecee86156a2b7dd029064.zip | |
add: handling to extra information in ptr_type
Diffstat (limited to 'src')
| -rw-r--r-- | src/Autodoc.zig | 93 |
1 files changed, 91 insertions, 2 deletions
diff --git a/src/Autodoc.zig b/src/Autodoc.zig index f5767f9d47..e99fe500f8 100644 --- a/src/Autodoc.zig +++ b/src/Autodoc.zig @@ -412,6 +412,10 @@ const DocData = struct { size: std.builtin.TypeInfo.Pointer.Size, child: Expr, sentinel: ?Expr = null, + @"align": ?Expr = null, + address_space: ?Expr = null, + bit_start: ?Expr = null, + host_size: ?Expr = null, is_allowzero: bool = false, is_mutable: bool = false, is_volatile: bool = false, @@ -537,6 +541,38 @@ const DocData = struct { try sentinel.jsonStringify(options, w); try w.print(",", .{}); } + if (v.@"align") |@"align"| { + try w.print( + \\"align": + , .{}); + if (options.whitespace) |*ws| ws.indent_level += 1; + try @"align".jsonStringify(options, w); + try w.print(",", .{}); + } + if (v.address_space) |address_space| { + try w.print( + \\"address_space": + , .{}); + if (options.whitespace) |*ws| ws.indent_level += 1; + try address_space.jsonStringify(options, w); + try w.print(",", .{}); + } + if (v.bit_start) |bit_start| { + try w.print( + \\"bit_start": + , .{}); + if (options.whitespace) |*ws| ws.indent_level += 1; + try bit_start.jsonStringify(options, w); + try w.print(",", .{}); + } + if (v.host_size) |host_size| { + try w.print( + \\"host_size": + , .{}); + if (options.whitespace) |*ws| ws.indent_level += 1; + try host_size.jsonStringify(options, w); + try w.print(",", .{}); + } if (options.whitespace) |ws| try ws.outputIndent(w); try w.print( \\"is_allowzero": {}, @@ -951,6 +987,7 @@ fn walkInstruction( .ptr_type => { const ptr = data[inst_index].ptr_type; const extra = file.zir.extraData(Zir.Inst.PtrType, ptr.payload_index); + var extra_index = extra.end; const type_slot_index = self.types.items.len; const elem_type_ref = try self.walkRef( @@ -960,9 +997,61 @@ fn walkInstruction( false, ); - const sentinel: ?DocData.Expr = if (ptr.flags.has_sentinel) DocData.Expr{ .int = .{ .value = 0, .negated = false } } else null; + // @check if `addrspace`, `bit_start` and `host_size` really need to be + // present in json + var sentinel: ?DocData.Expr = null; + if (ptr.flags.has_sentinel) { + const ref = @intToEnum(Zir.Inst.Ref, file.zir.extra[extra_index]); + const ref_result = try self.walkRef(file, parent_scope, ref, false); + sentinel = ref_result.expr; + extra_index += 1; + } + + var @"align": ?DocData.Expr = null; + if (ptr.flags.has_align) { + const ref = @intToEnum(Zir.Inst.Ref, file.zir.extra[extra_index]); + const ref_result = try self.walkRef(file, parent_scope, ref, false); + @"align" = ref_result.expr; + extra_index += 1; + } + var address_space: ?DocData.Expr = null; + if (ptr.flags.has_addrspace) { + const ref = @intToEnum(Zir.Inst.Ref, file.zir.extra[extra_index]); + const ref_result = try self.walkRef(file, parent_scope, ref, false); + address_space = ref_result.expr; + extra_index += 1; + } + var bit_start: ?DocData.Expr = null; + if (ptr.flags.has_bit_range) { + const ref = @intToEnum(Zir.Inst.Ref, file.zir.extra[extra_index]); + const ref_result = try self.walkRef(file, parent_scope, ref, false); + address_space = ref_result.expr; + extra_index += 1; + } + + var host_size: ?DocData.Expr = null; + if (ptr.flags.has_bit_range) { + const ref = @intToEnum(Zir.Inst.Ref, file.zir.extra[extra_index]); + const ref_result = try self.walkRef(file, parent_scope, ref, false); + host_size = ref_result.expr; + } + try self.types.append(self.arena, .{ - .Pointer = .{ .size = ptr.size, .child = elem_type_ref.expr, .sentinel = sentinel, .is_mutable = ptr.flags.is_mutable, .has_align = ptr.flags.has_align, .has_sentinel = ptr.flags.has_sentinel, .is_volatile = ptr.flags.is_volatile, .has_addrspace = ptr.flags.has_addrspace, .has_bit_range = ptr.flags.has_bit_range }, + .Pointer = .{ + .size = ptr.size, + .child = elem_type_ref.expr, + .has_align = ptr.flags.has_align, + .@"align" = @"align", + .has_addrspace = ptr.flags.has_addrspace, + .address_space = address_space, + .has_sentinel = ptr.flags.has_sentinel, + .sentinel = sentinel, + .is_mutable = ptr.flags.is_mutable, + .is_volatile = ptr.flags.is_volatile, + .has_bit_range = ptr.flags.has_bit_range, + .bit_start = bit_start, + .host_size = host_size, + }, }); return DocData.WalkResult{ .typeRef = .{ .type = @enumToInt(Ref.type_type) }, |
