1 static char *sccsid = "@(#)type.c 1.1 (Berkeley) 03/02/81"; 2 /* Copyright (c) 1979 Regents of the University of California */ 3 # 4 /* 5 * pxp - Pascal execution profiler 6 * 7 * Bill Joy UCB 8 * Version 1.2 January 1979 9 */ 10 11 #include "0.h" 12 #include "tree.h" 13 14 STATIC int typecnt -1; 15 /* 16 * Type declaration part 17 */ 18 typebeg(l, tline) 19 int l, tline; 20 { 21 22 line = l; 23 if (nodecl) 24 printoff(); 25 puthedr(); 26 putcm(); 27 ppnl(); 28 indent(); 29 ppkw("type"); 30 ppgoin(DECL); 31 typecnt = 0; 32 setline(tline); 33 } 34 35 type(tline, tid, tdecl) 36 int tline; 37 char *tid; 38 int *tdecl; 39 { 40 41 if (typecnt) 42 putcm(); 43 setline(tline); 44 ppitem(); 45 ppid(tid); 46 ppsep(" ="); 47 gtype(tdecl); 48 ppsep(";"); 49 setinfo(tline); 50 putcml(); 51 typecnt++; 52 } 53 54 typeend() 55 { 56 57 if (typecnt == -1) 58 return; 59 if (typecnt == 0) 60 ppid("{type decls}"); 61 ppgoout(DECL); 62 typecnt = -1; 63 } 64 65 /* 66 * A single type declaration 67 */ 68 gtype(r) 69 register int *r; 70 { 71 72 if (r == NIL) { 73 ppid("{type}"); 74 return; 75 } 76 if (r[0] != T_ID && r[0] != T_TYPACK) 77 setline(r[1]); 78 switch (r[0]) { 79 default: 80 panic("type"); 81 case T_ID: 82 ppspac(); 83 ppid(r[1]); 84 return; 85 case T_TYID: 86 ppspac(); 87 ppid(r[2]); 88 break; 89 case T_TYSCAL: 90 ppspac(); 91 tyscal(r); 92 break; 93 case T_TYRANG: 94 ppspac(); 95 tyrang(r); 96 break; 97 case T_TYPTR: 98 ppspac(); 99 ppop("^"); 100 gtype(r[2]); 101 break; 102 case T_TYPACK: 103 ppspac(); 104 ppkw("packed"); 105 gtype(r[2]); 106 break; 107 case T_TYARY: 108 ppspac(); 109 tyary(r); 110 break; 111 case T_TYREC: 112 ppspac(); 113 tyrec(r[2], NIL); 114 break; 115 case T_TYFILE: 116 ppspac(); 117 ppkw("file"); 118 ppspac(); 119 ppkw("of"); 120 gtype(r[2]); 121 break; 122 case T_TYSET: 123 ppspac(); 124 ppkw("set"); 125 ppspac(); 126 ppkw("of"); 127 gtype(r[2]); 128 break; 129 } 130 setline(r[1]); 131 putcml(); 132 } 133 134 /* 135 * Scalar type declaration 136 */ 137 tyscal(r) 138 register int *r; 139 { 140 register int i; 141 142 ppsep("("); 143 r = r[2]; 144 if (r != NIL) { 145 i = 0; 146 ppgoin(DECL); 147 for (;;) { 148 ppid(r[1]); 149 r = r[2]; 150 if (r == NIL) 151 break; 152 ppsep(", "); 153 i++; 154 if (i == 7) { 155 ppitem(); 156 i = 0; 157 } 158 } 159 ppgoout(DECL); 160 } else 161 ppid("{constant list}"); 162 ppsep(")"); 163 } 164 165 /* 166 * Subrange type declaration 167 */ 168 tyrang(r) 169 register int *r; 170 { 171 172 gconst(r[2]); 173 ppsep(".."); 174 gconst(r[3]); 175 } 176 177 /* 178 * Array type declaration 179 */ 180 tyary(r) 181 register int *r; 182 { 183 register int *tl; 184 185 ppkw("array"); 186 ppspac(); 187 ppsep("["); 188 tl = r[2]; 189 if (tl != NIL) { 190 ppunspac(); 191 for (;;) { 192 gtype(tl[1]); 193 tl = tl[2]; 194 if (tl == NIL) 195 break; 196 ppsep(","); 197 } 198 } else 199 ppid("{subscr list}"); 200 ppsep("]"); 201 ppspac(); 202 ppkw("of"); 203 gtype(r[3]); 204 } 205