From 627cf6ce482349c172150d058660f7a1646c2aac Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Mon, 31 Jan 2022 17:07:45 +0100 Subject: astgen: clean up source line calculation and management Clarify that `astgen.advanceSourceCursor` already increments absolute values of the line and columns numbers; i.e., `GenZir.calcLine` is thus not only obsolete but wrong by design. Incidentally, this clean up allows for specifying the `FnDecl` line numbers for DWARF use correctly as relative values with respect to the start of the parent `Decl`. This `Decl` in turn has its line number information specified relatively to its parent `Decl`, and so on, until we reach the global scope. --- src/Module.zig | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/Module.zig') diff --git a/src/Module.zig b/src/Module.zig index 35b7efb016..e2e2505927 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -375,6 +375,7 @@ pub const Decl = struct { src_node: Ast.Node.Index, /// Line number corresponding to `src_node`. Stored separately so that source files /// do not need to be loaded into memory in order to compute debug line numbers. + /// This value is absolute. src_line: u32, /// Index to ZIR `extra` array to the entry in the parent's decl structure /// (the part that says "for every decls_len"). The first item at this index is @@ -4122,7 +4123,8 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) SemaError!voi const has_linksection_or_addrspace = (flags & 0b1000) != 0; // zig fmt: on - const line = iter.parent_decl.relativeToLine(zir.extra[decl_sub_index + 4]); + const line_off = zir.extra[decl_sub_index + 4]; + const line = iter.parent_decl.relativeToLine(line_off); const decl_name_index = zir.extra[decl_sub_index + 5]; const decl_index = zir.extra[decl_sub_index + 6]; const decl_block_inst_data = zir.instructions.items(.data)[decl_index].pl_node; -- cgit v1.2.3