Refactory: smarty.ui plugin.
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / flow / ConditionalFlowInfo.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.FieldBinding;
14 import net.sourceforge.phpdt.internal.compiler.lookup.LocalVariableBinding;
15
16 /**
17  * Record conditional initialization status during definite assignment analysis
18  * 
19  */
20 public class ConditionalFlowInfo extends FlowInfo {
21
22         public FlowInfo initsWhenTrue;
23
24         public FlowInfo initsWhenFalse;
25
26         ConditionalFlowInfo(FlowInfo initsWhenTrue, FlowInfo initsWhenFalse) {
27
28                 this.initsWhenTrue = initsWhenTrue;
29                 this.initsWhenFalse = initsWhenFalse;
30         }
31
32         public FlowInfo addInitializationsFrom(FlowInfo otherInits) {
33
34                 this.initsWhenTrue.addInitializationsFrom(otherInits);
35                 this.initsWhenFalse.addInitializationsFrom(otherInits);
36                 return this;
37         }
38
39         public FlowInfo addPotentialInitializationsFrom(FlowInfo otherInits) {
40
41                 this.initsWhenTrue.addPotentialInitializationsFrom(otherInits);
42                 this.initsWhenFalse.addPotentialInitializationsFrom(otherInits);
43                 return this;
44         }
45
46         public FlowInfo asNegatedCondition() {
47
48                 FlowInfo extra = initsWhenTrue;
49                 initsWhenTrue = initsWhenFalse;
50                 initsWhenFalse = extra;
51                 return this;
52         }
53
54         public FlowInfo copy() {
55
56                 return new ConditionalFlowInfo(initsWhenTrue.copy(), initsWhenFalse
57                                 .copy());
58         }
59
60         public FlowInfo initsWhenFalse() {
61
62                 return initsWhenFalse;
63         }
64
65         public FlowInfo initsWhenTrue() {
66
67                 return initsWhenTrue;
68         }
69
70         /**
71          * Check status of definite assignment for a field.
72          */
73         public boolean isDefinitelyAssigned(FieldBinding field) {
74
75                 return initsWhenTrue.isDefinitelyAssigned(field)
76                                 && initsWhenFalse.isDefinitelyAssigned(field);
77         }
78
79         /**
80          * Check status of definite assignment for a local variable.
81          */
82         public boolean isDefinitelyAssigned(LocalVariableBinding local) {
83
84                 return initsWhenTrue.isDefinitelyAssigned(local)
85                                 && initsWhenFalse.isDefinitelyAssigned(local);
86         }
87
88         public int reachMode() {
89                 return unconditionalInits().reachMode();
90         }
91
92         public boolean isReachable() {
93
94                 return unconditionalInits().isReachable();
95                 // should maybe directly be: false
96         }
97
98         /**
99          * Check status of potential assignment for a field.
100          */
101         public boolean isPotentiallyAssigned(FieldBinding field) {
102
103                 return initsWhenTrue.isPotentiallyAssigned(field)
104                                 || initsWhenFalse.isPotentiallyAssigned(field);
105         }
106
107         /**
108          * Check status of potential assignment for a local variable.
109          */
110         public boolean isPotentiallyAssigned(LocalVariableBinding local) {
111
112                 return initsWhenTrue.isPotentiallyAssigned(local)
113                                 || initsWhenFalse.isPotentiallyAssigned(local);
114         }
115
116         /**
117          * Record a field got definitely assigned.
118          */
119         public void markAsDefinitelyAssigned(FieldBinding field) {
120
121                 initsWhenTrue.markAsDefinitelyAssigned(field);
122                 initsWhenFalse.markAsDefinitelyAssigned(field);
123         }
124
125         /**
126          * Record a field got definitely assigned.
127          */
128         public void markAsDefinitelyAssigned(LocalVariableBinding local) {
129
130                 initsWhenTrue.markAsDefinitelyAssigned(local);
131                 initsWhenFalse.markAsDefinitelyAssigned(local);
132         }
133
134         /**
135          * Clear the initialization info for a field
136          */
137         public void markAsDefinitelyNotAssigned(FieldBinding field) {
138
139                 initsWhenTrue.markAsDefinitelyNotAssigned(field);
140                 initsWhenFalse.markAsDefinitelyNotAssigned(field);
141         }
142
143         /**
144          * Clear the initialization info for a local variable
145          */
146         public void markAsDefinitelyNotAssigned(LocalVariableBinding local) {
147
148                 initsWhenTrue.markAsDefinitelyNotAssigned(local);
149                 initsWhenFalse.markAsDefinitelyNotAssigned(local);
150         }
151
152         public FlowInfo setReachMode(int reachMode) {
153
154                 initsWhenTrue.setReachMode(reachMode);
155                 initsWhenFalse.setReachMode(reachMode);
156                 return this;
157         }
158
159         /**
160          * Converts conditional receiver into inconditional one, updated in the
161          * following way:
162          * <ul>
163          * <li> intersection of definitely assigned variables,
164          * <li> union of potentially assigned variables.
165          * </ul>
166          */
167         public UnconditionalFlowInfo mergedWith(UnconditionalFlowInfo otherInits) {
168
169                 return unconditionalInits().mergedWith(otherInits);
170         }
171
172         public String toString() {
173
174                 return "FlowInfo<true: " + initsWhenTrue.toString() + ", false: " + initsWhenFalse.toString() + ">"; //$NON-NLS-1$ //$NON-NLS-3$ //$NON-NLS-2$
175         }
176
177         public UnconditionalFlowInfo unconditionalInits() {
178
179                 return initsWhenTrue.unconditionalInits().copy().mergedWith(
180                                 initsWhenFalse.unconditionalInits());
181         }
182 }