aboutsummaryrefslogtreecommitdiff
path: root/bootstrap/parse.c
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2022-08-15 12:22:47 +0200
committerlemon <lsof@mailbox.org>2022-08-15 12:22:47 +0200
commitf906d0b350b0b4ceb747669c9a9845d11bd0e486 (patch)
tree5f09a7b714e6ce93f6094a06e5f736513110fb8d /bootstrap/parse.c
parentf802bb99263aaa5be492999babd44cd2fdb1c65f (diff)
self hosted progress
Diffstat (limited to 'bootstrap/parse.c')
-rw-r--r--bootstrap/parse.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/bootstrap/parse.c b/bootstrap/parse.c
index 0c619fc..0d9ab16 100644
--- a/bootstrap/parse.c
+++ b/bootstrap/parse.c
@@ -785,7 +785,7 @@ parsetype(struct parser *P) {
lexexpect(P, ']');
} else if (!lexmatch(P, &tok, ']')) {
struct expr ex = parseexpr(P);
- if (!fold(&ex) || ex.t != Eintlit)
+ if (!fold(&ex) || (ex.t != Eintlit && !(ex.t == Eenumval && ex.ty->enu.lax)))
fatal(P, ex.span,
"array length should be a compile-time integral expression");
if ((length = ex.i) < 0)
@@ -1178,8 +1178,9 @@ pexprimary(struct parser *P) {
} else {
const struct aggfield *fld;
for (i = 0; i < ex.ty->agg.flds.n; ++i)
- if (!strcmp((fld = &ex.ty->agg.flds.d[i])->name, vname))
+ if (!strcmp((fld = &ex.ty->agg.flds.d[i])->name, vname)) {
goto found1;
+ }
fatal(P, tok.span, "tagged union %t contains no variant `%s'", ex.ty, vname);
found1:
P->used_targty = 1;
@@ -1187,6 +1188,7 @@ pexprimary(struct parser *P) {
ex.span = tok.span;
ex.euini.fnam = fld->name;
ex.euini.tag = ex.ty->agg.enumty->enu.vals.d[i].i;
+ P->targty = fld->ty;
if (fld->ty)
ex.euini.ini = exprdup(parseexpr(P));
}
@@ -1288,7 +1290,7 @@ pexpostfix(struct parser *P) {
if (lhs.ty->t != TYarr && lhs.ty->t != TYptr && lhs.ty->t != TYslice)
fatal(P, lhs.span, "indexee is not array or pointer type (%t)",
lhs.ty);
- if (rhs.ty->t != TYint)
+ if (rhs.ty->t != TYint && !(rhs.ty->t == TYenum && rhs.ty->enu.lax))
fatal(P, lhs.span, "index expression type is not integral (%t)",
rhs.ty);
if (lexmatch(P, NULL, '::')) {
@@ -1474,6 +1476,7 @@ pexpostfix(struct parser *P) {
fnam, ex.ty);
}
} else {
+ P->used_targty = 0;
break;
}
@@ -1532,7 +1535,7 @@ pexprefix(struct parser *P) {
if (ex.ty->t != TYptr)
fatal(P, ex.span, "invalid %t operand to dereference, not pointer", ex.ty);
if (!completetype(ex.ty->child) && ex.ty->child->t != TYfn)
- fatal(P, ex.span, "invalid %t operand to dereference, incomplete", ex.ty);
+ fatal(P, ex.span, "invalid %t operand to dereference, incomplete");
return (struct expr) {
Eprefix, tok.span, ex.ty->child, .unop = {
'*', exprdup(ex)
@@ -1541,7 +1544,7 @@ pexprefix(struct parser *P) {
} else if (lexmatch(P, &tok, '&')) {
struct expr ex = pexprefix(P);
struct type ty2 = { TYptr, g_targ.ptrsize, .child = ex.ty};
- if (!islvalue(&ex) && !(ex.t == Ename && ex.ref->t == Dfn))
+ if (!islvalue(&ex) && !(ex.t == Ename && ex.ref->t == Dfn) && !(ex.t == Ezeroini || ex.t == Eini))
fatal(P, ex.span, "invalid operand to `&': not an lvalue");
return (struct expr) {
Eprefix, tok.span, interntype(ty2), .unop = {
@@ -1875,7 +1878,7 @@ parsevardecl(decl_yielder_t yield, void *yarg, struct parser *P, bool let, bool
fatal(P, tok.span, "incompatible initializer type (%t, expected %t)",
ini->ty, ty);
- if (ty->t == TYarr && ty->length < 0) {
+ if (ini && ty->t == TYarr && ty->length < 0) {
struct type ty2 = *ty;
if (ini->t == Ezeroini) {
ty2.length = 0;
@@ -1888,7 +1891,7 @@ parsevardecl(decl_yielder_t yield, void *yarg, struct parser *P, bool let, bool
ty2.size = ty->child->size * ty2.length;
ty2.align = ty->child->align;
uninterntype(ty);
- ty = interntype(ty2);
+ ty = ini->ty = interntype(ty2);
}
if (!completetype(ty) && !(!let && externp))
@@ -2102,8 +2105,8 @@ psteuswitch(struct parser *P, const struct expr *test) {
if (lexpeek(P).t != TKident)
lexexpect(P, TKident);
}
+ struct env env = {P->curenv};
if (c.fld->ty && lexmatch(P, &tok, TKident)) {
- struct env env = {P->curenv};
const struct type *ty = c.fld->ty;
c.capt = tok.str;
@@ -2227,7 +2230,7 @@ parseexpandmacro(struct parser *P, const struct macro *macro) {
vec_t(struct tok) toks = {0};
struct toktree ttoks;
- for (;;) {
+ for (;;) {
tok = lex(P);
switch (tok.t) {
case '[': ++bkbal; break; case ']': --bkbal; break;
@@ -2937,8 +2940,8 @@ doimport(struct parser *P, const char *path) {
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);
+ // epri("warning: \"%s\": circular import detected: \"%s\" being processed\n",
+ // P->curfile, path);
}
return seen.data[i].cf;
}