Commit 9be9e4d02c

Vallahor <vallahor91@gmail.com>
2022-05-29 19:10:33
add: @enumToInt() WIP
1 parent 5fcf0b0
Changed files (2)
lib
docs
src
lib/docs/main.js
@@ -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];
src/Autodoc.zig
@@ -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;