source: tests/forall.cfa @ adf03a6

ADTast-experimentalpthread-emulationqualifiedEnum
Last change on this file since adf03a6 was 39d9b32, checked in by Andrew Beach <ajbeach@…>, 2 years ago

Adjusted line number in forall test.

  • Property mode set to 100644
File size: 4.3 KB
RevLine 
[39d9b32]1//
[6da49249]2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
[39d9b32]6//
7// forall.cfa --
8//
[6da49249]9// Author           : Peter A. Buhr
10// Created On       : Wed May  9 08:48:15 2018
11// Last Modified By : Peter A. Buhr
[53692b3]12// Last Modified On : Sat Jun  5 10:06:08 2021
13// Update Count     : 36
[39d9b32]14//
[8a95629]15
16void g1() {
[fd54fef]17        forall( T ) T f( T ) {};
[6da49249]18        void f( int ) {};
19        void h( void (*p)(void) ) {};
[e5b96bf]20
[8a95629]21        int x;
22        void (*y)(void);
23        char z;
24        float w;
[e5b96bf]25
[8a95629]26        f( x );
27        f( y );
28        f( z );
29        f( w );
30        h( f( y ) );
31}
32
33void g2() {
[fd54fef]34        forall( T ) void f( T, T ) {}
35        forall( T, U ) void f( T, U ) {}
[e5b96bf]36
[8a95629]37        int x;
38        float y;
39        int *z;
40        float *w;
[e5b96bf]41
[8a95629]42        f( x, y );
43        f( z, w );
44        f( x, z );
45}
46
[49a1684]47// commented this out since it is not clearly meaningful
48// and not really representable in the ast
49// typedef forall ( T ) int (* f)( int );
[51b7345]50
[fd54fef]51forall( T )
[a65d92e]52void swap( T left, T right ) {
[51b7345]53        T temp = left;
54        left = right;
55        right = temp;
[a65d92e]56}
[51b7345]57
[fd54fef]58trait sumable( T ) {
[6da49249]59        void ?{}( T &, zero_t );                                                        // 0 literal constructor
60        T ?+?( T, T );                                                                          // assortment of additions
61        T ?+=?( T &, T );
62        T ++?( T & );
63        T ?++( T & );
64}; // sumable
65
[fd54fef]66forall( T | sumable( T ) )                                              // use trait
[6da49249]67T sum( size_t size, T a[] ) {
68        T total = 0;                                                                            // initialize by 0 constructor
69        for ( size_t i = 0; i < size; i += 1 )
70                total = total + a[i];                                                   // select appropriate +
[51b7345]71        return total;
[6da49249]72} // sum
[51b7345]73
[fd54fef]74forall( T | { T ?+?( T, T ); T ?++( T & ); [T] ?+=?( T &,T ); } )
[a65d92e]75T twice( T t ) {
[51b7345]76        return t + t;
[a65d92e]77}
[51b7345]78
[fd54fef]79forall( T | { int ?<?(T, T); } )
[0b2961f]80T min( T t1, T t2 ) {
81        return t1 < t2 ? t1 : t2;
82}
83
[6da49249]84int fred() {
[0b2961f]85        int x = 1, y = 2, a[10];
86        float f;
[51b7345]87
[0b2961f]88        swap( x, y );
89        twice( x );
90        f = min( 4.0, 3.0 );
91        sum( 10, a );
[51b7345]92}
[a65d92e]93
[6da49249]94// Multiple forall
[fd54fef]95forall( T ) forall( S ) struct { int i; };
96forall( T ) struct { int i; } forall( S );
97struct { int i; } forall( T ) forall( S );
98forall( W ) struct { int i; } forall( T ) forall( S );
[6da49249]99
100// Distribution
101struct P { int i; };
[fd54fef]102forall( T ) struct Q { T i; };
103forall( T ) struct { int i; };
[6da49249]104struct KK { int i; };
105inline static {
106        void RT1() {}
107}
[fd54fef]108forall( T ) {
[6da49249]109        T RT2( T ) {
110                typedef int TD1;
111                struct S1 { T t; };
112        }
[fd54fef]113        forall( X ) {
[6da49249]114                typedef int TD2;
115                struct S2 {};
116                X RT2( T, X ) {
117                        int TD2;
118                }
119        }
120        extern "C" {
[fd54fef]121                forall( W ) {
[6da49249]122                        W RT3( W ) {}
123                        struct S3 {};
124                }
125        }
126        void RT4() {
[fd54fef]127                forall( W ) struct S4 {};
[6da49249]128                typedef int TD3;
129        }
130        static {
131                struct S5 {};
132                void RT5( T ) {
133                        struct S6 {};
134                        int TD2;
135                }
136        }
137        struct S7 {};
138        typedef int TD4;
139}
140TD2 t2;
141TD4 t4;
142struct Q( int ) t;
143struct S2( int, int ) t;
144struct S5( int ) t;
145struct S7( int ) t;
146
147int i = RT2( 3 );
148double j = RT2( 3, 4.5 );
149
150static inline {
[fd54fef]151        forall( T ) {
[6da49249]152                int RT6( T p );
153        }
[fd54fef]154        forall( T, U ) {
[6da49249]155                int RT7( T, U );
156        }
157}
[fd54fef]158static forall( T ) {
[6da49249]159        int RT8( T );
160}
[fd54fef]161forall( T ) inline static {
[66812dd]162        int RT9( T ) { T t; return 3; }
[6da49249]163}
164
[fd54fef]165forall( T | { T ?+?( T, T ); } ) {
166        forall( S | { T ?+?( T, S ); } ) {
167                forall( W ) T bar( T t, S s ) { return t + s; }
168                forall( W | { W ?+?( T, W ); } ) W baz( T t, S s, W w ) { return t + s + w; }
[6da49249]169                struct W { T t; } (int,int) ww;
170                struct P pp;
171        }
172}
173
[39d9b32]174forall( T | { T ?+?( T, T ); } ) forall( S | { T ?+?( T, S ); } )
[6da49249]175struct XW { T t; };
176XW(int,int) xww;
177
[fd54fef]178forall( T ) struct S { T t; } (int) x, y, z;
179forall( T ) struct { T t; } (int) a, b, c;
[6da49249]180
[fd54fef]181forall( T ) static forall( S ) {
182    forall( X ) struct U {
[6da49249]183                T x;
184    };
185}
186
[fd54fef]187forall( T ) {
[6da49249]188        extern "C" {
189                struct SS { T t; };
190                T foo( T ) {}
191        }
192}
193
194SS(int) s;
195W(int,int) w;
196
197int jane() {
198//      int j = bar( 3, 4 );
199        int k = baz( 3, 4, 5 );
200        int i = foo( 3 );
201}
202
[68b52b0]203forall( T ) void check_otype() {
204        T & tr = *0p;
205        T * tp = 0p;
206
207        &tr += 1;
208        tp += 1;
209        T & tx = tp[1];
210
211        T t;
212        T t2 = t;
213}
214
215forall( T * ) void check_dstype() {
216        T & tr = *0p;
217        T * tp = 0p;
218
219        &tr += 1;
220        tp += 1;
221        T & tx = tp[1];
222}
223
224forall( T & ) void check_dtype() {
225        T & tr = *0p;
226        T * tp = 0p;
227}
228
[6da49249]229//otype T1 | { void xxx( T1 ); };
230
231// otype T1 | { void ?{}( T1 &, zero_t ); T1 ?+?(T1, T1); T1 ?++(T1); [T1] ?+=?(T1,T1); },
232//      T2(otype P1, otype P2 ),
233//      T3 | sumable(T3);
234
235//otype T2(otype P1, otype P2) | sumable( T2( P1,P2 ) ) = struct { P1 i; P2 j; };
236
237// T2(int, int) w1;
238// typedef T2(int, int) w2;
239// w2 g2;
240// otype w3 = T2(int, int);
241// w3 g3;
242
[66812dd]243int main( void ) {
[53692b3]244    #pragma GCC warning "Compiled"                      // force non-empty .expect file, NO TABS!!!
[66812dd]245}
[6da49249]246
[a65d92e]247// Local Variables: //
248// tab-width: 4 //
[dc8511c]249// compile-command: "cfa forall.cfa" //
[a65d92e]250// End: //
Note: See TracBrowser for help on using the repository browser.