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