aboutsummaryrefslogtreecommitdiff
path: root/src/Module.zig
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2022-01-31 17:07:45 +0100
committerAndrew Kelley <andrew@ziglang.org>2022-01-31 22:29:29 -0500
commit627cf6ce482349c172150d058660f7a1646c2aac (patch)
treef786071370621bca7f51e95e4a35c626083b3de8 /src/Module.zig
parentabbcf4032770676aee0e4a37f19d9e9ad2bdd992 (diff)
downloadzig-627cf6ce482349c172150d058660f7a1646c2aac.tar.gz
zig-627cf6ce482349c172150d058660f7a1646c2aac.zip
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.
Diffstat (limited to 'src/Module.zig')
-rw-r--r--src/Module.zig4
1 files changed, 3 insertions, 1 deletions
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;