From 497289eb02927c75f6e77bba052bec2a4589c227 Mon Sep 17 00:00:00 2001 From: lemon Date: Sat, 20 Dec 2025 22:00:28 +0100 Subject: lexer: note source of #include when error occurs in #included file --- c/lex.c | 6 ++++++ c/lex.h | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/c/lex.c b/c/lex.c index 5c627f1..6fa6fa3 100644 --- a/c/lex.c +++ b/c/lex.c @@ -1507,6 +1507,7 @@ tryinclude(struct lexer *lx, const struct span *span, char *path) /* fallthru */ case LXOK: new.save = xmalloc(sizeof *new.save); + lx->inclnerror = nerror; memcpy(new.save, lx, sizeof *lx); *lx = new; @@ -1850,6 +1851,11 @@ Begin: markfileonce(lx->fileid, lx->inclguard); } struct lexer *sv = lx->save; + if (sv->inclnerror != nerror) { + int line; + const char *f = getfilepos(&line, NULL, sv->fileid, sv->chridx-2); + note(NULL, "in file included from %s:%d", f, line); + } memcpy(lx, sv, sizeof *lx); free(sv); --includedepth; diff --git a/c/lex.h b/c/lex.h index 21519f7..20b1bbd 100644 --- a/c/lex.h +++ b/c/lex.h @@ -101,7 +101,8 @@ struct lexer { bool eof, err; struct arena **tmparena; bool firstdirective; - ushort nppcnd0; + short nppcnd0; + short inclnerror; internstr inclguard; uchar chrbuf[1<<10]; uint chridxbuf[1<<10]; -- cgit v1.2.3