Tidy up types representation, combining pt_ptotype, ft_rettype, at_elttype into pt_re...
authorNick Downing <downing.nick@gmail.com>
Tue, 14 Feb 2017 07:29:46 +0000 (18:29 +1100)
committerNick Downing <downing.nick@gmail.com>
Tue, 14 Feb 2017 07:29:46 +0000 (18:29 +1100)
c0.h
c01.c
c02.c
c03.c
c04.c
ccom.h

diff --git a/c0.h b/c0.h
index 28cbec6..fbc8304 100644 (file)
--- a/c0.h
+++ b/c0.h
@@ -271,6 +271,7 @@ void rcexpr0 __P((register struct node *tp));
 void treeout __P((register struct node *tp, int isstruct));
 void branch0 __P((int lab));
 void label0 __P((int l));
+int XXXlength __P((struct node *cs));
 int plength __P((register struct node *p));
 int length __P((struct /*node*/type *cs));
 int rlength __P((struct /*node*/type *cs));
diff --git a/c01.c b/c01.c
index e4ce031..7ea6e53 100644 (file)
--- a/c01.c
+++ b/c01.c
@@ -46,7 +46,7 @@ void build(op) int op; {
         * sizeof gets turned into a number here.
         */
        if (op==SIZEOF) {
-               struct cnode *p = cblock(length(/*p1*/p1->n_dtype));
+               struct cnode *p = cblock(XXXlength(p1));
                p->cn_type = UNSIGN;
                *cp++ = (struct node *)p;
                return;
@@ -603,16 +603,17 @@ void error0(s, va_alist) char *s; va_dcl
 #define pt (*(struct ptype **)&t)
   pt = (struct ptype *)Tblock(sizeof(struct ptype));
   pt->pt_id = PTR;
-  pt->pt_ptotype = newtype((type >> TYLEN & ~TYPE) | (type & TYPE), dimp, strp);
-  break;
+reft:
+
+  goto reft;
 #undef pt
  case FUNC:
   fprintf(stderr, "func(");
 #define ft (*(struct ftype **)&t)
   ft = (struct ftype *)Tblock(sizeof(struct ftype));
-  ft->ft_id = PTR;
-  ft->ft_rettype = newtype((type >> TYLEN & ~TYPE) | (type & TYPE), dimp, strp);
-  break;
+  ft->ft_id = FUNC;
+  ft->ft_arglist = NULL;
+  goto reft;
 #undef ft
  case ARRAY:
   if (*dimp)
@@ -623,9 +624,12 @@ void error0(s, va_alist) char *s; va_dcl
   at = (struct atype *)Tblock(sizeof(struct atype));
   at->at_id = PTR;
   at->at_nelt = *dimp ? *(*dimp)++ : 0;
-  at->at_elttype = newtype((type >> TYLEN & ~TYPE) | (type & TYPE), dimp, strp);
-  break;
 #undef at
+ reft:
+#define pt ((struct ptype *)t)
+  pt->pt_reftype = newtype((type >> TYLEN & ~TYPE) | (type & TYPE), dimp, strp);
+  break;
+#undef pt
  default:
   fprintf(stderr, "basic(%d", type);
   if (type == STRUCT) {
@@ -683,7 +687,7 @@ struct nnode *nblock(ds) register struct nmlist *ds; {
        p->nn_type = ds->nl_type;
        p->nn_subsp = ds->nl_subsp;
        p->nn_strp = ds->nl_strp;
- p->nn_dtype = ds->nl_dtype;
+ /*p->nn_dtype = ds->nl_dtype;*/
        p->nn_nmlist = ds;
        p->nn_class = ds->nl_class==0?STATIC:ds->nl_class;
        p->nn_regno = 0;
@@ -696,14 +700,14 @@ struct nnode *nblock(ds) register struct nmlist *ds; {
  */
 struct cnode *cblock(value) _INT value; {
        register struct cnode *p;
- static struct type t_int = {INT};
+ /*static struct type t_int = {INT};*/
 
        p = (struct cnode *)Tblock(sizeof(struct cnode));
        p->cn_op = CON;
        p->cn_type = INT;
        p->cn_subsp = NULL;
        p->cn_strp = NULL;
- p->cn_dtype = &t_int;
+ /*p->cn_dtype = &t_int;*/
        p->cn_value = value;
        return(p);
 }
@@ -713,14 +717,14 @@ struct cnode *cblock(value) _INT value; {
  */
 struct lnode *lblock(lvalue) _LONG lvalue; {
        register struct lnode *p;
- static struct type t_long = {LONG};
+ /*static struct type t_long = {LONG};*/
 
        p = (struct lnode *)Tblock(sizeof(struct lnode));
        p->ln_op = LCON;
        p->ln_type = LONG;
        p->ln_subsp = NULL;
        p->ln_strp = NULL;
- p->ln_dtype = &t_long;
+ /*p->ln_dtype = &t_long;*/
        p->ln_lvalue = lvalue;
        return(p);
 }
@@ -730,14 +734,14 @@ struct lnode *lblock(lvalue) _LONG lvalue; {
  */
 struct fnode *fblock(value, fvalue) int value; _DOUBLE fvalue; {
        register struct fnode *p;
- static struct type t_double = {DOUBLE};
+ /*static struct type t_double = {DOUBLE};*/
 
        p = (struct fnode *)Tblock(sizeof(struct fnode));
        p->fn_op = FCON;
        p->fn_type = DOUBLE;
        p->fn_subsp = NULL;
        p->fn_strp = NULL;
- p->fn_dtype = &t_double;
+ /*p->fn_dtype = &t_double;*/
        p->fn_value = value;
        p->fn_fvalue = fvalue;
        return(p);
diff --git a/c02.c b/c02.c
index 2578b6d..154b19a 100644 (file)
--- a/c02.c
+++ b/c02.c
@@ -50,7 +50,7 @@ void extdef() {
  /* create a fake local variable of same type as function's return type */
                                funcblk.locnn_type = decref0(ds->nl_type);
                                funcblk.locnn_strp = ds->nl_strp;
- funcblk.locnn_dtype = ds->nl_dtype;
+ /*funcblk.locnn_dtype = ds->nl_dtype;*/
                                setinit(ds);
                                outcode("BS", SYMDEF, sclass==EXTERN?ds->nl_name:"");
                                cfunc();
@@ -157,7 +157,7 @@ int cinit(anp, flex, sclass) struct nmlist *anp; int flex; int sclass; {
        if (isarray) {
                np.nl_type = decref0(realtype);
                np.nl_subsp++;
- np.nl_dtype = ((struct atype *)np.nl_dtype)->at_elttype;
+ np.nl_dtype = ((struct atype *)np.nl_dtype)->at_reftype;
                if (width==0 && flex==0)
                        error0("0-length row: %s", anp->nl_name);
                o = length(/*(struct node *)&np*/np.nl_dtype);
diff --git a/c03.c b/c03.c
index a417cf3..dbf0d83 100644 (file)
--- a/c03.c
+++ b/c03.c
@@ -352,7 +352,7 @@ static int oldtype(dtype, dimp, strp) struct type *dtype; struct tdim *dimp; str
  switch (dtype->t_id) {
  case PTR:
   /*fprintf(stderr, "ptr(");*/
-  type = oldtype(((struct ptype *)dtype)->pt_ptotype, dimp, strp);
+  type = oldtype(((struct ptype *)dtype)->pt_reftype, dimp, strp);
   if (type & BIGTYPE) {
    typov();
    type = 0;
@@ -361,7 +361,7 @@ static int oldtype(dtype, dimp, strp) struct type *dtype; struct tdim *dimp; str
   break;
  case FUNC:
   /*fprintf(stderr, "func(");*/
-  type = oldtype(((struct ftype *)dtype)->ft_rettype, dimp, strp);
+  type = oldtype(((struct ftype *)dtype)->ft_reftype, dimp, strp);
   if (type & BIGTYPE) {
    typov();
    type = 0;
@@ -375,7 +375,7 @@ static int oldtype(dtype, dimp, strp) struct type *dtype; struct tdim *dimp; str
    dimp->rank = 4;
   }
   dimp->dimens[dimp->rank++] = ((struct atype *)dtype)->at_nelt;
-  type = oldtype(((struct atype *)dtype)->at_elttype, dimp, strp);
+  type = oldtype(((struct atype *)dtype)->at_reftype, dimp, strp);
   if (type & BIGTYPE) {
    typov();
    type = 0;
@@ -761,7 +761,7 @@ syntax:
 }*/
 static struct type *getail(dtype, nullok) struct type *dtype; int *nullok; {
        static struct type argtype = {INT};
-       struct type *t;
+       struct ptype *pt;
        register int o;
        register struct nmlist *ds;
 
@@ -777,12 +777,11 @@ static struct type *getail(dtype, nullok) struct type *dtype; int *nullok; {
                } else
                        if ((o=symbol()) != RPARN)
                                goto syntax;
-#define ft (*(struct ftype **)&t)
+#define ft (*(struct ftype **)&pt)
                ft = (struct ftype *)Dblock(sizeof(struct ftype));
                ft->ft_id = FUNC;
-               ft->ft_rettype = getail(dtype, nullok);
                ft->ft_arglist = NULL;
-               return (struct type *)ft;
+               goto gett;
 #undef ft
 
        case LBRACK:
@@ -800,13 +799,14 @@ static struct type *getail(dtype, nullok) struct type *dtype; int *nullok; {
                        cval = 0;
                }
                *nullok = 0;
-#define at (*(struct atype **)&t)
+#define at (*(struct atype **)&pt)
                at = (struct atype *)Dblock(sizeof(struct atype));
                at->at_id = ARRAY;
                at->at_nelt = cval;
-               at->at_elttype = getail(dtype, nullok); /* destroys cval */
-               return (struct type *)at;
 #undef at
+       gett:
+               pt->pt_reftype = getail(dtype, nullok);
+               return (struct type *)pt;
 
        default:
                peeksym = o;
@@ -816,7 +816,6 @@ syntax:
        decsyn(o);
        return(NULL);
 }
-
 struct type *getype(dtype, nullok, anonok) struct type *dtype; int *nullok; int anonok; {
        struct type *t;
        register int o;
@@ -829,7 +828,7 @@ getp:
 #define pt (*(struct ptype **)&t)
                pt = (struct ptype *)Dblock(sizeof(struct ptype));
                pt->pt_id = PTR;
-               pt->pt_ptotype = dtype;
+               pt->pt_reftype = dtype;
                dtype = (struct type *)pt;
                goto getp;
 #undef pt
@@ -887,7 +886,7 @@ int align(type, offset, aflen) /*int*/struct type *type; int offset; int aflen;
  /*    while ((t&XTYPE)==ARRAY)
                t = decref0(t);*/
  while (t->t_id == ARRAY)
-  t = ((struct atype *)t)->at_elttype;
+  t = ((struct atype *)t)->at_reftype;
        if (/*t*/t->t_id!=CHAR && /*t*/t->t_id!=UNCHAR) {
                a = (a+ALIGN) & ~ALIGN;
                if (a>offset)
diff --git a/c04.c b/c04.c
index a26c9d0..ee1616c 100644 (file)
--- a/c04.c
+++ b/c04.c
@@ -197,7 +197,7 @@ void label0(l) int l; {
  * is some kind of pointer; return the size of the object
  * to which the pointer points.
  */
-static int XXXlength(cs) struct node *cs; {
+int XXXlength(cs) struct node *cs; {
        register int t, elsz;
        long n;
        int nd;
@@ -265,15 +265,6 @@ int plength(p) register struct node *p; {
        l = XXXlength(p);
        p->n_type = t;
        return(l);
- /*switch (p->t_id) {
- case PTR:
-  return length(((struct ptype *)p)->pt_ptotype);
- case FUNC:
-  return length(((struct ftype *)p)->ft_rettype);
- case ARRAY:
-  return length(((struct atype *)p)->at_elttype);
- }
- return 1;*/
 }
 
 /*
@@ -294,7 +285,7 @@ int length(cs) struct /*node*/type *cs; {
                n *= cs->n_subsp[nd++];
        }*/
  n = 1;
- for (t = cs; t->t_id == ARRAY; t = ((struct atype *)t)->at_elttype)
+ for (t = cs; t->t_id == ARRAY; t = ((struct atype *)t)->at_reftype)
   n *= ((struct atype *)t)->at_nelt;
        if (/*(t&~TYPE)*/t->t_id==FUNC)
                return(0);
diff --git a/ccom.h b/ccom.h
index 393b73f..c79d1fe 100644 (file)
--- a/ccom.h
+++ b/ccom.h
@@ -103,19 +103,19 @@ struct    stype {
 struct ptype {
        struct type pt_type;
 #define pt_id pt_type.t_id
-       struct type *pt_ptotype;        /* pointed-to type */
+       struct type *pt_reftype;        /* referenced type */
 };
 struct ftype {
-       struct type ft_type;
-#define ft_id ft_type.t_id
-       struct type *ft_rettype;        /* return type */
+       struct ptype ft_ptype;
+#define ft_id ft_ptype.pt_id
+#define ft_reftype ft_ptype.pt_reftype
        struct nmlist **ft_arglist;     /* argument list */
 };
 struct atype {
-       struct type at_type;
-#define at_id at_type.t_id
+       struct ptype at_ptype;
+#define at_id at_ptype.pt_id
+#define at_reftype at_ptype.pt_reftype
        int     at_nelt;                /* number of elements */
-       struct type *at_elttype;        /* element type */
 };
 
 /*
@@ -128,7 +128,7 @@ struct      node {
        int     *n_subsp;       /* subscript list for arrays; pass 0 only */
        union   str *n_strp;    /* structure descr for structs; pass 0 only */
  /* to here */
-       struct  type *n_dtype;          /* detailed type */
+       /*struct        type *n_dtype;*/                /* detailed type */
 };
 
 struct tnode {
@@ -137,7 +137,7 @@ struct      tnode {
 #define tn_type tn_node.n_type
 #define tn_subsp tn_node.n_subsp
 #define tn_strp tn_node.n_strp
-#define tn_dtype tn_node.n_dtype
+/*#define tn_dtype tn_node.n_dtype*/
        struct  node *tn_tr1;
        struct  node *tn_tr2;
        int     tn_degree;              /* pass 1 only */
@@ -152,7 +152,7 @@ struct      nnode {
 #define nn_type nn_node.n_type
 #define nn_subsp nn_node.n_subsp
 #define nn_strp nn_node.n_strp
-#define nn_dtype nn_node.n_dtype
+/*#define nn_dtype nn_node.n_dtype*/
        struct  nmlist *nn_nmlist;      /* pass 0 only */
        char    nn_class;               /* pass 1 only */
        char    nn_regno;               /* pass 1 only */
@@ -174,7 +174,7 @@ struct      locnnode {
 #define locnn_type locnn_nnode.nn_type
 #define locnn_subsp locnn_nnode.nn_subsp
 #define locnn_strp locnn_nnode.nn_strp
-#define locnn_dtype locnn_nnode.nn_dtype
+/*#define locnn_dtype locnn_nnode.nn_dtype*/
 #define locnn_nmlist locnn_nnode.nn_nmlist
 #define locnn_class locnn_nnode.nn_class
 #define locnn_regno locnn_nnode.nn_regno
@@ -195,7 +195,7 @@ struct      extnnode {
 #define extnn_type extnn_nnode.nn_type
 #define extnn_subsp extnn_nnode.nn_subsp
 #define extnn_strp extnn_nnode.nn_strp
-#define extnn_dtype extnn_nnode.nn_dtype
+/*#define extnn_dtype extnn_nnode.nn_dtype*/
 #define extnn_nmlist extnn_nnode.nn_nmlist
 #define extnn_class extnn_nnode.nn_class
 #define extnn_regno extnn_nnode.nn_regno
@@ -212,7 +212,7 @@ struct      cnode {
 #define cn_type cn_node.n_type
 #define cn_subsp cn_node.n_subsp
 #define cn_strp cn_node.n_strp
-#define cn_dtype cn_node.n_dtype
+/*#define cn_dtype cn_node.n_dtype*/
        _INT    cn_value;
 };
 
@@ -225,7 +225,7 @@ struct      lnode {
 #define ln_type ln_node.n_type
 #define ln_subsp ln_node.n_subsp
 #define ln_strp ln_node.n_strp
-#define ln_dtype ln_node.n_dtype
+/*#define ln_dtype ln_node.n_dtype*/
        _LONG   ln_lvalue;
 };
 
@@ -238,7 +238,7 @@ struct      fnode {
 #define fn_type fn_cnode.cn_type
 #define fn_subsp fn_cnode.cn_subsp
 #define fn_strp fn_cnode.cn_strp
-#define fn_dtype fn_cnode.cn_dtype
+/*#define fn_dtype fn_cnode.cn_dtype*/
 #define fn_value fn_cnode.cn_value
        _DOUBLE fn_fvalue;
 };
@@ -252,7 +252,7 @@ struct      fasgn {
 #define fa_type fa_tnode.tn_type
 #define fa_subsp fa_tnode.tn_subsp
 #define fa_strp fa_tnode.tn_strp
-#define fa_dtype fa_tnode.tn_dtype
+/*#define fa_dtype fa_tnode.tn_dtype*/
 #define fa_tr1 fa_tnode.tn_tr1
 #define fa_tr2 fa_tnode.tn_tr2
 #define fa_degree fa_tnode.tn_degree