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.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 BreakStatement extends BranchStatement {
20 public BreakStatement(Expression expr, int sourceStart, int e) {
21 super(expr, sourceStart, e);
24 public FlowInfo analyseCode(BlockScope currentScope,
25 FlowContext flowContext, FlowInfo flowInfo) {
27 // here requires to generate a sequence of finally blocks invocations
28 // depending corresponding
29 // to each of the traversed try statements, so that execution will
30 // 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) {
38 // if (label == 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
56 // ASTNode[maxSub*=2]), 0, subIndex); // grow
58 // subroutines[subIndex++] = sub;
59 // if (sub.cannotReturn()) {
63 // traversedContext.recordReturnFrom(flowInfo.unconditionalInits());
66 // if ((node = traversedContext.associatedNode) instanceof TryStatement)
68 // TryStatement tryStatement = (TryStatement) node;
69 // flowInfo.addInitializationsFrom(tryStatement.subRoutineInits); //
71 // } else if (traversedContext == targetContext) {
72 // // only record break info once accumulated through subroutines, and
73 // only against target context
74 // targetContext.recordBreakFrom(flowInfo);
77 // } while ((traversedContext = traversedContext.parent) != null);
79 // // resize subroutines
80 // if (subIndex != maxSub) {
81 // System.arraycopy(subroutines, 0, (subroutines = new
82 // ASTNode[subIndex]), 0, subIndex);
84 return FlowInfo.DEAD_END;
87 public String toString(int tab) {
89 String s = tabString(tab);
90 s += "break "; //$NON-NLS-1$
91 if (expression != null)
92 s += expression.toString();
96 public StringBuffer printStatement(int tab, StringBuffer output) {
98 printIndent(tab, output).append("break "); //$NON-NLS-1$
99 if (expression != null)
100 output.append(expression);
101 return output.append(';');
104 public void traverse(IAbstractSyntaxTreeVisitor visitor,
105 BlockScope blockscope) {
107 visitor.visit(this, blockscope);
108 visitor.endVisit(this, blockscope);