Commit 8a9aa9e112

Krzysztof Wolicki <der.teufel.mail@gmail.com>
2023-09-07 12:42:15
autodoc: Handle `ref` ZIR instruction
1 parent 6df78c3
Changed files (2)
lib
docs
src
lib/docs/main.js
@@ -1361,6 +1361,12 @@ Happy writing!
         return;
       }
 
+      case "ref": {
+        yield { src: "&", tag: Tag.ampersand };
+        yield* ex(zigAnalysis.exprs[expr.ref], opts);
+        return;
+      }
+
       case "call": {
 
         let call = zigAnalysis.calls[expr.call];
src/Autodoc.zig
@@ -797,6 +797,7 @@ const DocData = struct {
         binOp: BinOp,
         binOpIndex: usize,
         load: usize, // index in `exprs`
+        ref: usize, // index in `exprs`
         const BinOp = struct {
             lhs: usize, // index in `exprs`
             rhs: usize, // index in `exprs`
@@ -1521,6 +1522,23 @@ fn walkInstruction(
                 .expr = .{ .load = load_idx },
             };
         },
+        .ref => {
+            const un_tok = data[inst_index].un_tok;
+            const operand = try self.walkRef(
+                file,
+                parent_scope,
+                parent_src,
+                un_tok.operand,
+                need_type,
+                call_ctx,
+            );
+            const ref_idx = self.exprs.items.len;
+            try self.exprs.append(self.arena, operand.expr);
+
+            return DocData.WalkResult{
+                .expr = .{ .ref = ref_idx },
+            };
+        },
 
         // @check array_cat and array_mul
         .add,