1) Fixed html syntax highlighting.
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / flow / FlowInfo.java
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
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpdt.internal.compiler.flow;
12
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;
17
18 public abstract class FlowInfo {
19
20         public final static int REACHABLE = 0;
21
22         public final static int UNREACHABLE = 1;
23
24         public static final UnconditionalFlowInfo DEAD_END; // Represents a dead
25                                                                                                                 // branch status of
26                                                                                                                 // initialization
27         static {
28                 DEAD_END = new UnconditionalFlowInfo();
29                 DEAD_END.reachMode = UNREACHABLE;
30         }
31
32         abstract public FlowInfo addInitializationsFrom(FlowInfo otherInits);
33
34         abstract public FlowInfo addPotentialInitializationsFrom(FlowInfo otherInits);
35
36         public FlowInfo asNegatedCondition() {
37
38                 return this;
39         }
40
41         public boolean complainIfUnreachable(Statement statement, BlockScope scope,
42                         boolean didAlreadyComplain) {
43
44                 // Report an error if necessary
45                 return false;
46         }
47
48         public static FlowInfo conditional(FlowInfo initsWhenTrue,
49                         FlowInfo initsWhenFalse) {
50
51                 // if (initsWhenTrue.equals(initsWhenFalse)) return initsWhenTrue; --
52                 // could optimize if #equals is defined
53                 return new ConditionalFlowInfo(initsWhenTrue, initsWhenFalse);
54         }
55
56         abstract public FlowInfo copy();
57
58         public static UnconditionalFlowInfo initial(int maxFieldCount) {
59                 UnconditionalFlowInfo info = new UnconditionalFlowInfo();
60                 info.maxFieldCount = maxFieldCount;
61                 return info;
62         }
63
64         abstract public FlowInfo initsWhenFalse();
65
66         abstract public FlowInfo initsWhenTrue();
67
68         /**
69          * Check status of definite assignment for a field.
70          */
71         abstract public boolean isDefinitelyAssigned(FieldBinding field);
72
73         /**
74          * Check status of definite assignment for a local.
75          */
76         public abstract boolean isDefinitelyAssigned(LocalVariableBinding local);
77
78         // abstract public int reachMode();
79
80         /**
81          * Check status of potential assignment for a field.
82          */
83         abstract public boolean isPotentiallyAssigned(FieldBinding field);
84
85         /**
86          * Check status of potential assignment for a local variable.
87          */
88
89         abstract public boolean isPotentiallyAssigned(LocalVariableBinding field);
90
91         abstract public boolean isReachable();
92
93         /**
94          * Record a field got definitely assigned.
95          */
96         abstract public void markAsDefinitelyAssigned(FieldBinding field);
97
98         /**
99          * Record a local got definitely assigned.
100          */
101         abstract public void markAsDefinitelyAssigned(LocalVariableBinding local);
102
103         /**
104          * Clear the initialization info for a field
105          */
106         abstract public void markAsDefinitelyNotAssigned(FieldBinding field);
107
108         /**
109          * Clear the initialization info for a local variable
110          */
111         abstract public void markAsDefinitelyNotAssigned(LocalVariableBinding local);
112
113         abstract public int reachMode();
114
115         abstract public FlowInfo setReachMode(int reachMode);
116
117         /**
118          * Returns the receiver updated in the following way:
119          * <ul>
120          * <li> intersection of definitely assigned variables,
121          * <li> union of potentially assigned variables.
122          * </ul>
123          */
124         abstract public UnconditionalFlowInfo mergedWith(
125                         UnconditionalFlowInfo otherInits);
126
127         public String toString() {
128
129                 if (this == DEAD_END) {
130                         return "FlowInfo.DEAD_END"; //$NON-NLS-1$
131                 }
132                 return super.toString();
133         }
134
135         abstract public UnconditionalFlowInfo unconditionalInits();
136 }