[2f22cc4] | 1 | // |
---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo |
---|
| 3 | // |
---|
| 4 | // The contents of this file are covered under the licence agreement in the |
---|
| 5 | // file "LICENCE" distributed with Cforall. |
---|
| 6 | // |
---|
[dc8511c] | 7 | // labelledExit.cfa -- |
---|
[2f22cc4] | 8 | // |
---|
| 9 | // Author : Peter A. Buhr |
---|
| 10 | // Created On : Wed Aug 10 07:29:39 2016 |
---|
| 11 | // Last Modified By : Peter A. Buhr |
---|
[53692b3] | 12 | // Last Modified On : Sat Jun 5 10:07:34 2021 |
---|
| 13 | // Update Count : 13 |
---|
[2f22cc4] | 14 | // |
---|
| 15 | |
---|
[10dc7491] | 16 | int foo() { |
---|
[62edde5] | 17 | int i; |
---|
| 18 | int x, y; |
---|
| 19 | |
---|
| 20 | x = 0; y = 0; |
---|
| 21 | |
---|
| 22 | // block, labelled exits |
---|
| 23 | |
---|
| 24 | Block: { |
---|
| 25 | if ( x == y ) { |
---|
| 26 | for ( ; i < y; ) { |
---|
| 27 | y += 1; |
---|
| 28 | if ( y < 10 ) break Block; |
---|
| 29 | } |
---|
| 30 | } |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | // loops, labelled exits |
---|
| 34 | |
---|
| 35 | w1: while ( y == 10 ); |
---|
| 36 | |
---|
| 37 | w2: while ( x < 10 ) { |
---|
| 38 | while (y < 5 ) { |
---|
| 39 | if ( y == 3 ) break w2; |
---|
| 40 | } |
---|
| 41 | x += 1; |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | A: for ( i = 0; i < 10; i += 1 ) { |
---|
| 45 | B: for ( i = 0; i < 10; i += 1 ) { |
---|
| 46 | C: for ( i = 0; i < 10; i += 1 ) { |
---|
| 47 | goto A; |
---|
| 48 | goto B; |
---|
| 49 | goto C; |
---|
| 50 | continue A; |
---|
| 51 | continue B; |
---|
| 52 | continue C; |
---|
| 53 | continue; |
---|
| 54 | break A; |
---|
| 55 | break B; |
---|
| 56 | break C; |
---|
| 57 | break; |
---|
| 58 | } |
---|
| 59 | } |
---|
| 60 | } |
---|
| 61 | |
---|
[adb6b30f] | 62 | D: for () { |
---|
[62edde5] | 63 | break D; |
---|
| 64 | continue D; |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | Z : i += 1; |
---|
| 68 | goto Z; |
---|
[adb6b30f] | 69 | X: Y: for () { |
---|
[62edde5] | 70 | i += 1; |
---|
| 71 | if ( i > 5 ) continue X; |
---|
| 72 | if ( i < 5 ) break X; |
---|
| 73 | if ( i < 5 ) break Y; |
---|
| 74 | break; |
---|
| 75 | } |
---|
[adb6b30f] | 76 | XX: for () { |
---|
| 77 | YY: for () { |
---|
| 78 | ZZ: for () { |
---|
[62edde5] | 79 | i += 1; |
---|
| 80 | if ( i > 5 ) continue XX; |
---|
| 81 | if ( i < 5 ) continue YY; |
---|
| 82 | if ( i < 5 ) continue ZZ; |
---|
| 83 | if ( i > 5 ) break XX; |
---|
| 84 | if ( i < 5 ) break YY; |
---|
| 85 | if ( i < 5 ) break ZZ; |
---|
| 86 | break; |
---|
| 87 | } |
---|
| 88 | } |
---|
| 89 | } |
---|
| 90 | |
---|
[adb6b30f] | 91 | for () ; |
---|
[62edde5] | 92 | for ( int i = 0 ;; ) ; |
---|
| 93 | for ( ; i < 0; ) ; |
---|
| 94 | for ( ; ; i += 1 ) ; |
---|
| 95 | L0: L1: L2: L3: L4: L5: L6: L7: L8: L9: |
---|
| 96 | L10: L11: L12: L13: L14: L15: L16: L17: L18: L19: |
---|
| 97 | L20: L21: L22: L23: L24: L25: L26: L27: L28: L29: |
---|
| 98 | L31: L32: L33: L34: |
---|
[adb6b30f] | 99 | for () { |
---|
[62edde5] | 100 | break L0; |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | // switch/choose, labelled exits |
---|
| 104 | |
---|
| 105 | Switch: switch ( i ) { |
---|
| 106 | default: |
---|
| 107 | i += 1; |
---|
| 108 | case 0: |
---|
| 109 | i += 1; |
---|
| 110 | break Switch; |
---|
| 111 | case 1: |
---|
| 112 | switch ( i ) { |
---|
| 113 | case 0: |
---|
| 114 | break Switch; |
---|
| 115 | default: |
---|
| 116 | ; break; |
---|
| 117 | } |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | Choose: choose ( i ) { |
---|
| 121 | default: |
---|
| 122 | i += 1; |
---|
| 123 | case 0: |
---|
| 124 | i += 1; |
---|
| 125 | break Choose; |
---|
| 126 | case 1: |
---|
| 127 | choose ( i ) { |
---|
| 128 | case 0: |
---|
| 129 | break; |
---|
| 130 | default: |
---|
| 131 | break Choose; |
---|
| 132 | } |
---|
| 133 | fallthru; |
---|
| 134 | case 2: |
---|
| 135 | i += 1; |
---|
| 136 | } |
---|
| 137 | |
---|
[9bdb8b7] | 138 | // all nested control options, labelled exits |
---|
| 139 | |
---|
| 140 | Comp: { |
---|
| 141 | Try: try { |
---|
| 142 | For: for ( ;; ) { |
---|
| 143 | While: while ( true ) { |
---|
| 144 | Do: do { |
---|
| 145 | If: if ( true ) { |
---|
| 146 | Switch2: switch ( 3 ) { |
---|
| 147 | case 3: |
---|
| 148 | break Try; |
---|
| 149 | break Comp; |
---|
| 150 | break For; continue For; |
---|
| 151 | break While; continue While; |
---|
| 152 | break Do; continue Do; |
---|
| 153 | break If; |
---|
| 154 | break Switch2; |
---|
| 155 | } // switch |
---|
| 156 | } // if |
---|
| 157 | } while ( true ); |
---|
| 158 | } // while |
---|
| 159 | } // for |
---|
| 160 | } finally {} // always executed |
---|
| 161 | } // compound |
---|
| 162 | |
---|
[62edde5] | 163 | // computed goto |
---|
[e53e5aa] | 164 | { |
---|
| 165 | void *array[] = { &&foo, &&bar, &&hack }; |
---|
| 166 | foo: bar: hack: |
---|
| 167 | &&foo; |
---|
| 168 | &&bar; |
---|
| 169 | goto *array[i]; |
---|
| 170 | } |
---|
[62edde5] | 171 | |
---|
| 172 | Q: if ( i > 5 ) { |
---|
| 173 | i += 1; |
---|
[540b275] | 174 | break Q; |
---|
| 175 | } |
---|
| 176 | else |
---|
[62edde5] | 177 | i += 1; |
---|
| 178 | } |
---|
| 179 | |
---|
[2f22cc4] | 180 | int main( int argc, char const *argv[] ) { |
---|
[53692b3] | 181 | #pragma GCC warning "Compiled" // force non-empty .expect file, NO TABS!!! |
---|
[aaf1f4d] | 182 | } |
---|
| 183 | |
---|
[62edde5] | 184 | // Local Variables: // |
---|
| 185 | // tab-width: 4 // |
---|
[dc8511c] | 186 | // compile-command: "cfa labelledExit.cfa" // |
---|
[62edde5] | 187 | // End: // |
---|