authorgravatar for vallahor91@gmail.comVallahor <vallahor91@gmail.com> 2022-05-29 14:10:33-03:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-07-19 19:10:12-07:00
log9be9e4d02c059e55c476fd98e789bbc02c08730a
tree88f1171f06898cc8263d5c1c4fef85ec2397f670
parent5fcf0b056544c32f30c4aa3bfe884fc3a9c675f1

add: @enumToInt() WIP


2 files changed, 41 insertions(+), 1 deletions(-)

lib/docs/main.js+15-1
......@@ -1062,13 +1062,27 @@ var zigAnalysis;
10621062 function exprName(expr, opts) {
10631063 switch (Object.keys(expr)[0]) {
10641064 default: throw "oh no";
1065 case "fieldRef" : {
1066 // const fieldRef = zigAnalysis.decls[expr.fieldRef.index];
1067 // const struct_name = zigAnalysis.decls[expr.struct[0].val.typeRef.refPath[0].declRef].name;
1068 console.log(expr)
1069 console.log(fieldRef)
1070 // return "@enumToInt(" + exprName(enumToInt, opts) + ")";
1071 // return exprName(fieldRef,opts);
1072 return "WIP"
1073 }
1074 case "enumToInt" : {
1075 console.log(expr);
1076 const enumToInt = zigAnalysis.exprs[expr.enumToInt];
1077 return "@enumToInt(" + exprName(enumToInt, opts) + ")";
1078 }
10651079 case "bitSizeOf" : {
10661080 const bitSizeOf = zigAnalysis.exprs[expr.bitSizeOf];
10671081 return "@bitSizeOf(" + exprName(bitSizeOf, opts) + ")";
10681082 }
10691083 case "sizeOf" : {
10701084 const sizeOf = zigAnalysis.exprs[expr.sizeOf];
1071 return "sizeOf(" + exprName(sizeOf, opts) + ")";
1085 return "@sizeOf(" + exprName(sizeOf, opts) + ")";
10721086 }
10731087 case "binOpIndex" : {
10741088 const binOpIndex = zigAnalysis.exprs[expr.binOpIndex];
src/Autodoc.zig+26
......@@ -656,6 +656,7 @@ const DocData = struct {
656656 as: As,
657657 sizeOf: usize, // index in `exprs`
658658 bitSizeOf: usize, // index in `exprs`
659 enumToInt: usize, // index in `exprs`
659660 compileError: []const u8,
660661 string: []const u8, // direct value
661662 // Index a `type` like struct with expressions
......@@ -736,6 +737,11 @@ const DocData = struct {
736737 \\{{ "bitSizeOf":{} }}
737738 , .{v});
738739 },
740 .enumToInt => |v| {
741 try w.print(
742 \\{{ "enumToInt":{} }}
743 , .{v});
744 },
739745 .fieldRef => |v| try std.json.stringify(
740746 struct { fieldRef: FieldRef }{ .fieldRef = v },
741747 options,
......@@ -2173,6 +2179,26 @@ fn walkInstruction(
21732179 .expr = .{ .bitSizeOf = operand_index },
21742180 };
21752181 },
2182 .enum_to_int => {
2183 // not working correctly with `align()`
2184 const un_node = data[inst_index].un_node;
2185 const operand = try self.walkRef(
2186 file,
2187 parent_scope,
2188 un_node.operand,
2189 false,
2190 );
2191 const operand_index = self.exprs.items.len;
2192 try self.exprs.append(self.arena, operand.expr);
2193
2194 std.debug.print("un_node = {any}\n", .{un_node});
2195 std.debug.print("operand = {any}\n", .{operand});
2196 std.debug.print("operand_expr = {any}\n", .{operand.expr});
2197 return DocData.WalkResult{
2198 .typeRef = .{ .type = @enumToInt(Ref.comptime_int_type) },
2199 .expr = .{ .enumToInt = operand_index },
2200 };
2201 },
21762202
21772203 .typeof => {
21782204 const un_node = data[inst_index].un_node;