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
9 * IBM Corporation - initial API and implementation
10 ******************************************************************************/
11 package net.sourceforge.phpdt.internal.compiler.ast;
13 import net.sourceforge.phpdt.internal.compiler.IAbstractSyntaxTreeVisitor;
14 import net.sourceforge.phpdt.internal.compiler.flow.FlowContext;
15 import net.sourceforge.phpdt.internal.compiler.flow.FlowInfo;
16 import net.sourceforge.phpdt.internal.compiler.lookup.BlockScope;
18 public class Break extends BranchStatement {
20 public Break(char[] label, int sourceStart, int e) {
21 super(label, sourceStart, e);
24 public FlowInfo analyseCode(
25 BlockScope currentScope,
26 FlowContext flowContext,
29 // here requires to generate a sequence of finally blocks invocations depending corresponding
30 // to each of the traversed try statements, so that execution will terminate properly.
32 // lookup the label, this should answer the returnContext
33 FlowContext targetContext;
35 targetContext = flowContext.getTargetContextForDefaultBreak();
37 targetContext = flowContext.getTargetContextForBreakLabel(label);
39 if (targetContext == null) {
41 currentScope.problemReporter().invalidBreak(this);
43 currentScope.problemReporter().undefinedLabel(this); // need to improve
46 targetLabel = targetContext.breakLabel();
47 targetContext.recordBreakFrom(flowInfo);
48 FlowContext traversedContext = flowContext;
49 int subIndex = 0, maxSub = 5;
50 subroutines = new AstNode[maxSub];
53 if ((sub = traversedContext.subRoutine()) != null) {
54 if (subIndex == maxSub) {
58 (subroutines = new AstNode[maxSub *= 2]),
63 subroutines[subIndex++] = sub;
64 if (sub.cannotReturn()) {
68 // remember the initialization at this
69 // point for dealing with blank final variables.
70 traversedContext.recordReturnFrom(flowInfo.unconditionalInits());
72 if (traversedContext == targetContext) {
75 traversedContext = traversedContext.parent;
79 if (subIndex != maxSub) {
83 (subroutines = new AstNode[subIndex]),
88 return FlowInfo.DeadEnd;
91 public String toString(int tab) {
93 String s = tabString(tab);
94 s = s + "break "; //$NON-NLS-1$
96 s = s + new String(label);
100 public void traverse(
101 IAbstractSyntaxTreeVisitor visitor,
102 BlockScope blockscope) {
104 visitor.visit(this, blockscope);
105 visitor.endVisit(this, blockscope);