Changeset 25cdca5 for tests/withStatement.cfa
- Timestamp:
- Jan 8, 2019, 11:31:21 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:
- 08222c7, 274da98
- Parents:
- 84b4d607 (diff), d5b2ac8 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/withStatement.cfa
r84b4d607 r25cdca5 9 9 // Author : Rob Schluntz 10 10 // Created On : Mon Dec 04 17:41:45 2017 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Mon Dec 04 17:45:07 201713 // Update Count : 211 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Dec 24 19:08:18 2018 13 // Update Count : 5 14 14 // 15 15 16 #include <fstream.hfa> 17 16 18 struct S { 17 18 19 19 int i; 20 // dynamically allocated member ensures ctor/dtors are called correctly on temporaries 21 int * ptr; 20 22 }; 21 23 22 24 // with clause on reference parameter 23 void ?{}( S & this, int n) with(this) {24 25 ptr = (int *)malloc(sizeof(int));25 void ?{}( S & this, int n ) with( this ) { 26 i = n; 27 ptr = (int *)malloc( sizeof(int) ); 26 28 } 27 29 28 void ?{}( S & this) {29 30 void ?{}( S & this ) { 31 this{ 0 }; 30 32 } 31 33 32 void ?{}( S & this, S other) {33 34 void ?{}( S & this, S other ) { 35 this{ other.i }; 34 36 } 35 37 36 S ?=?( S & this, S other) with(this) {37 38 39 38 S ?=?( S & this, S other ) with( this ) { 39 i = other.i; 40 *ptr = *other.ptr; 41 return this; 40 42 } 41 43 42 void ^?{}( S & this) with(this) {43 free(ptr);44 void ^?{}( S & this ) with( this ) { 45 free( ptr ); 44 46 } 45 47 46 48 struct S2 { 47 49 S s; 48 50 }; 49 51 50 void ?{}( S2 & this, int n) {51 52 void ?{}( S2 & this, int n ) { 53 (this.s){ n }; 52 54 } 53 55 54 forall( otype T)56 forall( otype T ) 55 57 struct Box { 56 58 T x; 57 59 }; 58 60 59 forall( otype T)60 void ?{}( Box(T) & this) with(this) { // with clause in polymorphic function61 61 forall( otype T ) 62 void ?{}( Box(T) & this ) with( this ) { // with clause in polymorphic function 63 x{}; 62 64 } 63 65 64 void print( int i) { printf("%d", i); }66 void print( int i ) { sout | i; } 65 67 66 forall(otype T | { void print(T); }) 67 void foo(T t) { 68 Box(T) b = { t }; 69 with(b) { // with statement in polymorphic function 70 print(x); 71 printf("\n"); 72 } 68 forall( otype T | { void print( T ); }) 69 void foo( T t ) { 70 Box( T ) b = { t }; 71 with( b ) { // with statement in polymorphic function 72 print( x ); 73 } 73 74 } 74 75 75 76 // ensure with-statement temporary generation works correctly 76 77 S mk() { 77 printf("called mk\n");78 return (S){ 444 };78 sout | "called mk"; 79 return (S){ 444 }; 79 80 } 80 81 81 82 // ensure with-statement temporary generation with reference-returning functions works correctly 82 83 S & ref() { 83 84 84 static S var = { 123456789 }; 85 return var; 85 86 } 86 87 87 88 int main() { 88 89 with (s2) {90 with(s) { // with s2.s91 printf("%d %d %d\n", i, s.i, s2.s.i);92 foo(i); // s.i93 with(mk()) {94 printf("%d %d %d\n", i, i, i);95 with(ref()) {96 printf("%d %d %d\n", i, i, i);97 98 with(ref()) {99 printf("%d %d %d\n", i, i, i);100 101 102 103 89 S2 s2 = { 12345 }; 90 with ( s2) { 91 with( s ) { // with s2.s 92 sout | i | s.i | s2.s.i; 93 foo( i ); // s.i 94 with( mk()) { 95 sout | i | i | i; 96 with( ref()) { 97 sout | i | i | i; 98 } // with ref() 99 with( ref()) { 100 sout | i | i | i; 101 } // with ref() 102 } // with mk() 103 } // with s 104 } // with s2 104 105 } 105 106
Note: See TracChangeset
for help on using the changeset viewer.