| ... | ... | @@ -2153,11 +2153,13 @@ fn walkInstruction( |
| 2153 | 2153 | }; |
| 2154 | 2154 | }, |
| 2155 | 2155 | .block => { |
| 2156 | | const res = DocData.WalkResult{ .expr = .{ |
| 2157 | | .comptimeExpr = self.comptime_exprs.items.len, |
| 2158 | | } }; |
| 2156 | const res = DocData.WalkResult{ |
| 2157 | .typeRef = .{ .type = @enumToInt(Ref.type_type) }, |
| 2158 | .expr = .{ .comptimeExpr = self.comptime_exprs.items.len }, |
| 2159 | }; |
| 2160 | const block_expr = try self.getBlockSource(file, parent_src, inst_index); |
| 2159 | 2161 | try self.comptime_exprs.append(self.arena, .{ |
| 2160 | | .code = "if (...) { ... }", |
| 2162 | .code = block_expr, |
| 2161 | 2163 | }); |
| 2162 | 2164 | return res; |
| 2163 | 2165 | }, |
| ... | ... | @@ -2167,11 +2169,13 @@ fn walkInstruction( |
| 2167 | 2169 | parent_scope, |
| 2168 | 2170 | parent_src, |
| 2169 | 2171 | getBlockInlineBreak(file.zir, inst_index) orelse { |
| 2170 | | const res = DocData.WalkResult{ .expr = .{ |
| 2171 | | .comptimeExpr = self.comptime_exprs.items.len, |
| 2172 | | } }; |
| 2172 | const res = DocData.WalkResult{ |
| 2173 | .typeRef = .{ .type = @enumToInt(Ref.type_type) }, |
| 2174 | .expr = .{ .comptimeExpr = self.comptime_exprs.items.len }, |
| 2175 | }; |
| 2176 | const block_inline_expr = try self.getBlockSource(file, parent_src, inst_index); |
| 2173 | 2177 | try self.comptime_exprs.append(self.arena, .{ |
| 2174 | | .code = "if (...) { ... }", |
| 2178 | .code = block_inline_expr, |
| 2175 | 2179 | }); |
| 2176 | 2180 | return res; |
| 2177 | 2181 | }, |
| ... | ... | @@ -3201,29 +3205,7 @@ fn analyzeDecl( |
| 3201 | 3205 | const decl_src = try self.srcLocInfo(file, value_pl_node.src_node, parent_src); |
| 3202 | 3206 | |
| 3203 | 3207 | 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 | | }, |
| 3208 | 0, 1, 2 => unreachable, // comptime or usingnamespace decl, decltest |
| 3227 | 3209 | else => blk: { |
| 3228 | 3210 | if (file.zir.string_bytes[decl_name_index] == 0) { |
| 3229 | 3211 | // test decl |
| ... | ... | @@ -3360,15 +3342,11 @@ fn analyzeDecltest( |
| 3360 | 3342 | const decl_name_index = file.zir.extra[d.sub_index + 7]; |
| 3361 | 3343 | |
| 3362 | 3344 | // This is known to work because decl values are always block_inlines |
| 3345 | const test_source_code = try self.getBlockSource(file, parent_src, value_index); |
| 3346 | |
| 3363 | 3347 | const value_pl_node = data[value_index].pl_node; |
| 3364 | 3348 | const decl_src = try self.srcLocInfo(file, value_pl_node.src_node, parent_src); |
| 3365 | 3349 | |
| 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); |
| 3371 | | |
| 3372 | 3350 | const decl_name: ?[]const u8 = if (decl_name_index != 0) |
| 3373 | 3351 | file.zir.nullTerminatedString(decl_name_index) |
| 3374 | 3352 | else |
| ... | ... | @@ -4814,6 +4792,43 @@ fn declIsVar( |
| 4814 | 4792 | return (tags[tok_idx] == .keyword_var); |
| 4815 | 4793 | } |
| 4816 | 4794 | |
| 4795 | fn getBlockSource( |
| 4796 | self: Autodoc, |
| 4797 | file: *File, |
| 4798 | parent_src: SrcLocInfo, |
| 4799 | value_index: usize, |
| 4800 | ) AutodocErrors![]const u8 { |
| 4801 | const data = file.zir.instructions.items(.data); |
| 4802 | const tags = file.zir.instructions.items(.tag); |
| 4803 | const tree = try file.getTree(self.comp_module.gpa); |
| 4804 | |
| 4805 | // This is known to work because decl values are always block_inlines |
| 4806 | const block_pl_node = data[value_index].pl_node; |
| 4807 | const block_src = try self.srcLocInfo(file, block_pl_node.src_node, parent_src); |
| 4808 | |
| 4809 | const blk_index = idx: { |
| 4810 | const pl_node = data[value_index].pl_node; |
| 4811 | const extra = file.zir.extraData(Zir.Inst.Block, pl_node.payload_index); |
| 4812 | const end_index = file.zir.extra[extra.end..][extra.data.body_len - 1]; |
| 4813 | |
| 4814 | if (tags[end_index] == .break_inline) { |
| 4815 | break :idx @as(usize, Zir.refToIndex(data[end_index].@"break".operand).?); |
| 4816 | } else { |
| 4817 | break :idx null; |
| 4818 | } |
| 4819 | }; |
| 4820 | |
| 4821 | const blk_source = src: { |
| 4822 | if (blk_index) |idx| { |
| 4823 | const pl_node = data[idx].pl_node; |
| 4824 | break :src try self.srcLocInfo(file, pl_node.src_node, block_src); |
| 4825 | } else { |
| 4826 | break :src block_src; |
| 4827 | } |
| 4828 | }; |
| 4829 | return tree.getNodeSource(blk_source.src_node); |
| 4830 | } |
| 4831 | |
| 4817 | 4832 | fn getTLDocComment(self: *Autodoc, file: *File) ![]const u8 { |
| 4818 | 4833 | const source = (try file.getSource(self.comp_module.gpa)).bytes; |
| 4819 | 4834 | var tokenizer = Tokenizer.init(source); |