A variable description (like PHPFunctionDeclaration)
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / flow / InitializationFlowContext.java
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
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.ast.AstNode;
14 import net.sourceforge.phpdt.internal.compiler.lookup.BlockScope;
15 import net.sourceforge.phpdt.internal.compiler.lookup.ReferenceBinding;
16 import net.sourceforge.phpdt.internal.compiler.lookup.TypeBinding;
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                         new ReferenceBinding[] { scope.getJavaLangThrowable()},
37                 // tolerate any kind of exception, but record them
38                 scope, FlowInfo.DeadEnd);
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 void recordHandlingException(
55                 ReferenceBinding exceptionType,
56                 UnconditionalFlowInfo flowInfo,
57                 TypeBinding raisedException,
58                 AstNode invocationSite,
59                 boolean wasMasked) {
60                         
61                 int size = thrownExceptions.length;
62                 if (exceptionCount == size) {
63                         System.arraycopy(
64                                 thrownExceptions,
65                                 0,
66                                 (thrownExceptions = new TypeBinding[size * 2]),
67                                 0,
68                                 size);
69                         System.arraycopy(
70                                 exceptionThrowers,
71                                 0,
72                                 (exceptionThrowers = new AstNode[size * 2]),
73                                 0,
74                                 size);
75                         System.arraycopy(
76                                 exceptionThrowerFlowInfos,
77                                 0,
78                                 (exceptionThrowerFlowInfos = new FlowInfo[size * 2]),
79                                 0,
80                                 size);
81                 }
82                 thrownExceptions[exceptionCount] = raisedException;
83                 exceptionThrowers[exceptionCount] = invocationSite;
84                 exceptionThrowerFlowInfos[exceptionCount++] = flowInfo.copy();
85         }       
86 }