commit 79ba801de33247c1dd2fd984497be0a27a757643
parent c8df77d2e357b7497e2a20f4e820de974abedf8b
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Fri, 14 Aug 2015 15:09:32 +0200
Merge pars and fields in Type
These members of Type are not used at the same time ever,
it is a good idea to join them in an union.
Diffstat:
5 files changed, 17 insertions(+), 15 deletions(-)
diff --git a/cc1/cc1.h b/cc1/cc1.h
@@ -32,8 +32,10 @@ struct type {
size_t align; /* align of the type */
Type *type; /* base type */
Type *next; /* next element in the hash */
- Type **pars; /* type parameters */
- Symbol **fields; /* fields of aggregate type */
+ union {
+ Type **pars; /* Function type parameters */
+ Symbol **fields; /* fields of aggregate type */
+ } p;
union {
unsigned char rank; /* convertion rank */
short elem; /* number of type parameters */
diff --git a/cc1/code.c b/cc1/code.c
@@ -245,19 +245,19 @@ emittype(Type *tp)
case UNION:
case STRUCT:
n = tp->n.elem;
- for (sp = tp->fields; n-- > 0; ++sp)
+ for (sp = tp->p.fields; n-- > 0; ++sp)
emittype((*sp)->type);
emitletter(tp);
puts("\t(");
n = tp->n.elem;
- for (sp = tp->fields; n-- > 0; ++sp)
+ for (sp = tp->p.fields; n-- > 0; ++sp)
emit(ODECL, *sp);
puts(")");
break;
case FTN:
emitletter(tp);
n = tp->n.elem;
- for (vp = tp->pars; n-- > 0; ++vp) {
+ for (vp = tp->p.pars; n-- > 0; ++vp) {
putchar('\t');
emitletter(*vp);
}
diff --git a/cc1/decl.c b/cc1/decl.c
@@ -161,8 +161,8 @@ parameter(struct decl *dcl)
if (n++ == NR_FUNPARAM)
error("too much parameters in function definition");
- funtp->pars = xrealloc(funtp->pars, n * sizeof(Type *));
- funtp->pars[n-1] = tp;
+ funtp->p.pars = xrealloc(funtp->p.pars, n * sizeof(Type *));
+ funtp->p.pars[n-1] = tp;
funtp->n.elem = n;
return sym;
@@ -176,7 +176,7 @@ static Symbol *dodcl(int rep,
static void
fundcl(struct declarators *dp)
{
- Type type = {.n = {.elem = -1}, .pars = NULL};
+ Type type = {.n = {.elem = -1}, .p = {.pars= NULL}};
Symbol *syms[NR_FUNPARAM], **sp;
size_t size;
Symbol *pars = NULL;
@@ -198,7 +198,7 @@ fundcl(struct declarators *dp)
pars = memcpy(xmalloc(size), syms, size);
}
}
- push(dp, FTN, type.n.elem, type.pars, pars);
+ push(dp, FTN, type.n.elem, type.p.pars, pars);
}
static void declarator(struct declarators *dp, unsigned ns);
@@ -391,7 +391,7 @@ newtag(void)
error("too much tags declared");
tp = mktype(NULL, tag, 0, NULL);
tp->ns = ns++;
- tp->fields = NULL;
+ tp->p.fields = NULL;
sym->type = tp;
}
@@ -507,8 +507,8 @@ field(struct decl *dcl)
sym->flags |= ISFIELD;
if (n++ == NR_FUNPARAM)
error("too much fields in struct/union");
- structp->fields = xrealloc(structp->fields, n * sizeof(*sym));
- structp->fields[n-1] = sym;
+ structp->p.fields = xrealloc(structp->p.fields, n * sizeof(*sym));
+ structp->p.fields[n-1] = sym;
structp->n.elem = n;
return sym;
diff --git a/cc1/expr.c b/cc1/expr.c
@@ -750,7 +750,7 @@ arguments(Node *np)
}
if (tp->op != FTN)
error("function or function pointer expected");
- targs = tp->pars;
+ targs = tp->p.pars;
expect('(');
diff --git a/cc1/types.c b/cc1/types.c
@@ -285,7 +285,7 @@ mktype(Type *tp, unsigned op, short nelem, Type *pars[])
type.op = op;
type.printed = 0;
type.letter = letters[op];
- type.pars = pars;
+ type.p.pars = pars;
type.n.elem = nelem;
type.ns = 0;
@@ -348,7 +348,7 @@ eqtype(Type *tp1, Type *tp2)
case FTN:
if (tp1->op != tp2->op || tp1->n.elem != tp2->n.elem)
return 0;
- p1 = tp1->pars, p2 = tp2->pars;
+ p1 = tp1->p.pars, p2 = tp2->p.pars;
for (n = tp1->n.elem; n > 0; --n) {
if (!eqtype(*p1++, *p2++))
return 0;