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.ast.Statement;
14 import net.sourceforge.phpdt.internal.compiler.lookup.BlockScope;
15 import net.sourceforge.phpdt.internal.compiler.lookup.FieldBinding;
16 import net.sourceforge.phpdt.internal.compiler.lookup.LocalVariableBinding;
18 public abstract class FlowInfo {
20 public final static int REACHABLE = 0;
22 public final static int UNREACHABLE = 1;
24 public static final UnconditionalFlowInfo DEAD_END; // Represents a dead
28 DEAD_END = new UnconditionalFlowInfo();
29 DEAD_END.reachMode = UNREACHABLE;
32 abstract public FlowInfo addInitializationsFrom(FlowInfo otherInits);
34 abstract public FlowInfo addPotentialInitializationsFrom(FlowInfo otherInits);
36 public FlowInfo asNegatedCondition() {
41 public boolean complainIfUnreachable(Statement statement, BlockScope scope,
42 boolean didAlreadyComplain) {
44 // Report an error if necessary
48 public static FlowInfo conditional(FlowInfo initsWhenTrue,
49 FlowInfo initsWhenFalse) {
51 // if (initsWhenTrue.equals(initsWhenFalse)) return initsWhenTrue; --
52 // could optimize if #equals is defined
53 return new ConditionalFlowInfo(initsWhenTrue, initsWhenFalse);
56 abstract public FlowInfo copy();
58 public static UnconditionalFlowInfo initial(int maxFieldCount) {
59 UnconditionalFlowInfo info = new UnconditionalFlowInfo();
60 info.maxFieldCount = maxFieldCount;
64 abstract public FlowInfo initsWhenFalse();
66 abstract public FlowInfo initsWhenTrue();
69 * Check status of definite assignment for a field.
71 abstract public boolean isDefinitelyAssigned(FieldBinding field);
74 * Check status of definite assignment for a local.
76 public abstract boolean isDefinitelyAssigned(LocalVariableBinding local);
78 // abstract public int reachMode();
81 * Check status of potential assignment for a field.
83 abstract public boolean isPotentiallyAssigned(FieldBinding field);
86 * Check status of potential assignment for a local variable.
89 abstract public boolean isPotentiallyAssigned(LocalVariableBinding field);
91 abstract public boolean isReachable();
94 * Record a field got definitely assigned.
96 abstract public void markAsDefinitelyAssigned(FieldBinding field);
99 * Record a local got definitely assigned.
101 abstract public void markAsDefinitelyAssigned(LocalVariableBinding local);
104 * Clear the initialization info for a field
106 abstract public void markAsDefinitelyNotAssigned(FieldBinding field);
109 * Clear the initialization info for a local variable
111 abstract public void markAsDefinitelyNotAssigned(LocalVariableBinding local);
113 abstract public int reachMode();
115 abstract public FlowInfo setReachMode(int reachMode);
118 * Returns the receiver updated in the following way:
120 * <li> intersection of definitely assigned variables,
121 * <li> union of potentially assigned variables.
124 abstract public UnconditionalFlowInfo mergedWith(
125 UnconditionalFlowInfo otherInits);
127 public String toString() {
129 if (this == DEAD_END) {
130 return "FlowInfo.DEAD_END"; //$NON-NLS-1$
132 return super.toString();
135 abstract public UnconditionalFlowInfo unconditionalInits();