Start the debugger through setting the url with "?DBGSESSID=1@clienthost:10001" in...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / internal / compiler / ast / Continue.java
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
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpeclipse.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 = (label == null)
35                                 ? flowContext.getTargetContextForDefaultContinue()
36                                 : flowContext.getTargetContextForContinueLabel(label);
37
38                 if (targetContext == null) {
39                         if (label == null) {
40                                 currentScope.problemReporter().invalidContinue(this);
41                         } else {
42                                 currentScope.problemReporter().undefinedLabel(this); 
43                         }
44                         return flowInfo; // pretend it did not continue since no actual target                  
45                 } 
46
47                 if (targetContext == FlowContext.NotContinuableContext) {
48                         currentScope.problemReporter().invalidContinue(this);
49                         return flowInfo; // pretend it did not continue since no actual target
50                 }
51                 targetLabel = targetContext.continueLabel();
52                 FlowContext traversedContext = flowContext;
53                 int subIndex = 0, maxSub = 5;
54                 subroutines = new ASTNode[maxSub];
55
56                 do {
57                         ASTNode sub;
58                         if ((sub = traversedContext.subRoutine()) != null) {
59                                 if (subIndex == maxSub) {
60                                         System.arraycopy(subroutines, 0, (subroutines = new ASTNode[maxSub*=2]), 0, subIndex); // grow
61                                 }
62                                 subroutines[subIndex++] = sub;
63                                 if (sub.cannotReturn()) {
64                                         break;
65                                 }
66                         }
67                         traversedContext.recordReturnFrom(flowInfo.unconditionalInits());
68
69                         ASTNode node;
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);
76                                 break;
77                         }
78                 } while ((traversedContext = traversedContext.parent) != null);
79                 
80                 // resize subroutines
81                 if (subIndex != maxSub) {
82                         System.arraycopy(subroutines, 0, (subroutines = new ASTNode[subIndex]), 0, subIndex);
83                 }
84                 return FlowInfo.DEAD_END;
85         }
86
87         public String toString(int tab) {
88
89                 String s = tabString(tab);
90                 s += "continue "; //$NON-NLS-1$
91                 if (label != null)
92                         s += new String(label);
93                 return s;
94         }
95
96         public void traverse(
97                 IAbstractSyntaxTreeVisitor visitor,
98                 BlockScope blockScope) {
99
100                 visitor.visit(this, blockScope);
101                 visitor.endVisit(this, blockScope);
102         }
103 }