1: # include "mfile1"
   2: 
   3: struct instk {
   4:     int in_sz;   /* size of array element */
   5:     int in_x;    /* current index for structure member in structure initializations */
   6:     int in_n;    /* number of initializations seen */
   7:     int in_s;    /* sizoff */
   8:     int in_d;    /* dimoff */
   9:     TWORD in_t;    /* type */
  10:     int in_id;   /* stab index */
  11:     int in_fl;   /* flag which says if this level is controlled by {} */
  12:     OFFSZ in_off;  /* offset of the beginning of this level */
  13:     }
  14: instack[10],
  15: *pstk;
  16: 
  17:     /* defines used for getting things off of the initialization stack */
  18: 
  19: 
  20: struct symtab *relook();
  21: 
  22: 
  23: extern ddebug;
  24: 
  25: defid( q, class )  NODE *q; {
  26:     register struct symtab *p;
  27:     int idp;
  28:     TWORD type;
  29:     TWORD stp;
  30:     int scl;
  31:     int dsym, ddef;
  32:     int slev, temp;
  33: 
  34:     if( q == NIL ) return;  /* an error was detected */
  35: 
  36:     if( q < node || q >= &node[TREESZ] ) cerror( "defid call" );
  37: 
  38:     idp = q->rval;
  39: 
  40:     if( idp < 0 ) cerror( "tyreduce" );
  41:     p = &stab[idp];
  42: 
  43:     if( ddebug ){
  44:         printf( "defid( %.8s (%d), ", p->sname, idp );
  45:         tprint( q->type );
  46:         printf( ", %s, (%d,%d) ), level %d\n", scnames(class), q->cdim, q->csiz, blevel );
  47:         }
  48: 
  49:     fixtype( q, class );
  50: 
  51:     type = q->type;
  52:     class = fixclass( class, type );
  53: 
  54:     stp = p->stype;
  55:     slev = p->slevel;
  56: 
  57:     if( ddebug ){
  58:         printf( "	modified to " );
  59:         tprint( type );
  60:         printf( ", %s\n", scnames(class) );
  61:         printf( "	previous def'n: " );
  62:         tprint( stp );
  63:         printf( ", %s, (%d,%d) ), level %d\n", scnames(p->sclass), p->dimoff, p->sizoff, slev );
  64:         }
  65: 
  66:     if( stp == UNDEF|| stp == FARG ){
  67:         if( blevel==1 && stp!=FARG ) switch( class ){
  68: 
  69:         default:
  70:             if(!(class&FIELD)) uerror( "declared argument %.8s is missing", p->sname );
  71:         case MOS:
  72:         case STNAME:
  73:         case MOU:
  74:         case UNAME:
  75:         case MOE:
  76:         case ENAME:
  77:         case TYPEDEF:
  78:             ;
  79:             }
  80:         goto enter;
  81:         }
  82:     if( type != stp ) goto mismatch;
  83:     /* test (and possibly adjust) dimensions */
  84:     dsym = p->dimoff;
  85:     ddef = q->cdim;
  86:     for( temp=type; temp&TMASK; temp = DECREF(temp) ){
  87:         if( ISARY(temp) ){
  88:             if( dimtab[dsym] == 0 ) dimtab[dsym] = dimtab[ddef];
  89:             else if( dimtab[ddef]!=0 && dimtab[dsym] != dimtab[ddef] ){
  90:                 goto mismatch;
  91:                 }
  92:             ++dsym;
  93:             ++ddef;
  94:             }
  95:         }
  96: 
  97:     /* check that redeclarations are to the same structure */
  98:     if( (temp==STRTY||temp==UNIONTY||temp==ENUMTY) && p->sizoff != q->csiz && (type&TMASK) ) {
  99:         goto mismatch;
 100:         }
 101: 
 102:     scl = ( p->sclass );
 103: 
 104:     if( ddebug ){
 105:         printf( "	previous class: %s\n", scnames(scl) );
 106:         }
 107: 
 108:     if( class&FIELD ){
 109:         /* redefinition */
 110:         if( !falloc( p, class&FLDSIZ, 1, NIL ) ) {
 111:             /* successful allocation */
 112:             psave( idp );
 113:             return;
 114:             }
 115:         /* blew it: resume at end of switch... */
 116:         }
 117: 
 118:     else switch( class ){
 119: 
 120:     case EXTERN:
 121:         switch( scl ){
 122:         case STATIC:
 123:         case USTATIC:
 124:             if( slev==0 ) return;
 125:             break;
 126:         case EXTDEF:
 127:         case EXTERN:
 128:         case FORTRAN:
 129:         case UFORTRAN:
 130:             return;
 131:             }
 132:         break;
 133: 
 134:     case STATIC:
 135:         if( scl==USTATIC || (scl==EXTERN && blevel==0) ){
 136:             p->sclass = STATIC;
 137:             if( ISFTN(type) ) curftn = idp;
 138:             return;
 139:             }
 140:         break;
 141: 
 142:     case USTATIC:
 143:         if( scl==STATIC || scl==USTATIC ) return;
 144:         break;
 145: 
 146:     case LABEL:
 147:         if( scl == ULABEL ){
 148:             p->sclass = LABEL;
 149:             deflab( p->offset );
 150:             return;
 151:             }
 152:         break;
 153: 
 154:     case TYPEDEF:
 155:         if( scl == class ) return;
 156:         break;
 157: 
 158:     case UFORTRAN:
 159:         if( scl == UFORTRAN || scl == FORTRAN ) return;
 160:         break;
 161: 
 162:     case FORTRAN:
 163:         if( scl == UFORTRAN ){
 164:             p->sclass = FORTRAN;
 165:             if( ISFTN(type) ) curftn = idp;
 166:             return;
 167:             }
 168:         break;
 169: 
 170:     case MOU:
 171:     case MOS:
 172:         if( scl == class ) {
 173:             if( oalloc( p, &strucoff ) ) break;
 174:             if( class == MOU ) strucoff = 0;
 175:             psave( idp );
 176:             return;
 177:             }
 178:         break;
 179: 
 180:     case MOE:
 181:         if( scl == class ){
 182:             if( p->offset!= strucoff++ ) break;
 183:             psave( idp );
 184:             }
 185:         break;
 186: 
 187:     case EXTDEF:
 188:         if( scl == EXTERN ) {
 189:             p->sclass = EXTDEF;
 190:             if( ISFTN(type) ) curftn = idp;
 191:             return;
 192:             }
 193:         break;
 194: 
 195:     case STNAME:
 196:     case UNAME:
 197:     case ENAME:
 198:         if( scl != class ) break;
 199:         if( dimtab[p->sizoff] == 0 ) return;  /* previous entry just a mention */
 200:         break;
 201: 
 202:     case ULABEL:
 203:         if( scl == LABEL || scl == ULABEL ) return;
 204:     case PARAM:
 205:     case AUTO:
 206:     case REGISTER:
 207:         ;  /* mismatch.. */
 208: 
 209:         }
 210: 
 211:     mismatch:
 212:     if( blevel > slev && class != EXTERN && class != FORTRAN &&
 213:         class != UFORTRAN && !( class == LABEL && slev >= 2 ) ){
 214:         q->rval = idp = hide( p );
 215:         p = &stab[idp];
 216:         goto enter;
 217:         }
 218:     uerror( "redeclaration of %.8s", p->sname );
 219:     if( class==EXTDEF && ISFTN(type) ) curftn = idp;
 220:     return;
 221: 
 222:     enter:  /* make a new entry */
 223: 
 224:     if( ddebug ) printf( "	new entry made\n" );
 225:     p->stype = type;
 226:     p->sclass = class;
 227:     p->slevel = blevel;
 228:     p->offset = NOOFFSET;
 229:     p->suse = lineno;
 230:     if( class == STNAME || class == UNAME || class == ENAME ) {
 231:         p->sizoff = curdim;
 232:         dstash( 0 );  /* size */
 233:         dstash( -1 ); /* index to members of str or union */
 234:         dstash( ALSTRUCT );  /* alignment */
 235:         }
 236:     else {
 237:         switch( BTYPE(type) ){
 238:         case STRTY:
 239:         case UNIONTY:
 240:         case ENUMTY:
 241:             p->sizoff = q->csiz;
 242:             break;
 243:         default:
 244:             p->sizoff = BTYPE(type);
 245:             }
 246:         }
 247: 
 248:     /* copy dimensions */
 249: 
 250:     p->dimoff = q->cdim;
 251: 
 252:     /* allocate offsets */
 253:     if( class&FIELD ){
 254:         falloc( p, class&FLDSIZ, 0, NIL );  /* new entry */
 255:         psave( idp );
 256:         }
 257:     else switch( class ){
 258: 
 259:     case AUTO:
 260:         oalloc( p, &autooff );
 261:         break;
 262:     case STATIC:
 263:     case EXTDEF:
 264:         p->offset = getlab();
 265:         if( ISFTN(type) ) curftn = idp;
 266:         break;
 267:     case ULABEL:
 268:     case LABEL:
 269:         p->offset = getlab();
 270:         p->slevel = 2;
 271:         if( class == LABEL ){
 272:             locctr( PROG );
 273:             deflab( p->offset );
 274:             }
 275:         break;
 276: 
 277:     case EXTERN:
 278:     case UFORTRAN:
 279:     case FORTRAN:
 280:         p->offset = getlab();
 281:         p->slevel = 0;
 282:         break;
 283:     case MOU:
 284:     case MOS:
 285:         oalloc( p, &strucoff );
 286:         if( class == MOU ) strucoff = 0;
 287:         psave( idp );
 288:         break;
 289: 
 290:     case MOE:
 291:         p->offset = strucoff++;
 292:         psave( idp );
 293:         break;
 294:     case REGISTER:
 295:         p->offset = regvar--;
 296:         if( blevel == 1 ) p->sflags |= SSET;
 297:         if( regvar < minrvar ) minrvar = regvar;
 298:         break;
 299:         }
 300: 
 301:     /* user-supplied routine to fix up new definitions */
 302: 
 303:     FIXDEF(p);
 304: 
 305:     if( ddebug ) printf( "	dimoff, sizoff, offset: %d, %d, %d\n", p->dimoff, p->sizoff, p->offset );
 306: 
 307:     }

Defined functions

defid defined in line 25; never used

Defined variables

instack defined in line 14; never used
pstk defined in line 15; never used

Defined struct's

instk defined in line 3; never used
Last modified: 1982-08-28
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 850
Valid CSS Valid XHTML 1.0 Strict