authorgravatar for vallahor91@gmail.comVallahor <vallahor91@gmail.com> 2022-05-29 13:31:47-03:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-07-19 19:10:12-07:00
log5fcf0b056544c32f30c4aa3bfe884fc3a9c675f1
tree5d2cdc2a775d288fecd7b50b8ddb64ef5e9bd98f
parenta529d747c9e4b2064fa3e399025c804e05e5fdf5

add: handling @bitSizeOf() need to check why not working correctly with `align()`


2 files changed, 26 insertions(+), 0 deletions(-)

lib/docs/main.js+4
...@@ -1062,6 +1062,10 @@ var zigAnalysis;...@@ -1062,6 +1062,10 @@ var zigAnalysis;
1062 function exprName(expr, opts) {1062 function exprName(expr, opts) {
1063 switch (Object.keys(expr)[0]) {1063 switch (Object.keys(expr)[0]) {
1064 default: throw "oh no";1064 default: throw "oh no";
1065 case "bitSizeOf" : {
1066 const bitSizeOf = zigAnalysis.exprs[expr.bitSizeOf];
1067 return "@bitSizeOf(" + exprName(bitSizeOf, opts) + ")";
1068 }
1065 case "sizeOf" : {1069 case "sizeOf" : {
1066 const sizeOf = zigAnalysis.exprs[expr.sizeOf];1070 const sizeOf = zigAnalysis.exprs[expr.sizeOf];
1067 return "sizeOf(" + exprName(sizeOf, opts) + ")";1071 return "sizeOf(" + exprName(sizeOf, opts) + ")";
src/Autodoc.zig+22
...@@ -655,6 +655,7 @@ const DocData = struct {...@@ -655,6 +655,7 @@ const DocData = struct {
655 errorUnion: usize, // index in `exprs`655 errorUnion: usize, // index in `exprs`
656 as: As,656 as: As,
657 sizeOf: usize, // index in `exprs`657 sizeOf: usize, // index in `exprs`
658 bitSizeOf: usize, // index in `exprs`
658 compileError: []const u8,659 compileError: []const u8,
659 string: []const u8, // direct value660 string: []const u8, // direct value
660 // Index a `type` like struct with expressions661 // Index a `type` like struct with expressions
...@@ -730,6 +731,11 @@ const DocData = struct {...@@ -730,6 +731,11 @@ const DocData = struct {
730 \\{{ "sizeOf":{} }}731 \\{{ "sizeOf":{} }}
731 , .{v});732 , .{v});
732 },733 },
734 .bitSizeOf => |v| {
735 try w.print(
736 \\{{ "bitSizeOf":{} }}
737 , .{v});
738 },
733 .fieldRef => |v| try std.json.stringify(739 .fieldRef => |v| try std.json.stringify(
734 struct { fieldRef: FieldRef }{ .fieldRef = v },740 struct { fieldRef: FieldRef }{ .fieldRef = v },
735 options,741 options,
...@@ -2151,6 +2157,22 @@ fn walkInstruction(...@@ -2151,6 +2157,22 @@ fn walkInstruction(
2151 .expr = .{ .sizeOf = operand_index },2157 .expr = .{ .sizeOf = operand_index },
2152 };2158 };
2153 },2159 },
2160 .bit_size_of => {
2161 // not working correctly with `align()`
2162 const un_node = data[inst_index].un_node;
2163 const operand = try self.walkRef(
2164 file,
2165 parent_scope,
2166 un_node.operand,
2167 false,
2168 );
2169 const operand_index = self.exprs.items.len;
2170 try self.exprs.append(self.arena, operand.expr);
2171 return DocData.WalkResult{
2172 .typeRef = .{ .type = @enumToInt(Ref.comptime_int_type) },
2173 .expr = .{ .bitSizeOf = operand_index },
2174 };
2175 },
21542176
2155 .typeof => {2177 .typeof => {
2156 const un_node = data[inst_index].un_node;2178 const un_node = data[inst_index].un_node;