| ... | ... | @@ -58,7 +58,7 @@ const RefPathResumeInfo = struct { |
| 58 | 58 | const SrcLocInfo = struct { |
| 59 | 59 | bytes: u32 = 0, |
| 60 | 60 | line: usize = 0, |
| 61 | | src_node: i32 = 0, |
| 61 | src_node: u32 = 0, |
| 62 | 62 | }; |
| 63 | 63 | |
| 64 | 64 | var arena_allocator: std.heap.ArenaAllocator = undefined; |
| ... | ... | @@ -481,6 +481,7 @@ const DocData = struct { |
| 481 | 481 | line: usize = 0, |
| 482 | 482 | col: usize = 0, |
| 483 | 483 | name: ?[]const u8 = null, |
| 484 | code: ?[]const u8 = null, |
| 484 | 485 | docs: ?[]const u8 = null, |
| 485 | 486 | fields: ?[]usize = null, // index into astNodes |
| 486 | 487 | @"comptime": bool = false, |
| ... | ... | @@ -2441,7 +2442,10 @@ fn walkInstruction( |
| 2441 | 2442 | break :blk src_node; |
| 2442 | 2443 | } else null; |
| 2443 | 2444 | |
| 2444 | | const src_info = try self.srcLocInfo(file, src_node, parent_src); |
| 2445 | const src_info = if (src_node) |sn| |
| 2446 | try self.srcLocInfo(file, sn, parent_src) |
| 2447 | else |
| 2448 | parent_src; |
| 2445 | 2449 | _ = src_info; |
| 2446 | 2450 | |
| 2447 | 2451 | const decls_len = if (small.has_decls_len) blk: { |
| ... | ... | @@ -2500,7 +2504,10 @@ fn walkInstruction( |
| 2500 | 2504 | break :blk src_node; |
| 2501 | 2505 | } else null; |
| 2502 | 2506 | |
| 2503 | | const src_info = try self.srcLocInfo(file, src_node, parent_src); |
| 2507 | const src_info = if (src_node) |sn| |
| 2508 | try self.srcLocInfo(file, sn, parent_src) |
| 2509 | else |
| 2510 | parent_src; |
| 2504 | 2511 | |
| 2505 | 2512 | const tag_type: ?Ref = if (small.has_tag_type) blk: { |
| 2506 | 2513 | const tag_type = file.zir.extra[extra_index]; |
| ... | ... | @@ -2623,7 +2630,10 @@ fn walkInstruction( |
| 2623 | 2630 | break :blk src_node; |
| 2624 | 2631 | } else null; |
| 2625 | 2632 | |
| 2626 | | const src_info = try self.srcLocInfo(file, src_node, parent_src); |
| 2633 | const src_info = if (src_node) |sn| |
| 2634 | try self.srcLocInfo(file, sn, parent_src) |
| 2635 | else |
| 2636 | parent_src; |
| 2627 | 2637 | |
| 2628 | 2638 | const tag_type: ?Ref = if (small.has_tag_type) blk: { |
| 2629 | 2639 | const tag_type = file.zir.extra[extra_index]; |
| ... | ... | @@ -2770,7 +2780,10 @@ fn walkInstruction( |
| 2770 | 2780 | break :blk src_node; |
| 2771 | 2781 | } else null; |
| 2772 | 2782 | |
| 2773 | | const src_info = try self.srcLocInfo(file, src_node, parent_src); |
| 2783 | const src_info = if (src_node) |sn| |
| 2784 | try self.srcLocInfo(file, sn, parent_src) |
| 2785 | else |
| 2786 | parent_src; |
| 2774 | 2787 | |
| 2775 | 2788 | const fields_len = if (small.has_fields_len) blk: { |
| 2776 | 2789 | const fields_len = file.zir.extra[extra_index]; |
| ... | ... | @@ -2911,6 +2924,7 @@ fn walkDecls( |
| 2911 | 2924 | priv_decl_indexes: *std.ArrayListUnmanaged(usize), |
| 2912 | 2925 | extra_start: usize, |
| 2913 | 2926 | ) AutodocErrors!usize { |
| 2927 | const data = file.zir.instructions.items(.data); |
| 2914 | 2928 | const bit_bags_count = std.math.divCeil(usize, decls_len, 8) catch unreachable; |
| 2915 | 2929 | var extra_index = extra_start + bit_bags_count; |
| 2916 | 2930 | var bit_bag_index: usize = extra_start; |
| ... | ... | @@ -2938,7 +2952,7 @@ fn walkDecls( |
| 2938 | 2952 | // const hash_u32s = file.zir.extra[extra_index..][0..4]; |
| 2939 | 2953 | extra_index += 4; |
| 2940 | 2954 | |
| 2941 | | //const line = file.zir.extra[extra_index]; |
| 2955 | // const line = file.zir.extra[extra_index]; |
| 2942 | 2956 | extra_index += 1; |
| 2943 | 2957 | const decl_name_index = file.zir.extra[extra_index]; |
| 2944 | 2958 | extra_index += 1; |
| ... | ... | @@ -2968,10 +2982,11 @@ fn walkDecls( |
| 2968 | 2982 | }; |
| 2969 | 2983 | _ = addrspace_inst; |
| 2970 | 2984 | |
| 2971 | | // const pub_str = if (is_pub) "pub " else ""; |
| 2972 | | // const hash_bytes = @bitCast([16]u8, hash_u32s.*); |
| 2985 | // This is known to work because decl values are always block_inlines |
| 2986 | const value_pl_node = data[value_index].pl_node; |
| 2987 | const decl_src = try self.srcLocInfo(file, value_pl_node.src_node, parent_src); |
| 2973 | 2988 | |
| 2974 | | var is_test = false; // we discover if it's a test by lookin at its name |
| 2989 | var is_test = false; // we discover if it's a test by looking at its name |
| 2975 | 2990 | const name: []const u8 = blk: { |
| 2976 | 2991 | if (decl_name_index == 0) { |
| 2977 | 2992 | break :blk if (is_exported) "usingnamespace" else "comptime"; |
| ... | ... | @@ -2979,84 +2994,32 @@ fn walkDecls( |
| 2979 | 2994 | is_test = true; |
| 2980 | 2995 | break :blk "test"; |
| 2981 | 2996 | } else if (decl_name_index == 2) { |
| 2982 | | is_test = true; |
| 2983 | | // TODO: remove temporary hack |
| 2984 | | break :blk "test"; |
| 2985 | | // // it is a decltest |
| 2986 | | // const decl_being_tested = scope.resolveDeclName(doc_comment_index); |
| 2987 | | // const ast_node_index = idx: { |
| 2988 | | // const idx = self.ast_nodes.items.len; |
| 2989 | | // const file_source = file.getSource(self.module.gpa) catch unreachable; // TODO fix this |
| 2990 | | // const source_of_decltest_function = srcloc: { |
| 2991 | | // const func_index = getBlockInlineBreak(file.zir, value_index); |
| 2992 | | // // a decltest is always a function |
| 2993 | | // const tag = file.zir.instructions.items(.tag)[Zir.refToIndex(func_index).?]; |
| 2994 | | // std.debug.assert(tag == .func_extended); |
| 2995 | | |
| 2996 | | // const pl_node = file.zir.instructions.items(.data)[Zir.refToIndex(func_index).?].pl_node; |
| 2997 | | // const extra = file.zir.extraData(Zir.Inst.ExtendedFunc, pl_node.payload_index); |
| 2998 | | // const bits = @bitCast(Zir.Inst.ExtendedFunc.Bits, extra.data.bits); |
| 2999 | | |
| 3000 | | // var extra_index_for_this_func: usize = extra.end; |
| 3001 | | // if (bits.has_lib_name) extra_index_for_this_func += 1; |
| 3002 | | // if (bits.has_cc) extra_index_for_this_func += 1; |
| 3003 | | // if (bits.has_align) extra_index_for_this_func += 1; |
| 3004 | | |
| 3005 | | // const ret_ty_body = file.zir.extra[extra_index_for_this_func..][0..extra.data.ret_body_len]; |
| 3006 | | // extra_index_for_this_func += ret_ty_body.len; |
| 3007 | | |
| 3008 | | // const body = file.zir.extra[extra_index_for_this_func..][0..extra.data.body_len]; |
| 3009 | | // extra_index_for_this_func += body.len; |
| 3010 | | |
| 3011 | | // var src_locs: Zir.Inst.Func.SrcLocs = undefined; |
| 3012 | | // if (body.len != 0) { |
| 3013 | | // src_locs = file.zir.extraData(Zir.Inst.Func.SrcLocs, extra_index_for_this_func).data; |
| 3014 | | // } else { |
| 3015 | | // src_locs = .{ |
| 3016 | | // .lbrace_line = line, |
| 3017 | | // .rbrace_line = line, |
| 3018 | | // .columns = 0, // TODO get columns when body.len == 0 |
| 3019 | | // }; |
| 3020 | | // } |
| 3021 | | // break :srcloc src_locs; |
| 3022 | | // }; |
| 3023 | | // const source_slice = slice: { |
| 3024 | | // var start_byte_offset: u32 = 0; |
| 3025 | | // var end_byte_offset: u32 = 0; |
| 3026 | | // const rbrace_col = @truncate(u16, source_of_decltest_function.columns >> 16); |
| 3027 | | // var lines: u32 = 0; |
| 3028 | | // for (file_source.bytes) |b, i| { |
| 3029 | | // if (b == '\n') { |
| 3030 | | // lines += 1; |
| 3031 | | // } |
| 3032 | | // if (lines == source_of_decltest_function.lbrace_line) { |
| 3033 | | // start_byte_offset = @intCast(u32, i); |
| 3034 | | // } |
| 3035 | | // if (lines == source_of_decltest_function.rbrace_line) { |
| 3036 | | // end_byte_offset = @intCast(u32, i) + rbrace_col; |
| 3037 | | // break; |
| 3038 | | // } |
| 3039 | | // } |
| 3040 | | // break :slice file_source.bytes[start_byte_offset..end_byte_offset]; |
| 3041 | | // }; |
| 3042 | | // try self.ast_nodes.append(self.arena, .{ |
| 3043 | | // .file = 0, |
| 3044 | | // .line = line, |
| 3045 | | // .col = 0, |
| 3046 | | // .name = try self.arena.dupe(u8, source_slice), |
| 3047 | | // }); |
| 3048 | | // break :idx idx; |
| 3049 | | // }; |
| 3050 | | // self.decls.items[decl_being_tested].decltest = ast_node_index; |
| 3051 | | // self.decls.items[decls_slot_index] = .{ |
| 3052 | | // ._analyzed = true, |
| 3053 | | // .name = "test", |
| 3054 | | // .isTest = true, |
| 3055 | | // .src = ast_node_index, |
| 3056 | | // .value = .{ .expr = .{ .type = 0 } }, |
| 3057 | | // .kind = "const", |
| 3058 | | // }; |
| 3059 | | // continue; |
| 2997 | // it is a decltest |
| 2998 | const decl_being_tested = scope.resolveDeclName(doc_comment_index); |
| 2999 | const func_index = getBlockInlineBreak(file.zir, value_index); |
| 3000 | |
| 3001 | const pl_node = data[Zir.refToIndex(func_index).?].pl_node; |
| 3002 | const fn_src = try self.srcLocInfo(file, pl_node.src_node, decl_src); |
| 3003 | const tree = try file.getTree(self.module.gpa); |
| 3004 | const test_source_code = tree.getNodeSource(fn_src.src_node); |
| 3005 | |
| 3006 | const ast_node_index = self.ast_nodes.items.len; |
| 3007 | try self.ast_nodes.append(self.arena, .{ |
| 3008 | .file = 0, |
| 3009 | .line = 0, |
| 3010 | .col = 0, |
| 3011 | .code = test_source_code, |
| 3012 | }); |
| 3013 | self.decls.items[decl_being_tested].decltest = ast_node_index; |
| 3014 | self.decls.items[decls_slot_index] = .{ |
| 3015 | ._analyzed = true, |
| 3016 | .name = "test", |
| 3017 | .isTest = true, |
| 3018 | .src = ast_node_index, |
| 3019 | .value = .{ .expr = .{ .type = 0 } }, |
| 3020 | .kind = "const", |
| 3021 | }; |
| 3022 | continue; |
| 3060 | 3023 | } else { |
| 3061 | 3024 | const raw_decl_name = file.zir.nullTerminatedString(decl_name_index); |
| 3062 | 3025 | if (raw_decl_name.len == 0) { |
| ... | ... | @@ -3073,11 +3036,6 @@ fn walkDecls( |
| 3073 | 3036 | else |
| 3074 | 3037 | null; |
| 3075 | 3038 | |
| 3076 | | // This is known to work because decl values are always block_inlines |
| 3077 | | const data = file.zir.instructions.items(.data); |
| 3078 | | const value_pl_node = data[value_index].pl_node; |
| 3079 | | const decl_src = try self.srcLocInfo(file, value_pl_node.src_node, parent_src); |
| 3080 | | |
| 3081 | 3039 | // astnode |
| 3082 | 3040 | const ast_node_index = idx: { |
| 3083 | 3041 | const idx = self.ast_nodes.items.len; |
| ... | ... | @@ -4215,24 +4173,20 @@ fn writePackageTableToJson( |
| 4215 | 4173 | fn srcLocInfo( |
| 4216 | 4174 | self: Autodoc, |
| 4217 | 4175 | file: *File, |
| 4218 | | src_node: ?i32, |
| 4176 | src_node: i32, |
| 4219 | 4177 | parent_src: SrcLocInfo, |
| 4220 | 4178 | ) !SrcLocInfo { |
| 4221 | | if (src_node) |unwrapped_src_node| { |
| 4222 | | const sn = parent_src.src_node + unwrapped_src_node; |
| 4223 | | const tree = try file.getTree(self.module.gpa); |
| 4224 | | const node_idx = @bitCast(Ast.Node.Index, sn); |
| 4225 | | const tokens = tree.nodes.items(.main_token); |
| 4226 | | |
| 4227 | | const tok_idx = tokens[node_idx]; |
| 4228 | | const start = tree.tokens.items(.start)[tok_idx]; |
| 4229 | | const loc = tree.tokenLocation(parent_src.bytes, tok_idx); |
| 4230 | | return SrcLocInfo{ |
| 4231 | | .line = parent_src.line + loc.line, |
| 4232 | | .bytes = start, |
| 4233 | | .src_node = sn, |
| 4234 | | }; |
| 4235 | | } else { |
| 4236 | | return parent_src; |
| 4237 | | } |
| 4179 | const sn = @intCast(u32, @intCast(i32, parent_src.src_node) + src_node); |
| 4180 | const tree = try file.getTree(self.module.gpa); |
| 4181 | const node_idx = @bitCast(Ast.Node.Index, sn); |
| 4182 | const tokens = tree.nodes.items(.main_token); |
| 4183 | |
| 4184 | const tok_idx = tokens[node_idx]; |
| 4185 | const start = tree.tokens.items(.start)[tok_idx]; |
| 4186 | const loc = tree.tokenLocation(parent_src.bytes, tok_idx); |
| 4187 | return SrcLocInfo{ |
| 4188 | .line = parent_src.line + loc.line, |
| 4189 | .bytes = start, |
| 4190 | .src_node = sn, |
| 4191 | }; |
| 4238 | 4192 | } |