1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 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 net.sourceforge.phpeclipse.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 BreakStatement extends BranchStatement {
20 public BreakStatement(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 = (label == null)
34 ? flowContext.getTargetContextForDefaultBreak()
35 : flowContext.getTargetContextForBreakLabel(label);
37 if (targetContext == null) {
39 currentScope.problemReporter().invalidBreak(this);
41 currentScope.problemReporter().undefinedLabel(this);
43 return flowInfo; // pretend it did not break since no actual target
46 targetLabel = targetContext.breakLabel();
47 FlowContext traversedContext = flowContext;
48 int subIndex = 0, maxSub = 5;
49 subroutines = new ASTNode[maxSub];
53 if ((sub = traversedContext.subRoutine()) != null) {
54 if (subIndex == maxSub) {
55 System.arraycopy(subroutines, 0, (subroutines = new ASTNode[maxSub*=2]), 0, subIndex); // grow
57 subroutines[subIndex++] = sub;
58 if (sub.cannotReturn()) {
62 traversedContext.recordReturnFrom(flowInfo.unconditionalInits());
65 if ((node = traversedContext.associatedNode) instanceof TryStatement) {
66 TryStatement tryStatement = (TryStatement) node;
67 flowInfo.addInitializationsFrom(tryStatement.subRoutineInits); // collect inits
68 } else if (traversedContext == targetContext) {
69 // only record break info once accumulated through subroutines, and only against target context
70 targetContext.recordBreakFrom(flowInfo);
73 } while ((traversedContext = traversedContext.parent) != null);
76 if (subIndex != maxSub) {
77 System.arraycopy(subroutines, 0, (subroutines = new ASTNode[subIndex]), 0, subIndex);
79 return FlowInfo.DEAD_END;
82 public String toString(int tab) {
84 String s = tabString(tab);
85 s += "break "; //$NON-NLS-1$
87 s += new String(label);
90 public StringBuffer printStatement(int tab, StringBuffer output) {
92 printIndent(tab, output).append("break "); //$NON-NLS-1$
93 if (label != null) output.append(label);
94 return output.append(';');
97 IAbstractSyntaxTreeVisitor visitor,
98 BlockScope blockscope) {
100 visitor.visit(this, blockscope);
101 visitor.endVisit(this, blockscope);