KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > compiler > flow > ConditionalFlowInfo


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.compiler.flow;
12
13 import org.eclipse.jdt.internal.compiler.lookup.FieldBinding;
14 import org.eclipse.jdt.internal.compiler.lookup.LocalVariableBinding;
15
16 /**
17  * Record conditional initialization status during definite assignment analysis
18  *
19  */

20 public class ConditionalFlowInfo extends FlowInfo {
21     
22     public FlowInfo initsWhenTrue;
23     public FlowInfo initsWhenFalse;
24     
25 ConditionalFlowInfo(FlowInfo initsWhenTrue, FlowInfo initsWhenFalse){
26     
27     this.initsWhenTrue = initsWhenTrue;
28     this.initsWhenFalse = initsWhenFalse;
29 }
30
31 public FlowInfo addInitializationsFrom(FlowInfo otherInits) {
32     
33     this.initsWhenTrue.addInitializationsFrom(otherInits);
34     this.initsWhenFalse.addInitializationsFrom(otherInits);
35     return this;
36 }
37
38 public FlowInfo addPotentialInitializationsFrom(FlowInfo otherInits) {
39     
40     this.initsWhenTrue.addPotentialInitializationsFrom(otherInits);
41     this.initsWhenFalse.addPotentialInitializationsFrom(otherInits);
42     return this;
43 }
44
45 public FlowInfo asNegatedCondition() {
46     
47     FlowInfo extra = initsWhenTrue;
48     initsWhenTrue = initsWhenFalse;
49     initsWhenFalse = extra;
50     return this;
51 }
52
53 public FlowInfo copy() {
54     
55     return new ConditionalFlowInfo(initsWhenTrue.copy(), initsWhenFalse.copy());
56 }
57
58 public FlowInfo initsWhenFalse() {
59     
60     return initsWhenFalse;
61 }
62
63 public FlowInfo initsWhenTrue() {
64     
65     return initsWhenTrue;
66 }
67     
68 public boolean isDefinitelyAssigned(FieldBinding field) {
69     
70     return initsWhenTrue.isDefinitelyAssigned(field)
71             && initsWhenFalse.isDefinitelyAssigned(field);
72 }
73
74 public boolean isDefinitelyAssigned(LocalVariableBinding local) {
75     
76     return initsWhenTrue.isDefinitelyAssigned(local)
77             && initsWhenFalse.isDefinitelyAssigned(local);
78 }
79     
80 public boolean isDefinitelyNonNull(LocalVariableBinding local) {
81     return initsWhenTrue.isDefinitelyNonNull(local)
82             && initsWhenFalse.isDefinitelyNonNull(local);
83 }
84     
85 public boolean isDefinitelyNull(LocalVariableBinding local) {
86     return initsWhenTrue.isDefinitelyNull(local)
87             && initsWhenFalse.isDefinitelyNull(local);
88 }
89
90 public boolean isDefinitelyUnknown(LocalVariableBinding local) {
91     return initsWhenTrue.isDefinitelyUnknown(local)
92             && initsWhenFalse.isDefinitelyUnknown(local);
93 }
94     
95 public boolean isPotentiallyAssigned(FieldBinding field) {
96     return initsWhenTrue.isPotentiallyAssigned(field)
97             || initsWhenFalse.isPotentiallyAssigned(field);
98 }
99
100 public boolean isPotentiallyAssigned(LocalVariableBinding local) {
101     return initsWhenTrue.isPotentiallyAssigned(local)
102             || initsWhenFalse.isPotentiallyAssigned(local);
103 }
104     
105 public boolean isPotentiallyNonNull(LocalVariableBinding local) {
106     return initsWhenTrue.isPotentiallyNonNull(local)
107         || initsWhenFalse.isPotentiallyNonNull(local);
108 }
109     
110 public boolean isPotentiallyNull(LocalVariableBinding local) {
111     return initsWhenTrue.isPotentiallyNull(local)
112         || initsWhenFalse.isPotentiallyNull(local);
113 }
114
115 public boolean isPotentiallyUnknown(LocalVariableBinding local) {
116     return initsWhenTrue.isPotentiallyUnknown(local)
117         || initsWhenFalse.isPotentiallyUnknown(local);
118 }
119
120 public boolean isProtectedNonNull(LocalVariableBinding local) {
121     return initsWhenTrue.isProtectedNonNull(local)
122         && initsWhenFalse.isProtectedNonNull(local);
123 }
124     
125 public boolean isProtectedNull(LocalVariableBinding local) {
126     return initsWhenTrue.isProtectedNull(local)
127         && initsWhenFalse.isProtectedNull(local);
128 }
129     
130 public void markAsComparedEqualToNonNull(LocalVariableBinding local) {
131     initsWhenTrue.markAsComparedEqualToNonNull(local);
132     initsWhenFalse.markAsComparedEqualToNonNull(local);
133 }
134
135 public void markAsComparedEqualToNull(LocalVariableBinding local) {
136     initsWhenTrue.markAsComparedEqualToNull(local);
137     initsWhenFalse.markAsComparedEqualToNull(local);
138 }
139     
140 public void markAsDefinitelyAssigned(FieldBinding field) {
141     initsWhenTrue.markAsDefinitelyAssigned(field);
142     initsWhenFalse.markAsDefinitelyAssigned(field);
143 }
144
145 public void markAsDefinitelyAssigned(LocalVariableBinding local) {
146     initsWhenTrue.markAsDefinitelyAssigned(local);
147     initsWhenFalse.markAsDefinitelyAssigned(local);
148 }
149
150 public void markAsDefinitelyNonNull(LocalVariableBinding local) {
151     initsWhenTrue.markAsDefinitelyNonNull(local);
152     initsWhenFalse.markAsDefinitelyNonNull(local);
153 }
154
155 public void markAsDefinitelyNull(LocalVariableBinding local) {
156     initsWhenTrue.markAsDefinitelyNull(local);
157     initsWhenFalse.markAsDefinitelyNull(local);
158 }
159
160 public void markAsDefinitelyUnknown(LocalVariableBinding local) {
161     initsWhenTrue.markAsDefinitelyUnknown(local);
162     initsWhenFalse.markAsDefinitelyUnknown(local);
163 }
164
165 public FlowInfo setReachMode(int reachMode) {
166     if (reachMode == REACHABLE) {
167         this.tagBits &= ~UNREACHABLE;
168     }
169     else {
170         this.tagBits |= UNREACHABLE;
171     }
172     initsWhenTrue.setReachMode(reachMode);
173     initsWhenFalse.setReachMode(reachMode);
174     return this;
175 }
176     
177 public UnconditionalFlowInfo mergedWith(UnconditionalFlowInfo otherInits) {
178     return unconditionalInits().mergedWith(otherInits);
179 }
180
181 public UnconditionalFlowInfo nullInfoLessUnconditionalCopy() {
182     return unconditionalInitsWithoutSideEffect().
183         nullInfoLessUnconditionalCopy();
184 }
185
186 public String JavaDoc toString() {
187     
188     return "FlowInfo<true: " + initsWhenTrue.toString() + ", false: " + initsWhenFalse.toString() + ">"; //$NON-NLS-1$ //$NON-NLS-3$ //$NON-NLS-2$
189
}
190
191 public FlowInfo safeInitsWhenTrue() {
192     return initsWhenTrue;
193 }
194
195 public UnconditionalFlowInfo unconditionalCopy() {
196     return initsWhenTrue.unconditionalCopy().
197             mergedWith(initsWhenFalse.unconditionalInits());
198 }
199
200 public UnconditionalFlowInfo unconditionalFieldLessCopy() {
201     return initsWhenTrue.unconditionalFieldLessCopy().
202         mergedWith(initsWhenFalse.unconditionalFieldLessCopy());
203     // should never happen, hence suboptimal does not hurt
204
}
205
206 public UnconditionalFlowInfo unconditionalInits() {
207     return initsWhenTrue.unconditionalInits().
208             mergedWith(initsWhenFalse.unconditionalInits());
209 }
210
211 public UnconditionalFlowInfo unconditionalInitsWithoutSideEffect() {
212     // cannot do better here than unconditionalCopy - but still a different
213
// operation for UnconditionalFlowInfo
214
return initsWhenTrue.unconditionalCopy().
215             mergedWith(initsWhenFalse.unconditionalInits());
216 }
217 }
218
Popular Tags