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;...@@ -1062,13 +1062,27 @@ 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 "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 }
1065 case "bitSizeOf" : {1079 case "bitSizeOf" : {
1066 const bitSizeOf = zigAnalysis.exprs[expr.bitSizeOf];1080 const bitSizeOf = zigAnalysis.exprs[expr.bitSizeOf];
1067 return "@bitSizeOf(" + exprName(bitSizeOf, opts) + ")";1081 return "@bitSizeOf(" + exprName(bitSizeOf, opts) + ")";
1068 }1082 }
1069 case "sizeOf" : {1083 case "sizeOf" : {
1070 const sizeOf = zigAnalysis.exprs[expr.sizeOf];1084 const sizeOf = zigAnalysis.exprs[expr.sizeOf];
1071 return "sizeOf(" + exprName(sizeOf, opts) + ")";1085 return "@sizeOf(" + exprName(sizeOf, opts) + ")";
1072 }1086 }
1073 case "binOpIndex" : {1087 case "binOpIndex" : {
1074 const binOpIndex = zigAnalysis.exprs[expr.binOpIndex];1088 const binOpIndex = zigAnalysis.exprs[expr.binOpIndex];
src/Autodoc.zig+26
...@@ -656,6 +656,7 @@ const DocData = struct {...@@ -656,6 +656,7 @@ const DocData = struct {
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 bitSizeOf: usize, // index in `exprs`
659 enumToInt: usize, // index in `exprs`
659 compileError: []const u8,660 compileError: []const u8,
660 string: []const u8, // direct value661 string: []const u8, // direct value
661 // Index a `type` like struct with expressions662 // Index a `type` like struct with expressions
...@@ -736,6 +737,11 @@ const DocData = struct {...@@ -736,6 +737,11 @@ const DocData = struct {
736 \\{{ "bitSizeOf":{} }}737 \\{{ "bitSizeOf":{} }}
737 , .{v});738 , .{v});
738 },739 },
740 .enumToInt => |v| {
741 try w.print(
742 \\{{ "enumToInt":{} }}
743 , .{v});
744 },
739 .fieldRef => |v| try std.json.stringify(745 .fieldRef => |v| try std.json.stringify(
740 struct { fieldRef: FieldRef }{ .fieldRef = v },746 struct { fieldRef: FieldRef }{ .fieldRef = v },
741 options,747 options,
...@@ -2173,6 +2179,26 @@ fn walkInstruction(...@@ -2173,6 +2179,26 @@ fn walkInstruction(
2173 .expr = .{ .bitSizeOf = operand_index },2179 .expr = .{ .bitSizeOf = operand_index },
2174 };2180 };
2175 },2181 },
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
2177 .typeof => {2203 .typeof => {
2178 const un_node = data[inst_index].un_node;2204 const un_node = data[inst_index].un_node;