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;
24 public FlowInfo initsWhenFalse;
26 ConditionalFlowInfo(FlowInfo initsWhenTrue, FlowInfo initsWhenFalse) {
28 this.initsWhenTrue = initsWhenTrue;
29 this.initsWhenFalse = initsWhenFalse;
32 public FlowInfo addInitializationsFrom(FlowInfo otherInits) {
34 this.initsWhenTrue.addInitializationsFrom(otherInits);
35 this.initsWhenFalse.addInitializationsFrom(otherInits);
39 public FlowInfo addPotentialInitializationsFrom(FlowInfo otherInits) {
41 this.initsWhenTrue.addPotentialInitializationsFrom(otherInits);
42 this.initsWhenFalse.addPotentialInitializationsFrom(otherInits);
46 public FlowInfo asNegatedCondition() {
48 FlowInfo extra = initsWhenTrue;
49 initsWhenTrue = initsWhenFalse;
50 initsWhenFalse = extra;
54 public FlowInfo copy() {
56 return new ConditionalFlowInfo(initsWhenTrue.copy(), initsWhenFalse
60 public FlowInfo initsWhenFalse() {
62 return initsWhenFalse;
65 public FlowInfo initsWhenTrue() {
71 * Check status of definite assignment for a field.
73 public boolean isDefinitelyAssigned(FieldBinding field) {
75 return initsWhenTrue.isDefinitelyAssigned(field)
76 && initsWhenFalse.isDefinitelyAssigned(field);
80 * Check status of definite assignment for a local variable.
82 public boolean isDefinitelyAssigned(LocalVariableBinding local) {
84 return initsWhenTrue.isDefinitelyAssigned(local)
85 && initsWhenFalse.isDefinitelyAssigned(local);
88 public int reachMode() {
89 return unconditionalInits().reachMode();
92 public boolean isReachable() {
94 return unconditionalInits().isReachable();
95 // should maybe directly be: false
99 * Check status of potential assignment for a field.
101 public boolean isPotentiallyAssigned(FieldBinding field) {
103 return initsWhenTrue.isPotentiallyAssigned(field)
104 || initsWhenFalse.isPotentiallyAssigned(field);
108 * Check status of potential assignment for a local variable.
110 public boolean isPotentiallyAssigned(LocalVariableBinding local) {
112 return initsWhenTrue.isPotentiallyAssigned(local)
113 || initsWhenFalse.isPotentiallyAssigned(local);
117 * Record a field got definitely assigned.
119 public void markAsDefinitelyAssigned(FieldBinding field) {
121 initsWhenTrue.markAsDefinitelyAssigned(field);
122 initsWhenFalse.markAsDefinitelyAssigned(field);
126 * Record a field got definitely assigned.
128 public void markAsDefinitelyAssigned(LocalVariableBinding local) {
130 initsWhenTrue.markAsDefinitelyAssigned(local);
131 initsWhenFalse.markAsDefinitelyAssigned(local);
135 * Clear the initialization info for a field
137 public void markAsDefinitelyNotAssigned(FieldBinding field) {
139 initsWhenTrue.markAsDefinitelyNotAssigned(field);
140 initsWhenFalse.markAsDefinitelyNotAssigned(field);
144 * Clear the initialization info for a local variable
146 public void markAsDefinitelyNotAssigned(LocalVariableBinding local) {
148 initsWhenTrue.markAsDefinitelyNotAssigned(local);
149 initsWhenFalse.markAsDefinitelyNotAssigned(local);
152 public FlowInfo setReachMode(int reachMode) {
154 initsWhenTrue.setReachMode(reachMode);
155 initsWhenFalse.setReachMode(reachMode);
160 * Converts conditional receiver into inconditional one, updated in the
163 * <li> intersection of definitely assigned variables,
164 * <li> union of potentially assigned variables.
167 public UnconditionalFlowInfo mergedWith(UnconditionalFlowInfo otherInits) {
169 return unconditionalInits().mergedWith(otherInits);
172 public String toString() {
174 return "FlowInfo<true: " + initsWhenTrue.toString() + ", false: " + initsWhenFalse.toString() + ">"; //$NON-NLS-1$ //$NON-NLS-3$ //$NON-NLS-2$
177 public UnconditionalFlowInfo unconditionalInits() {
179 return initsWhenTrue.unconditionalInits().copy().mergedWith(
180 initsWhenFalse.unconditionalInits());