// // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo // // The contents of this file are covered under the licence agreement in the // file "LICENCE" distributed with Cforall. // // loopctrl.cfa -- // // Author : Peter A. Buhr // Created On : Wed Aug 8 18:32:59 2018 // Last Modified By : Peter A. Buhr // Last Modified On : Fri Aug 2 08:42:55 2024 // Update Count : 185 // #include void fred() { // Test all possible loop syntax. int s = 0, c = 10, i = 2; for ( c ) { sout | "A"; } sout | nl; for ( ~= c ) { sout | "B"; } sout | nl; for ( -~ c ) { sout | "C"; } sout | nl; for ( -~= c ) { sout | "D"; } sout | nl; for ( s ~ c ) { sout | "A"; } sout | nl; for ( s ~= c ) { sout | "B"; } sout | nl; for ( s -~ c ) { sout | "C"; } sout | nl; for ( s -~= c ) { sout | "D"; } sout | nl; for ( s ~ c ~ i ) { sout | "A"; } sout | nl; for ( s ~= c ~ i ) { sout | "B"; } sout | nl; for ( s -~ c ~ i ) { sout | "C"; } sout | nl; for ( s -~= c ~ i ) { sout | "D"; } sout | nl; for ( j; c ) { sout | j; } sout | nl; for ( j; ~= c ) { sout | j; } sout | nl; for ( j; -~ c ) { sout | j; } sout | nl; for ( j; -~= c ) { sout | j; } sout | nl; for ( j; s ~ c ) { sout | j; } sout | nl; for ( j; s ~= c ) { sout | j; } sout | nl; for ( j; s -~ c ) { sout | j; } sout | nl; for ( j; s -~= c ) { sout | j; } sout | nl; for ( j; s ~ c ~ i ) { sout | j; } sout | nl; for ( j; s ~= c ~ i ) { sout | j; } sout | nl; for ( j; s -~ c ~ i ) { sout | j; } sout | nl; for ( j; s -~= c ~ i ) { sout | j; } sout | nl; // CANNOT DIRECTLY INITIALIZE INDEX VARIABLE, ONLY SINGLE LOOP INDEX VARIABLE IN DECLARATION for ( j; c ) { sout | j; } sout | nl; for ( int j; c ) { sout | j; } sout | nl; for ( int j; ~= c ) { sout | j; } sout | nl; for ( int j; -~ c ) { sout | j; } sout | nl; for ( int j; -~= c ) { sout | j; } sout | nl; for ( int j; s ~ c ) { sout | j; } sout | nl; for ( int j; s ~= c ) { sout | j; } sout | nl; for ( int j; s -~ c ) { sout | j; } sout | nl; for ( int j; s -~= c ) { sout | j; } sout | nl; for ( int j; s ~ c ~ i ) { sout | j; } sout | nl; for ( int j; s ~= c ~ i ) { sout | j; } sout | nl; for ( int j; s -~ c ~ i ) { sout | j; } sout | nl; for ( int j; s -~= c ~ i ) { sout | j; } sout | nl; for ( j; s ~ @ ) { if ( j == 10 ) break; sout | j; } sout | nl; for ( j; @ -~ s ) { if ( j == -10 ) break; sout | j; } sout | nl; for ( j; s ~ @ ~ i ) { if ( j == 10 ) break; sout | j; } sout | nl; for ( j; @ -~ s ~ i ) { if ( j == -10 ) break; sout | j; } sout | nl; for ( j; s ~ @ ~ @ ) { if ( j == 10 ) break; sout | j; j += 1; } sout | nl; for ( int j; s ~ @ ) { if ( j == 10 ) break; sout | j; j += 1; } sout | nl; for ( int j; @ -~ s ) { if ( j == -10 ) break; sout | j; j -= 1; } sout | nl; for ( int j; s ~ @ ~ i ) { if ( j == 10 ) break; sout | j; } sout | nl; for ( int j; @ -~ s ~ i ) { if ( j == -10 ) break; sout | j; } sout | nl; for ( int j; s ~ @ ~ @ ) { if ( j == 10 ) break; sout | j; j += 1; } sout | nl; enum(int) E { A, B, C, D }; for ( E e; A ~= C ) { sout | e; } sout | nl; for ( e; A ~= D ) { sout | e; } sout | nl; for ( e; A -~= D ~ 2 ) { sout | e; } sout | nl; for ( e; E ) { sout | e; } sout | nl; for ( e; -~= E ) { sout | e; } sout | nl; } struct S { int i, j; }; void ?{}( S & s ) { s.[i, j] = 0; } void ?{}( S & s, int i ) { s.[i, j] = [i, 0]; } void ?{}( S & s, int i, int j ) { s.[i, j] = [i, j]; } void ?{}( S & s, zero_t ) { s.[i, j] = 0; } void ?{}( S & s, one_t ) { s.[i, j] = 1; } int ??( S s1, S s2 ) { return s1.i > s2.i || s1.j > s2.j; } int ?>=?( S s1, S s2 ) { return s1.i >= s2.i || s1.j >= s2.j; } S ?+=?( S & s1, S s2 ) { s1.i += s2.i; s1.j += s2.j; return s1; } S ?+=?( S & s, one_t ) { s.i += 1; s.j += 1; return s; } S ?-=?( S & s1, S s2 ) { s1.i -= s2.i; s1.j -= s2.j; return s1; } S ?-=?( S & s, one_t ) { s.i -= 1; s.j -= 1; return s; } ofstream & ?|?( ofstream & os, S s ) { return os | '(' | s.i | s.j | ')'; } void & ?|?( ofstream & os, S s ) { (ofstream &)(os | s); ends( os ); } int main() { // Test some loop options. sout | nlOff; // turn off auto newline while () { sout | "empty"; break; } sout | nl; do { sout | "empty"; break; } while (); sout | nl; for () { sout | "empty"; break; } sout | nl | nl; for ( 0 ) { sout | "A"; } sout | "zero" | nl; for ( 1 ) { sout | "A"; } sout | nl; for ( 10 ) { sout | "A"; } sout | nl; for ( ~= 10 ) { sout | "A"; } sout | nl; for ( 1 ~= 10 ~ 2 ) { sout | "B"; } sout | nl; for ( 1 -~= 10 ~ 2 ) { sout | "C"; } sout | nl; for ( 0.5 ~ 5.5 ) { sout | "D"; } sout | nl; for ( 0.5 -~ 5.5 ) { sout | "E"; } sout | nl | nl; for ( i; 10 ) { sout | i; } sout | nl; for ( i; ~= 10 ) { sout | i; } sout | nl; for ( i; 1 ~= 10 ~ 2 ) { sout | i; } sout | nl; for ( i; 1 -~= 10 ~ 2 ) { sout | i; } sout | nl; for ( i; 0.5 ~ 5.5 ) { sout | i; } sout | nl; for ( i; 0.5 -~ 5.5 ) { sout | i; } sout | nl; for ( ui; 2u ~= 10u ~ 2u ) { sout | ui; } sout | nl; for ( ui; 2u -~= 10u ~ 2u ) { sout | ui; } sout | nl | nl; // @ means do nothing for ( i; 1 ~ @ ) { if ( i > 10 ) break; sout | i; } sout | nl; for ( i; @ -~ 10 ) { if ( i < 0 ) break; sout | i; } sout | nl; for ( i; 2 ~ @ ~ 2 ) { if ( i > 10 ) break; sout | i; } sout | nl; for ( i; 2.1 ~ @ ~ @ ) { if ( i > 10.5 ) break; sout | i; i += 1.7; } sout | nl; for ( i; @ -~ 10 ~ 2 ) { if ( i < 0 ) break; sout | i; } sout | nl; for ( i; 12.1 ~ @ ~ @ ) { if ( i < 2.5 ) break; sout | i; i -= 1.7; } sout | nl | nl; enum { N = 10 }; for ( N ) { sout | "N"; } sout | nl; for ( i; N ) { sout | i; } sout | nl; for ( i; ~= N ) { sout | i; } sout | nl; for ( i; -~= N ) { sout | i; } sout | nl | nl; const int start = 3, comp = 10, inc = 2; for ( i; start ~ comp ~ inc + 1 ) { sout | i; } sout | nl | nl; for ( i; 10 : j; -5 ~ @ ) { sout | i | j; } sout | nl; for ( i; 10 : j; @ -~ -5 ) { sout | i | j; } sout | nl; for ( i; 10 : j; -5 ~ @ ~ 2 ) { sout | i | j; } sout | nl; for ( i; 10 : j; @ -~ -5 ~ 2 ) { sout | i | j; } sout | nl | nl; for ( j; -5 ~ @ : i; 10 ) { sout | i | j; } sout | nl; for ( j; @ -~ -5 : i; 10 ) { sout | i | j; } sout | nl; for ( j; -5 ~ @ ~ 2 : i; 10 ) { sout | i | j; } sout | nl; for ( j; @ -~ -5 ~ 2 : i; 10 ) { sout | i | j; } sout | nl | nl; for ( j; @ -~ -5 ~ 2 : i; 10 : k; 1.5 ~ @ ) { sout | i | j | k; } sout | nl; for ( j; @ -~ -5 ~ 2 : k; 1.5 ~ @ : i; 10 ) { sout | i | j | k; } sout | nl; for ( k; 1.5 ~ @ : j; @ -~ -5 ~ 2 : i; 10 ) { sout | i | j | k; } sout | nl; for ( S s = (S){0}; s < (S){10,10}; s += (S){1} ) { sout | s; } sout | nl; // 0 does not work for ( s; (S){10,10} ) { sout | s; } sout | nl; sout | nl; for ( s; (S){0} ~ (S){10,10} ) { sout | s; } sout | nl; for ( s; (S){0} ~ (S){10,10} ~ (S){1} ) { sout | s; } sout | nl; for ( s; (S){0} ~= (S){10,10} ) { sout | s; } sout | nl; for ( s; (S){0} ~= (S){10,10} ~ (S){1} ) { sout | s; } sout | nl; sout | nl; for ( s; (S){0} -~ (S){10,10} ) { sout | s; } sout | nl; for ( s; (S){0} -~ (S){10,10} ~ (S){1} ) { sout | s; } sout | nl; for ( s; (S){0} -~= (S){10,10} ) { sout | s; } sout | nl; for ( s; (S){0} -~= (S){10,10} ~ (S){1} ) { sout | s; } sout | nl | nl; int i = 10; double d = 10.; char c = 'e'; S s = { 7 }; for ( anon; 3 ~ i ) sout | anon; sout | nl; for ( anon; 3 ~ i ) sout | anon; sout | nl; for ( anon; 3 -~ i ) sout | anon; sout | nl; for ( anon; 3.5 ~ d ) sout | anon; sout | nl; for ( anon; 'a' ~= c ) sout | anon; sout | nl; for ( anon; 'a' -~= c ) sout | anon; sout | nl; for ( anon; (S){0} ~ s ) sout | anon; sout | nl; // 0 does not work for ( anon; (S){1} ~ s ) sout | anon; sout | nl; // 1 does not work for ( anon; (S){3} ~ s ) sout | anon; sout | nl; for ( anon; (S){3} -~ s ) sout | anon; sout | nl | nl; fred(); } // Local Variables: // // tab-width: 4 // // compile-command: "cfa loopctrl.cfa" // // End: //