adding a test case
[IRC.git] / Robust / src / Tests / OwnershipAnalysisTest / test02 / test02.java
1 public class Parameter {
2   flag w;
3   int a;
4   int b;
5   Parameter f;
6   Parameter g;
7   Penguin penguin;
8   public Parameter() { a = 0; b = 0; f = null; g = null; }
9   public void bar() { foo(); }
10   public void foo() { bar(); }
11 }
12
13 public class Penguin {
14   int x;
15   int y;  
16   public Penguin() { x = 0; y = 0; }
17   public void bar() { x = 1; }
18 }
19
20 public class Voo {
21   flag f; int x; Baw b; Baw bb;
22   public Voo() {}
23 }
24
25 public class Baw {
26   int y;
27   Foo f;
28   public Baw() {}
29   public void doTheBaw( Voo v ) { v = new Voo(); }
30 }
31
32 public class Foo {
33   flag f;
34   public Foo() {}
35   public Foo x;
36   public Foo y;
37   public Foo z;
38
39   public void ruinSomeFoos( Foo a, Foo b ) {
40     a.x = b.x;
41   }
42
43   static public void aStaticMethod( Foo p0, Foo p1 ) {
44     Foo f0 = new Foo();
45     Foo f1 = new Foo();
46     Foo f2 = new Foo();    
47     f0.x = f1;
48     p0.x = f0;
49     p1.x = f1;
50     p1.x = f2;
51   }
52 }
53
54 public class Zub {
55   flag q;
56   public Zub() {}
57   public Fub f;
58   public Zod z;
59
60   public void addStuff() {
61     f = new Fub();
62     z.h = new Hod();
63   }
64 }
65
66 public class Zod {
67   flag r;
68   public Zod() {}
69   public Hod h;
70 }
71
72 public class Fub { public Fub() {} }
73 public class Hod { public Hod() {} }
74
75 task improveMethodCallWithGlobal( Parameter notUsed{w} ) {
76
77   Zub a0 = new Zub();
78   a0.z = new Zod();
79   a0.addStuff();
80
81   taskexit( notUsed{!w} );
82 }
83
84
85 task Startup( StartupObject s{ initialstate } ) {
86   
87   /*
88     Parameter p = new Parameter(){!w};
89     p.foo();
90     
91     Penguin g = new Penguin();
92     g.bar();
93   */
94   
95   Parameter p;
96   
97   for( int i = 0; i < 3; ++i ) {
98     p = new Parameter();
99     p.penguin = new Penguin();
100     p.penguin.bar();
101   }
102   
103   p = null;
104   
105   taskexit( s{ !initialstate } );
106 }
107
108 /*
109 task aliasFromObjectAssignment
110   ( Parameter p1{!w}, Parameter p2{!w} ) {
111   
112   p1.f = p2.g;
113   
114   taskexit( p1{w}, p2{w} );
115 }
116
117 task noAliasFromPrimitiveAssignment
118   ( Parameter p1{!w}, Parameter p2{!w} ) {
119   
120   p1.a = p2.b;
121   
122   taskexit( p1{w}, p2{w} );
123 }
124
125 task aliasWithTwoLinks
126   ( Parameter p1{!w}, Parameter p2{!w} ) {
127   
128   Parameter j = p1.f;
129   p2.f = j;
130   
131   taskexit( p1{w}, p2{w} );
132 }
133
134 task aliasWithThreeLinks
135   ( Parameter p1{!w}, Parameter p2{!w} ) {
136   
137   Parameter j = p1.f;
138   Parameter k = j;
139   p2.f = k;
140   
141   taskexit( p1{w}, p2{w} );
142 }
143
144 task noAliasBreakLinks
145   ( Parameter p1{!w}, Parameter p2{!w} ) {
146   
147   Parameter j = p1.f;
148   Parameter k = j;
149   k = p2.f;
150   p2.f = k;
151   
152   taskexit( p1{w}, p2{w} );
153 }
154
155 task possibleAliasConditional
156   ( Parameter p1{!w}, Parameter p2{!w} ) {
157   
158   Parameter y;
159   
160   if( p1.a == 0 ) {
161     y = p1.f;
162   } else {
163     y = p2.f;
164   }
165   
166   p2.g = y;
167   
168   taskexit( p1{w}, p2{w} );
169 }
170
171 task bunchOfPaths
172   ( Parameter p1{!w}, Parameter p2{!w} ) {
173   
174   Parameter y;
175   
176   for( int i =0; i < 100; ++i ) {
177     
178     if( y == p1 ) {
179       Parameter z;
180       
181       for( int j = 0; i < 50; ++j ) {
182         if( z == y ) {
183           p1.f = y;
184         } else {
185           z = p2.g;
186         }
187         
188         p1.f = z;
189       }
190       
191       y = p1.g;
192     } else {
193       
194       p2.f = y;
195     }
196   }
197   
198   p1.f = p2.g;
199   
200   
201   taskexit( p1{w}, p2{w} );
202 }
203
204 task literalTest( Parameter p1{!w} ) {
205   Parameter x = null;
206   int y = 5;
207   String s = "Dude";
208   
209   taskexit( p1{w} );
210 }
211
212 task newNoAlias
213   ( Parameter p1{!w}, Parameter p2{!w} ) {
214   
215   for( int i = 0; i < 1; ++i ) {
216     p1.f = new Parameter();
217   }
218   
219   taskexit( p1{w}, p2{w} );
220 }
221
222 task newPossibleAlias
223   ( Parameter p1{!w}, Parameter p2{!w} ) {
224   
225   Parameter x, y;
226   
227   for( int i = 0; i < 1; ++i ) {
228     p1.f = new Parameter();
229     if( true ) {
230       x = p1.f;
231     } else {
232       y = p1.f;
233     }
234   }
235   
236   p2.f = y;
237   
238   taskexit( p1{w}, p2{w} );
239 }
240
241 task NoAliasNewInLoop( Voo v{ f } ) {
242   
243   for( int i = 0; i < 10; ++i ) {
244     Voo w = new Voo();
245     w.b   = new Baw();
246     w.b.f = new Foo();
247   }
248   
249   taskexit( v{ !f } );
250 }
251
252
253 task NoAliasNewInLoopAnotherWay( Voo v{ f } ) {
254   
255   for( int i = 0; i < 10; ++i ) {
256     Voo w = new Voo();
257     Baw b = new Baw();
258     Foo f = new Foo();
259     
260     w.b = b;
261     b.f = f;
262   }
263   
264   taskexit( v{ !f } );
265 }
266
267
268 task AliasParamToNew( Voo v{ f }, Voo w{ f } ) {
269   
270   Baw m = new Baw();
271   w.b = m;
272
273   Voo x = new Voo();
274   x.b = m;
275
276   taskexit( v{ !f }, w{ !f } );
277 }
278
279 task AliasNewToNew( Voo v{ f }, Voo w{ f } ) {
280   
281   Baw m = new Baw();
282
283   Voo x = new Voo();
284   x.b = m;
285
286   taskexit( v{ !f }, w{ !f } );
287 }
288 */