diff options
| author | 2022-08-07 09:35:07 +0200 | |
|---|---|---|
| committer | 2022-08-07 09:35:07 +0200 | |
| commit | f97e08b3da14c79f7f78e439d06988753c79384b (patch) | |
| tree | f4d51145f057a38c99bc304d15a422546dc766ef /bootstrap/env.c | |
| parent | 59988a43079d0097151f57f941ea8f01a0b714d7 (diff) | |
many decl bugfixes
Diffstat (limited to 'bootstrap/env.c')
| -rw-r--r-- | bootstrap/env.c | 29 |
1 files changed, 13 insertions, 16 deletions
diff --git a/bootstrap/env.c b/bootstrap/env.c index 477c267..ddd06b2 100644 --- a/bootstrap/env.c +++ b/bootstrap/env.c @@ -14,20 +14,7 @@ envfind(const struct env *env, const char *name) { static bool declsshadowable(const struct decl *a, const struct decl *b) { - return b->t == Dlet; -} - -static bool -declscompatible(const struct decl *a, const struct decl *b) { - if (a->t != b->t) - return 0; - if (a->t == Dfn && a->externp == b->externp && a->fn.selfty == b->fn.selfty && !a->fn.body) - return 1; - if (a->t == Dstatic && a->externp == b->externp && a->var.ty == b->var.ty && !a->var.ini) - return 1; - if (a->t == Dtype && a->ty == b->ty) - return 1; - return 0; + return a->t == Dlet && b->t == Dlet; } struct decl * @@ -38,10 +25,10 @@ envput(struct env *env, const struct decl *decl) { }; struct decl *d0; if ((d0 = envfind(&env_noparent, decl->name))) { + // modify existing forward declarations? for (int kind = TYstruct; kind <= TYunion; ++kind) { if (d0->t == Dtype && d0->ty->t == kind && decl->t == Dtype && decl->ty->t == kind && d0->ty->agg.fwd) { - // modify existing forward declaration *(size_t *)&d0->ty->size = decl->ty->size; *(size_t *)&d0->ty->align = decl->ty->align; *(bool *)&d0->ty->agg.fwd = 0; @@ -53,7 +40,17 @@ envput(struct env *env, const struct decl *decl) { return d0; } } - if (!declsshadowable(d0, decl) && !declscompatible(d0, decl)) { + if (d0->t == Dfn && d0->externp == decl->externp && d0->fn.selfty == decl->fn.selfty && !d0->fn.body && decl->fn.body) { + d0->fn.body = decl->fn.body; + return d0; + } + if (d0->t == Dfn && d0->externp == decl->externp && d0->fn.selfty == decl->fn.selfty && !d0->fn.body) + return d0; + if (d0->t == Dstatic && d0->externp == decl->externp && d0->var.ty == decl->var.ty && !d0->var.ini) + return d0; + if (d0->t == Dtype && d0->ty == decl->ty) + return d0; + if (!declsshadowable(d0, decl)) { return NULL; } } |