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 ContinueStatement extends BranchStatement {
20 public ContinueStatement(char[] l, int s, int e) {
25 public FlowInfo analyseCode(
26 BlockScope currentScope,
27 FlowContext flowContext,
30 // here requires to generate a sequence of finally blocks invocations depending corresponding
31 // to each of the traversed try statements, so that execution will terminate properly.
33 // lookup the label, this should answer the returnContext
34 FlowContext targetContext = (label == null)
35 ? flowContext.getTargetContextForDefaultContinue()
36 : flowContext.getTargetContextForContinueLabel(label);
38 if (targetContext == null) {
40 currentScope.problemReporter().invalidContinue(this);
42 currentScope.problemReporter().undefinedLabel(this);
44 return flowInfo; // pretend it did not continue since no actual target
47 if (targetContext == FlowContext.NotContinuableContext) {
48 currentScope.problemReporter().invalidContinue(this);
49 return flowInfo; // pretend it did not continue since no actual target
51 targetLabel = targetContext.continueLabel();
52 FlowContext traversedContext = flowContext;
53 int subIndex = 0, maxSub = 5;
54 subroutines = new ASTNode[maxSub];
58 if ((sub = traversedContext.subRoutine()) != null) {
59 if (subIndex == maxSub) {
60 System.arraycopy(subroutines, 0, (subroutines = new ASTNode[maxSub*=2]), 0, subIndex); // grow
62 subroutines[subIndex++] = sub;
63 if (sub.cannotReturn()) {
67 traversedContext.recordReturnFrom(flowInfo.unconditionalInits());
70 if ((node = traversedContext.associatedNode) instanceof TryStatement) {
71 TryStatement tryStatement = (TryStatement) node;
72 flowInfo.addInitializationsFrom(tryStatement.subRoutineInits); // collect inits
73 } else if (traversedContext == targetContext) {
74 // only record continue info once accumulated through subroutines, and only against target context
75 targetContext.recordContinueFrom(flowInfo);
78 } while ((traversedContext = traversedContext.parent) != null);
81 if (subIndex != maxSub) {
82 System.arraycopy(subroutines, 0, (subroutines = new ASTNode[subIndex]), 0, subIndex);
84 return FlowInfo.DEAD_END;
86 public StringBuffer printStatement(int tab, StringBuffer output) {
88 printIndent(tab, output).append("continue "); //$NON-NLS-1$
89 if (label != null) output.append(label);
90 return output.append(';');
92 public String toString(int tab) {
94 String s = tabString(tab);
95 s += "continue "; //$NON-NLS-1$
97 s += new String(label);
101 public void traverse(
102 IAbstractSyntaxTreeVisitor visitor,
103 BlockScope blockScope) {
105 visitor.visit(this, blockScope);
106 visitor.endVisit(this, blockScope);