1 /*******************************************************************************
2 * Copyright (c) 2000, 2001, 2002 International Business Machines Corp. and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v0.5
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v05.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 {
21 public FlowInfo initsWhenTrue;
22 public FlowInfo initsWhenFalse;
23 ConditionalFlowInfo(FlowInfo initsWhenTrue, FlowInfo initsWhenFalse){
24 this.initsWhenTrue = initsWhenTrue;
25 this.initsWhenFalse = initsWhenFalse;
27 public UnconditionalFlowInfo addInitializationsFrom(UnconditionalFlowInfo otherInits) {
28 return unconditionalInits().addInitializationsFrom(otherInits);
30 public UnconditionalFlowInfo addPotentialInitializationsFrom(UnconditionalFlowInfo otherInits) {
31 return unconditionalInits().addPotentialInitializationsFrom(otherInits);
33 public FlowInfo asNegatedCondition() {
34 FlowInfo extra = initsWhenTrue;
35 initsWhenTrue = initsWhenFalse;
36 initsWhenFalse = extra;
39 public FlowInfo copy() {
40 return new ConditionalFlowInfo(initsWhenTrue.copy(), initsWhenFalse.copy());
42 public FlowInfo initsWhenFalse() {
43 return initsWhenFalse;
45 public FlowInfo initsWhenTrue() {
49 * Check status of definite assignment for a field.
51 public boolean isDefinitelyAssigned(FieldBinding field) {
52 return initsWhenTrue.isDefinitelyAssigned(field)
53 && initsWhenFalse.isDefinitelyAssigned(field);
57 * Check status of definite assignment for a local variable.
59 public boolean isDefinitelyAssigned(LocalVariableBinding local) {
60 return initsWhenTrue.isDefinitelyAssigned(local)
61 && initsWhenFalse.isDefinitelyAssigned(local);
64 public boolean isFakeReachable(){
65 return unconditionalInits().isFakeReachable();
66 //should maybe directly be: false
69 * Check status of potential assignment for a field.
71 public boolean isPotentiallyAssigned(FieldBinding field) {
72 return initsWhenTrue.isPotentiallyAssigned(field)
73 || initsWhenFalse.isPotentiallyAssigned(field);
77 * Check status of potential assignment for a local variable.
79 public boolean isPotentiallyAssigned(LocalVariableBinding local) {
80 return initsWhenTrue.isPotentiallyAssigned(local)
81 || initsWhenFalse.isPotentiallyAssigned(local);
85 * Record a field got definitely assigned.
87 public void markAsDefinitelyAssigned(FieldBinding field) {
88 initsWhenTrue.markAsDefinitelyAssigned(field);
89 initsWhenFalse.markAsDefinitelyAssigned(field);
92 * Record a field got definitely assigned.
94 public void markAsDefinitelyAssigned(LocalVariableBinding local) {
95 initsWhenTrue.markAsDefinitelyAssigned(local);
96 initsWhenFalse.markAsDefinitelyAssigned(local);
99 * Clear the initialization info for a field
101 public void markAsDefinitelyNotAssigned(FieldBinding field) {
102 initsWhenTrue.markAsDefinitelyNotAssigned(field);
103 initsWhenFalse.markAsDefinitelyNotAssigned(field);
106 * Clear the initialization info for a local variable
108 public void markAsDefinitelyNotAssigned(LocalVariableBinding local) {
109 initsWhenTrue.markAsDefinitelyNotAssigned(local);
110 initsWhenFalse.markAsDefinitelyNotAssigned(local);
112 public FlowInfo markAsFakeReachable(boolean isFakeReachable) {
113 initsWhenTrue.markAsFakeReachable(isFakeReachable);
114 initsWhenFalse.markAsFakeReachable(isFakeReachable);
117 public UnconditionalFlowInfo mergedWith(UnconditionalFlowInfo otherInits) {
118 return unconditionalInits().mergedWith(otherInits);
120 public String toString() {
121 return "FlowInfo<true: " + initsWhenTrue.toString() + ", false: " + initsWhenFalse.toString() + ">"; //$NON-NLS-1$ //$NON-NLS-3$ //$NON-NLS-2$
123 public UnconditionalFlowInfo unconditionalInits() {
124 return initsWhenTrue.unconditionalInits().copy()
125 .mergedWith(initsWhenFalse.unconditionalInits());