add: @enumToInt() WIP

This commit is contained in:
Vallahor 2022-05-29 14:10:33 -03:00 committed by Andrew Kelley
parent 5fcf0b0565
commit 9be9e4d02c
2 changed files with 41 additions and 1 deletions

View File

@ -1062,13 +1062,27 @@ var zigAnalysis;
function exprName(expr, opts) {
switch (Object.keys(expr)[0]) {
default: throw "oh no";
case "fieldRef" : {
// const fieldRef = zigAnalysis.decls[expr.fieldRef.index];
// const struct_name = zigAnalysis.decls[expr.struct[0].val.typeRef.refPath[0].declRef].name;
console.log(expr)
console.log(fieldRef)
// return "@enumToInt(" + exprName(enumToInt, opts) + ")";
// return exprName(fieldRef,opts);
return "WIP"
}
case "enumToInt" : {
console.log(expr);
const enumToInt = zigAnalysis.exprs[expr.enumToInt];
return "@enumToInt(" + exprName(enumToInt, opts) + ")";
}
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) + ")";
return "@sizeOf(" + exprName(sizeOf, opts) + ")";
}
case "binOpIndex" : {
const binOpIndex = zigAnalysis.exprs[expr.binOpIndex];

View File

@ -656,6 +656,7 @@ const DocData = struct {
as: As,
sizeOf: usize, // index in `exprs`
bitSizeOf: usize, // index in `exprs`
enumToInt: usize, // index in `exprs`
compileError: []const u8,
string: []const u8, // direct value
// Index a `type` like struct with expressions
@ -736,6 +737,11 @@ const DocData = struct {
\\{{ "bitSizeOf":{} }}
, .{v});
},
.enumToInt => |v| {
try w.print(
\\{{ "enumToInt":{} }}
, .{v});
},
.fieldRef => |v| try std.json.stringify(
struct { fieldRef: FieldRef }{ .fieldRef = v },
options,
@ -2173,6 +2179,26 @@ fn walkInstruction(
.expr = .{ .bitSizeOf = operand_index },
};
},
.enum_to_int => {
// 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);
std.debug.print("un_node = {any}\n", .{un_node});
std.debug.print("operand = {any}\n", .{operand});
std.debug.print("operand_expr = {any}\n", .{operand.expr});
return DocData.WalkResult{
.typeRef = .{ .type = @enumToInt(Ref.comptime_int_type) },
.expr = .{ .enumToInt = operand_index },
};
},
.typeof => {
const un_node = data[inst_index].un_node;