diff options
Diffstat (limited to 'bootstrap/parse.c')
| -rw-r--r-- | bootstrap/parse.c | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/bootstrap/parse.c b/bootstrap/parse.c index 99c9310..3f854d7 100644 --- a/bootstrap/parse.c +++ b/bootstrap/parse.c @@ -785,6 +785,18 @@ parsearrini(struct parser *P, const struct type *ty) { return ex; } +static const struct type * +fntype(const struct fn *fn) { + struct type ty = { TYfn, 0, g_targ.sizesize }; + vec_t(const struct type *) params = {0}; + ty.fn.retty = fn->retty; + for (int i = 0; i < fn->params.n; ++i) + vec_push(¶ms, fn->params.d[i].ty); + vec_slice_cpy(&ty.fn.params, ¶ms); + ty.fn.variadic = fn->variadic; + return interntype(ty); +} + static struct expr pexprimary(struct parser *P) { struct expr ex = {0}; @@ -861,6 +873,8 @@ pexprimary(struct parser *P) { } else if (decl->t == Dstatic) { ex.ty = decl->var.ty; } else if (decl->t == Dfn) { + if (!decl->fn.selfty) + ((struct decl *)decl)->fn.selfty = fntype(&decl->fn); ex.ty = decl->fn.selfty; } else assert(0); } @@ -1764,18 +1778,6 @@ parseblock(struct parser *P) { return st; } -static const struct type * -fntype(const struct fn *fn) { - struct type ty = { TYfn, 0, g_targ.sizesize }; - vec_t(const struct type *) params = {0}; - ty.fn.retty = fn->retty; - for (int i = 0; i < fn->params.n; ++i) - vec_push(¶ms, fn->params.d[i].ty); - vec_slice_cpy(&ty.fn.params, ¶ms); - ty.fn.variadic = fn->variadic; - return interntype(ty); -} - static void parsefn(struct decl *decl, struct parser *P) { vec_t(struct fnparam) params = {0}; @@ -1812,7 +1814,6 @@ parsefn(struct decl *decl, struct parser *P) { fatal(P, tok.span, "return type is incomplete (%t)", fn->retty); } - fn->selfty = fntype(fn); if (!lexmatch(P, &tok, ';')) { struct env *env = xcalloc(1, sizeof *env); static int id; |