w6c+selfhost: cross-module same-leaf type disambiguation via Sym.mod

This commit is contained in:
2026-05-15 10:26:20 +09:00
parent e349536f62
commit 66d6408cbe
15 changed files with 614 additions and 60 deletions

View File

@@ -1340,6 +1340,14 @@ parsefile(Parser *p)
Node *file = newnode(p->a, N_FILE, pp);
Node *head = NULL, *tail = NULL;
while (p->cur.kind != TK_EOF) {
/* Stamp the lex's current `// MODULE: foo` directive on the
* decl BEFORE parsing. cgen uses this for name-mangling and
* check uses it for cross-module type disambiguation. Capture
* before parsing so the closing `expect(SEMI)` doesn't
* accidentally advance the lexer past the *next* `// MODULE:`
* directive — that would stamp this decl with the next
* module's name. */
const char *mod = p->l->module;
Node *attrs = parseattrs(p);
int exp = accept(p, TK_EXPORT);
Node *d = NULL;
@@ -1363,10 +1371,7 @@ parsefile(Parser *p)
advance(p);
continue;
}
/* Stamp the lex's current `// MODULE: foo` directive on the
* decl. cgen uses it to mangle non-exported names so two
* modules can each privately define `cstrlen`/`streq`/etc. */
if (d != NULL) d->module = p->l->module;
if (d != NULL) d->module = mod;
if (head == NULL) head = d;
else tail->next = d;
tail = d;