diff options
| author | 2022-08-06 16:11:26 +0200 | |
|---|---|---|
| committer | 2022-08-06 16:11:26 +0200 | |
| commit | 0c6330ce7ee50c1fa241793588fa83a3c00bc3c1 (patch) | |
| tree | 3c8c42804a8056a61b267d690a13688d6580630a /bootstrap/parse.c | |
| parent | c53e17496d97a2fb638544cee414de97d81770fc (diff) | |
inferred length array init
Diffstat (limited to 'bootstrap/parse.c')
| -rw-r--r-- | bootstrap/parse.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/bootstrap/parse.c b/bootstrap/parse.c index 9ab1b53..e32a2a3 100644 --- a/bootstrap/parse.c +++ b/bootstrap/parse.c @@ -786,6 +786,7 @@ parsearrini(struct parser *P, const struct type *ty) { fatal(P, e.span, "excess elements in array initializer"); vec_push(&args, ((struct iniarg) { .idx = iota++, e })); + ex.ini.maxn = MAX(ex.ini.maxn, iota - 1); if (!lexmatch(P, &tok, ',')) { lexexpect(P, '}'); @@ -1511,6 +1512,21 @@ parsevardecl(decl_yielder_t yield, void *yarg, struct parser *P) { fatal(P, tok.span, "incompatible initializer type (%t, expected %t)", ini->ty, ty); + if (ty->t == TYarr && ty->length < 0) { + struct type ty2 = *ty; + if (ini->t == Ezeroini) { + ty2.length = 0; + } else if (ini->t == Eini) { + ty2.length = ini->ini.maxn + 1; + } else { + fatal(P, ini->span, + "initializer of inferred-length array must be compound literal"); + } + ty2.size = ty->child->size * ty2.length; + ty2.align = ty->child->align; + ty = interntype(ty2); + } + if (!completetype(ty)) fatal(P, tok.span, "let `%s': variable type %t is incomplete", name, ty); |