aboutsummaryrefslogtreecommitdiff
path: root/bootstrap/parse.c
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2022-08-14 11:16:03 +0200
committerlemon <lsof@mailbox.org>2022-08-14 11:16:03 +0200
commit0d1e125832d0fd8ca31c5f782e7c3db774ae5a02 (patch)
treee4622f75a8307d8ee1970f8bd6cc92766582f0ba /bootstrap/parse.c
parentc129f77ad724aa940b53a125de0e1e4de0ca7240 (diff)
woa
Diffstat (limited to 'bootstrap/parse.c')
-rw-r--r--bootstrap/parse.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/bootstrap/parse.c b/bootstrap/parse.c
index 4a1721d..0c619fc 100644
--- a/bootstrap/parse.c
+++ b/bootstrap/parse.c
@@ -2925,7 +2925,7 @@ getbasedir(const char *path) {
static struct comfile
doimport(struct parser *P, const char *path) {
- static vec_t(struct entry { const char *s; struct comfile cf; }) seen;
+ static vec_t(struct entry { const char *s; struct comfile cf; bool wip; }) seen;
char path2[PATH_MAX], _rpath[PATH_MAX], *rpath;
struct comfile cf = {0};
struct parser P2;
@@ -2934,16 +2934,23 @@ doimport(struct parser *P, const char *path) {
if (!(rpath = realpath(path2, _rpath)))
fatal(P, P->tokspan, "import %q: %s", path, strerror(errno));
- for (int i = 0; i < seen.length; ++i)
- if (!strcmp(seen.data[i].s, rpath))
- return seen.data[i].cf;
+ for (int i = 0; i < seen.length; ++i) {
+ if (!strcmp(seen.data[i].s, rpath)) {
+ if (seen.data[i].wip) {
+ epri("warning: \"%s\": circular import detected: \"%s\" being processed\n",
+ P->curfile, path);
+ }
+ return seen.data[i].cf;
+ }
+ }
rpath = xstrdup(rpath);
// P2.primenv = P->primenv;
initparser(&P2, rpath);
P2.is_header = 1;
- vec_push(&seen, ((struct entry) { rpath, cf }));
+ vec_push(&seen, ((struct entry) { rpath, cf, 1 }));
parse(&cf, &P2);
+ seen.data[seen.length - 1].wip = 0;
seen.data[seen.length - 1].cf = cf;
return cf;
}