Added fields to ReferenceEdgeProperties and combed over all classes that need proper...
[IRC.git] / Robust / src / Tests / OwnershipAnalysisTest / test01 / test01.java
1
2 public class Parameter {
3     flag w;
4     int a, b;
5     Parameter f, g;
6     Penguin penguin;
7
8     public Parameter() { a = 0; b = 0; f = null; g = null; }
9
10     public void bar() { foo(); }
11     public void foo() { bar(); }
12 }
13
14 public class Penguin {
15     int x, y;
16
17     public Penguin() { x = 0; y = 0; }
18
19     public void bar() { x = 1; }
20 }
21
22 public class Voo {
23     flag f; int x; Baw b; Baw bb;
24
25     public Voo() {}
26 }
27
28 public class Baw {
29     int y;
30     Foo f;
31
32     public Baw() {}
33
34     public void doTheBaw( Voo v ) { v = new Voo(); }
35 }
36
37
38 public class Foo {
39     flag f;
40
41     public Foo() {}
42
43     public Foo x;
44
45     public void ruinSomeFoos( Foo a, Foo b ) {
46         a.x = b.x;
47     }
48
49     static public void test( Foo p0, Foo p1 ) {
50         Foo f0 = new Foo();
51         Foo f1 = new Foo();
52         Foo f2 = new Foo();
53
54         f0.x = f1;
55         p0.x = f0;
56         p1.x = f1;
57         p1.x = f2;
58     }
59 }
60
61
62 // this empty task should still create a non-empty
63 // ownership graph showing parameter allocation
64 // look for the parameter s as a label referencing
65 // a heap region that is multi-object, flagged, not summary
66 task Startup( StartupObject s{ initialstate } ) {
67     
68     /*
69     while( false ) {
70         Foo a = new Foo();
71         a.x   = new Foo();
72         a.x.x = new Foo();
73
74         //Foo z = a.x;
75         //z.x = new Foo();
76     }
77     
78
79
80     Foo d = new Foo();
81     Foo e = new Foo();
82     Foo f = new Foo();
83     Foo g = new Foo();
84
85     d.x = e;
86     e.x = f;
87     f.x = g;
88
89
90     Foo h = new Foo();
91     Foo i = new Foo();
92     Foo j = new Foo();
93     Foo k = new Foo();
94
95     j.x = k;
96     i.x = j;
97     h.x = i;
98
99
100     
101
102     // to look like Foo a above
103     //d.x.x = f;
104
105
106     Foo b;
107     while( false ) {
108         Foo c = new Foo();
109         c.x = b;
110         b = c;
111     }
112     */
113     
114     /*
115     aa.x = ab;
116     ab.x = ac;
117     ab.x = aa;
118     ad.x = aa;
119     */
120
121     taskexit( s{ !initialstate } );
122 }
123
124
125 task methodTest( Foo p0{ f } ) {
126
127     Foo a0;
128     if( false ) {
129         a0 = new Foo();
130     } else {
131         a0   = new Foo();
132         a0.x = new Foo();
133         p0.x = a0;
134     }
135
136     Foo a1 = new Foo();
137
138     if( false ) {       
139         p0.x = a1;
140     }
141
142     Foo.test( a0, a1 );
143
144     taskexit( p0{ !f } );
145 }
146
147 /*
148 task NewObject( Foo a{ f }, Foo b{ f } ) {
149
150     Foo c = new Foo();
151
152     a.x = c;
153
154     taskexit( a{ !f }, b{ !f } );
155 }
156 */
157
158 /*
159 task NewObjectA( Foo a{ f }, Foo b{ f } ) {
160
161     Foo c = new Foo();
162     Foo d = new Foo();
163
164     c.x = d;
165     a.x = c;
166
167     taskexit( a{ !f }, b{ !f } );
168 }
169
170 task NewObjectB( Foo a{ f }, Foo b{ f } ) {
171
172     Foo c = new Foo();
173     Foo d = new Foo();
174
175     a.x = c;
176     c.x = d;
177
178     taskexit( a{ !f }, b{ !f } );
179 }
180 */
181
182 /*
183 task NewObject2( Foo a{ f }, Foo b{ f } ) {
184
185     Foo c;
186
187     while( false ) {
188         c   = new Foo();
189         c.x = new Foo();
190     }
191
192     taskexit( a{ !f }, b{ !f } );
193 }
194 */
195
196
197 /*
198 // this task allocates a new object, so there should
199 // be a heap region for the parameter, and several
200 // heap regions for the allocation site, but the label
201 // merely points to the newest region
202 task NewObject( Voo v{ f } ) {
203     Voo w = new Voo();
204     Baw b = new Baw();
205     b.doTheBaw( w );
206
207     taskexit( v{ !f } );
208 }
209
210
211 // this task 
212 task Branch( Voo v{ f } ) {
213     Voo w = new Voo();
214     Baw j = new Baw();
215     Baw k = new Baw();
216
217     if( v.x == 0 ) {
218         w.b = j;
219     } else {
220         w.b = k;
221     }
222
223     taskexit( v{ !f } );
224 }
225
226
227 task NoAliasNewInLoop( Voo v{ f } ) {
228
229     for( int i = 0; i < 10; ++i ) {
230         Voo w = new Voo();
231         w.b   = new Baw();
232         w.b.f = new Foo();
233     }
234
235     taskexit( v{ !f } );
236 }
237
238
239 task NoAliasNewInLoopAnotherWay( Voo v{ f } ) {
240
241     for( int i = 0; i < 10; ++i ) {
242         Voo w = new Voo();
243         Baw b = new Baw();
244         Foo f = new Foo();
245
246         w.b = b;
247         b.f = f;
248     }
249
250     taskexit( v{ !f } );
251 }
252
253
254 task ClobberInitParamReflex( Voo v{ f }, Voo w{ f } ) {
255     v.b = v.bb;
256
257     taskexit( v{ !f }, w{ !f } );
258 }
259 */