[hackers] [scc] Merge pars and fields in Type || Roberto E. Vargas Caballero
commit 79ba801de33247c1dd2fd984497be0a27a757643
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Fri Aug 14 15:09:32 2015 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Fri Aug 14 15:09:32 2015 +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.
diff --git a/cc1/cc1.h b/cc1/cc1.h
index 094f358..3e69d9b 100644
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
_AT_@ -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
index 9932694..677af97 100644
--- a/cc1/code.c
+++ b/cc1/code.c
_AT_@ -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
index 673b091..ceb93de 100644
--- a/cc1/decl.c
+++ b/cc1/decl.c
_AT_@ -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;
_AT_@ -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;
_AT_@ -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);
_AT_@ -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;
}
_AT_@ -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
index f6530f5..c4890ef 100644
--- a/cc1/expr.c
+++ b/cc1/expr.c
_AT_@ -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
index 05aac8a..d2d9740 100644
--- a/cc1/types.c
+++ b/cc1/types.c
_AT_@ -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;
_AT_@ -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;
Received on Fri Aug 14 2015 - 17:08:59 CEST
This archive was generated by hypermail 2.3.0
: Fri Aug 14 2015 - 17:12:20 CEST