bug fix: when calculating methods dependent on a new result, only include methods...
[IRC.git] / Robust / src / Tests / OwnershipAnalysisTest / test02 / test02.java
1 public class Parameter {
2     flag w;
3     int a, b;
4     Parameter f, g;
5     Penguin penguin;
6
7     public Parameter() { a = 0; b = 0; f = null; g = null; }
8
9     public void bar() { foo(); }
10     public void foo() { bar(); }
11 }
12
13 public class Penguin {
14     int x, y;
15
16     public Penguin() { x = 0; y = 0; }
17
18     public void bar() { x = 1; }
19 }
20
21 public class Voo {
22     flag f; int x; Baw b; Baw bb;
23
24     public Voo() {}
25 }
26
27 public class Baw {
28     int y;
29     Foo f;
30
31     public Baw() {}
32
33     public void doTheBaw( Voo v ) { v = new Voo(); }
34 }
35
36 public class Foo {
37     flag f;
38
39     public Foo() {}
40
41     public Foo x;
42     public Foo y;
43     public Foo z;
44
45     public void ruinSomeFoos( Foo a, Foo b ) {
46         a.x = b.x;
47     }
48
49     static public void aStaticMethod( 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 task Startup( StartupObject s{ initialstate } ) {
62
63     /*
64     Parameter p = new Parameter(){!w};
65     p.foo();
66
67     Penguin g = new Penguin();
68     g.bar();
69     */
70
71     Parameter p;
72
73     for( int i = 0; i < 3; ++i ) {
74         p = new Parameter();
75         p.penguin = new Penguin();
76         p.penguin.bar();
77     }
78
79     p = null;
80
81     taskexit( s{ !initialstate } );
82 }
83
84
85 task aliasFromObjectAssignment
86     ( Parameter p1{!w}, Parameter p2{!w} ) {
87     
88     p1.f = p2.g;
89
90     taskexit( p1{w}, p2{w} );
91 }
92
93 task noAliasFromPrimitiveAssignment
94     ( Parameter p1{!w}, Parameter p2{!w} ) {
95     
96     p1.a = p2.b;
97
98     taskexit( p1{w}, p2{w} );
99 }
100
101 task aliasWithTwoLinks
102     ( Parameter p1{!w}, Parameter p2{!w} ) {
103     
104     Parameter j = p1.f;
105     p2.f = j;
106
107     taskexit( p1{w}, p2{w} );
108 }
109
110 task aliasWithThreeLinks
111     ( Parameter p1{!w}, Parameter p2{!w} ) {
112     
113     Parameter j = p1.f;
114     Parameter k = j;
115     p2.f = k;
116
117     taskexit( p1{w}, p2{w} );
118 }
119
120 task noAliasBreakLinks
121     ( Parameter p1{!w}, Parameter p2{!w} ) {
122     
123     Parameter j = p1.f;
124     Parameter k = j;
125     k = p2.f;
126     p2.f = k;
127
128     taskexit( p1{w}, p2{w} );
129 }
130
131 task possibleAliasConditional
132     ( Parameter p1{!w}, Parameter p2{!w} ) {
133     
134     Parameter y;
135
136     if( p1.a == 0 ) {
137         y = p1.f;
138     } else {
139         y = p2.f;
140     }
141
142     p2.g = y;
143
144     taskexit( p1{w}, p2{w} );
145 }
146
147 task bunchOfPaths
148     ( Parameter p1{!w}, Parameter p2{!w} ) {
149
150     Parameter y;
151
152     for( int i =0; i < 100; ++i ) {
153
154         if( y == p1 ) {
155             Parameter z;
156
157             for( int j = 0; i < 50; ++j ) {
158                 if( z == y ) {
159                     p1.f = y;
160                 } else {
161                     z = p2.g;
162                 }
163
164                 p1.f = z;
165             }
166
167             y = p1.g;
168         } else {
169
170             p2.f = y;
171         }
172     }
173
174     p1.f = p2.g;
175
176
177     taskexit( p1{w}, p2{w} );
178 }
179
180 task literalTest( Parameter p1{!w} ) {
181     Parameter x = null;
182     int y = 5;
183     String s = "Dude";
184
185     taskexit( p1{w} );
186 }
187
188 task newNoAlias
189     ( Parameter p1{!w}, Parameter p2{!w} ) {
190
191     for( int i = 0; i < 1; ++i ) {
192         p1.f = new Parameter();
193     }
194
195     taskexit( p1{w}, p2{w} );
196 }
197
198 task newPossibleAlias
199     ( Parameter p1{!w}, Parameter p2{!w} ) {
200
201     Parameter x, y;
202
203     for( int i = 0; i < 1; ++i ) {
204         p1.f = new Parameter();
205         if( true ) {
206             x = p1.f;
207         } else {
208             y = p1.f;
209         }
210     }
211
212     p2.f = y;
213
214     taskexit( p1{w}, p2{w} );
215 }
216
217 task NoAliasNewInLoop( Voo v{ f } ) {
218
219     for( int i = 0; i < 10; ++i ) {
220         Voo w = new Voo();
221         w.b   = new Baw();
222         w.b.f = new Foo();
223     }
224
225     taskexit( v{ !f } );
226 }
227
228
229 task NoAliasNewInLoopAnotherWay( Voo v{ f } ) {
230
231     for( int i = 0; i < 10; ++i ) {
232         Voo w = new Voo();
233         Baw b = new Baw();
234         Foo f = new Foo();
235
236         w.b = b;
237         b.f = f;
238     }
239
240     taskexit( v{ !f } );
241 }