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.*;
15 import net.sourceforge.phpdt.internal.compiler.lookup.*;
17 public class Break extends BranchStatement {
19 public Break(char[] label, int sourceStart, int e) {
20 super(label, sourceStart, e);
23 public FlowInfo analyseCode(
24 BlockScope currentScope,
25 FlowContext flowContext,
28 // here requires to generate a sequence of finally blocks invocations depending corresponding
29 // to each of the traversed try statements, so that execution will terminate properly.
31 // lookup the label, this should answer the returnContext
32 FlowContext targetContext;
34 targetContext = flowContext.getTargetContextForDefaultBreak();
36 targetContext = flowContext.getTargetContextForBreakLabel(label);
38 if (targetContext == null) {
40 currentScope.problemReporter().invalidBreak(this);
42 currentScope.problemReporter().undefinedLabel(this); // need to improve
45 targetLabel = targetContext.breakLabel();
46 targetContext.recordBreakFrom(flowInfo);
47 FlowContext traversedContext = flowContext;
48 int subIndex = 0, maxSub = 5;
49 subroutines = new AstNode[maxSub];
52 if ((sub = traversedContext.subRoutine()) != null) {
53 if (subIndex == maxSub) {
57 (subroutines = new AstNode[maxSub *= 2]),
62 subroutines[subIndex++] = sub;
63 if (sub.cannotReturn()) {
67 // remember the initialization at this
68 // point for dealing with blank final variables.
69 traversedContext.recordReturnFrom(flowInfo.unconditionalInits());
71 if (traversedContext == targetContext) {
74 traversedContext = traversedContext.parent;
78 if (subIndex != maxSub) {
82 (subroutines = new AstNode[subIndex]),
87 return FlowInfo.DeadEnd;
90 public String toString(int tab) {
92 String s = tabString(tab);
93 s = s + "break "; //$NON-NLS-1$
95 s = s + new String(label);
100 IAbstractSyntaxTreeVisitor visitor,
101 BlockScope blockscope) {
103 visitor.visit(this, blockscope);
104 visitor.endVisit(this, blockscope);