cproc

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/cproc
Log | Files | Refs | Submodules | README | LICENSE

commit 70cbf1e90934b1902769d53a4a43c0e6aa200dfd
parent 7e5a07cfff793e5656d9868cae9cc5281f92e0d0
Author: Michael Forney <mforney@mforney.org>
Date:   Fri,  5 Apr 2019 14:36:45 -0700

Separate unqualified type and qualifiers in struct param

Diffstat:
Mcc.h | 1+
Mdecl.c | 6+++---
Mqbe.c | 4++--
Mtype.c | 3+++
4 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/cc.h b/cc.h @@ -159,6 +159,7 @@ enum typeprop { struct param { char *name; struct type *type; + enum typequal qual; struct value *value; struct param *next; }; diff --git a/decl.c b/decl.c @@ -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; } } diff --git a/qbe.c b/qbe.c @@ -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); } diff --git a/type.c b/type.c @@ -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;