1 /*- 2 * Copyright (c) 1980, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 static char sccsid[] = "@(#)case.c 8.1 (Berkeley) 06/06/93"; 10 #endif /* not lint */ 11 12 /* 13 * pxp - Pascal execution profiler 14 * 15 * Bill Joy UCB 16 * Version 1.2 January 1979 17 */ 18 19 #include "0.h" 20 #include "tree.h" 21 22 /* 23 * Case statement 24 * r [0] T_CASE 25 * [1] lineof "case" 26 * [2] expression 27 * [3] list of cased statements: 28 * cstat [0] T_CSTAT 29 * [1] lineof ":" 30 * [2] list of constant labels 31 * [3] statement 32 */ 33 caseop(r) 34 int *r; 35 { 36 register *cl, *cs, i; 37 struct pxcnt scnt; 38 # ifdef RMOTHERS 39 int *othersp; /* tree where others is, or NIL */ 40 int hasothers; /* 1 if others found, else 0 */ 41 # endif RMOTHERS 42 43 # ifdef RMOTHERS 44 if (rmothers) { 45 hasothers = needscaseguard(r,&othersp); 46 if (hasothers) { 47 precaseguard(r); 48 } 49 } 50 # endif RMOTHERS 51 savecnt(&scnt); 52 ppkw("case"); 53 ppspac(); 54 rvalue(r[2], NIL); 55 ppspac(); 56 ppkw("of"); 57 for (cl = r[3]; cl != NIL;) { 58 cs = cl[1]; 59 if (cs == NIL) 60 continue; 61 baroff(); 62 ppgoin(DECL); 63 setline(cs[1]); 64 ppnl(); 65 indent(); 66 ppbra(NIL); 67 cs = cs[2]; 68 if (cs != NIL) { 69 i = 0; 70 for (;;) { 71 gconst(cs[1]); 72 cs = cs[2]; 73 if (cs == NIL) 74 break; 75 i++; 76 if (i == 7) { 77 ppsep(","); 78 ppitem(); 79 i = 0; 80 } else 81 ppsep(", "); 82 } 83 } else 84 ppid("{case label list}"); 85 ppket(":"); 86 cs = cl[1]; 87 cs = cs[3]; 88 getcnt(); 89 ppgoin(STAT); 90 if (cs != NIL && cs[0] == T_BLOCK) { 91 ppnl(); 92 indent(); 93 baron(); 94 ppstbl1(cs, STAT); 95 baroff(); 96 ppstbl2(); 97 baron(); 98 } else { 99 baron(); 100 statement(cs); 101 } 102 ppgoout(STAT); 103 ppgoout(DECL); 104 cl = cl[2]; 105 if (cl == NIL) 106 break; 107 ppsep(";"); 108 } 109 if (rescnt(&scnt)) 110 getcnt(); 111 ppnl(); 112 indent(); 113 ppkw("end"); 114 # ifdef RMOTHERS 115 if (rmothers) { 116 if (hasothers) { 117 postcaseguard(othersp); 118 } 119 } 120 # endif RMOTHERS 121 } 122