Makefile fixup
[org.ibex.tool.git] / src / org / eclipse / jdt / internal / compiler / ast / ContinueStatement.java
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
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[] l, int s, int e) {
20                 
21                 super(l, s, e);
22         }
23         
24         public FlowInfo analyseCode(
25                 BlockScope currentScope,
26                 FlowContext flowContext,
27                 FlowInfo flowInfo) {
28
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.
31
32                 // lookup the label, this should answer the returnContext
33                 FlowContext targetContext = (label == null)
34                                 ? flowContext.getTargetContextForDefaultContinue()
35                                 : flowContext.getTargetContextForContinueLabel(label);
36
37                 if (targetContext == null) {
38                         if (label == null) {
39                                 currentScope.problemReporter().invalidContinue(this);
40                         } else {
41                                 currentScope.problemReporter().undefinedLabel(this); 
42                         }
43                         return flowInfo; // pretend it did not continue since no actual target                  
44                 } 
45
46                 if (targetContext == FlowContext.NotContinuableContext) {
47                         currentScope.problemReporter().invalidContinue(this);
48                         return flowInfo; // pretend it did not continue since no actual target
49                 }
50                 targetLabel = targetContext.continueLabel();
51                 FlowContext traversedContext = flowContext;
52                 int subIndex = 0, maxSub = 5;
53                 subroutines = new SubRoutineStatement[maxSub];
54
55                 do {
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
60                                 }
61                                 subroutines[subIndex++] = sub;
62                                 if (sub.isSubRoutineEscaping()) {
63                                         break;
64                                 }
65                         }
66                         traversedContext.recordReturnFrom(flowInfo.unconditionalInits());
67
68                         ASTNode node;
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);
75                                 break;
76                         }
77                 } while ((traversedContext = traversedContext.parent) != null);
78                 
79                 // resize subroutines
80                 if (subIndex != maxSub) {
81                         System.arraycopy(subroutines, 0, (subroutines = new SubRoutineStatement[subIndex]), 0, subIndex);
82                 }
83                 return FlowInfo.DEAD_END;
84         }
85
86         public StringBuffer printStatement(int tab, StringBuffer output) {
87
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(
94                 ASTVisitor visitor,
95                 BlockScope blockScope) {
96
97                 visitor.visit(this, blockScope);
98                 visitor.endVisit(this, blockScope);
99         }
100 }