ADTast-experimentalenumforall-pointer-decaypthread-emulationqualifiedEnum
Last change
on this file since cd4c605 was
fd54fef,
checked in by Michael Brooks <mlbrooks@…>, 4 years ago
|
Converting the project to use the new syntax for otype, dtype and ttytpe.
Changed prelude (gen), libcfa and test suite to use it. Added a simple deprecation rule of the old syntax to the parser; we might wish to support both syntaxes "officially," like with an extra CLI switch, but this measure should serve as a simple reminder for our team to try the new syntax.
|
-
Property mode set to
100644
|
File size:
1.9 KB
|
Line | |
---|
1 | // |
---|
2 | // Cforall Version 1.0.0 Copyright (C) 2017 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 | // tupleFunction.c -- |
---|
8 | // |
---|
9 | // Author : Rob Schluntz |
---|
10 | // Created On : Mon Dec 04 17:41:45 2017 |
---|
11 | // Last Modified By : Peter A. Buhr |
---|
12 | // Last Modified On : Mon Dec 24 19:08:18 2018 |
---|
13 | // Update Count : 5 |
---|
14 | // |
---|
15 | |
---|
16 | #include <fstream.hfa> |
---|
17 | |
---|
18 | struct S { |
---|
19 | int i; |
---|
20 | // dynamically allocated member ensures ctor/dtors are called correctly on temporaries |
---|
21 | int * ptr; |
---|
22 | }; |
---|
23 | |
---|
24 | // with clause on reference parameter |
---|
25 | void ?{}( S & this, int n ) with( this ) { |
---|
26 | i = n; |
---|
27 | ptr = (int *)malloc( sizeof(int) ); |
---|
28 | } |
---|
29 | |
---|
30 | void ?{}( S & this ) { |
---|
31 | this{ 0 }; |
---|
32 | } |
---|
33 | |
---|
34 | void ?{}( S & this, S other ) { |
---|
35 | this{ other.i }; |
---|
36 | } |
---|
37 | |
---|
38 | S ?=?( S & this, S other ) with( this ) { |
---|
39 | i = other.i; |
---|
40 | *ptr = *other.ptr; |
---|
41 | return this; |
---|
42 | } |
---|
43 | |
---|
44 | void ^?{}( S & this ) with( this ) { |
---|
45 | free( ptr ); |
---|
46 | } |
---|
47 | |
---|
48 | struct S2 { |
---|
49 | S s; |
---|
50 | }; |
---|
51 | |
---|
52 | void ?{}( S2 & this, int n ) { |
---|
53 | (this.s){ n }; |
---|
54 | } |
---|
55 | |
---|
56 | forall( T ) |
---|
57 | struct Box { |
---|
58 | T x; |
---|
59 | }; |
---|
60 | |
---|
61 | forall( T ) |
---|
62 | void ?{}( Box(T) & this ) with( this ) { // with clause in polymorphic function |
---|
63 | x{}; |
---|
64 | } |
---|
65 | |
---|
66 | void print( int i ) { sout | i; } |
---|
67 | |
---|
68 | forall( 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 | } |
---|
74 | } |
---|
75 | |
---|
76 | // ensure with-statement temporary generation works correctly |
---|
77 | S mk() { |
---|
78 | sout | "called mk"; |
---|
79 | return (S){ 444 }; |
---|
80 | } |
---|
81 | |
---|
82 | // ensure with-statement temporary generation with reference-returning functions works correctly |
---|
83 | S & ref() { |
---|
84 | static S var = { 123456789 }; |
---|
85 | return var; |
---|
86 | } |
---|
87 | |
---|
88 | int main() { |
---|
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 |
---|
105 | } |
---|
106 | |
---|
107 | // Local Variables: // |
---|
108 | // tab-width: 4 // |
---|
109 | // End: // |
---|
Note: See
TracBrowser
for help on using the repository browser.