1: #ifndef lint
   2: static char sccsid[] = "@(#)4.out.c	4.1	(Berkeley)	2/11/83";
   3: #endif not lint
   4: 
   5: #include <stdio.h>
   6: #include "def.h"
   7: #include "4.def.h"
   8: #include "3.def.h"
   9: 
  10: outrat(v,tab,tabfirst)
  11: VERT v;
  12: int tab;        /* number of tabs to indent */
  13: LOGICAL tabfirst;   /* FALSE if doing IF of ELSE IF */
  14:     {
  15:     LOGICAL ndcomma;
  16:     VERT w;
  17:     int type,i;
  18:     type = NTYPE(v);
  19:     if (hascom[type])
  20:         prcom(v);
  21:     if (!LABEL(v) && type == FMTVX)
  22:         {
  23:         OUTSTR("#following unreferenced format statement commented out\n");
  24:         OUTSTR("#");
  25:         }
  26:     if (LABEL(v) && type != ITERVX)
  27:         {
  28:         ASSERT(tabfirst, outrat);
  29:         prlab(LABEL(v),tab);
  30:         }
  31:     else if (tabfirst && type != DUMVX && type != ITERVX)
  32:         TABOVER(tab);
  33: 
  34:     switch(type)
  35:         {
  36:         case DUMVX:
  37:             newlevel(v,0,tab,YESTAB);
  38:             break;
  39:         case GOVX:
  40:             OUTSTR("go to ");
  41:             OUTNUM(LABEL(ARC(v,0)));
  42:             OUTSTR("\n");
  43:             break;
  44:         case STOPVX:
  45:             if (progtype != blockdata)
  46:                 OUTSTR("stop\n");
  47:             break;
  48:         case RETVX:
  49:             OUTSTR("return\n");
  50:             break;
  51:         case BRKVX:
  52:             if (!levbrk)
  53:                 {
  54:                 ASSERT(LEVEL(v) == 1,outrat);
  55:                 OUTSTR("break\n");
  56:                 }
  57:             else
  58:                 {
  59:                 OUTSTR("break ");
  60:                 OUTNUM(LEVEL(v));
  61:                 OUTSTR("\n");
  62:                 }
  63:             break;
  64:         case NXTVX:
  65:             if (!levnxt)
  66:                 {
  67:                 ASSERT(LEVEL(v) == 1,outrat);
  68:                 OUTSTR("next\n");
  69:                 }
  70:             else
  71:                 {
  72:                 OUTSTR("next ");
  73:                 OUTNUM(LEVEL(v));
  74:                 OUTSTR("\n");
  75:                 }
  76:             break;
  77:         case ASGOVX:
  78:         case COMPVX:
  79:             OUTSTR("goto ");
  80:             if (type == ASGOVX)
  81:                 {
  82:                 OUTSTR(EXP(v));
  83:                 OUTSTR(",");
  84:                 }
  85:             OUTSTR("(");
  86:             for (i = ARCNUM(v)-1; i >=0; --i)       /* arcs were stored backward */
  87:                 {
  88:                 OUTNUM(LABEL(ARC(v,i)));
  89:                 if (i > 0) OUTSTR(",");
  90:                 }
  91:             OUTSTR(")");
  92:             if (type == COMPVX)
  93:                 {
  94:                 OUTSTR(",");
  95:                 OUTSTR(EXP(v));
  96:                 }
  97:             OUTSTR("\n");
  98:             break;
  99:         case ASVX:
 100:             OUTSTR("assign ");
 101:             OUTNUM(LABEL(LABREF(v)));
 102:             OUTSTR(" to ");
 103:             OUTSTR(EXP(v));
 104:             OUTSTR("\n");
 105:             break;
 106:         case IFVX:
 107:             OUTSTR("IF");
 108:             prpred(v,TRUE);
 109:             if (IFTHEN(v))
 110:                 newlevel(v,THEN,tab+1,YESTAB);
 111:             else
 112:                 {
 113:                 newlevel(v,THEN,tab+1,YESTAB);
 114:                 TABOVER(tab);
 115:                 OUTSTR("ELSE ");
 116:                 w = LCHILD(v,ELSE);
 117:                 ASSERT(DEFINED(w),outrat);
 118:                 if (NTYPE(w) == IFVX && !LABEL(w) && !DEFINED(RSIB(w)) &&
 119:                     !HASBRACE(v,ELSE) )
 120:                     newlevel(v,ELSE,tab,NOTAB);
 121:                 else
 122:                     newlevel(v,ELSE,tab+1,YESTAB);
 123:                 }
 124:             break;
 125:         case ITERVX:
 126:             newlevel(v,0,tab,YESTAB);
 127:             ASSERT(DEFINED(NXT(v)),outrat);
 128:             if (LABEL(NXT(v)))
 129:                 {
 130:                 prlab(LABEL(NXT(v)),tab);
 131:                 OUTSTR("continue\n");
 132:                 }
 133:             break;
 134:         case DOVX:
 135:             OUTSTR("DO ");
 136:             OUTSTR(INC(v));
 137:             newlevel(v,0,tab+1,YESTAB);
 138:             break;
 139:         case LOOPVX:
 140:         case UNTVX:
 141:             OUTSTR("REPEAT");
 142:             newlevel(v,0,tab+1,YESTAB);
 143:             if (type == UNTVX)
 144:                 {
 145:                 TABOVER(tab+1);
 146:                 OUTSTR("UNTIL");
 147:                 ASSERT(DEFINED(ARC(v,0)),outrat);
 148:                 prpred(LPRED(ARC(v,0)),TRUE);
 149:                 OUTSTR("\n");
 150:                 }
 151:             break;
 152:         case WHIVX:
 153:             OUTSTR("WHILE");
 154:             ASSERT(DEFINED(ARC(v,0)),outrat);
 155:             ASSERT(DEFINED(LPRED(ARC(v,0))),outrat);
 156:             prpred(LPRED(ARC(v,0)),TRUE);
 157:             newlevel(v,0,tab+1,YESTAB);
 158:             break;
 159:         case STLNVX:
 160:         case FMTVX:
 161:             prstln(v,tab);
 162:             break;
 163:         case SWCHVX:
 164:                 OUTSTR("SWITCH");
 165:                 if (DEFINED(EXP(v)))
 166:                     {
 167:                     OUTSTR("(");
 168:                     OUTSTR(EXP(v));
 169:                     OUTSTR(")");
 170:                     }
 171:                 newlevel(v,0,tab+1,YESTAB);
 172:                 break;
 173:         case ICASVX:
 174:         case ACASVX:
 175:             OUTSTR("CASE ");
 176:             if (type == ACASVX)
 177:                 prpred(v,FALSE);
 178:             else
 179:                 OUTSTR(EXP(v));
 180:             OUTSTR(":\n");
 181:             newlevel(v,0,tab+1,YESTAB);
 182:             if (type == ACASVX &&DEFINED(LCHILD(v,ELSE)))
 183:                 {
 184:                 TABOVER(tab);
 185:                 OUTSTR("DEFAULT:\n");
 186:                 newlevel(v,1,tab+1,YESTAB);
 187:                 }
 188:             break;
 189:         case IOVX:
 190:             OUTSTR(PRERW(v));
 191:             ndcomma = FALSE;
 192:             if (DEFINED(FMTREF(v)))
 193:                 {
 194:                 OUTNUM(LABEL(FMTREF(v)));
 195:                 ndcomma = TRUE;
 196:                 }
 197:             if (DEFINED(ARC(v,ENDEQ)))
 198:                 {
 199:                 if (ndcomma)
 200:                     OUTSTR(",");
 201:                 OUTSTR("end = ");
 202:                 OUTNUM(LABEL(ARC(v,ENDEQ)));
 203:                 ndcomma = TRUE;
 204:                 }
 205:             if (DEFINED(ARC(v,ERREQ)))
 206:                 {
 207:                 if (ndcomma)
 208:                     OUTSTR(",");
 209:                 OUTSTR("err = ");
 210:                 OUTNUM(LABEL(ARC(v,ERREQ)));
 211:                 ndcomma = TRUE;
 212:                 }
 213:             OUTSTR(POSTRW(v));
 214:             OUTSTR("\n");
 215:             break;
 216:         }
 217:     }
 218: 
 219: 
 220: newlevel(v,ch,tab,tabfirst)
 221: VERT v;
 222: int ch;     /* number of lchild of v being processed */
 223: int tab;        /* number of tabs to indent */
 224: LOGICAL tabfirst;   /* same as for outrat */
 225:     {
 226:     LOGICAL addbrace;
 227:     VERT w;
 228:     if (NTYPE(v) == ACASVX || NTYPE(v) == ICASVX)
 229:         addbrace = FALSE;
 230:     else
 231:         addbrace = HASBRACE(v,ch);
 232:     ASSERT(tabfirst || !addbrace,newlevel);
 233:     if (addbrace)
 234:         OUTSTR(" {");
 235:     if(tabfirst && NTYPE(v)!=ITERVX && NTYPE(v)!=DUMVX) OUTSTR("\n");
 236:     for (w = LCHILD(v,ch); DEFINED(w); w = RSIB(w))
 237:         outrat(w,tab,tabfirst);
 238:     if (addbrace)
 239:         {
 240:         TABOVER(tab);
 241:         OUTSTR("}\n");
 242:         }
 243:     }
 244: 
 245: 
 246: 
 247: 
 248: 
 249: prpred(v,addpar)
 250: VERT v;
 251: LOGICAL addpar;
 252:     {
 253:     if (addpar)
 254:         OUTSTR("(");
 255:     if (NEG(v)) OUTSTR("!(");
 256:     OUTSTR(PRED(v));
 257:     if (NEG(v)) OUTSTR(")");
 258:     if (addpar)
 259:         OUTSTR(")");
 260:     }
 261: 
 262: prlab(n,tab)
 263: int n,tab;
 264:     {
 265:     TABOVER(tab);
 266:     OUTSTR("~");
 267:     OUTNUM(n);
 268:     OUTSTR(" ");
 269:     }
 270: 
 271: prstln(v,tab)
 272: VERT v;
 273: int tab;
 274:     {
 275:     ASSERT(NTYPE(v) == STLNVX || NTYPE(v) == FMTVX,prstln);
 276:     if (!ONDISK(v))
 277:         {
 278:         OUTSTR(BEGCODE(v));
 279:         OUTSTR("\n");
 280:         }
 281:     else
 282:         {
 283:         empseek(BEGCODE(v));
 284:         prcode(ONDISK(v),tab);
 285:         }
 286:     }
 287: 
 288: prcom(v)
 289: VERT v;
 290:     {
 291:     if (DEFINED(BEGCOM(v)))
 292:         {
 293:         empseek(BEGCOM(v));
 294:         comprint();
 295:         }
 296:     }

Defined functions

newlevel defined in line 220; used 13 times
outrat defined in line 10; used 10 times
prcom defined in line 288; used 1 times
  • in line 20
prlab defined in line 262; used 2 times
prpred defined in line 249; used 4 times
prstln defined in line 271; used 2 times

Defined variables

sccsid defined in line 2; never used
Last modified: 1987-02-17
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2714
Valid CSS Valid XHTML 1.0 Strict