1 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 public abstract class FlowInfo { 17 18 public int tagBits; public final static int REACHABLE = 0; 20 public final static int UNREACHABLE = 1; 21 public final static int NULL_FLAG_MASK = 2; 22 23 public final static int UNKNOWN = 0; 24 public final static int NULL = 1; 25 public final static int NON_NULL = -1; 26 27 public static final UnconditionalFlowInfo DEAD_END; static { 29 DEAD_END = new UnconditionalFlowInfo(); 30 DEAD_END.tagBits = UNREACHABLE; 31 } 32 33 40 abstract public FlowInfo addInitializationsFrom(FlowInfo otherInits); 41 42 43 53 abstract public FlowInfo addPotentialInitializationsFrom(FlowInfo otherInits); 54 55 public FlowInfo asNegatedCondition() { 56 57 return this; 58 } 59 60 public static FlowInfo conditional(FlowInfo initsWhenTrue, FlowInfo initsWhenFalse){ 61 62 return new ConditionalFlowInfo(initsWhenTrue, initsWhenFalse); 64 } 65 66 77 public boolean cannotBeDefinitelyNullOrNonNull(LocalVariableBinding local) { 78 return isPotentiallyUnknown(local) || 79 isPotentiallyNonNull(local) && isPotentiallyNull(local); 80 } 81 82 88 public boolean cannotBeNull(LocalVariableBinding local) { 89 return isDefinitelyNonNull(local) || isProtectedNonNull(local); 90 } 91 92 98 public boolean canOnlyBeNull(LocalVariableBinding local) { 99 return isDefinitelyNull(local) || isProtectedNull(local); 100 } 101 102 106 abstract public FlowInfo copy(); 107 108 public static UnconditionalFlowInfo initial(int maxFieldCount) { 109 UnconditionalFlowInfo info = new UnconditionalFlowInfo(); 110 info.maxFieldCount = maxFieldCount; 111 return info; 112 } 113 114 123 abstract public FlowInfo initsWhenFalse(); 124 125 134 abstract public FlowInfo initsWhenTrue(); 135 136 139 abstract public boolean isDefinitelyAssigned(FieldBinding field); 140 141 144 public abstract boolean isDefinitelyAssigned(LocalVariableBinding local); 145 146 151 public abstract boolean isDefinitelyNonNull(LocalVariableBinding local); 152 153 158 public abstract boolean isDefinitelyNull(LocalVariableBinding local); 159 160 165 public abstract boolean isDefinitelyUnknown(LocalVariableBinding local); 166 167 170 abstract public boolean isPotentiallyAssigned(FieldBinding field); 171 172 175 176 abstract public boolean isPotentiallyAssigned(LocalVariableBinding field); 177 178 185 public abstract boolean isPotentiallyNonNull(LocalVariableBinding local); 186 187 197 public abstract boolean isPotentiallyNull(LocalVariableBinding local); 198 199 204 public abstract boolean isPotentiallyUnknown(LocalVariableBinding local); 205 206 212 public abstract boolean isProtectedNonNull(LocalVariableBinding local); 213 214 219 public abstract boolean isProtectedNull(LocalVariableBinding local); 220 221 225 abstract public void markAsComparedEqualToNonNull(LocalVariableBinding local); 226 227 231 abstract public void markAsComparedEqualToNull(LocalVariableBinding local); 232 233 236 abstract public void markAsDefinitelyAssigned(FieldBinding field); 237 238 241 abstract public void markAsDefinitelyNonNull(LocalVariableBinding local); 242 243 246 abstract public void markAsDefinitelyNull(LocalVariableBinding local); 247 248 251 abstract public void markAsDefinitelyAssigned(LocalVariableBinding local); 252 253 256 abstract public void markAsDefinitelyUnknown(LocalVariableBinding local); 257 258 261 public static UnconditionalFlowInfo mergedOptimizedBranches( 262 FlowInfo initsWhenTrue, boolean isOptimizedTrue, 263 FlowInfo initsWhenFalse, boolean isOptimizedFalse, 264 boolean allowFakeDeadBranch) { 265 UnconditionalFlowInfo mergedInfo; 266 if (isOptimizedTrue){ 267 if (initsWhenTrue == FlowInfo.DEAD_END && allowFakeDeadBranch) { 268 mergedInfo = initsWhenFalse.setReachMode(FlowInfo.UNREACHABLE). 269 unconditionalInits(); 270 } 271 else { 272 mergedInfo = 273 initsWhenTrue.addPotentialInitializationsFrom(initsWhenFalse. 274 nullInfoLessUnconditionalCopy()). 275 unconditionalInits(); 276 } 277 } 278 else if (isOptimizedFalse) { 279 if (initsWhenFalse == FlowInfo.DEAD_END && allowFakeDeadBranch) { 280 mergedInfo = initsWhenTrue.setReachMode(FlowInfo.UNREACHABLE). 281 unconditionalInits(); 282 } 283 else { 284 mergedInfo = 285 initsWhenFalse.addPotentialInitializationsFrom(initsWhenTrue. 286 nullInfoLessUnconditionalCopy()). 287 unconditionalInits(); 288 } 289 } 290 else { 291 mergedInfo = initsWhenTrue. 292 mergedWith(initsWhenFalse.unconditionalInits()); 293 } 294 return mergedInfo; 295 } 296 297 303 public int reachMode() { 304 return this.tagBits & UNREACHABLE; 305 } 306 307 314 abstract public FlowInfo safeInitsWhenTrue(); 315 316 321 abstract public FlowInfo setReachMode(int reachMode); 322 323 337 abstract public UnconditionalFlowInfo mergedWith( 338 UnconditionalFlowInfo otherInits); 339 340 345 abstract public UnconditionalFlowInfo nullInfoLessUnconditionalCopy(); 346 347 public String toString(){ 348 349 if (this == DEAD_END){ 350 return "FlowInfo.DEAD_END"; } 352 return super.toString(); 353 } 354 355 361 abstract public UnconditionalFlowInfo unconditionalCopy(); 362 363 369 abstract public UnconditionalFlowInfo unconditionalFieldLessCopy(); 370 371 379 abstract public UnconditionalFlowInfo unconditionalInits(); 380 381 388 abstract public UnconditionalFlowInfo unconditionalInitsWithoutSideEffect(); 389 } 390 | Popular Tags |