aboutsummaryrefslogtreecommitdiff
path: root/bootstrap/parse.c
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2022-08-11 06:25:30 +0200
committerlemon <lsof@mailbox.org>2022-08-11 06:25:30 +0200
commit99cb50d4f13d587e3a0e0f2a44485f301409afb4 (patch)
treec285338782ae3cd760252337a488f10fe940e45b /bootstrap/parse.c
parent8d3c3d919183a4a6ba7ad8010587dee6f5f96baa (diff)
fixs
Diffstat (limited to 'bootstrap/parse.c')
-rw-r--r--bootstrap/parse.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/bootstrap/parse.c b/bootstrap/parse.c
index 49f01b1..297f2a9 100644
--- a/bootstrap/parse.c
+++ b/bootstrap/parse.c
@@ -754,8 +754,8 @@ parsetype(struct parser *P) {
lexexpect(P, ']');
}
child = parsetype(P);
- if (!completetype(child))
- fatal(P, tok.span, "%s of incomplete type (%t)", slice ? "slice" : "array", child);
+ if (!slice && !completetype(child))
+ fatal(P, tok.span, "array of incomplete type (%t)", child);
if (slice)
return mkslicetype(child);
else
@@ -2641,17 +2641,17 @@ parseagg(struct parser *P, const char *name, int kind, struct decl **retdecl) {
return interntype(ty);
} else {
if (name) {
- int iid;
struct env env_noparent = *P->curenv;
env_noparent.parent = NULL;
struct decl *decl = (struct decl *)envfind(&env_noparent, P->envage, name);
- if (decl && decl->ty->t == kind)
- iid = decl->ty->agg.id;
- else
- iid = id++;
- pty = interntype((struct type) {
- kind, .agg.name = name, .agg.id = iid
- });
+ if (decl && decl->t == Dtype && decl->ty->t == kind) {
+ pty = decl->ty;
+ } else {
+ pty = interntype((struct type) {
+ kind, .agg.name = name, .agg.id = id++
+ });
+ }
+
*retdecl = decl = putdecl(P, P->tokspan, &(struct decl) {
Dtype, name, .span = P->tokspan, .ty = pty });
} else {
@@ -2753,11 +2753,13 @@ parseagg(struct parser *P, const char *name, int kind, struct decl **retdecl) {
};
pushenv(P, &env);
+ P->container = pty;
while (!lexmatch(P, &tok, '}')) {
ppty->agg.decls.d = decls.data;
ppty->agg.decls.n = decls.length;
parsedecl(aggdeclyield, &yarg, P, 0);
}
+ P->container = NULL;
vec_slice_cpy(&ppty->agg.decls, &decls);
popenv(P);
@@ -2916,6 +2918,7 @@ parsedecl(decl_yielder_t yield, void *yarg, struct parser *P, bool toplevel) {
struct decl decl = {0};
struct decl* decl2 = NULL;
struct attr attr = {0};
+ decl.container = P->container;
if (lexmatch(P, &tok, '#')) {
lexexpect(P, '[');