diff options
author | Michael Forney <mforney@mforney.org> | 2019-04-05 14:36:45 -0700 |
---|---|---|
committer | Michael Forney <mforney@mforney.org> | 2019-04-06 12:01:38 -0700 |
commit | 70cbf1e90934b1902769d53a4a43c0e6aa200dfd (patch) | |
tree | 5800971aca75e788b068f8afd570f7ea5cb9b9cb | |
parent | 7e5a07cfff793e5656d9868cae9cc5281f92e0d0 (diff) |
Separate unqualified type and qualifiers in struct param
-rw-r--r-- | cc.h | 1 | ||||
-rw-r--r-- | decl.c | 6 | ||||
-rw-r--r-- | qbe.c | 4 | ||||
-rw-r--r-- | type.c | 3 |
4 files changed, 9 insertions, 5 deletions
@@ -159,6 +159,7 @@ enum typeprop { struct param { char *name; struct type *type; + enum typequal qual; struct value *value; struct param *next; }; @@ -490,7 +490,7 @@ declaratortypes(struct scope *s, struct list *result, char **name, bool allowabs break; } } - if (typeunqual(t->func.params->type, NULL)->kind == TYPEVOID && !t->func.params->next) + if (t->func.params->type->kind == TYPEVOID && !t->func.params->next) t->func.params = NULL; break; case TRPAREN: @@ -600,7 +600,7 @@ parameter(struct scope *s) if (sc && sc != SCREGISTER) error(&tok.loc, "parameter declaration has invalid storage-class specifier"); p = mkparam(NULL, t); - p->type = adjust(declarator(s, p->type, &p->name, true)); + p->type = typeunqual(adjust(declarator(s, p->type, &p->name, true)), &p->qual); return p; } @@ -619,7 +619,7 @@ paramdecl(struct scope *s, struct param *params) t = adjust(declarator(s, base, &name, false)); for (p = params; p; p = p->next) { if (strcmp(name, p->name) == 0) { - p->type = t; + p->type = typeunqual(t, &p->qual); break; } } @@ -364,7 +364,7 @@ mkfunc(char *name, struct type *t, struct scope *s) if (!t->func.isprototype && !typecompatible(p->type, typeargpromote(p->type))) error(&tok.loc, "old-style function definition with parameter type incompatible with promoted type is not yet supported"); emittype(p->type); - d = mkdecl(DECLOBJECT, p->type, LINKNONE); + d = mkdecl(DECLOBJECT, mkqualifiedtype(p->type, p->qual), LINKNONE); p->value = xmalloc(sizeof(*p->value)); functemp(f, p->value, p->type->repr); if (p->type->repr->abi.id) { @@ -373,7 +373,7 @@ mkfunc(char *name, struct type *t, struct scope *s) d->value->repr = &iptr; } else { funcinit(f, d, NULL); - funcstore(f, typeunqual(p->type, NULL), QUALNONE, d->value, p->value); + funcstore(f, p->type, QUALNONE, d->value, p->value); } scopeputdecl(s, p->name, d); } @@ -206,6 +206,8 @@ typecompatible(struct type *t1, struct type *t2) return true; } for (p1 = t1->func.params, p2 = t2->func.params; p1 && p2; p1 = p1->next, p2 = p2->next) { + if (p1->qual != p2->qual) + return false; tmp = t2->func.isprototype ? p2->type : typeargpromote(p2->type); if (!typecompatible(p1->type, tmp)) return false; @@ -326,6 +328,7 @@ mkparam(char *name, struct type *t) p = xmalloc(sizeof(*p)); p->name = name; p->type = t; + p->qual = QUALNONE; p->next = NULL; return p; |