1 static char *sccsid = "@(#)case.c 1.2 (Berkeley) 05/12/83"; 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 /* 15 * Case statement 16 * r [0] T_CASE 17 * [1] lineof "case" 18 * [2] expression 19 * [3] list of cased statements: 20 * cstat [0] T_CSTAT 21 * [1] lineof ":" 22 * [2] list of constant labels 23 * [3] statement 24 */ 25 caseop(r) 26 int *r; 27 { 28 register *cl, *cs, i; 29 struct pxcnt scnt; 30 # ifdef RMOTHERS 31 int *othersp; /* tree where others is, or NIL */ 32 int hasothers; /* 1 if others found, else 0 */ 33 # endif RMOTHERS 34 35 # ifdef RMOTHERS 36 if (rmothers) { 37 hasothers = needscaseguard(r,&othersp); 38 if (hasothers) { 39 precaseguard(r); 40 } 41 } 42 # endif RMOTHERS 43 savecnt(&scnt); 44 ppkw("case"); 45 ppspac(); 46 rvalue(r[2], NIL); 47 ppspac(); 48 ppkw("of"); 49 for (cl = r[3]; cl != NIL;) { 50 cs = cl[1]; 51 if (cs == NIL) 52 continue; 53 baroff(); 54 ppgoin(DECL); 55 setline(cs[1]); 56 ppnl(); 57 indent(); 58 ppbra(NIL); 59 cs = cs[2]; 60 if (cs != NIL) { 61 i = 0; 62 for (;;) { 63 gconst(cs[1]); 64 cs = cs[2]; 65 if (cs == NIL) 66 break; 67 i++; 68 if (i == 7) { 69 ppsep(","); 70 ppitem(); 71 i = 0; 72 } else 73 ppsep(", "); 74 } 75 } else 76 ppid("{case label list}"); 77 ppket(":"); 78 cs = cl[1]; 79 cs = cs[3]; 80 getcnt(); 81 ppgoin(STAT); 82 if (cs != NIL && cs[0] == T_BLOCK) { 83 ppnl(); 84 indent(); 85 baron(); 86 ppstbl1(cs, STAT); 87 baroff(); 88 ppstbl2(); 89 baron(); 90 } else { 91 baron(); 92 statement(cs); 93 } 94 ppgoout(STAT); 95 ppgoout(DECL); 96 cl = cl[2]; 97 if (cl == NIL) 98 break; 99 ppsep(";"); 100 } 101 if (rescnt(&scnt)) 102 getcnt(); 103 ppnl(); 104 indent(); 105 ppkw("end"); 106 # ifdef RMOTHERS 107 if (rmothers) { 108 if (hasothers) { 109 postcaseguard(othersp); 110 } 111 } 112 # endif RMOTHERS 113 } 114