| ... | ... | @@ -1876,12 +1876,14 @@ fn walkInstruction( |
| 1876 | 1876 | // WIP |
| 1877 | 1877 | const pl_node = data[inst_index].pl_node; |
| 1878 | 1878 | const extra = file.zir.extraData(Zir.Inst.SwitchBlock, pl_node.payload_index); |
| 1879 | | const cond_index = self.exprs.items.len; |
| 1880 | 1879 | |
| 1881 | | _ = try self.walkRef(file, parent_scope, parent_src, extra.data.operand, false); |
| 1880 | const switch_cond = try self.walkRef(file, parent_scope, parent_src, extra.data.operand, false); |
| 1881 | const cond_index = self.exprs.items.len; |
| 1882 | try self.exprs.append(self.arena, switch_cond.expr); |
| 1883 | _ = cond_index; |
| 1882 | 1884 | |
| 1883 | | const ast_index = self.ast_nodes.items.len; |
| 1884 | | const type_index = self.types.items.len - 1; |
| 1885 | // const ast_index = self.ast_nodes.items.len; |
| 1886 | // const type_index = self.types.items.len - 1; |
| 1885 | 1887 | |
| 1886 | 1888 | // const ast_line = self.ast_nodes.items[ast_index - 1]; |
| 1887 | 1889 | |
| ... | ... | @@ -1894,12 +1896,18 @@ fn walkInstruction( |
| 1894 | 1896 | // log.debug("{s}", .{sep}); |
| 1895 | 1897 | |
| 1896 | 1898 | const switch_index = self.exprs.items.len; |
| 1897 | | try self.exprs.append(self.arena, .{ .switchOp = .{ |
| 1898 | | .cond_index = cond_index, |
| 1899 | | .file_name = file.sub_file_path, |
| 1900 | | .src = ast_index, |
| 1901 | | .outer_decl = type_index, |
| 1902 | | } }); |
| 1899 | |
| 1900 | // const src_loc = try self.srcLocInfo(file, pl_node.src_node, parent_src); |
| 1901 | |
| 1902 | const switch_expr = try self.getBlockSource(file, parent_src, pl_node.src_node); |
| 1903 | try self.exprs.append(self.arena, .{ .comptimeExpr = self.comptime_exprs.items.len }); |
| 1904 | try self.comptime_exprs.append(self.arena, .{ .code = switch_expr }); |
| 1905 | // try self.exprs.append(self.arena, .{ .switchOp = .{ |
| 1906 | // .cond_index = cond_index, |
| 1907 | // .file_name = file.sub_file_path, |
| 1908 | // .src = ast_index, |
| 1909 | // .outer_decl = type_index, |
| 1910 | // } }); |
| 1903 | 1911 | |
| 1904 | 1912 | return DocData.WalkResult{ |
| 1905 | 1913 | .typeRef = .{ .type = @enumToInt(Ref.type_type) }, |
| ... | ... | @@ -2153,11 +2161,14 @@ fn walkInstruction( |
| 2153 | 2161 | }; |
| 2154 | 2162 | }, |
| 2155 | 2163 | .block => { |
| 2156 | | const res = DocData.WalkResult{ .expr = .{ |
| 2157 | | .comptimeExpr = self.comptime_exprs.items.len, |
| 2158 | | } }; |
| 2164 | const res = DocData.WalkResult{ |
| 2165 | .typeRef = .{ .type = @enumToInt(Ref.type_type) }, |
| 2166 | .expr = .{ .comptimeExpr = self.comptime_exprs.items.len }, |
| 2167 | }; |
| 2168 | const pl_node = data[inst_index].pl_node; |
| 2169 | const block_expr = try self.getBlockSource(file, parent_src, pl_node.src_node); |
| 2159 | 2170 | try self.comptime_exprs.append(self.arena, .{ |
| 2160 | | .code = "if (...) { ... }", |
| 2171 | .code = block_expr, |
| 2161 | 2172 | }); |
| 2162 | 2173 | return res; |
| 2163 | 2174 | }, |
| ... | ... | @@ -2167,11 +2178,14 @@ fn walkInstruction( |
| 2167 | 2178 | parent_scope, |
| 2168 | 2179 | parent_src, |
| 2169 | 2180 | getBlockInlineBreak(file.zir, inst_index) orelse { |
| 2170 | | const res = DocData.WalkResult{ .expr = .{ |
| 2171 | | .comptimeExpr = self.comptime_exprs.items.len, |
| 2172 | | } }; |
| 2181 | const res = DocData.WalkResult{ |
| 2182 | .typeRef = .{ .type = @enumToInt(Ref.type_type) }, |
| 2183 | .expr = .{ .comptimeExpr = self.comptime_exprs.items.len }, |
| 2184 | }; |
| 2185 | const pl_node = data[inst_index].pl_node; |
| 2186 | const block_inline_expr = try self.getBlockSource(file, parent_src, pl_node.src_node); |
| 2173 | 2187 | try self.comptime_exprs.append(self.arena, .{ |
| 2174 | | .code = "if (...) { ... }", |
| 2188 | .code = block_inline_expr, |
| 2175 | 2189 | }); |
| 2176 | 2190 | return res; |
| 2177 | 2191 | }, |
| ... | ... | @@ -3201,29 +3215,7 @@ fn analyzeDecl( |
| 3201 | 3215 | const decl_src = try self.srcLocInfo(file, value_pl_node.src_node, parent_src); |
| 3202 | 3216 | |
| 3203 | 3217 | const name: []const u8 = switch (decl_name_index) { |
| 3204 | | 0, 1 => unreachable, // comptime or usingnamespace decl |
| 3205 | | 2 => { |
| 3206 | | unreachable; |
| 3207 | | // decl test |
| 3208 | | // const decl_status = scope.resolveDeclName(doc_comment_index); |
| 3209 | | // const decl_being_tested = decl_status.Analyzed; |
| 3210 | | // const func_index = getBlockInlineBreak(file.zir, value_index).?; |
| 3211 | | |
| 3212 | | // const pl_node = data[Zir.refToIndex(func_index).?].pl_node; |
| 3213 | | // const fn_src = try self.srcLocInfo(file, pl_node.src_node, decl_src); |
| 3214 | | // const tree = try file.getTree(self.comp_module.gpa); |
| 3215 | | // const test_source_code = tree.getNodeSource(fn_src.src_node); |
| 3216 | | |
| 3217 | | // const ast_node_index = self.ast_nodes.items.len; |
| 3218 | | // try self.ast_nodes.append(self.arena, .{ |
| 3219 | | // .file = 0, |
| 3220 | | // .line = 0, |
| 3221 | | // .col = 0, |
| 3222 | | // .code = test_source_code, |
| 3223 | | // }); |
| 3224 | | // self.decls.items[decl_being_tested].decltest = ast_node_index; |
| 3225 | | // continue; |
| 3226 | | }, |
| 3218 | 0, 1, 2 => unreachable, // comptime or usingnamespace decl, decltest |
| 3227 | 3219 | else => blk: { |
| 3228 | 3220 | if (file.zir.string_bytes[decl_name_index] == 0) { |
| 3229 | 3221 | // test decl |
| ... | ... | @@ -3359,15 +3351,10 @@ fn analyzeDecltest( |
| 3359 | 3351 | const value_index = file.zir.extra[d.sub_index + 6]; |
| 3360 | 3352 | const decl_name_index = file.zir.extra[d.sub_index + 7]; |
| 3361 | 3353 | |
| 3362 | | // This is known to work because decl values are always block_inlines |
| 3363 | 3354 | const value_pl_node = data[value_index].pl_node; |
| 3364 | 3355 | const decl_src = try self.srcLocInfo(file, value_pl_node.src_node, parent_src); |
| 3365 | 3356 | |
| 3366 | | const func_index = getBlockInlineBreak(file.zir, value_index).?; |
| 3367 | | const pl_node = data[Zir.refToIndex(func_index).?].pl_node; |
| 3368 | | const fn_src = try self.srcLocInfo(file, pl_node.src_node, decl_src); |
| 3369 | | const tree = try file.getTree(self.comp_module.gpa); |
| 3370 | | const test_source_code = tree.getNodeSource(fn_src.src_node); |
| 3357 | const test_source_code = try self.getBlockSource(file, parent_src, value_pl_node.src_node); |
| 3371 | 3358 | |
| 3372 | 3359 | const decl_name: ?[]const u8 = if (decl_name_index != 0) |
| 3373 | 3360 | file.zir.nullTerminatedString(decl_name_index) |
| ... | ... | @@ -4814,6 +4801,17 @@ fn declIsVar( |
| 4814 | 4801 | return (tags[tok_idx] == .keyword_var); |
| 4815 | 4802 | } |
| 4816 | 4803 | |
| 4804 | fn getBlockSource( |
| 4805 | self: Autodoc, |
| 4806 | file: *File, |
| 4807 | parent_src: SrcLocInfo, |
| 4808 | block_src_node: i32, |
| 4809 | ) AutodocErrors![]const u8 { |
| 4810 | const tree = try file.getTree(self.comp_module.gpa); |
| 4811 | const block_src = try self.srcLocInfo(file, block_src_node, parent_src); |
| 4812 | return tree.getNodeSource(block_src.src_node); |
| 4813 | } |
| 4814 | |
| 4817 | 4815 | fn getTLDocComment(self: *Autodoc, file: *File) ![]const u8 { |
| 4818 | 4816 | const source = (try file.getSource(self.comp_module.gpa)).bytes; |
| 4819 | 4817 | var tokenizer = Tokenizer.init(source); |