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.FieldBinding;
14 import net.sourceforge.phpdt.internal.compiler.lookup.LocalVariableBinding;
17 * Record conditional initialization status during definite assignment analysis
20 public class ConditionalFlowInfo extends FlowInfo {
22 public FlowInfo initsWhenTrue;
23 public FlowInfo initsWhenFalse;
25 ConditionalFlowInfo(FlowInfo initsWhenTrue, FlowInfo initsWhenFalse){
27 this.initsWhenTrue = initsWhenTrue;
28 this.initsWhenFalse = initsWhenFalse;
31 public FlowInfo addInitializationsFrom(FlowInfo otherInits) {
33 this.initsWhenTrue.addInitializationsFrom(otherInits);
34 this.initsWhenFalse.addInitializationsFrom(otherInits);
38 public FlowInfo addPotentialInitializationsFrom(FlowInfo otherInits) {
40 this.initsWhenTrue.addPotentialInitializationsFrom(otherInits);
41 this.initsWhenFalse.addPotentialInitializationsFrom(otherInits);
45 public FlowInfo asNegatedCondition() {
47 FlowInfo extra = initsWhenTrue;
48 initsWhenTrue = initsWhenFalse;
49 initsWhenFalse = extra;
53 public FlowInfo copy() {
55 return new ConditionalFlowInfo(initsWhenTrue.copy(), initsWhenFalse.copy());
58 public FlowInfo initsWhenFalse() {
60 return initsWhenFalse;
63 public FlowInfo initsWhenTrue() {
69 * Check status of definite assignment for a field.
71 public boolean isDefinitelyAssigned(FieldBinding field) {
73 return initsWhenTrue.isDefinitelyAssigned(field)
74 && initsWhenFalse.isDefinitelyAssigned(field);
78 * Check status of definite assignment for a local variable.
80 public boolean isDefinitelyAssigned(LocalVariableBinding local) {
82 return initsWhenTrue.isDefinitelyAssigned(local)
83 && initsWhenFalse.isDefinitelyAssigned(local);
86 public int reachMode(){
87 return unconditionalInits().reachMode();
90 public boolean isReachable(){
92 return unconditionalInits().isReachable();
93 //should maybe directly be: false
97 * Check status of potential assignment for a field.
99 public boolean isPotentiallyAssigned(FieldBinding field) {
101 return initsWhenTrue.isPotentiallyAssigned(field)
102 || initsWhenFalse.isPotentiallyAssigned(field);
106 * Check status of potential assignment for a local variable.
108 public boolean isPotentiallyAssigned(LocalVariableBinding local) {
110 return initsWhenTrue.isPotentiallyAssigned(local)
111 || initsWhenFalse.isPotentiallyAssigned(local);
115 * Record a field got definitely assigned.
117 public void markAsDefinitelyAssigned(FieldBinding field) {
119 initsWhenTrue.markAsDefinitelyAssigned(field);
120 initsWhenFalse.markAsDefinitelyAssigned(field);
124 * Record a field got definitely assigned.
126 public void markAsDefinitelyAssigned(LocalVariableBinding local) {
128 initsWhenTrue.markAsDefinitelyAssigned(local);
129 initsWhenFalse.markAsDefinitelyAssigned(local);
133 * Clear the initialization info for a field
135 public void markAsDefinitelyNotAssigned(FieldBinding field) {
137 initsWhenTrue.markAsDefinitelyNotAssigned(field);
138 initsWhenFalse.markAsDefinitelyNotAssigned(field);
142 * Clear the initialization info for a local variable
144 public void markAsDefinitelyNotAssigned(LocalVariableBinding local) {
146 initsWhenTrue.markAsDefinitelyNotAssigned(local);
147 initsWhenFalse.markAsDefinitelyNotAssigned(local);
150 public FlowInfo setReachMode(int reachMode) {
152 initsWhenTrue.setReachMode(reachMode);
153 initsWhenFalse.setReachMode(reachMode);
158 * Converts conditional receiver into inconditional one, updated in the following way: <ul>
159 * <li> intersection of definitely assigned variables,
160 * <li> union of potentially assigned variables.
163 public UnconditionalFlowInfo mergedWith(UnconditionalFlowInfo otherInits) {
165 return unconditionalInits().mergedWith(otherInits);
168 public String toString() {
170 return "FlowInfo<true: " + initsWhenTrue.toString() + ", false: " + initsWhenFalse.toString() + ">"; //$NON-NLS-1$ //$NON-NLS-3$ //$NON-NLS-2$
173 public UnconditionalFlowInfo unconditionalInits() {
175 return initsWhenTrue.unconditionalInits().copy()
176 .mergedWith(initsWhenFalse.unconditionalInits());