1 /*******************************************************************************
2 * Copyright (c) 2000, 2004 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 org.eclipse.jdt.internal.compiler.ast;
13 import org.eclipse.jdt.internal.compiler.ASTVisitor;
14 import org.eclipse.jdt.internal.compiler.flow.*;
15 import org.eclipse.jdt.internal.compiler.lookup.*;
17 public class ContinueStatement extends BranchStatement {
19 public ContinueStatement(char[] l, int s, int 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.getTargetContextForDefaultContinue()
35 : flowContext.getTargetContextForContinueLabel(label);
37 if (targetContext == null) {
39 currentScope.problemReporter().invalidContinue(this);
41 currentScope.problemReporter().undefinedLabel(this);
43 return flowInfo; // pretend it did not continue since no actual target
46 if (targetContext == FlowContext.NotContinuableContext) {
47 currentScope.problemReporter().invalidContinue(this);
48 return flowInfo; // pretend it did not continue since no actual target
50 targetLabel = targetContext.continueLabel();
51 FlowContext traversedContext = flowContext;
52 int subIndex = 0, maxSub = 5;
53 subroutines = new SubRoutineStatement[maxSub];
56 SubRoutineStatement sub;
57 if ((sub = traversedContext.subRoutine()) != null) {
58 if (subIndex == maxSub) {
59 System.arraycopy(subroutines, 0, (subroutines = new SubRoutineStatement[maxSub*=2]), 0, subIndex); // grow
61 subroutines[subIndex++] = sub;
62 if (sub.isSubRoutineEscaping()) {
66 traversedContext.recordReturnFrom(flowInfo.unconditionalInits());
69 if ((node = traversedContext.associatedNode) instanceof TryStatement) {
70 TryStatement tryStatement = (TryStatement) node;
71 flowInfo.addInitializationsFrom(tryStatement.subRoutineInits); // collect inits
72 } else if (traversedContext == targetContext) {
73 // only record continue info once accumulated through subroutines, and only against target context
74 targetContext.recordContinueFrom(flowInfo);
77 } while ((traversedContext = traversedContext.parent) != null);
80 if (subIndex != maxSub) {
81 System.arraycopy(subroutines, 0, (subroutines = new SubRoutineStatement[subIndex]), 0, subIndex);
83 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(';');
95 BlockScope blockScope) {
97 visitor.visit(this, blockScope);
98 visitor.endVisit(this, blockScope);