A variable description (like PHPFunctionDeclaration)
[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.*;
15 import net.sourceforge.phpdt.internal.compiler.lookup.*;
16
17 public class Continue extends BranchStatement {
18
19         public Continue(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;
34                 if (label == null) {
35                         targetContext = flowContext.getTargetContextForDefaultContinue();
36                 } else {
37                         targetContext = flowContext.getTargetContextForContinueLabel(label);
38                 }
39                 if (targetContext == null) {
40                         if (label == null) {
41                                 currentScope.problemReporter().invalidContinue(this);
42                         } else {
43                                 currentScope.problemReporter().undefinedLabel(this); // need to improve
44                         }
45                 } else {
46                         if (targetContext == FlowContext.NotContinuableContext) {
47                                 currentScope.problemReporter().invalidContinue(this);
48                                 return FlowInfo.DeadEnd;
49                         }
50                         targetLabel = targetContext.continueLabel();
51                         targetContext.recordContinueFrom(flowInfo);
52                         FlowContext traversedContext = flowContext;
53                         int subIndex = 0, maxSub = 5;
54                         subroutines = new AstNode[maxSub];
55                         while (true) {
56                                 AstNode sub;
57                                 if ((sub = traversedContext.subRoutine()) != null) {
58                                         if (subIndex == maxSub) {
59                                                 System.arraycopy(
60                                                         subroutines,
61                                                         0,
62                                                         (subroutines = new AstNode[maxSub *= 2]),
63                                                         0,
64                                                         subIndex);
65                                                 // grow
66                                         }
67                                         subroutines[subIndex++] = sub;
68                                         if (sub.cannotReturn()) {
69                                                 break;
70                                         }
71                                 }
72                                 // remember the initialization at this
73                                 // point for dealing with blank final variables.
74                                 traversedContext.recordReturnFrom(flowInfo.unconditionalInits());
75
76                                 if (traversedContext == targetContext) {
77                                         break;
78                                 } else {
79                                         traversedContext = traversedContext.parent;
80                                 }
81                         }
82                         // resize subroutines
83                         if (subIndex != maxSub) {
84                                 System.arraycopy(
85                                         subroutines,
86                                         0,
87                                         (subroutines = new AstNode[subIndex]),
88                                         0,
89                                         subIndex);
90                         }
91                 }
92                 return FlowInfo.DeadEnd;
93         }
94
95         public String toString(int tab) {
96
97                 String s = tabString(tab);
98                 s = s + "continue "; //$NON-NLS-1$
99                 if (label != null)
100                         s = s + new String(label);
101                 return s;
102         }
103
104         public void traverse(
105                 IAbstractSyntaxTreeVisitor visitor,
106                 BlockScope blockScope) {
107
108                 visitor.visit(this, blockScope);
109                 visitor.endVisit(this, blockScope);
110         }
111 }