1 /*******************************************************************************
2 * Copyright (c) 2000, 2004 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 org.eclipse.jdt.internal.compiler.ast;
13 import org.eclipse.jdt.internal.compiler.codegen.CodeStream;
14 import org.eclipse.jdt.internal.compiler.codegen.ExceptionLabel;
15 import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
18 * Extra behavior for statements which are generating subroutines
20 public abstract class SubRoutineStatement extends Statement {
22 public static final ExceptionLabel[] NO_EXCEPTION_HANDLER = new ExceptionLabel[0];
23 ExceptionLabel[] anyExceptionLabels = NO_EXCEPTION_HANDLER;
24 int anyExceptionLabelsCount = 0;
26 public abstract boolean isSubRoutineEscaping();
28 public abstract void generateSubRoutineInvocation(BlockScope currentScope, CodeStream codeStream);
30 public ExceptionLabel enterAnyExceptionHandler(CodeStream codeStream) {
33 if ((length = this.anyExceptionLabelsCount) == this.anyExceptionLabels.length) {
34 System.arraycopy(this.anyExceptionLabels, 0 , this.anyExceptionLabels=new ExceptionLabel[length*2 + 1], 0, length);
36 ExceptionLabel exceptionLabel = new ExceptionLabel(codeStream, null);
37 this.anyExceptionLabels[this.anyExceptionLabelsCount++] = exceptionLabel;
38 return exceptionLabel;
41 public void exitAnyExceptionHandler() {
42 if (this.anyExceptionLabelsCount == 0) return;
43 ExceptionLabel currentLabel = this.anyExceptionLabels[this.anyExceptionLabelsCount-1];
44 if (currentLabel.start == currentLabel.codeStream.position) {
45 // discard empty exception handler
46 this.anyExceptionLabels[--this.anyExceptionLabelsCount] = null;
48 currentLabel.placeEnd();
51 public void placeAllAnyExceptionHandlers() {
53 for (int i = 0; i < this.anyExceptionLabelsCount; i++) {
54 this.anyExceptionLabels[i].place();
58 public static void reenterExceptionHandlers(SubRoutineStatement[] subroutines, int max, CodeStream codeStream) {
59 if (subroutines == null) return;
60 if (max < 0) max = subroutines.length;
61 for (int i = 0; i < max; i++) {
62 subroutines[i].enterAnyExceptionHandler(codeStream);