feat(selfhost): multi-file #line paths from Decl.sourceFile

Stamp each merged .bux path onto decls, propagate to HirFunc, and emit
#line N \"path\" per function without requiring BUX_DEBUG_FILE.

- Decl.sourceFile + Cli_StampSourceFile on merge/project parse
- HirFunc.sourceFile; CBE switches currentFile per function
- Stdlib and multi-file user packages get distinct paths automatically
This commit is contained in:
2026-07-19 23:13:02 +03:00
parent ed07cf8921
commit 70321075a6
7 changed files with 75 additions and 10 deletions
+33
View File
@@ -611,6 +611,27 @@ func Cli_CollectStdlibImports(mod: *Module, outPaths: *String, maxCount: int, st
return count;
}
/// Stamp sourceFile on a decl and nested module items (for multi-file #line).
func Cli_StampSourceFile(decl: *Decl, path: String) {
if decl == null as *Decl { return; }
decl.sourceFile = path;
if decl.kind == dkModule {
var inner: *Decl = decl.childDecl1;
while inner != null as *Decl {
Cli_StampSourceFile(inner, path);
inner = inner.childDecl2;
}
}
// Impl methods
if decl.kind == dkImpl {
var m: *Decl = decl.childDecl1;
while m != null as *Decl {
Cli_StampSourceFile(m, path);
m = m.childDecl2;
}
}
}
func Cli_MergeFileInto(target: *Module, path: String, skipNames: *String, skipCount: int) -> int {
if !FileExists(path) {
Print("Error: stdlib file not found: ");
@@ -623,6 +644,12 @@ func Cli_MergeFileInto(target: *Module, path: String, skipNames: *String, skipCo
if Lexer_DiagCount(lex) > 0 { return 0; }
let mod: *Module = Parser_Parse(lex.tokens, lex.tokenCount);
if mod == null as *Module { return 0; }
// Tag every decl from this file for #line maps
var stamp: *Decl = mod.firstItem;
while stamp != null as *Decl {
Cli_StampSourceFile(stamp, path);
stamp = stamp.childDecl2;
}
var added: int = 0;
var decl: *Decl = mod.firstItem;
@@ -1431,6 +1458,12 @@ func Cli_BuildProject(projectDir: String, targetTriple: String, isRelease: bool)
PrintLine(path);
return 1;
}
// Tag decls with this source path for multi-file #line
var stampUser: *Decl = mod.firstItem;
while stampUser != null as *Decl {
Cli_StampSourceFile(stampUser, path);
stampUser = stampUser.childDecl2;
}
// Merge declarations from this module into userMerged
var decl: *Decl = mod.firstItem;
var fileDeclCount: int = 0;