diff options
| author | Xavier Del Campo Romero <xavi92@disroot.org> | 2026-11-03 00:16:51 +0100 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi92@disroot.org> | 2026-11-03 00:33:24 +0100 |
| commit | 3ee275dbb8bcf5df7f54e7659b4a9a8f4f49911d (patch) | |
| tree | f943671c3136c87797468668ea9b705f01f51714 /src/prc1/td.c | |
| parent | 9a1643a92301e8f91ed20d46a25b0afa0da9dd95 (diff) | |
| download | prc-3ee275dbb8bcf5df7f54e7659b4a9a8f4f49911d.tar.gz | |
Add initial support for opaque types
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; |
