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.*;
13: import org.eclipse.jdt.internal.compiler.lookup.*;
14:
15: public abstract class BranchStatement extends Statement {
16:
17: public char[] label;
18: public BranchLabel targetLabel;
19: public SubRoutineStatement[] subroutines;
20: public int initStateIndex = -1;
21:
22: /**
23: * BranchStatement constructor comment.
24: */
25: public BranchStatement(char[] label, int sourceStart, int sourceEnd) {
26: this .label = label;
27: this .sourceStart = sourceStart;
28: this .sourceEnd = sourceEnd;
29: }
30:
31: /**
32: * Branch code generation
33: *
34: * generate the finallyInvocationSequence.
35: */
36: public void generateCode(BlockScope currentScope,
37: CodeStream codeStream) {
38: if ((this .bits & ASTNode.IsReachable) == 0) {
39: return;
40: }
41: int pc = codeStream.position;
42:
43: // generation of code responsible for invoking the finally
44: // blocks in sequence
45: if (this .subroutines != null) {
46: for (int i = 0, max = this .subroutines.length; i < max; i++) {
47: SubRoutineStatement sub = this .subroutines[i];
48: boolean didEscape = sub.generateSubRoutineInvocation(
49: currentScope, codeStream, this .targetLabel,
50: this .initStateIndex, null);
51: if (didEscape) {
52: codeStream
53: .recordPositionsFrom(pc, this .sourceStart);
54: SubRoutineStatement.reenterAllExceptionHandlers(
55: this .subroutines, i, codeStream);
56: if (this .initStateIndex != -1) {
57: codeStream
58: .removeNotDefinitelyAssignedVariables(
59: currentScope,
60: this .initStateIndex);
61: codeStream.addDefinitelyAssignedVariables(
62: currentScope, this .initStateIndex);
63: }
64: return;
65: }
66: }
67: }
68: codeStream.goto_(this .targetLabel);
69: codeStream.recordPositionsFrom(pc, this .sourceStart);
70: SubRoutineStatement.reenterAllExceptionHandlers(
71: this .subroutines, -1, codeStream);
72: if (this .initStateIndex != -1) {
73: codeStream.removeNotDefinitelyAssignedVariables(
74: currentScope, this .initStateIndex);
75: codeStream.addDefinitelyAssignedVariables(currentScope,
76: this .initStateIndex);
77: }
78: }
79:
80: public void resolve(BlockScope scope) {
81: // nothing to do during name resolution
82: }
83: }
|