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.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;
19 * Reflects the context of code analysis, keeping track of enclosing try
20 * statements, exception handlers, etc...
22 public class InitializationFlowContext extends ExceptionHandlingFlowContext {
24 public int exceptionCount;
26 public TypeBinding[] thrownExceptions = new TypeBinding[5];
28 public ASTNode[] exceptionThrowers = new ASTNode[5];
30 public FlowInfo[] exceptionThrowerFlowInfos = new FlowInfo[5];
32 public InitializationFlowContext(FlowContext parent,
33 ASTNode associatedNode, BlockScope scope) {
34 super(parent, associatedNode, NoExceptions, // no exception allowed by
36 scope, FlowInfo.DEAD_END);
39 public void checkInitializerExceptions(BlockScope currentScope,
40 FlowContext initializerContext, FlowInfo flowInfo) {
41 for (int i = 0; i < exceptionCount; i++) {
42 initializerContext.checkExceptionHandlers(thrownExceptions[i],
43 exceptionThrowers[i], exceptionThrowerFlowInfos[i],
48 public String individualToString() {
50 StringBuffer buffer = new StringBuffer("Initialization flow context"); //$NON-NLS-1$
51 for (int i = 0; i < exceptionCount; i++) {
52 buffer.append('[').append(thrownExceptions[i].readableName());
53 buffer.append('-').append(exceptionThrowerFlowInfos[i].toString())
56 return buffer.toString();
59 public void recordHandlingException(ReferenceBinding exceptionType,
60 UnconditionalFlowInfo flowInfo, TypeBinding raisedException,
61 ASTNode invocationSite, boolean wasMasked) {
63 // even if unreachable code, need to perform unhandled exception
65 int size = thrownExceptions.length;
66 if (exceptionCount == size) {
67 System.arraycopy(thrownExceptions, 0,
68 (thrownExceptions = new TypeBinding[size * 2]), 0, size);
69 System.arraycopy(exceptionThrowers, 0,
70 (exceptionThrowers = new ASTNode[size * 2]), 0, size);
71 System.arraycopy(exceptionThrowerFlowInfos, 0,
72 (exceptionThrowerFlowInfos = new FlowInfo[size * 2]), 0,
75 thrownExceptions[exceptionCount] = raisedException;
76 exceptionThrowers[exceptionCount] = invocationSite;
77 exceptionThrowerFlowInfos[exceptionCount++] = flowInfo.copy();