From 5fcf0b056544c32f30c4aa3bfe884fc3a9c675f1 Mon Sep 17 00:00:00 2001 From: Vallahor Date: Sun, 29 May 2022 13:31:47 -0300 Subject: [PATCH] add: handling @bitSizeOf() need to check why not working correctly with `align()` --- lib/docs/main.js | 4 ++++ src/Autodoc.zig | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/lib/docs/main.js b/lib/docs/main.js index 12cd00a151..835b4a644b 100644 --- a/lib/docs/main.js +++ b/lib/docs/main.js @@ -1062,6 +1062,10 @@ var zigAnalysis; function exprName(expr, opts) { switch (Object.keys(expr)[0]) { default: throw "oh no"; + case "bitSizeOf" : { + const bitSizeOf = zigAnalysis.exprs[expr.bitSizeOf]; + return "@bitSizeOf(" + exprName(bitSizeOf, opts) + ")"; + } case "sizeOf" : { const sizeOf = zigAnalysis.exprs[expr.sizeOf]; return "sizeOf(" + exprName(sizeOf, opts) + ")"; diff --git a/src/Autodoc.zig b/src/Autodoc.zig index 6e51938065..53499dd838 100644 --- a/src/Autodoc.zig +++ b/src/Autodoc.zig @@ -655,6 +655,7 @@ const DocData = struct { errorUnion: usize, // index in `exprs` as: As, sizeOf: usize, // index in `exprs` + bitSizeOf: usize, // index in `exprs` compileError: []const u8, string: []const u8, // direct value // Index a `type` like struct with expressions @@ -730,6 +731,11 @@ const DocData = struct { \\{{ "sizeOf":{} }} , .{v}); }, + .bitSizeOf => |v| { + try w.print( + \\{{ "bitSizeOf":{} }} + , .{v}); + }, .fieldRef => |v| try std.json.stringify( struct { fieldRef: FieldRef }{ .fieldRef = v }, options, @@ -2151,6 +2157,22 @@ fn walkInstruction( .expr = .{ .sizeOf = operand_index }, }; }, + .bit_size_of => { + // not working correctly with `align()` + const un_node = data[inst_index].un_node; + const operand = try self.walkRef( + file, + parent_scope, + un_node.operand, + false, + ); + const operand_index = self.exprs.items.len; + try self.exprs.append(self.arena, operand.expr); + return DocData.WalkResult{ + .typeRef = .{ .type = @enumToInt(Ref.comptime_int_type) }, + .expr = .{ .bitSizeOf = operand_index }, + }; + }, .typeof => { const un_node = data[inst_index].un_node;