Using the standard console for "PHPConsole" output now!
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / flow / InitializationFlowContext.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.ReferenceBinding;
15 import net.sourceforge.phpdt.internal.compiler.lookup.TypeBinding;
16 import net.sourceforge.phpeclipse.internal.compiler.ast.ASTNode;
17
18 /**
19  * Reflects the context of code analysis, keeping track of enclosing
20  *      try statements, exception handlers, etc...
21  */
22 public class InitializationFlowContext extends ExceptionHandlingFlowContext {
23
24         public int exceptionCount;
25         public TypeBinding[] thrownExceptions = new TypeBinding[5];
26         public ASTNode[] exceptionThrowers = new ASTNode[5];
27         public FlowInfo[] exceptionThrowerFlowInfos = new FlowInfo[5];
28         
29         public InitializationFlowContext(
30                 FlowContext parent,
31                 ASTNode associatedNode,
32                 BlockScope scope) {
33                 super(
34                         parent,
35                         associatedNode,
36                         NoExceptions, // no exception allowed by default
37                         scope, 
38                         FlowInfo.DEAD_END);
39         }
40
41         public void checkInitializerExceptions(
42                 BlockScope currentScope,
43                 FlowContext initializerContext,
44                 FlowInfo flowInfo) {
45                 for (int i = 0; i < exceptionCount; i++) {
46                         initializerContext.checkExceptionHandlers(
47                                 thrownExceptions[i],
48                                 exceptionThrowers[i],
49                                 exceptionThrowerFlowInfos[i],
50                                 currentScope);
51                 }
52         }
53
54         public String individualToString() {
55                 
56                 StringBuffer buffer = new StringBuffer("Initialization flow context"); //$NON-NLS-1$
57                 for (int i = 0; i < exceptionCount; i++) {
58                         buffer.append('[').append(thrownExceptions[i].readableName());
59                         buffer.append('-').append(exceptionThrowerFlowInfos[i].toString()).append(']');
60                 }
61                 return buffer.toString();
62         }
63         
64         public void recordHandlingException(
65                 ReferenceBinding exceptionType,
66                 UnconditionalFlowInfo flowInfo,
67                 TypeBinding raisedException,
68                 ASTNode invocationSite,
69                 boolean wasMasked) {
70                         
71                 // even if unreachable code, need to perform unhandled exception diagnosis
72                 int size = thrownExceptions.length;
73                 if (exceptionCount == size) {
74                         System.arraycopy(
75                                 thrownExceptions,
76                                 0,
77                                 (thrownExceptions = new TypeBinding[size * 2]),
78                                 0,
79                                 size);
80                         System.arraycopy(
81                                 exceptionThrowers,
82                                 0,
83                                 (exceptionThrowers = new ASTNode[size * 2]),
84                                 0,
85                                 size);
86                         System.arraycopy(
87                                 exceptionThrowerFlowInfos,
88                                 0,
89                                 (exceptionThrowerFlowInfos = new FlowInfo[size * 2]),
90                                 0,
91                                 size);
92                 }
93                 thrownExceptions[exceptionCount] = raisedException;
94                 exceptionThrowers[exceptionCount] = invocationSite;
95                 exceptionThrowerFlowInfos[exceptionCount++] = flowInfo.copy();
96         }       
97 }