KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > compiler > ast > ContinueStatement


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.compiler.ast;
12
13 import org.eclipse.jdt.internal.compiler.ASTVisitor;
14 import org.eclipse.jdt.internal.compiler.flow.*;
15 import org.eclipse.jdt.internal.compiler.lookup.*;
16
17 public class ContinueStatement extends BranchStatement {
18
19 public ContinueStatement(char[] label, int sourceStart, int sourceEnd) {
20     super(label, sourceStart, sourceEnd);
21 }
22
23 public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) {
24
25     // here requires to generate a sequence of finally blocks invocations depending corresponding
26
// to each of the traversed try statements, so that execution will terminate properly.
27

28     // lookup the label, this should answer the returnContext
29
FlowContext targetContext = (label == null)
30             ? flowContext.getTargetContextForDefaultContinue()
31             : flowContext.getTargetContextForContinueLabel(label);
32
33     if (targetContext == null) {
34         if (label == null) {
35             currentScope.problemReporter().invalidContinue(this);
36         } else {
37             currentScope.problemReporter().undefinedLabel(this);
38         }
39         return flowInfo; // pretend it did not continue since no actual target
40
}
41
42     if (targetContext == FlowContext.NotContinuableContext) {
43         currentScope.problemReporter().invalidContinue(this);
44         return flowInfo; // pretend it did not continue since no actual target
45
}
46     this.initStateIndex =
47         currentScope.methodScope().recordInitializationStates(flowInfo);
48
49     targetLabel = targetContext.continueLabel();
50     FlowContext traversedContext = flowContext;
51     int subCount = 0;
52     subroutines = new SubRoutineStatement[5];
53
54     do {
55         SubRoutineStatement sub;
56         if ((sub = traversedContext.subroutine()) != null) {
57             if (subCount == subroutines.length) {
58                 System.arraycopy(subroutines, 0, subroutines = new SubRoutineStatement[subCount*2], 0, subCount); // grow
59
}
60             subroutines[subCount++] = sub;
61             if (sub.isSubRoutineEscaping()) {
62                 break;
63             }
64         }
65         traversedContext.recordReturnFrom(flowInfo.unconditionalInits());
66
67         if (traversedContext instanceof InsideSubRoutineFlowContext) {
68             ASTNode node = traversedContext.associatedNode;
69             if (node instanceof TryStatement) {
70                 TryStatement tryStatement = (TryStatement) node;
71                 flowInfo.addInitializationsFrom(tryStatement.subRoutineInits); // collect inits
72
}
73         } else if (traversedContext == targetContext) {
74             // only record continue info once accumulated through subroutines, and only against target context
75
targetContext.recordContinueFrom(flowContext, flowInfo);
76             break;
77         }
78     } while ((traversedContext = traversedContext.parent) != null);
79     
80     // resize subroutines
81
if (subCount != subroutines.length) {
82         System.arraycopy(subroutines, 0, subroutines = new SubRoutineStatement[subCount], 0, subCount);
83     }
84     return FlowInfo.DEAD_END;
85 }
86
87 public StringBuffer JavaDoc printStatement(int tab, StringBuffer JavaDoc output) {
88     printIndent(tab, output).append("continue "); //$NON-NLS-1$
89
if (label != null) output.append(label);
90     return output.append(';');
91 }
92
93 public void traverse(ASTVisitor visitor, BlockScope blockScope) {
94     visitor.visit(this, blockScope);
95     visitor.endVisit(this, blockScope);
96 }
97 }
98
Popular Tags