Put the rest of the top-level interface together
[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 task Startup( StartupObject s{ initialstate } ) {
55   
56   /*
57     Parameter p = new Parameter(){!w};
58     p.foo();
59     
60     Penguin g = new Penguin();
61     g.bar();
62   */
63   
64   Parameter p;
65   
66   for( int i = 0; i < 3; ++i ) {
67     p = new Parameter();
68     p.penguin = new Penguin();
69     p.penguin.bar();
70   }
71   
72   p = null;
73   
74   taskexit( s{ !initialstate } );
75 }
76
77
78 task aliasFromObjectAssignment
79   ( Parameter p1{!w}, Parameter p2{!w} ) {
80   
81   p1.f = p2.g;
82   
83   taskexit( p1{w}, p2{w} );
84 }
85
86 task noAliasFromPrimitiveAssignment
87   ( Parameter p1{!w}, Parameter p2{!w} ) {
88   
89   p1.a = p2.b;
90   
91   taskexit( p1{w}, p2{w} );
92 }
93
94 task aliasWithTwoLinks
95   ( Parameter p1{!w}, Parameter p2{!w} ) {
96   
97   Parameter j = p1.f;
98   p2.f = j;
99   
100   taskexit( p1{w}, p2{w} );
101 }
102
103 task aliasWithThreeLinks
104   ( Parameter p1{!w}, Parameter p2{!w} ) {
105   
106   Parameter j = p1.f;
107   Parameter k = j;
108   p2.f = k;
109   
110   taskexit( p1{w}, p2{w} );
111 }
112
113 task noAliasBreakLinks
114   ( Parameter p1{!w}, Parameter p2{!w} ) {
115   
116   Parameter j = p1.f;
117   Parameter k = j;
118   k = p2.f;
119   p2.f = k;
120   
121   taskexit( p1{w}, p2{w} );
122 }
123
124 task possibleAliasConditional
125   ( Parameter p1{!w}, Parameter p2{!w} ) {
126   
127   Parameter y;
128   
129   if( p1.a == 0 ) {
130     y = p1.f;
131   } else {
132     y = p2.f;
133   }
134   
135   p2.g = y;
136   
137   taskexit( p1{w}, p2{w} );
138 }
139
140 task bunchOfPaths
141   ( Parameter p1{!w}, Parameter p2{!w} ) {
142   
143   Parameter y;
144   
145   for( int i =0; i < 100; ++i ) {
146     
147     if( y == p1 ) {
148       Parameter z;
149       
150       for( int j = 0; i < 50; ++j ) {
151         if( z == y ) {
152           p1.f = y;
153         } else {
154           z = p2.g;
155         }
156         
157         p1.f = z;
158       }
159       
160       y = p1.g;
161     } else {
162       
163       p2.f = y;
164     }
165   }
166   
167   p1.f = p2.g;
168   
169   
170   taskexit( p1{w}, p2{w} );
171 }
172
173 task literalTest( Parameter p1{!w} ) {
174   Parameter x = null;
175   int y = 5;
176   String s = "Dude";
177   
178   taskexit( p1{w} );
179 }
180
181 task newNoAlias
182   ( Parameter p1{!w}, Parameter p2{!w} ) {
183   
184   for( int i = 0; i < 1; ++i ) {
185     p1.f = new Parameter();
186   }
187   
188   taskexit( p1{w}, p2{w} );
189 }
190
191 task newPossibleAlias
192   ( Parameter p1{!w}, Parameter p2{!w} ) {
193   
194   Parameter x, y;
195   
196   for( int i = 0; i < 1; ++i ) {
197     p1.f = new Parameter();
198     if( true ) {
199       x = p1.f;
200     } else {
201       y = p1.f;
202     }
203   }
204   
205   p2.f = y;
206   
207   taskexit( p1{w}, p2{w} );
208 }
209
210 task NoAliasNewInLoop( Voo v{ f } ) {
211   
212   for( int i = 0; i < 10; ++i ) {
213     Voo w = new Voo();
214     w.b   = new Baw();
215     w.b.f = new Foo();
216   }
217   
218   taskexit( v{ !f } );
219 }
220
221
222 task NoAliasNewInLoopAnotherWay( Voo v{ f } ) {
223   
224   for( int i = 0; i < 10; ++i ) {
225     Voo w = new Voo();
226     Baw b = new Baw();
227     Foo f = new Foo();
228     
229     w.b = b;
230     b.f = f;
231   }
232   
233   taskexit( v{ !f } );
234 }
235
236
237 task AliasParamToNew( Voo v{ f }, Voo w{ f } ) {
238   
239   Baw m = new Baw();
240   w.b = m;
241
242   Voo x = new Voo();
243   x.b = m;
244
245   taskexit( v{ !f }, w{ !f } );
246 }
247
248 task AliasNewToNew( Voo v{ f }, Voo w{ f } ) {
249   
250   Baw m = new Baw();
251
252   Voo x = new Voo();
253   x.b = m;
254
255   taskexit( v{ !f }, w{ !f } );
256 }