Changeset d5b2ac8
- Timestamp:
- Dec 26, 2018, 7:21:08 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:
- 0689cd9, 25cdca5
- Parents:
- f498c51
- Location:
- tests
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/genericUnion.cfa
rf498c51 rd5b2ac8 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // genericUnion.cfa -- 8 // 9 // Author : Peter A. Buhr 10 // Created On : Tue Dec 25 14:42:46 2018 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 25 14:46:33 2018 13 // Update Count : 2 14 // 15 1 16 #include <limits.hfa> 2 17 … … 4 19 union ByteView { 5 20 T val; 6 char bytes[(sizeof(int))]; 21 char bytes[(sizeof(int))]; // want to change to sizeof(T) 7 22 }; 8 23 9 24 forall(otype T) 10 25 void print(ByteView(T) x) { 11 for (int i = 0; i < sizeof(int); i++) { 26 for (int i = 0; i < sizeof(int); i++) { // want to change to sizeof(T) 12 27 printf("%02x", x.bytes[i] & 0xff); 13 28 } … … 29 44 f(i, -1); 30 45 } 46 47 // Local Variables: // 48 // tab-width: 4 // 49 // compile-command: "cfa genericUnion.cfa" // 50 // End: // -
tests/withStatement.cfa
rf498c51 rd5b2ac8 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.