aboutsummaryrefslogtreecommitdiffhomepage
path: root/c
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2025-10-20 11:04:47 +0200
committerlemon <lsof@mailbox.org>2025-10-20 11:04:47 +0200
commit21be6c1317078691de33c658dfd77755c9f43592 (patch)
treec592dc837c3de5272799e9412f542bb9931a25d7 /c
parenta587564cef96ff5cce1c31a6445858f0f6553b1d (diff)
refactor vec_of(T) and misc
Diffstat (limited to 'c')
-rw-r--r--c/lex.c21
-rw-r--r--c/lex.h1
2 files changed, 15 insertions, 7 deletions
diff --git a/c/lex.c b/c/lex.c
index 951bb5a..135972a 100644
--- a/c/lex.c
+++ b/c/lex.c
@@ -1199,7 +1199,10 @@ advancemacro(struct lexer *lx, struct token *tk)
assert(lx->macstk);
rl = lx->macstk->rlist;
if (lx->macstk->idx == rl.n) {
- if (lx->macstk->stop) return tk->t = TKEOF;
+ if (lx->macstk->stop) {
+ tk->t = TKEOF;
+ return 1;
+ }
popmac(lx);
return 0;
}
@@ -1208,7 +1211,7 @@ advancemacro(struct lexer *lx, struct token *tk)
tk->span.ex = lx->macstk->exspan;
if (tryexpand(lx, tk))
return 0;
- return tk->t;
+ return 1;
}
static struct token epeektk;
@@ -1538,13 +1541,16 @@ ppelse(struct lexer *lx, const struct span *span)
enum { MAXINCLUDE = 200 };
static bool
-tryinclude(struct lexer *lx, const struct span *span, const char *path)
+tryinclude(struct lexer *lx, const struct span *span, char *path)
{
struct lexer new;
const char *err;
switch (initlexer(&new, &err, path)) {
default: assert(0);
case LXERR: return 0;
+ case LXFILESEEN:
+ xbfree(path);
+ /* fallthru */
case LXOK:
new.save = xmalloc(sizeof *new.save);
memcpy(new.save, lx, sizeof *lx);
@@ -1553,7 +1559,8 @@ tryinclude(struct lexer *lx, const struct span *span, const char *path)
if (++includedepth == MAXINCLUDE)
fatal(span, "Maximum nested include depth of %d reached", includedepth);
break;
- case LXFILESEEN:
+ case LXFILESKIP:
+ xbfree(path);
break;
}
return 1;
@@ -1913,15 +1920,15 @@ initlexer(struct lexer *lx, const char **err, const char *file)
fileid = openfile(err, &f, file);
if (fileid < 0)
return LXERR;
- if (isoncefile(fileid) && isfileseen(fileid))
- return LXFILESEEN;
+ if (isfileseen(fileid) && isoncefile(fileid))
+ return LXFILESKIP;
memset(lx, 0, sizeof *lx);
lx->fileid = fileid;
markfileseen(fileid);
lx->dat = f->p;
lx->ndat = f->n;
lx->tmparena = &tmparena;
- return LXOK;
+ return getfilename(fileid) != file ? LXFILESEEN : LXOK;
}
/* callback to let lexer release temp memory for arena allocated token data */
diff --git a/c/lex.h b/c/lex.h
index 4ea7327..60a28bf 100644
--- a/c/lex.h
+++ b/c/lex.h
@@ -101,6 +101,7 @@ struct lexer {
enum initlexer {
LXOK,
LXFILESEEN,
+ LXFILESKIP,
LXERR,
};