aboutsummaryrefslogtreecommitdiff
path: root/bootstrap/parse.c
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2022-08-12 18:03:44 +0200
committerlemon <lsof@mailbox.org>2022-08-12 18:03:44 +0200
commitd98b1ecb7a23b369e533f20386cb7aa83156d25d (patch)
treef17675a6338026bc828f33e24ce0d721b08d0f9b /bootstrap/parse.c
parent1eb17cda6780476b166b55d0fedc3ad355969e87 (diff)
fix #FILE #LINE
Diffstat (limited to 'bootstrap/parse.c')
-rw-r--r--bootstrap/parse.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/bootstrap/parse.c b/bootstrap/parse.c
index 7ff52bf..bf6b534 100644
--- a/bootstrap/parse.c
+++ b/bootstrap/parse.c
@@ -324,6 +324,18 @@ lex(struct parser *P) {
}
}
}
+ } else if (tok.t == '#FIL' || tok.t == '#LIN') {
+ struct expan *ep;
+ for (ep = P->curexpan; ep->prev; ep = ep->prev)
+ ;
+ if (tok.t == '#FIL') {
+ return (struct tok) { TKstrlit, tok.span,
+ .str = fileid2path(ep->span.fileid),
+ .strlen = strlen(fileid2path(ep->span.fileid)) };
+ } else {
+ return (struct tok) { TKintlit, tok.span,
+ .ilit.i = ep->span.line };
+ }
}
return tok;
}
@@ -379,13 +391,9 @@ lex(struct parser *P) {
tok.t = TKlabel;
tok.str = xstrdup(s);
} else if (!strcmp(s, "#FILE")) {
- tok.t = TKstrlit;
- tok.str = P->curfile;
- tok.strlen = strlen(P->curfile);
+ tok.t = '#FIL';
} else if (!strcmp(s, "#LINE")) {
- tok.t = TKintlit;
- tok.ty = ty_uint;
- tok.ilit.i = P->tokspan.line;
+ tok.t = '#LIN';
} else {
fatal(P, P->tokspan, "invalid #keyword");
}
@@ -1706,10 +1714,12 @@ static struct expr
pexcond(struct parser *P) {
struct expr ex;
struct tok tok;
+ const struct type *targty = P->targty;
ex = pexlog(P);
if (P->used_targty) return ex;
if (lexmatch(P, &tok, '?')) {
+ P->targty = targty;
struct expr ex2 = parseexpr(P);
struct expr ex3;
const struct type *ty;
@@ -1718,6 +1728,7 @@ pexcond(struct parser *P) {
fatal(P, ex.span, "invalid test operand %t to conditional operator", ex.ty);
lexexpect(P, ':');
+ P->targty = targty;
ex3 = pexcond(P);
if (!(ty = typeof2(ex2.ty, ex3.ty)))
fatal(P, tok.span,