ww: add file-scoped import aliases

This commit is contained in:
2026-08-14 10:56:34 +09:00
parent 351f4a25bc
commit 792b6ecbe5
14 changed files with 587 additions and 430 deletions

View File

@@ -2853,7 +2853,11 @@ fn sepresolvesourceimport(g: *sepgraph, context: i32, name: *u8,
};
fn sepusecmp(a: *syntax.node, b: *syntax.node) i32 = {
let r: i32 = strings.compare(a.usepath, b.usepath): i32;
let apath: str = a.usesource;
if (apath.len == 0) { apath = a.usepath; };
let bpath: str = b.usesource;
if (bpath.len == 0) { bpath = b.usepath; };
let r: i32 = strings.compare(apath, bpath): i32;
if (r != 0) { return r; };
r = strings.compare(a.file, b.file): i32;
if (r != 0) { return r; };
@@ -2977,12 +2981,14 @@ fn sepscanfile(g: *sepgraph, pi: i32, file: *u8, context: i32,
ui = 0;
for (ui < nuse) {
u = uses[ui];
let idp: *u8 = u.usepath.ptr;
let idn: u64 = u.usepath.len: u64;
if (reservedimport(u.usepath)) {
let sourcepath: str = u.usesource;
if (sourcepath.len == 0) { sourcepath = u.usepath; };
let idp: *u8 = sourcepath.ptr;
let idn: u64 = sourcepath.len: u64;
if (reservedimport(sourcepath)) {
cerrpos(u.file, u.line, u.col);
cerr(": error: package path ");
cerr(u.usepath); cerr(" is reserved\n");
cerr(sourcepath); cerr(" is reserved\n");
return -1;
};
let nm: []u8;
@@ -3085,7 +3091,7 @@ fn sepscanfile(g: *sepgraph, pi: i32, file: *u8, context: i32,
let childcontext: i32 = sepchildcontextfor(g, context,
resolved.entry, resolved.sourceroot);
if (childcontext < 0
|| !sepbindadd(bindings, 'D': u8, u.usepath, di,
|| !sepbindadd(bindings, 'D': u8, sourcepath, di,
u.file, u.line, u.col)
|| !sepadddep(g, pi, di)
|| !sepchildrenadd(children, di, childcontext)) {
@@ -3108,7 +3114,7 @@ fn sepscanfile(g: *sepgraph, pi: i32, file: *u8, context: i32,
cerr("\n");
return -1;
} else {
if (!sepbindadd(bindings, 'I': u8, u.usepath, -1,
if (!sepbindadd(bindings, 'I': u8, sourcepath, -1,
u.file, u.line, u.col)) {
return -1;
};
@@ -4360,14 +4366,14 @@ fn validatecommandoutputpath(out: *u8) i32 = {
fn workdirstamptext(istest: i32, emitasm: i32) str = {
if (istest != 0) {
if (emitasm != 0) {
return "ww workdir fmt 13 mode test asm 1\n";
return "ww workdir fmt 14 mode test asm 1\n";
};
return "ww workdir fmt 13 mode test asm 0\n";
return "ww workdir fmt 14 mode test asm 0\n";
};
if (emitasm != 0) {
return "ww workdir fmt 14 mode build asm 1\n";
return "ww workdir fmt 15 mode build asm 1\n";
};
return "ww workdir fmt 14 mode build asm 0\n";
return "ww workdir fmt 15 mode build asm 0\n";
};
fn stampmatches(path: *u8, want: str) bool = {