diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/prc1/print.c | 5 | ||||
| -rw-r--r-- | src/prc1/td.c | 15 | ||||
| -rw-r--r-- | src/prc1/type.c | 35 |
3 files changed, 36 insertions, 19 deletions
diff --git a/src/prc1/print.c b/src/prc1/print.c index c40672d..2a2bfe3 100644 --- a/src/prc1/print.c +++ b/src/prc1/print.c @@ -58,15 +58,16 @@ static int settype(struct prv *p, const struct sym *s, struct prisym *ps) { const struct type *t = sym_type(p, s); const struct tk *tk = s->tk; + const struct sym *is; if (!t) { errloc(tk, "undefined reference to \"%s\"", tk->s); return -1; } - else if (inner(s)->type == SYM_LIT) + else if ((is = inner(s))->type == SYM_LIT) { - const struct lit *l = lit_push(tk, p); + const struct lit *l = lit_push(is->tk, p); if (!l) return -1; diff --git a/src/prc1/td.c b/src/prc1/td.c index b38a9d3..b3c6692 100644 --- a/src/prc1/td.c +++ b/src/prc1/td.c @@ -114,7 +114,7 @@ static int cid(const struct lex *l, struct prv *p) struct type *nt; const struct loc *loc; - if (t) + if (t && t->type != OP) { loc = &t->tk->loc; errloc(id, "type \"%s\" already defined at %s:%d:%d", id->s, loc->f, @@ -263,7 +263,7 @@ static int c(const struct lex *l, struct prv *p) const struct tdconstant *tdc = p->tdc; const struct loc *loc; - if (t) + if (t && t->type != OP) { loc = &t->tk->loc; errloc(id, "type \"%s\" already defined at %s:%d:%d", id->s, loc->f, @@ -372,13 +372,7 @@ static int op(const struct lex *l, struct prv *p) 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; - } + goto end; else if (!(nt = malloc(sizeof *nt))) { perror("realloc(3)"); @@ -393,6 +387,7 @@ static int op(const struct lex *l, struct prv *p) insert(td, nt); dbg("\tadd opaque type %s (%d:%d)\n", id->s, loc->line, loc->col); +end: reset(p); return 0; } @@ -480,7 +475,7 @@ static int s(const struct lex *l, struct prv *p) struct type *nt; const struct type *t = type_find(fn, tr, id->s); - if (t) + if (t && t->type != OP) { const struct loc *loc = &t->tk->loc; diff --git a/src/prc1/type.c b/src/prc1/type.c index 72940c8..36e222e 100644 --- a/src/prc1/type.c +++ b/src/prc1/type.c @@ -166,22 +166,43 @@ const struct type *type_ufind(const struct fn *fn, const char *tr, const char *s) { const struct td *td = fn->td; - const struct type *t; + const struct type *t, *op = NULL; if (fn->parent && (t = type_find(fn->parent, tr, s))) - return t; - else if ((t = triplet_type(tr, s))) - return t; + { + if (t->type == OP) + op = t; + else + return t; + } + + if ((t = triplet_type(tr, s))) + { + if (t->type == OP) + op = t; + else + return t; + } else if (td) for (const struct type *t = td->types; t; t = t->next) if (!strcmp(t->tk->s, s)) - return t; + { + if (t->type == OP) + op = t; + else + return t; + } for (size_t i = 0; i < fn->nimps; i++) if ((t = type_ufind(fn->imps[i].ast.fns, tr, s))) - return t; + { + if (t->type == OP) + op = t; + else + return t; + } - return NULL; + return op; } const struct type *type_find(const struct fn *fn, const char *tr, const char *s) |
