01: /*******************************************************************************
02: * Copyright (c) 2000, 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.internal.compiler.ast;
11:
12: import org.eclipse.jdt.internal.compiler.codegen.CodeStream;
13: import org.eclipse.jdt.internal.compiler.codegen.ExceptionLabel;
14: import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
15: import org.eclipse.jdt.internal.compiler.lookup.LocalVariableBinding;
16:
17: /**
18: * Extra behavior for statements which are generating subroutines
19: */
20: public abstract class SubRoutineStatement extends Statement {
21:
22: public static void reenterAllExceptionHandlers(
23: SubRoutineStatement[] subroutines, int max,
24: CodeStream codeStream) {
25: if (subroutines == null)
26: return;
27: if (max < 0)
28: max = subroutines.length;
29: for (int i = 0; i < max; i++) {
30: SubRoutineStatement sub = subroutines[i];
31: sub.enterAnyExceptionHandler(codeStream);
32: sub.enterDeclaredExceptionHandlers(codeStream);
33: }
34: }
35:
36: ExceptionLabel anyExceptionLabel;
37:
38: public ExceptionLabel enterAnyExceptionHandler(CodeStream codeStream) {
39:
40: if (this .anyExceptionLabel == null) {
41: this .anyExceptionLabel = new ExceptionLabel(codeStream,
42: null /*any exception*/);
43: }
44: this .anyExceptionLabel.placeStart();
45: return this .anyExceptionLabel;
46: }
47:
48: public void enterDeclaredExceptionHandlers(CodeStream codeStream) {
49: // do nothing by default
50: }
51:
52: public void exitAnyExceptionHandler() {
53: if (this .anyExceptionLabel != null) {
54: this .anyExceptionLabel.placeEnd();
55: }
56: }
57:
58: public void exitDeclaredExceptionHandlers(CodeStream codeStream) {
59: // do nothing by default
60: }
61:
62: /**
63: * Generate an invocation of a subroutine (e.g. jsr finally) in current context.
64: * @param currentScope
65: * @param codeStream
66: * @param targetLocation
67: * @param stateIndex
68: * @param secretLocal
69: * @return boolean, <code>true</code> if the generated code will abrupt completion
70: */
71: public abstract boolean generateSubRoutineInvocation(
72: BlockScope currentScope, CodeStream codeStream,
73: Object targetLocation, int stateIndex,
74: LocalVariableBinding secretLocal);
75:
76: public abstract boolean isSubRoutineEscaping();
77:
78: public void placeAllAnyExceptionHandler() {
79: this.anyExceptionLabel.place();
80: }
81: }
|