ref: 79ba801de33247c1dd2fd984497be0a27a757643
parent: c8df77d2e357b7497e2a20f4e820de974abedf8b
author: Roberto E. Vargas Caballero <[email protected]>
date: Fri Aug 14 11:09:32 EDT 2015
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.
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
@@ -32,8 +32,10 @@
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 */
--- a/cc1/code.c
+++ b/cc1/code.c
@@ -245,12 +245,12 @@
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;
@@ -257,7 +257,7 @@
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);
}
--- a/cc1/decl.c
+++ b/cc1/decl.c
@@ -161,8 +161,8 @@
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 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 @@
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 @@
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 @@
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;
--- a/cc1/expr.c
+++ b/cc1/expr.c
@@ -750,7 +750,7 @@
}
if (tp->op != FTN)
error("function or function pointer expected");
- targs = tp->pars;
+ targs = tp->p.pars;
expect('(');
--- a/cc1/types.c
+++ b/cc1/types.c
@@ -285,7 +285,7 @@
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 @@
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;