- Timestamp:
- Dec 26, 2018, 7:20:39 AM (6 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, no_list, persistent-indexer, pthread-emulation, qualifiedEnum
- Children:
- d5b2ac8
- Parents:
- ef346f7c
- Location:
- tests
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/fallthrough.cfa
ref346f7c rf498c51 10 10 // Created On : Wed Mar 14 10:06:25 2018 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Dec 20 22:02:38201813 // Update Count : 2 012 // Last Modified On : Mon Dec 24 11:24:35 2018 13 // Update Count : 22 14 14 // 15 15 … … 61 61 sout | "case 1"; 62 62 for ( int i = 0; i < 4; i += 1 ) { 63 printf("%d\n", i);63 sout | i; 64 64 if ( i == 2 ) fallthru common; 65 65 } // for … … 77 77 } // if 78 78 common: 79 printf( "common\n" );79 sout | "common"; 80 80 fallthru; 81 81 break; 82 82 default: 83 printf( "default\n" );83 sout | "default"; 84 84 fallthru; 85 85 } // switch -
tests/polymorphism.cfa
ref346f7c rf498c51 9 9 // Author : Rob Schluntz 10 10 // Created On : Tue Oct 17 12:19:48 2017 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Tue Oct 17 12:21:07 201713 // Update Count : 111 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 25 14:40:24 2018 13 // Update Count : 3 14 14 // 15 15 16 16 #include <assert.h> 17 17 #include <inttypes.h> 18 #include <fstream.hfa> 18 19 19 20 forall(otype T) … … 61 62 int y = 456; 62 63 int z = f(x, y); 63 printf("%d %d %d\n", x, y, z);64 sout | x | y | z; 64 65 } 65 66 66 { 67 67 // explicitly specialize function 68 68 int (*f)(int) = ident; 69 69 ((int(*)(int))ident); 70 printf("%d %d\n", f(5), ((int(*)(int))ident)(5));70 sout | f(5) | ((int(*)(int))ident)(5); 71 71 } 72 73 72 { 74 73 // test aggregates with polymorphic members … … 100 99 101 100 void print(x_type x) { 102 printf("%"PRIu32"\n", x);101 sout | x; 103 102 } 104 103 105 104 void print(y_type y) { 106 printf("%"PRIu64"\n", y);105 sout | y; 107 106 } 108 107 -
tests/references.cfa
ref346f7c rf498c51 9 9 // Author : Rob Schluntz 10 10 // Created On : Wed Aug 23 16:11:50 2017 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Wed Aug 23 16:12:0313 // Update Count : 211 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 25 14:31:48 2018 13 // Update Count : 11 14 14 // 15 15 16 #include <fstream.hfa> 17 16 18 struct Y { int i; }; 17 void ?{}( Y & y) { printf("Default constructing a Y\n"); }18 void ?{}( Y & y, Y other) { printf("Copy constructing a Y\n"); }19 void ^?{}( Y & y) { printf("Destructing a Y\n"); }20 Y ?=?( Y & y, Y other) { printf("Assigning a Y\n"); return y; }21 void ?{}( Y & y, int i) { printf("Value constructing a Y %d\n", i); y.i = i; }19 void ?{}( Y & y ) { sout | "Default constructing a Y"; } 20 void ?{}( Y & y, Y other ) { sout | "Copy constructing a Y"; } 21 void ^?{}( Y & y ) { sout | "Destructing a Y"; } 22 Y ?=?( Y & y, Y other ) { sout | "Assigning a Y"; return y; } 23 void ?{}( Y & y, int i ) { sout | "Value constructing a Y" | i; y.i = i; } 22 24 23 25 struct X { Y & r; Y y; }; 24 void ?{}( X & x) {26 void ?{}( X & x ) { 25 27 // ensure that r is not implicitly constructed 26 28 } 27 void ?{}( X & x, X other) {29 void ?{}( X & x, X other ) { 28 30 // ensure that r is not implicitly constructed 29 31 } 30 void ^?{}( X & x) {32 void ^?{}( X & x ) { 31 33 // ensure that r is not implicitly destructed 32 34 } 33 X ?=?( X & x, X other) { return x; }35 X ?=?( X & x, X other ) { return x; } 34 36 35 37 // ensure that generated functions do not implicitly operate on references … … 48 50 int x = 123456, x2 = 789, *p1 = &x, **p2 = &p1, ***p3 = &p2, 49 51 &r1 = x, &&r2 = r1, &&&r3 = r2; 50 ***p3 = 3; 51 **p3 = &x; 52 *p3 = &p1; 53 int y = 0, z = 11, & ar[3] = { x, y, z }; 54 // &ar[1] = &z; // change reference array element55 // typeof( ar[1] ) p = 3; // is int, i.e., the type of referenced object56 // typeof( &ar[1] ) q = &x; // is int *, i.e., the type of pointer52 ***p3 = 3; // change x 53 **p3 = &x; // change p1 54 *p3 = &p1; // change p2 55 int y = 0, z = 11, & ar[3] = { x, y, z }; // initialize array of references 56 // &ar[1] = &z; // change reference array element 57 // typeof( ar[1] ) p = 3; // is int, i.e., the type of referenced object 58 // typeof( &ar[1] ) q = &x; // is int *, i.e., the type of pointer 57 59 // _Static_assert( sizeof( ar[1] ) == sizeof( int ), "Array type should be int." ); // is true, i.e., the size of referenced object 58 60 // _Static_assert( sizeof( &ar[1] ) == sizeof( int *), "Address of array should be int *." ); // is true, i.e., the size of a reference 59 61 60 ((int*&)&r3) = &x; 62 ((int*&)&r3) = &x; // change r1, (&*)**r3 61 63 x = 3; 62 64 // test that basic reference properties are true - r1 should be an alias for x 63 printf("%d %d %d\n", x, r1, &x == &r1);65 sout | x | r1 | &x == &r1; 64 66 r1 = 12; 65 printf("%d %d %d\n", x, r1, &x == &r1);67 sout | x | r1 | &x == &r1; 66 68 67 69 // test that functions using basic references work 68 printf("%d %d %d %d\n", toref(&x), toref(p1), toptr(r1) == toptr(x), toptr(r1) == &x);70 sout | toref( &x ) | toref( p1 ) | toptr( r1 ) == toptr( x ) | toptr( r1 ) == &x; 69 71 70 72 changeRef( x ); 71 73 changeRef( y ); 72 74 changeRef( z ); 73 printf("%d %d %d\n", x, y, z);75 sout | x | y | z; 74 76 changeRef( r1 ); 75 printf("%d %d\n", r1, x);77 sout | r1 | x; 76 78 77 r3 = 6; 78 printf("x = %d ; x2 = %d\n", x, x2);// check that x was changed79 &r3 = &x2; 80 r3 = 999; 81 printf("x = %d ; x2 = %d\n", x, x2);// check that x2 was changed82 ((int**&)&&r3) = p2; 83 r3 = 12345; 84 printf("x = %d ; x2 = %d\n", x, x2);// check that x was changed85 &&&r3 = p3; 86 ((int&)r3) = 22222; 87 printf("x = %d ; x2 = %d\n", x, x2);// check that x was changed79 r3 = 6; // change x, ***r3 80 sout | "x = " | x | " ; x2 = " | x2; // check that x was changed 81 &r3 = &x2; // change r1 to refer to x2, (&*)**r3 82 r3 = 999; // modify x2 83 sout | "x = " | x | " ; x2 = " | x2; // check that x2 was changed 84 ((int**&)&&r3) = p2; // change r2, (&(&*)*)*r3, ensure explicit cast to reference works 85 r3 = 12345; // modify x 86 sout | "x = " | x | " ; x2 = " | x2; // check that x was changed 87 &&&r3 = p3; // change r3 to p3, (&(&(&*)*)*)r3 88 ((int&)r3) = 22222; // modify x, ensure explicit cast to reference works 89 sout | "x = " | x | " ; x2 = " | x2; // check that x was changed 88 90 89 91 // test that reference members are not implicitly constructed/destructed/assigned … … 102 104 struct S { double x, y; }; 103 105 void f( int & i, int & j, S & s, int v[] ) { 104 printf("%d %d { %g, %g }, [%d, %d, %d]\n", i, j, s.[x, y], v[0], v[1], v[2]);106 sout | i | j | "{ " | s.[x, y] | " }," | "[" | v[0] | "," | v[1] | "," | v[2] | "]"; 105 107 } 106 void g(int & i) { printf("%d\n", i); }107 void h(int &&& i) { printf("%d\n", i); }108 void g(int & i) { sout | i; } 109 void h(int &&& i) { sout | i; } 108 110 109 int &&& r = 3; 111 int &&& r = 3; // rvalue to reference 110 112 int i = r; 111 printf("%d %d\n", i, r);// both 3113 sout | i | r; // both 3 112 114 113 g( 3 ); 114 h( (int &&&)3 ); 115 g( 3 ); // rvalue to reference 116 h( (int &&&)3 ); // rvalue to reference 115 117 116 118 int a = 5, b = 4;
Note: See TracChangeset
for help on using the changeset viewer.