*** empty log message ***
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / ast / Continue.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2001, 2002 International Business Machines Corp. and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v0.5 
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v05.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  ******************************************************************************/
11 package net.sourceforge.phpdt.internal.compiler.ast;
12
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;
17
18 public class Continue extends BranchStatement {
19
20         public Continue(char[] l, int s, int e) {
21                 
22                 super(l, s, e);
23         }
24         
25         public FlowInfo analyseCode(
26                 BlockScope currentScope,
27                 FlowContext flowContext,
28                 FlowInfo flowInfo) {
29
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.
32
33                 // lookup the label, this should answer the returnContext
34                 FlowContext targetContext;
35                 if (label == null) {
36                         targetContext = flowContext.getTargetContextForDefaultContinue();
37                 } else {
38                         targetContext = flowContext.getTargetContextForContinueLabel(label);
39                 }
40                 if (targetContext == null) {
41                         if (label == null) {
42                                 currentScope.problemReporter().invalidContinue(this);
43                         } else {
44                                 currentScope.problemReporter().undefinedLabel(this); // need to improve
45                         }
46                 } else {
47                         if (targetContext == FlowContext.NotContinuableContext) {
48                                 currentScope.problemReporter().invalidContinue(this);
49                                 return FlowInfo.DeadEnd;
50                         }
51                         targetLabel = targetContext.continueLabel();
52                         targetContext.recordContinueFrom(flowInfo);
53                         FlowContext traversedContext = flowContext;
54                         int subIndex = 0, maxSub = 5;
55                         subroutines = new AstNode[maxSub];
56                         while (true) {
57                                 AstNode sub;
58                                 if ((sub = traversedContext.subRoutine()) != null) {
59                                         if (subIndex == maxSub) {
60                                                 System.arraycopy(
61                                                         subroutines,
62                                                         0,
63                                                         (subroutines = new AstNode[maxSub *= 2]),
64                                                         0,
65                                                         subIndex);
66                                                 // grow
67                                         }
68                                         subroutines[subIndex++] = sub;
69                                         if (sub.cannotReturn()) {
70                                                 break;
71                                         }
72                                 }
73                                 // remember the initialization at this
74                                 // point for dealing with blank final variables.
75                                 traversedContext.recordReturnFrom(flowInfo.unconditionalInits());
76
77                                 if (traversedContext == targetContext) {
78                                         break;
79                                 } else {
80                                         traversedContext = traversedContext.parent;
81                                 }
82                         }
83                         // resize subroutines
84                         if (subIndex != maxSub) {
85                                 System.arraycopy(
86                                         subroutines,
87                                         0,
88                                         (subroutines = new AstNode[subIndex]),
89                                         0,
90                                         subIndex);
91                         }
92                 }
93                 return FlowInfo.DeadEnd;
94         }
95
96         public String toString(int tab) {
97
98                 String s = tabString(tab);
99                 s = s + "continue "; //$NON-NLS-1$
100                 if (label != null)
101                         s = s + new String(label);
102                 return s;
103         }
104
105         public void traverse(
106                 IAbstractSyntaxTreeVisitor visitor,
107                 BlockScope blockScope) {
108
109                 visitor.visit(this, blockScope);
110                 visitor.endVisit(this, blockScope);
111         }
112 }