1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.compiler.flow;
13 import net.sourceforge.phpdt.internal.compiler.lookup.BlockScope;
14 import net.sourceforge.phpdt.internal.compiler.lookup.FieldBinding;
15 import net.sourceforge.phpdt.internal.compiler.lookup.LocalVariableBinding;
16 import net.sourceforge.phpeclipse.internal.compiler.ast.Statement;
18 public abstract class FlowInfo {
20 public final static int REACHABLE = 0;
21 public final static int UNREACHABLE = 1;
23 public static final UnconditionalFlowInfo DEAD_END; // Represents a dead branch status of initialization
25 DEAD_END = new UnconditionalFlowInfo();
26 DEAD_END.reachMode = UNREACHABLE;
28 abstract public FlowInfo addInitializationsFrom(FlowInfo otherInits);
30 abstract public FlowInfo addPotentialInitializationsFrom(FlowInfo otherInits);
32 public FlowInfo asNegatedCondition() {
37 public boolean complainIfUnreachable(Statement statement, BlockScope scope, boolean didAlreadyComplain) {
39 // Report an error if necessary
43 public static FlowInfo conditional(FlowInfo initsWhenTrue, FlowInfo initsWhenFalse){
45 // if (initsWhenTrue.equals(initsWhenFalse)) return initsWhenTrue; -- could optimize if #equals is defined
46 return new ConditionalFlowInfo(initsWhenTrue, initsWhenFalse);
49 abstract public FlowInfo copy();
51 public static UnconditionalFlowInfo initial(int maxFieldCount) {
52 UnconditionalFlowInfo info = new UnconditionalFlowInfo();
53 info.maxFieldCount = maxFieldCount;
57 abstract public FlowInfo initsWhenFalse();
59 abstract public FlowInfo initsWhenTrue();
62 * Check status of definite assignment for a field.
64 abstract public boolean isDefinitelyAssigned(FieldBinding field);
67 * Check status of definite assignment for a local.
69 public abstract boolean isDefinitelyAssigned(LocalVariableBinding local);
71 //abstract public int reachMode();
74 * Check status of potential assignment for a field.
76 abstract public boolean isPotentiallyAssigned(FieldBinding field);
79 * Check status of potential assignment for a local variable.
82 abstract public boolean isPotentiallyAssigned(LocalVariableBinding field);
84 abstract public boolean isReachable();
87 * Record a field got definitely assigned.
89 abstract public void markAsDefinitelyAssigned(FieldBinding field);
92 * Record a local got definitely assigned.
94 abstract public void markAsDefinitelyAssigned(LocalVariableBinding local);
97 * Clear the initialization info for a field
99 abstract public void markAsDefinitelyNotAssigned(FieldBinding field);
102 * Clear the initialization info for a local variable
104 abstract public void markAsDefinitelyNotAssigned(LocalVariableBinding local);
106 abstract public int reachMode();
108 abstract public FlowInfo setReachMode(int reachMode);
111 * Returns the receiver updated in the following way: <ul>
112 * <li> intersection of definitely assigned variables,
113 * <li> union of potentially assigned variables.
116 abstract public UnconditionalFlowInfo mergedWith(UnconditionalFlowInfo otherInits);
118 public String toString(){
120 if (this == DEAD_END){
121 return "FlowInfo.DEAD_END"; //$NON-NLS-1$
123 return super.toString();
126 abstract public UnconditionalFlowInfo unconditionalInits();