// // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo // // The contents of this file are covered under the licence agreement in the // file "LICENCE" distributed with Cforall. // // labelledExit.cfa -- // // Author : Peter A. Buhr // Created On : Wed Aug 10 07:29:39 2016 // Last Modified By : Peter A. Buhr // Last Modified On : Sat Jun 5 10:07:34 2021 // Update Count : 13 // int foo() { int i; int x, y; x = 0; y = 0; // block, labelled exits Block: { if ( x == y ) { for ( ; i < y; ) { y += 1; if ( y < 10 ) break Block; } } } // loops, labelled exits w1: while ( y == 10 ); w2: while ( x < 10 ) { while (y < 5 ) { if ( y == 3 ) break w2; } x += 1; } A: for ( i = 0; i < 10; i += 1 ) { B: for ( i = 0; i < 10; i += 1 ) { C: for ( i = 0; i < 10; i += 1 ) { goto A; goto B; goto C; continue A; continue B; continue C; continue; break A; break B; break C; break; } } } D: for () { break D; continue D; } Z : i += 1; goto Z; X: Y: for () { i += 1; if ( i > 5 ) continue X; if ( i < 5 ) break X; if ( i < 5 ) break Y; break; } XX: for () { YY: for () { ZZ: for () { i += 1; if ( i > 5 ) continue XX; if ( i < 5 ) continue YY; if ( i < 5 ) continue ZZ; if ( i > 5 ) break XX; if ( i < 5 ) break YY; if ( i < 5 ) break ZZ; break; } } } for () ; for ( int i = 0 ;; ) ; for ( ; i < 0; ) ; for ( ; ; i += 1 ) ; L0: L1: L2: L3: L4: L5: L6: L7: L8: L9: L10: L11: L12: L13: L14: L15: L16: L17: L18: L19: L20: L21: L22: L23: L24: L25: L26: L27: L28: L29: L31: L32: L33: L34: for () { break L0; } // switch/choose, labelled exits Switch: switch ( i ) { default: i += 1; case 0: i += 1; break Switch; case 1: switch ( i ) { case 0: break Switch; default: ; break; } } Choose: choose ( i ) { default: i += 1; case 0: i += 1; break Choose; case 1: choose ( i ) { case 0: break; default: break Choose; } fallthru; case 2: i += 1; } // all nested control options, labelled exits Comp: { Try: try { For: for ( ;; ) { While: while ( true ) { Do: do { If: if ( true ) { Switch2: switch ( 3 ) { case 3: break Try; break Comp; break For; continue For; break While; continue While; break Do; continue Do; break If; break Switch2; } // switch } // if } while ( true ); } // while } // for } finally {} // always executed } // compound // computed goto { void *array[] = { &&foo, &&bar, &&hack }; foo: bar: hack: &&foo; &&bar; goto *array[i]; } Q: if ( i > 5 ) { i += 1; break Q; } else i += 1; } int main( int argc, char const *argv[] ) { #pragma GCC warning "Compiled" // force non-empty .expect file, NO TABS!!! } // Local Variables: // // tab-width: 4 // // compile-command: "cfa labelledExit.cfa" // // End: //