Changeset 55ba7339
- Timestamp:
- Jun 14, 2016, 12:33:57 PM (9 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- e04ef3a
- Parents:
- 4c82a3c
- Location:
- src/Tests
- Files:
-
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Tests/Abstype.c
r4c82a3c r55ba7339 1 type T | { T x( T ); };1 otype T | { T x( T ); }; 2 2 3 3 T y( T t ) { … … 6 6 } 7 7 8 forall( type T ) lvalue T *?( T * );8 forall( otype T ) lvalue T *?( T * ); 9 9 int ?++( int * ); 10 10 int ?=?( int *, int ); 11 11 forall( dtype DT ) DT * ?=?( DT **, DT * ); 12 12 13 type U = int *;13 otype U = int *; 14 14 15 15 U x( U u ) { -
src/Tests/Array.c
r4c82a3c r55ba7339 1 1 int a1[]; 2 int a2[*];3 double a4[3.0];2 //int a2[*]; 3 //double a4[3.0]; 4 4 5 5 int m1[][3]; 6 int m2[*][*];6 //int m2[*][*]; 7 7 int m4[3][3]; 8 8 … … 10 10 11 11 int fred() { 12 int a1[];13 int a2[*];12 // int a1[]; 13 // int a2[*]; 14 14 int a4[3]; 15 15 int T[3]; -
src/Tests/Attributes.c
r4c82a3c r55ba7339 6 6 // @max 7 7 // 8 // 2. a direct application to a manifest type8 // 2. a direct application to a manifest otype 9 9 // 10 10 // @max( int ) 11 11 // 12 // 3. constraining a type variable; the application is implicitly performed at the call site as in (2)12 // 3. constraining a otype variable; the application is implicitly performed at the call site as in (2) 13 13 // 14 // forall( type T | { T @max( T ); } ) T x( T t );14 // forall( otype T | { T @max( T ); } ) T x( T t ); 15 15 // 16 16 // … … 23 23 // x = (*attr_var); 24 24 // 25 // 2. an indirect application to a manifest type25 // 2. an indirect application to a manifest otype 26 26 // 27 27 // (*attr_var)( int ) 28 28 // 29 // 3. a direct application to a type variable29 // 3. a direct application to a otype variable 30 30 // 31 31 // @max( T ) … … 47 47 // 3. polymorphic 48 48 // 49 // forall( type T | constraint( T ) ) int @attr( T );49 // forall( otype T | constraint( T ) ) int @attr( T ); 50 50 51 51 int @max = 3; … … 53 53 int main() { 54 54 int x; 55 type @type(type t); // compiler intrinsic56 type @widest(type t);57 @ type(x) *y; // gcc:typeof(x) *y;58 const @widest(double) *w; // gcc: const typeof(x) *w;59 * @ type(3 + 4) z; // cfa declaration syntax55 otype @otype(otype t); // compiler intrinsic 56 otype @widest(otype t); 57 @otype(x) *y; // gcc: otypeof(x) *y; 58 const @widest(double) *w; // gcc: const otypeof(x) *w; 59 * @otype(3 + 4) z; // cfa declaration syntax 60 60 y = @max; 61 61 z = @max(x) + @size(int); -
src/Tests/Context.c
r4c82a3c r55ba7339 1 context has_q( type T ) {1 context has_q( otype T ) { 2 2 T q( T ); 3 3 }; 4 4 5 forall( type z | has_q( z ) ) void f() {6 context has_r( type T,type U ) {5 forall( otype z | has_q( z ) ) void f() { 6 context has_r( otype T, otype U ) { 7 7 T r( T, T (T,U) ); 8 8 }; 9 9 10 extern type x, y | has_r( x, y );10 extern otype x, y | has_r( x, y ); 11 11 } 12 12 -
src/Tests/Forall.c
r4c82a3c r55ba7339 7 7 8 8 void g1() { 9 forall( type T ) T f( T );9 forall( otype T ) T f( T ); 10 10 void f( int ); 11 11 void h( void (*p)(void) ); … … 24 24 25 25 void g2() { 26 forall( type T ) void f( T, T );27 forall( type T,type U ) void f( T, U );26 forall( otype T ) void f( T, T ); 27 forall( otype T, otype U ) void f( T, U ); 28 28 29 29 int x; … … 37 37 } 38 38 39 typedef forall ( type T ) int (*f)( int );39 typedef forall ( otype T ) int (*f)( int ); 40 40 41 forall( type T )41 forall( otype T ) 42 42 void swap( T left, T right ) { 43 43 T temp = left; … … 46 46 } 47 47 48 context sumable( type T ) {48 context sumable( otype T ) { 49 49 const T 0; 50 50 T ?+?(T, T); … … 53 53 }; 54 54 55 type T1 | { const T1 0; T1 ?+?(T1, T1); T1 ?++(T1); [T1] ?+=?(T1,T1); },56 T2( type P1,type P2 ),55 otype T1 | { const T1 0; T1 ?+?(T1, T1); T1 ?++(T1); [T1] ?+=?(T1,T1); }, 56 T2(otype P1, otype P2 ), 57 57 T3 | sumable(T3); 58 58 59 type T2(type P1,type P2) | sumable(T2(P1,P2)) = struct { P1 i; P2 j; };59 otype T2(otype P1, otype P2) | sumable(T2(P1,P2)) = struct { P1 i; P2 j; }; 60 60 61 61 T2(int, int) w1; 62 62 typedef T2(int, int) w2; 63 63 w2 g2; 64 type w3 = T2(int, int);64 otype w3 = T2(int, int); 65 65 w3 g3; 66 66 67 forall( type T | sumable( T ) )67 forall( otype T | sumable( T ) ) 68 68 T sum( int n, T a[] ) { 69 69 T total = 0; … … 74 74 } 75 75 76 forall( type T | { const T 0; T ?+?(T, T); T ?++(T); [T] ?+=?(T,T); } )76 forall( otype T | { const T 0; T ?+?(T, T); T ?++(T); [T] ?+=?(T,T); } ) 77 77 T twice( T t ) { 78 78 return t + t; 79 79 } 80 80 81 forall( type T | { const T 0; int ?!=?(T, T); int ?<?(T, T); } )81 forall( otype T | { const T 0; int ?!=?(T, T); int ?<?(T, T); } ) 82 82 T min( T t1, T t2 ) { 83 83 return t1 < t2 ? t1 : t2; -
src/Tests/Functions.c
r4c82a3c r55ba7339 28 28 int ((*f12())[])[3] {} 29 29 30 // "implicit int" type specifier (not ANSI)30 // "implicit int" otype specifier (not ANSI) 31 31 32 32 fII1( int i ) {} -
src/Tests/GccExtensions.c
r4c82a3c r55ba7339 19 19 __signed s2; 20 20 21 __ typeof(s1) t1;22 __ typeof__(s1) t2;21 __otypeof(s1) t1; 22 __otypeof__(s1) t2; 23 23 24 24 __volatile int v1; -
src/Tests/InferParam.c
r4c82a3c r55ba7339 3 3 double ?=?( double*, double ); 4 4 5 forall( type T,type U | { U f(T); } ) U g(T);5 forall( otype T, otype U | { U f(T); } ) U g(T); 6 6 float f( int ); 7 7 double f( int ); … … 13 13 } 14 14 15 context has_f_and_j( type T,type U ) {15 context has_f_and_j( otype T, otype U ) { 16 16 U f( T ); 17 17 U j( T, U ); … … 19 19 20 20 float j( int, float ); 21 forall( type T,type U | has_f_and_j( T, U ) ) U k( T );21 forall( otype T, otype U | has_f_and_j( T, U ) ) U k( T ); 22 22 23 23 void l() { -
src/Tests/Makefile
r4c82a3c r55ba7339 1 CFA ?= ../ cfa-cpp1 CFA ?= ../driver/cfa-cpp 2 2 CFAOPT ?= -a 3 3 OUTPUT ?= Output … … 32 32 33 33 ${OUTPUTDIR} : 34 mkdir $@34 mkdir -p $@ 35 35 36 36 # remove the expected results directories to generate new ones from the current output -
src/Tests/Members.c
r4c82a3c r55ba7339 3 3 float ?=?( float*, float ); 4 4 forall( dtype DT ) DT * ?=?( DT**, DT* ); 5 forall( type T) lvalue T *?( T* );5 forall(otype T) lvalue T *?( T* ); 6 6 char *__builtin_memcpy(); 7 7 -
src/Tests/OccursError.c
r4c82a3c r55ba7339 1 forall( type T ) void f( void (*)( T, T* ) );2 forall( type U ) void g( U*, U );1 forall( otype T ) void f( void (*)( T, T* ) ); 2 forall( otype U ) void g( U*, U ); 3 3 4 4 void test() { -
src/Tests/Quad.c
r4c82a3c r55ba7339 2 2 int ?*?( int, int ); 3 3 4 forall( type T | { T ?*?( T, T ); } )4 forall( otype T | { T ?*?( T, T ); } ) 5 5 T square( T t ) { 6 6 return t * t; 7 7 } 8 8 9 forall( type U | { U square( U ); } )9 forall( otype U | { U square( U ); } ) 10 10 U quad( U u ) { 11 11 return square( square( u ) ); -
src/Tests/Rank2.c
r4c82a3c r55ba7339 3 3 4 4 void a() { 5 forall( type T ) void f( T );6 void g( forall( type U ) void p( U ) );5 forall( otype T ) void f( T ); 6 void g( forall( otype U ) void p( U ) ); 7 7 g( f ); 8 8 } … … 10 10 void g() { 11 11 void h( int *null ); 12 forall( type T ) T id( T );12 forall( otype T ) T id( T ); 13 13 forall( dtype T ) T *0; 14 14 int 0; -
src/Tests/Scope.c
r4c82a3c r55ba7339 3 3 typedef float t; 4 4 y z; 5 type u = struct { int a; double b; };5 otype u = struct { int a; double b; }; 6 6 int f( int y ); 7 7 y q; 8 8 9 9 y w( y y, u v ) { 10 type x | { x t(u); };10 otype x | { x t(u); }; 11 11 u u = y; 12 12 x z = t(u); … … 15 15 y p; 16 16 17 context has_u( type z ) {17 context has_u( otype z ) { 18 18 z u(z); 19 19 }; 20 20 21 forall( type t | has_u( t ) )21 forall( otype t | has_u( t ) ) 22 22 y q( t the_t ) { 23 23 t y = u( the_t ); -
src/Tests/Subrange.c
r4c82a3c r55ba7339 1 // A small context defining the notion of an ordered type. (The standard1 // A small context defining the notion of an ordered otype. (The standard 2 2 // library should probably contain a context for this purpose.) 3 context ordered( type T) {3 context ordered(otype T) { 4 4 int ?<?(T, T), ?<=?(T, T); 5 5 }; 6 6 7 // A subrange type resembling an Ada subtype with a basetype and a range7 // A subrange otype resembling an Ada subotype with a base otype and a range 8 8 // constraint. 9 type subrange(type base_t | ordered(base_t), base_t low = 0, base_t high = 8) = base_t;9 otype subrange(otype base_t | ordered(base_t), base_t low = 0, base_t high = 8) = base_t; 10 10 11 // Note that subrange() can be applied to floating-point and pointer types, not12 // just integral types.13 // This requires a " type generator" extension to Cforall. Type generators14 // must accept type and non-type parameters, which is beyond what we discussed11 // Note that subrange() can be applied to floating-point and pointer otypes, not 12 // just integral otypes. 13 // This requires a "otype generator" extension to Cforall. Type generators 14 // must accept otype and non-otype parameters, which is beyond what we discussed 15 15 // previously. Type parameters must be usable in the declaration of 16 16 // subsequent parameters: parameter T is used to declare parameters "low" … … 22 22 subrange(int, 0, (rand() & 0xF) ) foo; 23 23 24 // What sorts of expressions can be used as arguments of type generators? Is24 // What sorts of expressions can be used as arguments of otype generators? Is 25 25 // "subrange(int, 0, rand() & 0xF)" legal? Probably. The nearest C equivalent 26 26 // to the "low" and "high" arguments is the array size in a variable-length … … 28 28 29 29 // Convenient access to subrange bounds, for instance for iteration: 30 forall ( type T, T low, T high)30 forall (otype T, T low, T high) 31 31 T lbound( subrange(T, low, high) v) { 32 32 return low; 33 33 } 34 34 35 forall ( type T, T low, T high)35 forall (otype T, T low, T high) 36 36 T hbound( subrange(T, low, high) v) { 37 37 return high; … … 41 41 unsigned lday = lbound(day_of_month); 42 42 43 // Assignment from the base type, with bounds checking. I'll ignore the issue43 // Assignment from the base otype, with bounds checking. I'll ignore the issue 44 44 // of exception handling here. Inlining allows the compiler to eliminate 45 45 // bounds checks. 46 forall ( type T | ordered(T), T low, T high)46 forall (otype T | ordered(T), T low, T high) 47 47 inline subrange(T, low, high) ?=?(subrange(T, low, high)* target, T source) { 48 48 if (low <= source && source <= high) *((T*)target) = source; … … 51 51 } 52 52 53 // Assignment between subranges with a common base type. The bounds check53 // Assignment between subranges with a common base otype. The bounds check 54 54 // compares range bounds so that the compiler can optimize checks away when the 55 55 // ranges are known to overlap. 56 forall ( type T | ordered(T), T t_low, T t_high, T s_low, T s_high)56 forall (otype T | ordered(T), T t_low, T t_high, T s_low, T s_high) 57 57 inline subrange(T, t_low, t_high) ?=?(subrange(T, t_low, t_high)* target, 58 58 subrange(T, s_low, s_high) source) { -
src/Tests/TypeGenerator.c
r4c82a3c r55ba7339 1 context addable( type T ) {1 context addable( otype T ) { 2 2 T ?+?( T,T ); 3 3 T ?=?( T*, T); 4 4 }; 5 5 6 type List1(type T | addable( T ) ) = struct { T data; List1( T ) *next; } *;6 otype List1( otype T | addable( T ) ) = struct { T data; List1( T ) *next; } *; 7 7 typedef List1( int ) ListOfIntegers; 8 8 //List1( int ) li; … … 11 11 [int] h( * List1( int ) p ); // new declaration syntax 12 12 13 struct( type T ) S2 { T i; }; // actual definition13 struct( otype T ) S2 { T i; }; // actual definition 14 14 struct( int ) S3 v1, *p; // expansion and instantiation 15 struct( type T )( int ) S24 { T i; } v2; // actual definition, expansion and instantiation16 struct( type T )( int ) { T i; } v2; // anonymous actual definition, expansion and instantiation15 struct( otype T )( int ) S24 { T i; } v2; // actual definition, expansion and instantiation 16 struct( otype T )( int ) { T i; } v2; // anonymous actual definition, expansion and instantiation 17 17 18 struct( type T | addable( T ) ) node { T data; struct( T ) node *next; };19 type List(type T ) = struct( T ) node *;18 struct( otype T | addable( T ) ) node { T data; struct( T ) node *next; }; 19 otype List( otype T ) = struct( T ) node *; 20 20 List( int ) my_list; 21 21 22 type Complex | addable( Complex );22 otype Complex | addable( Complex ); 23 23 24 24 int main() { -
src/Tests/Typedef.c
r4c82a3c r55ba7339 18 18 a c; 19 19 20 typedef typeof(3) x, y; // GCC20 typedef otypeof(3) x, y; // GCC 21 21 22 22 x p; … … 24 24 25 25 int main() { 26 typedef typeof(3) z, p;26 typedef otypeof(3) z, p; 27 27 z w; 28 28 p x; -
src/Tests/Typeof.c
r4c82a3c r55ba7339 1 1 int main() { 2 2 int *v1; 3 typeof(v1) v2;4 typeof(*v1) v3[4];3 otypeof(v1) v2; 4 otypeof(*v1) v3[4]; 5 5 char *v4[4]; 6 typeof(typeof(char *)[4]) v5;7 typeof (int *) v6;8 typeof( int ( int, int p ) ) *v7;9 typeof( [int] ( int, int p ) ) *v8;6 otypeof(otypeof(char *)[4]) v5; 7 otypeof (int *) v6; 8 otypeof( int ( int, int p ) ) *v7; 9 otypeof( [int] ( int, int p ) ) *v8; 10 10 }
Note: See TracChangeset
for help on using the changeset viewer.