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

This commit is contained in:
Vallahor
2022-05-29 13:31:47 -03:00
committed by Andrew Kelley
parent a529d747c9
commit 5fcf0b0565
2 changed files with 26 additions and 0 deletions

View File

@@ -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) + ")";

View File

@@ -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;