summaryrefslogtreecommitdiff
path: root/parse/type.c
diff options
context:
space:
mode:
authorOri Bernstein <ori@markovcorp.com>2017-08-23 11:46:44 -0700
committerOri Bernstein <ori@markovcorp.com>2017-08-23 11:46:44 -0700
commit5711ab3b30b229b651424f7978bc39f0b044e193 (patch)
treee94fa1839c4c105045a21f8d12faaad0d1b0f17a /parse/type.c
parentf363110a62803e055334516ba0e1899e62be65ac (diff)
downloadmc-5711ab3b30b229b651424f7978bc39f0b044e193.tar.gz
Check constraints correctly on typarams.
Diffstat (limited to 'parse/type.c')
-rw-r--r--parse/type.c85
1 files changed, 0 insertions, 85 deletions
diff --git a/parse/type.c b/parse/type.c
index 92d611d..2de0add 100644
--- a/parse/type.c
+++ b/parse/type.c
@@ -851,91 +851,6 @@ tyeq(void *a, void *b)
return eq;
}
-/* this doesn't walk through named types, so it can't recurse infinitely. */
-int
-tymatchrank(Type *pat, Type *to)
-{
- int match, q;
- size_t i;
- Ucon *puc, *tuc;
-
- pat = tysearch(pat);
- to = tysearch(to);
- if (pat->type == Typaram)
- return 0;
- else if (pat->type != to->type)
- return -1;
-
- match = 0;
- switch (pat->type) {
- case Tystruct:
- if (pat->nmemb != to->nmemb)
- return -1;
- for (i = 0; i < pat->nmemb; i++) {
- if (!streq(declname(pat->sdecls[i]),declname( to->sdecls[i])))
- return -1;
- q = tymatchrank(decltype(pat->sdecls[i]), decltype(to->sdecls[i]));
- if (q < 0)
- return -1;
- match += q;
- }
- break;
- case Tyunion:
- if (pat->nmemb != to->nmemb)
- return -1;
- for (i = 0; i < pat->nmemb; i++) {
- if (!nameeq(pat->udecls[i], to->udecls[i]))
- return -1;
- puc = pat->udecls[i];
- tuc = to->udecls[i];
- if (puc->etype && tuc->etype) {
- q = tymatchrank(puc->etype, tuc->etype);
- if (q < 0)
- return -1;
- match += q;
- } else if (puc->etype != tuc->etype) {
- return -1;
- }
- }
- break;
- case Tyname:
- if (!nameeq(pat->name, to->name))
- return -1;
- if (pat->narg != to->narg)
- return -1;
- for (i = 0; i < pat->narg; i++) {
- q = tymatchrank(pat->arg[i], to->arg[i]);
- if (q < 0)
- return -1;
- match += q;
- }
- break;
- case Tyarray:
- /* unsized arrays are ok */
- if (pat->asize && to->asize) {
- if (!!litvaleq(pat->asize->expr.args[0], to->asize->expr.args[0]))
- return -1;
- } else if (pat->asize != to->asize) {
- return -1;
- }
- else return tymatchrank(pat->sub[0], to->sub[0]);
- break;
- default:
- if (pat->nsub != to->nsub)
- break;
- if (pat->type == to->type)
- match = 1;
- for (i = 0; i < pat->nsub; i++) {
- q = tymatchrank(pat->sub[i], to->sub[i]);
- if (q < 0)
- return -1;
- match += q;
- }
- break;
- }
- return match;
-}
-
size_t
tyidfmt(char *buf, size_t sz, Type *ty)
{