Remove old types from struct nmlist altogether, just convert to old type when copying...
authorNick Downing <downing.nick@gmail.com>
Thu, 16 Feb 2017 03:01:42 +0000 (14:01 +1100)
committerNick Downing <downing.nick@gmail.com>
Thu, 16 Feb 2017 03:01:42 +0000 (14:01 +1100)
c0.h
c00.c
c01.c
c02.c
c03.c
c04.c
ccom.h

diff --git a/c0.h b/c0.h
index 503171b..15f263f 100644 (file)
--- a/c0.h
+++ b/c0.h
@@ -253,6 +253,7 @@ int declist __P((int sclass));
 /*int*/struct type *getkeywords __P((int *scptr/*, struct nmlist *tptr*/));
 /*union str*/struct stype *strdec __P((int mosf, int kind));
 int declare __P((int askw, struct /*nmlist*/type *tptr, int offset));
+int XXXoldtype __P((struct type *dtype, struct tdim *dimp, struct SS **strp));
 int decl1 __P((int askw, struct /*nmlist*/type *atptr, int offset, struct nmlist *absname));
 struct nmlist *pushdecl __P((register struct nmlist *sp));
 /*int getype __P((register struct tdim *dimp, struct nmlist *absname));*/
diff --git a/c00.c b/c00.c
index 0068fab..299a78f 100644 (file)
--- a/c00.c
+++ b/c00.c
@@ -154,10 +154,10 @@ int lookup() {
        rp->nl_nextnm = hshtab[ihash];
        hshtab[ihash] = rp;
        rp->nl_class = 0;
-       rp->nl_type = 0;
+ /*    rp->nl_type = 0;*/
        rp->nl_offset = 0;
      rp->nl_subsp = NULL;
-       rp->nl_strp = NULL;
/*    rp->nl_subsp = NULL;
+       rp->nl_strp = NULL;*/
  rp->nl_dtype = NULL;
        rp->nl_sparent = NULL;
        rp->nl_blklev = blklev;
@@ -636,6 +636,10 @@ struct node *tree(/*eflag*/) /*int eflag;*/ {
        int p, ps, os, xo = 0, *xop;
        /*char *svtree;*/
        static struct cnode garbage = { { CON, INT, (int *)NULL, (union str *)NULL}, 0 };
+ static struct type t_int = {INT};
+ static struct ftype t_func_int = {{{FUNC}, &t_int}, (struct nmlist **)NULL};
+ static struct type t_char = {CHAR};
+ static struct type t_unchar = {UNCHAR};
 
        /*svtree = starttree();*/
        op = opst;
@@ -655,11 +659,12 @@ advanc:
                        *cp++ = (struct node *)cblock(cs->nl_offset);
                        goto tand;
                }
-               if (cs->nl_class==0 && cs->nl_type==0)
+               if (cs->nl_class==0 && /*cs->nl_type==0*/cs->nl_dtype==NULL)
                        if(nextchar()=='(') {
                                /* set function */
                                cs->nl_class = EXTERN;
-                               cs->nl_type = FUNC;
+ /*                            cs->nl_type = FUNC;*/
+ cs->nl_dtype = (struct type *)&t_func_int;
                        } else {
                                cs->nl_class = STATIC;
                                error0("%s undefined; func. %s", cs->nl_name,
@@ -716,9 +721,13 @@ advanc:
                *cp++ = block(NAME, unscflg? ARRAY+UNCHAR:ARRAY+CHAR, &nchstr,
                  (union str *)NULL, (struct node *)cs, (struct node *)NULL);*/
                cs->nl_flag = 0;
              cs->nl_type = unscflg? ARRAY+UNCHAR:ARRAY+CHAR;
/*            cs->nl_type = unscflg? ARRAY+UNCHAR:ARRAY+CHAR;
                cs->nl_subsp = &nchstr;
-               cs->nl_strp = (union str *)NULL;
+               cs->nl_strp = (union str *)NULL;*/
+ cs->nl_dtype = (struct type *)Tblock(sizeof(struct atype));
+ ((struct atype *)cs->nl_dtype)->at_id = REF | ARRAY;
+ ((struct atype *)cs->nl_dtype)->at_reftype = unscflg ? &t_unchar : &t_char;
+ ((struct atype *)cs->nl_dtype)->at_nelt = nchstr;
                cs->nl_offset = cval;
                cs->nl_nextnm = 0;
                cs->nl_sparent = 0;
@@ -921,6 +930,10 @@ struct tnode *xprtype() {
        int sc;
        register struct node **scp;
  struct type *dtype;
+ struct tdim dim;
+ int type;
+ union str *strp;
+ int *subsp, a;
 
        scp = cp;
        sc = DEFXTRN;           /* will cause error if class mentioned */
@@ -928,14 +941,19 @@ struct tnode *xprtype() {
  dtype = getkeywords(&sc);
        absname.nl_class = 0;
        absname.nl_blklev = blklev;
      absname.nl_subsp = NULL;
/*    absname.nl_subsp = NULL;
        absname.nl_strp = NULL;
-       absname.nl_type = 0;
+       absname.nl_type = 0;*/
  absname.nl_dtype = NULL;
        decl1(sc, /*&typer*/dtype, 0, &absname);
        cp = scp;
-       return(block(ETYPE, absname.nl_type, absname.nl_subsp,
-          absname.nl_strp, (struct node *)NULL, (struct node *)NULL));
+ dim.rank = 0;
+ type = XXXoldtype(absname.nl_dtype, &dim, (struct SS **)&strp);
+ subsp = dim.rank ? (int *)Tblock(dim.rank*sizeof(dim.rank)) : NULL;
+ for (a=0; a<dim.rank; a++)
+  subsp[a] = dim.dimens[a];
+       return(block(ETYPE, /*absname.nl_*/type, /*absname.nl_*/subsp,
+          /*absname.nl_*/strp, (struct node *)NULL, (struct node *)NULL));
 }
 
 /*char *copnum(len) int len; {
diff --git a/c01.c b/c01.c
index f588ed3..e360eb7 100644 (file)
--- a/c01.c
+++ b/c01.c
@@ -155,7 +155,6 @@ void build(op) int op; {
 
        case AMPER:
                if (p1->n_op==NAME || p1->n_op==STAR) {
- /*fprintf(stderr, "amper %p type %x strp %p\n", p1, p1->n_type, p1->n_strp);*/
                        *cp++ = (struct node *)block(op,incref0(p1->n_type),p1->n_subsp,p1->n_strp,p1,(struct node *)NULL);
                        return;
                }
@@ -389,18 +388,34 @@ void build(op) int op; {
        }
 }
 
+int XXXeqtype(struct type *t0, struct type *t1) {
+ while (t0->t_id == t1->t_id) {
+  if ((t0->t_id & TYPE) != REF)
+   return 1;
+  t0 = ((struct rtype *)t0)->rt_reftype;
+  t1 = ((struct rtype *)t1)->rt_reftype;
+ }
+ return 0;
+}
 void structident(p1, p2) register struct node *p1; register struct nnode *p2; {
        register struct nmlist *np, *nporig;
        int vartypes = 0, namesame = 1;
+ struct tdim dim;
+ int a;
 
  /*fprintf(stderr, "structident %p op %d type %x strp %p field %s\n", p1, p1->n_op, p1->n_type, p1->n_strp, p2->nn_nmlist->nl_name);*/
        np = nporig = p2->nn_nmlist;
        for (;;) {
                if (namesame && p1->n_type==STRUCT+PTR && p1->n_strp == np->nl_sparent) {
  /*fprintf(stderr, "found %p type %x strp %p\n", np, np->nl_type, np->nl_strp);*/
                      p2->nn_type = np->nl_type;
/*                    p2->nn_type = np->nl_type;
                        p2->nn_strp = np->nl_strp;
-                       p2->nn_subsp = np->nl_subsp;
+                       p2->nn_subsp = np->nl_subsp;*/
+ dim.rank = 0;
+ p2->nn_type = XXXoldtype(np->nl_dtype, &dim, (struct SS **)&p2->nn_strp);
+ p2->nn_subsp = dim.rank ? (int *)Tblock(dim.rank*sizeof(dim.rank)) : NULL;
+ for (a=0; a<dim.rank; a++)
+  p2->nn_subsp[a] = dim.dimens[a];
                        p2->nn_nmlist = np;
                        return;
                }
@@ -413,7 +428,7 @@ void structident(p1, p2) register struct node *p1; register struct nnode *p2; {
                if ((nporig->nl_flag&FKIND) != (np->nl_flag&FMOS))
                        continue;
                namesame = 1;
-               if (nporig->nl_type==np->nl_type && nporig->nl_offset==np->nl_offset)
+               if (/*nporig->nl_type==np->nl_type*/XXXeqtype(nporig->nl_dtype, np->nl_dtype) && nporig->nl_offset==np->nl_offset)
                        continue;
                vartypes++;
        }
@@ -559,6 +574,7 @@ void werror0(s, va_alist) char *s; va_dcl
        vfprintf(stderr, s, argp);
        va_end(argp);
        fprintf(stderr, "\n");
+ abort();
 }
 
 #ifdef __STDC__
@@ -577,6 +593,7 @@ void error0(s, va_alist) char *s; va_dcl
        vfprintf(stderr, s, argp);
        va_end(argp);
        fprintf(stderr, "\n");
+ abort();
 }
 
 /*
@@ -671,6 +688,8 @@ struct tnode *block(op, t, subs, str, p1, p2) int op; int t; int *subs; union st
 struct nnode *nblock(ds) register struct nmlist *ds; {
  /*    return(block(NAME, ds->nl_type, ds->nl_subsp, ds->nl_strp, (struct node *)ds, (struct node *)NULL));*/
        struct nnode *p;
+ struct tdim dim;
+ int a;
 
        if (ds->nl_class == EXTERN) {
 #define extp (*(struct extnnode **)&p)
@@ -688,10 +707,14 @@ struct nnode *nblock(ds) register struct nmlist *ds; {
        }
  /*fprintf(stderr, "nblock %p name %s type %x strp %p\n", p, ds->nl_name, ds->nl_type, ds->nl_strp);*/
        p->nn_op = NAME;
      p->nn_type = ds->nl_type;
/*    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_strp = ds->nl_strp;*/
+ dim.rank = 0;
+ p->nn_type = XXXoldtype(ds->nl_dtype, &dim, (struct SS **)&p->nn_strp);
+ p->nn_subsp = dim.rank ? (int *)Tblock(dim.rank*sizeof(dim.rank)) : NULL;
+ for (a=0; a<dim.rank; a++)
+  p->nn_subsp[a] = dim.dimens[a];
        p->nn_nmlist = ds;
        p->nn_class = ds->nl_class==0?STATIC:ds->nl_class;
        p->nn_regno = 0;
@@ -1075,10 +1098,10 @@ struct nmlist *gentemp(type) int type; {
 
        tp = (struct nmlist *)Tblock(sizeof(struct nmlist));
        tp->nl_class = AUTO;
-       tp->nl_type = type;
+ /*    tp->nl_type = type;*/
        tp->nl_flag = 0;
      tp->nl_subsp = NULL;
-       tp->nl_strp = NULL;
/*    tp->nl_subsp = NULL;
+       tp->nl_strp = NULL;*/
  tp->nl_dtype = basic_types + type;
        tp->nl_blklev = blklev;
        autolen -= rlength(/*(struct node *)tp*/tp->nl_dtype);
diff --git a/c02.c b/c02.c
index f9208fc..0242c63 100644 (file)
--- a/c02.c
+++ b/c02.c
@@ -14,6 +14,8 @@ void extdef() {
  /*    struct nmlist typer;*/
  struct type *dtype;
        register struct nmlist *ds;
+ struct tdim dim;
+ int a;
 
        if(((o=symbol())==EOFC) || o==SEMI)
                return;
@@ -48,9 +50,13 @@ void extdef() {
                        if ((peeksym=symbol())==LBRACE || peeksym==KEYW
                         || (peeksym==NAME && csym->nl_class==TYPEDEF)) {
  /* 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_type = decref0(ds->nl_type);
+                               funcblk.locnn_strp = ds->nl_strp;*/
+ dim.rank = 0;
+ funcblk.locnn_type = XXXoldtype(((struct ftype *)ds->nl_dtype)->ft_reftype, &dim, (struct SS **)&funcblk.locnn_strp);
+ funcblk.locnn_subsp = dim.rank ? (int *)Tblock(dim.rank*sizeof(dim.rank)) : NULL;
+ for (a=0; a<dim.rank; a++)
+  funcblk.locnn_subsp[a] = dim.dimens[a];
                                setinit(ds);
                                outcode("BS", SYMDEF, sclass==EXTERN?ds->nl_name:"");
                                cfunc();
@@ -134,13 +140,18 @@ void cfunc() {
 int cinit(anp, flex, sclass) struct nmlist *anp; int flex; int sclass; {
        struct nmlist np;
        register int nel, ninit;
-       int width, isarray, o, brace, realtype;
+       int width, isarray, o, brace/*, realtype*/;
+ struct type *realtype;
        struct node *s;
+ struct tdim dim;
+ int type;
+ union str *strp;
+ int *subsp, a;
 
        np = *anp;
-       realtype = np.nl_type;
+       realtype = /*np.nl_type*/np.nl_dtype;
        isarray = 0;
-       if ((realtype&XTYPE) == ARRAY)
+       if (/*(realtype&XTYPE) == ARRAY*/realtype->t_id == (REF | ARRAY))
                isarray++;
        else
                flex = 0;
@@ -152,12 +163,12 @@ int cinit(anp, flex, sclass) struct nmlist *anp; int flex; int sclass; {
         * an array of.
         */
        if (sclass==AUTO)
-               if (isarray || realtype==STRUCT)
+               if (isarray || /*realtype*/realtype->t_id==STRUCT)
                        error0("No auto. aggregate initialization");
        if (isarray) {
              np.nl_type = decref0(realtype);
-               np.nl_subsp++;
- np.nl_dtype = ((struct atype *)np.nl_dtype)->at_reftype;
/*            np.nl_type = decref0(realtype);
+               np.nl_subsp++;*/
+ np.nl_dtype = ((struct atype *)realtype)->at_reftype;
                if (width==0 && flex==0)
                        error0("0-length row: %s", anp->nl_name);
                o = length(/*(struct node *)&np*/np.nl_dtype);
@@ -165,7 +176,7 @@ int cinit(anp, flex, sclass) struct nmlist *anp; int flex; int sclass; {
                width = o;
        }
        brace = 0;
-       if ((peeksym=symbol())==LBRACE && (isarray || np.nl_type!=STRUCT)) {
+       if ((peeksym=symbol())==LBRACE && (isarray || /*np.nl_type*/np.nl_dtype->t_id!=STRUCT)) {
                peeksym = -1;
                brace++;
        }
@@ -174,7 +185,7 @@ int cinit(anp, flex, sclass) struct nmlist *anp; int flex; int sclass; {
                if ((o=symbol())==RBRACE)
                        break;
                peeksym = o;
-               if (o==STRING && (realtype==ARRAY+CHAR || realtype==ARRAY+UNCHAR)) {
+               if (o==STRING && /*(realtype==ARRAY+CHAR || realtype==ARRAY+UNCHAR)*/realtype->t_id == (REF | ARRAY) && (((struct atype *)realtype)->at_reftype->t_id == CHAR || ((struct atype *)realtype)->at_reftype->t_id == UNCHAR)) {
                        if (sclass==AUTO)
                                error0("No strings in automatic");
                        peeksym = -1;
@@ -182,9 +193,9 @@ int cinit(anp, flex, sclass) struct nmlist *anp; int flex; int sclass; {
                        ninit += nchstr;
                        o = symbol();
                        break;
-               } else if (np.nl_type==STRUCT) {
+               } else if (/*np.nl_type*/np.nl_dtype->t_id==STRUCT) {
                        strinit(&np, sclass);
-               } else if ((np.nl_type&ARRAY)==ARRAY || peeksym==LBRACE)
+               } else if (/*(np.nl_type&ARRAY)==ARRAY*/np.nl_dtype->t_id==(REF|ARRAY) || peeksym==LBRACE)
                        cinit(&np, 0, sclass);
                else {
                        char *st;
@@ -204,8 +215,15 @@ int cinit(anp, flex, sclass) struct nmlist *anp; int flex; int sclass; {
                                        error0("Illegal enum constant for %s", anp->nl_name);
                                anp->nl_offset = ((struct cnode *)s)->cn_value;
                        } else
-                               rcexpr0((struct node *)block(INIT,np.nl_type,(int *)NULL,
-                                 (union str *)NULL, ((struct tnode *)(*--cp))->tn_tr2, (struct node *)NULL));
+ {
+  dim.rank = 0;
+  type = XXXoldtype(np.nl_dtype, &dim, (struct SS **)&strp);
+  subsp = dim.rank ? (int *)Tblock(dim.rank*sizeof(dim.rank)) : NULL;
+  for (a=0; a<dim.rank; a++)
+   subsp[a] = dim.dimens[a];
+                               rcexpr0((struct node *)block(INIT,/*np.nl_type*/type,/*(int *)NULL*/subsp,
+                                 /*(union str *)NULL*/strp, ((struct tnode *)(*--cp))->tn_tr2, (struct node *)NULL));
+ }
                        endtree(st);
                }
                ninit++;
@@ -224,7 +242,15 @@ int cinit(anp, flex, sclass) struct nmlist *anp; int flex; int sclass; {
                outcode("BN", SSPACE, (nel-ninit)*width);
        else if (ninit>nel) {
                if (flex && nel==0) {
-                       np.nl_subsp[-1] = ninit;
+ /* note: nel==0 implies isarray, since otherwise nel must be 1 */
+ /*                    np.nl_subsp[-1] = ninit;*/
+#define arealtype (*(struct atype **)&realtype)
+ arealtype = (struct atype *)Dblock(sizeof(struct atype));
+ arealtype->at_id = REF | ARRAY;
+ arealtype->at_reftype = np.nl_dtype;
+ arealtype->at_nelt = ninit;
+ anp->nl_dtype = (struct type *)arealtype;
+#undef arealtype
                } else
                        error0("Too many initializers: %s", anp->nl_name);
                nel = ninit;
@@ -236,12 +262,13 @@ int cinit(anp, flex, sclass) struct nmlist *anp; int flex; int sclass; {
  * Initialize a structure
  */
 void strinit(np, sclass) struct nmlist *np; int sclass; {
-       static struct nmlist junk;
+ /*    static*/ struct nmlist junk;
+ static struct type t_int = {INT};
        register struct nmlist **mlp;
        static struct nmlist *zerloc = NULL;
        register int o, brace;
 
-       if ((mlp = np->nl_strp->S.memlist)==NULL) {
+       if ((mlp = /*np->nl_strp->S.memlist*/((struct stype *)np->nl_dtype)->st_memlist)==NULL) {
                mlp = &zerloc;
                error0("Undefined structure initialization");
        }
@@ -255,6 +282,9 @@ void strinit(np, sclass) struct nmlist *np; int sclass; {
                        break;
                peeksym = o;
                if (*mlp==0) {
+ /* change this to a static struct nmlist later when nmlist has stabilized */
+ bzero(&junk, sizeof(struct nmlist));
+ junk.nl_dtype = &t_int;
                        error0("Too many structure initializers");
                        cinit(&junk, 0, sclass);
                } else
@@ -272,7 +302,7 @@ void strinit(np, sclass) struct nmlist *np; int sclass; {
        } while ((o=symbol())==COMMA && (*mlp || brace));
        if (sclass!=AUTO && sclass!=REG) {
                if (*mlp)
-                       outcode("BN", SSPACE, np->nl_strp->S.ssize - (*mlp)->nl_offset);
+                       outcode("BN", SSPACE, /*np->nl_strp->S.ssize*/((struct stype *)np->nl_dtype)->st_ssize - (*mlp)->nl_offset);
                outcode("B", EVEN);
        }
        if (o!=RBRACE || brace==0)
@@ -292,6 +322,7 @@ void setinit(np) register struct nmlist *np; {
 /*
  * Process one statement in a function.
  */
+struct type gototype = {0}; /* dummy type distinguished by its address */
 void statement() {
        register int o, o1;
        int sauto, sreg;
@@ -543,7 +574,8 @@ stmt:
                                }
                        }
                        np->nl_class = STATIC;
-                       np->nl_type = ARRAY;
+ /*                    np->nl_type = ARRAY;*/
+ np->nl_dtype = &gototype;
                        np->nl_flag |= FLABL;
                        if (np->nl_offset==0)
                                np->nl_offset = isn0++;
@@ -688,32 +720,45 @@ void pswitch0() {
 /*
  * Structure resembling a block for a register variable.
  */
-struct nmlist  hreg    = { REG, 0, 0, NULL, NULL, 0 };
+struct nmlist  hreg    = { REG, 0, /*0, (int *)NULL, (union str *)NULL,*/ (struct type *)NULL, 0/*nl_offset*/ }; /* note: remaining fields not initialized */
 struct locnnode areg   = { { { NAME, 0, (int *)NULL, (union str *)NULL }, &hreg, 0/*nn_class*/, 0/*nn_regno*/, 0/*nn_offset*/}, 0/*locnn_nloc*/ };
 void funchead() {
        register int pl;
        register struct nmlist *cs;
        register char *st;
+ static struct type t_double = {DOUBLE};
+ struct tdim dim;
+ int a;
 
        pl = STARG;
        while(paraml) {
                parame->nl_sparent = NULL;
                cs = paraml;
                paraml = &paraml->nl_sparent->P;
-               if (cs->nl_type==FLOAT)
-                       cs->nl_type = DOUBLE;
+               if (cs->/*nl_type*/nl_dtype->t_id==FLOAT)
+                       cs->/*nl_type*/nl_dtype = /*DOUBLE*/&t_double;
                cs->nl_offset = pl;
-               if ((cs->nl_type&XTYPE) == ARRAY) {
-                       cs->nl_type -= (ARRAY-PTR);     /* set ptr */
-                       cs->nl_subsp++;         /* pop dims */
+               if (/*(cs->nl_type&XTYPE) == ARRAY*/cs->nl_dtype->t_id == (REF | ARRAY)) {
+/*                     cs->nl_type -= (ARRAY-PTR);     *//* set ptr *//*
+                       cs->nl_subsp++;*/               /* pop dims */
+ struct rtype *rt = (struct rtype *)Dblock(sizeof(struct rtype));
+ rt->rt_id = REF | PTR;
+ rt->rt_reftype = ((struct rtype *)cs->nl_dtype)->rt_reftype;
+ cs->nl_dtype = (struct type *)rt;
                }
                pl += rlength(/*(struct node *)cs*/cs->nl_dtype);
                if (cs->nl_class==AREG && (hreg.nl_offset=goodreg(cs))>=0) {
+ hreg.nl_dtype = cs->nl_dtype; /* probably not necessary, but be safe */
                        st = starttree();
                        *cp++ = (struct node *)&areg;
                        *cp++ = (struct node *)nblock(cs);
-                       areg.locnn_type = cs->nl_type;
-                       areg.locnn_strp = cs->nl_strp;
+ /*                    areg.locnn_type = cs->nl_type;
+                       areg.locnn_strp = cs->nl_strp;*/
+ dim.rank = 0;
+ areg.locnn_type = XXXoldtype(cs->nl_dtype, &dim, (struct SS **)&areg.locnn_strp);
+ areg.locnn_subsp = dim.rank ? (int *)Tblock(dim.rank*sizeof(dim.rank)) : NULL;
+ for (a=0; a<dim.rank; a++)
+  areg.locnn_subsp[a] = dim.dimens[a];
                        cs->nl_class = AUTO;
                        build(ASSIGN);
                        rcexpr0(*--cp);
diff --git a/c03.c b/c03.c
index 6654800..06434e5 100644 (file)
--- a/c03.c
+++ b/c03.c
@@ -66,8 +66,8 @@ int declist(sclass) int sclass; {
                if (o==NAME && csym->nl_class==TYPEDEF) {
                        if (tkw >= 0)
                                error0("type clash");
                      tkw = csym->nl_type;
/*                    tptr->nl_subsp = csym->nl_subsp;
/*                    tkw = csym->nl_type;
                      tptr->nl_subsp = csym->nl_subsp;
                        tptr->nl_strp = csym->nl_strp;*/
  dtype = csym->nl_dtype;
                        isadecl++;
@@ -219,7 +219,7 @@ int declist(sclass) int sclass; {
  stype->st_id = STRUCT;
                        /*ssym->nl_strp->S.ssize*/stype->st_ssize = 0;
                        /*ssym->nl_strp->S.memlist*/stype->st_memlist = NULL;
- ssym->nl_strp = (union str *)&stype->st_S;
+ /*ssym->nl_strp = (union str *)&stype->st_S;*/
  ssym->nl_dtype = (struct type *)stype;
                }
  /*            strp = ssym->nl_strp;*/
@@ -317,9 +317,10 @@ int declare(askw, tptr, offset) int askw; struct /*nmlist*/type *tptr; int offse
                if (skw == MOS) {
                        abs.nl_class = 0;
                        abs.nl_flag = 0;
                      abs.nl_type = 0;
/*                    abs.nl_type = 0;
                        abs.nl_subsp = 0;
-                       abs.nl_strp = 0;
+                       abs.nl_strp = 0;*/
+ abs.nl_dtype = NULL;
                        abs.nl_nextnm = 0;
                        abs.nl_sparent = 0;
                        abs.nl_blklev = blklev;
@@ -348,12 +349,12 @@ int declare(askw, tptr, offset) int askw; struct /*nmlist*/type *tptr; int offse
  * Process a single declarator
  */
 /* convert detailed type description to old type description */
-static int oldtype(dtype, dimp, strp) struct type *dtype; struct tdim *dimp; struct SS **strp; {
+int XXXoldtype(dtype, dimp, strp) struct type *dtype; struct tdim *dimp; struct SS **strp; {
  int type;
  switch (dtype->t_id) {
  case REF | PTR:
   /*fprintf(stderr, "ptr(");*/
-  type = oldtype(((struct rtype *)dtype)->rt_reftype, dimp, strp);
+  type = XXXoldtype(((struct rtype *)dtype)->rt_reftype, dimp, strp);
   if (type & BIGTYPE) {
    typov();
    type = 0;
@@ -362,7 +363,7 @@ static int oldtype(dtype, dimp, strp) struct type *dtype; struct tdim *dimp; str
   break;
  case REF | FUNC:
   /*fprintf(stderr, "func(");*/
-  type = oldtype(((struct ftype *)dtype)->ft_reftype, dimp, strp);
+  type = XXXoldtype(((struct ftype *)dtype)->ft_reftype, dimp, strp);
   if (type & BIGTYPE) {
    typov();
    type = 0;
@@ -376,7 +377,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_reftype, dimp, strp);
+  type = XXXoldtype(((struct atype *)dtype)->at_reftype, dimp, strp);
   if (type & BIGTYPE) {
    typov();
    type = 0;
@@ -384,13 +385,20 @@ static int oldtype(dtype, dimp, strp) struct type *dtype; struct tdim *dimp; str
   type = (type & TYPE) | (type & ~TYPE) << TYLEN | ARRAY;
   break;
  case STRUCT:
+  /*fprintf(stderr, "struct(%d", dtype->t_id);*/
   *strp = &((struct stype *)dtype)->st_S;
   goto got_strp;
+ case BITFLD:
+  /*fprintf(stderr, "bitfld(%d", dtype->t_id);*/
+  *strp = NULL;
+  type = UNSIGN;
+  break;
  default:
+  /*fprintf(stderr, "basic(%d", dtype->t_id);*/
   *strp = NULL;
  got_strp:
-  /*fprintf(stderr, "basic(%d", dtype->t_id);*/
   type = dtype->t_id;
+  break;
  }
  /*fprintf(stderr, ")", type);*/
  return type;
@@ -402,7 +410,7 @@ int decl1(askw, atptr, offset, absname) int askw; struct /*nmlist*/type *atptr;
  /*    int type;*/
        register struct nmlist *dsym;
        register struct /*nmlist*/type *tptr;
-       struct tdim dim;
+ /*    struct tdim dim;*/
  /*struct SS *strp;
        int *dp;*/
        int isinit;
@@ -571,16 +579,12 @@ int decl1(askw, atptr, offset, absname) int askw; struct /*nmlist*/type *atptr;
  }
  else
   dsym->nl_dtype = dtype;
- /* XXX this is only for compatibility */
- dim.rank = 0;
- /*fprintf(stderr, "oldtype ");*/
- dsym->nl_type = oldtype(dtype, &dim, &dsym->nl_strp);
- /*fprintf(stderr, "\n");*/
+ /*dim.rank = 0;
+ dsym->nl_type = XXXoldtype(dtype, &dim, (struct SS **)&dsym->nl_strp);
  if (dim.rank && dsym->nl_subsp == 0)
   dsym->nl_subsp = (int *)Dblock(dim.rank*sizeof(dim.rank));
  for (a=0; a<dim.rank; a++)
-  dsym->nl_subsp[a] = dim.dimens[a];
- /* XXX to here */
+  dsym->nl_subsp[a] = dim.dimens[a];*/
        if (skw==TYPEDEF) {
                dsym->nl_class = TYPEDEF;
                return(0);
@@ -617,7 +621,7 @@ int decl1(askw, atptr, offset, absname) int askw; struct /*nmlist*/type *atptr;
  bdtype->bt_id = BITFLD;
  bdtype->bt_flen = t1;
  bdtype->bt_bitoffs = bitoffs;
- dsym->nl_strp = (union str *)&bdtype->bt_F;
+ /*dsym->nl_strp = (union str *)&bdtype->bt_F;*/
  dsym->nl_dtype = (struct type *)bdtype;
 #undef bdtype
                        }
@@ -710,12 +714,12 @@ struct nmlist *pushdecl(sp) register struct nmlist *sp; {
        *nsp = *sp;
        nsp->nl_class = 0;
        nsp->nl_flag &= FKIND;
-       nsp->nl_type = 0;
+ /*    nsp->nl_type = 0;*/
  nsp->nl_dtype = NULL;
        nsp->nl_offset = 0;
        nsp->nl_blklev = blklev;
      nsp->nl_strp = NULL;
-       nsp->nl_subsp = NULL;
/*    nsp->nl_strp = NULL;
+       nsp->nl_subsp = NULL;*/
        nsp->nl_sparent = NULL;
        hsp = &hshtab[hash(sp->nl_name)];
        nsp->nl_nextnm = *hsp;
@@ -983,7 +987,6 @@ void decsyn(o) int o; {
  */
 void redec() {
        error0("%s redeclared", defsym->nl_name);
- abort();
 }
 
 /*
@@ -991,11 +994,13 @@ void redec() {
  * a register; if so return the register number
  */
 int goodreg(hp) struct nmlist *hp; {
-       int type;
+ /*    int type;*/
+ struct type *dtype;
 
-       type = hp->nl_type;
-       if ((type!=INT && type!=UNSIGN && (type&XTYPE)==0)
-        || (type&XTYPE)>PTR || regvar<3)
+ /*    type = hp->nl_type;*/
+ dtype = hp->nl_dtype;
+       if ((/*type*/dtype->t_id!=INT && /*type*/dtype->t_id!=UNSIGN && /*(type&XTYPE)==0*/dtype->t_id!=(REF|PTR))
+        || /*(type&XTYPE)>PTR ||*/ regvar<3)
                return(-1);
        return(--regvar);
 }
diff --git a/c04.c b/c04.c
index f06de54..ff1031b 100644 (file)
--- a/c04.c
+++ b/c04.c
@@ -349,6 +349,7 @@ int rlength(cs) struct /*node*/type *cs; {
  * After an "if (...) goto", look to see if the transfer
  * is to a simple label.
  */
+extern struct type gototype; /* dummy type distinguished by its address */
 int simplegoto() {
        register struct nmlist *csp;
 
@@ -356,14 +357,15 @@ int simplegoto() {
                csp = csym;
                if (csp->nl_blklev == 0)
                        csp = pushdecl(csp);
-               if (csp->nl_class==0 && csp->nl_type==0) {
-                       csp->nl_type = ARRAY;
+               if (csp->nl_class==0 && csp->/*nl_type==0*/nl_dtype==NULL) {
+ /*                    csp->nl_type = ARRAY;*/
+ csp->nl_dtype = &gototype;
                        csp->nl_flag |= FLABL;
                        if (csp->nl_offset==0)
                                csp->nl_offset = isn0++;
                }
                if ((csp->nl_class==0||csp->nl_class==STATIC)
-                &&  csp->nl_type==ARRAY) {
+                &&  /*csp->nl_type==ARRAY*/csp->nl_dtype==&gototype) {
                        peeksym = -1;
                        return(csp->nl_offset);
                }
diff --git a/ccom.h b/ccom.h
index 9f5b8a9..e37119b 100644 (file)
--- a/ccom.h
+++ b/ccom.h
@@ -32,11 +32,13 @@ struct nmlist {
  /* nl_type, nl_subsp fields, because of length(), rlength() computations */
        char    nl_class;               /* storage class */
        char    nl_flag;                /* various flags */
+#if 0
  /* note: these will be phased out in favour of nl_dtype: */
        int     nl_type;                /* type */
        int     *nl_subsp;              /* subscript list */
        union   str *nl_strp;           /* structure description */
  /* to here */
+#endif
        struct  type *nl_dtype;         /* detailed type */
        int     nl_offset;              /* post-allocation location */
        struct  nmlist *nl_nextnm;      /* next name in chain */