diff options
Diffstat (limited to 'src/prc1/td.c')
| -rw-r--r-- | src/prc1/td.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/prc1/td.c b/src/prc1/td.c index 0c455f2..b38a9d3 100644 --- a/src/prc1/td.c +++ b/src/prc1/td.c @@ -24,6 +24,7 @@ static int s(const struct lex *, struct prv *); static int c(const struct lex *, struct prv *); static int a(const struct lex *, struct prv *); static int p(const struct lex *, struct prv *); +static int op(const struct lex *, struct prv *); static const struct seq seqs[] = { @@ -39,6 +40,7 @@ static const struct seq seqs[] = {(struct step[]){{ID}, {ID, "struct"}, {0}}, .fn = s}, {(struct step[]){{ID}, {ID, "constant"}, {0}}, .fn = c}, {(struct step[]){{ID}, {ID, "prototype"}, {0}}, .fn = p}, + {(struct step[]){{ID}, {ID, "opaque"}, {0}}, .fn = op}, {0} }; @@ -359,6 +361,42 @@ failure: return -1; } +static int op(const struct lex *l, struct prv *p) +{ + const struct tk *id = p->stk; + const struct loc *loc = &id->loc; + const char *tr = triplet(p); + struct fn *fn = fn_cur(p); + struct td *td = fn->td; + struct type *nt; + const struct type *t = type_find(fn, tr, id->s); + + if (t) + { + const struct loc *loc = &t->tk->loc; + + errloc(id, "type \"%s\" already defined at %s:%d:%d", id->s, loc->f, + loc->line, loc->col); + return -1; + } + else if (!(nt = malloc(sizeof *nt))) + { + perror("realloc(3)"); + return -1; + } + + *nt = (struct type) + { + .type = OP, + .tk = id + }; + + insert(td, nt); + dbg("\tadd opaque type %s (%d:%d)\n", id->s, loc->line, loc->col); + reset(p); + return 0; +} + static int ends(struct type *t) { const struct s *s = &t->u.s; |
