*** empty log message ***
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / ast / BranchStatement.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.codegen.CodeStream;
14 import net.sourceforge.phpdt.internal.compiler.codegen.Label;
15 import net.sourceforge.phpdt.internal.compiler.lookup.BlockScope;
16
17 public abstract class BranchStatement extends Statement {
18         public char[] label;
19         public Label targetLabel;
20         public AstNode[] subroutines;
21 /**
22  * BranchStatement constructor comment.
23  */
24 public BranchStatement(char[] l, int s,int e) {
25         label = l ;
26         sourceStart = s;
27         sourceEnd = e;
28 }
29 /**
30  * Branch code generation
31  *
32  *   generate the finallyInvocationSequence.
33  */
34 public void generateCode(BlockScope currentScope, CodeStream codeStream) {
35
36         if ((bits & IsReachableMASK) == 0) {
37                 return;
38         }
39         int pc = codeStream.position;
40
41         // generation of code responsible for invoking the finally 
42         // blocks in sequence
43         if (subroutines != null){
44                 for (int i = 0, max = subroutines.length; i < max; i++){
45                         AstNode sub;
46                         if ((sub = subroutines[i]) instanceof SynchronizedStatement){
47                                 codeStream.load(((SynchronizedStatement)sub).synchroVariable);
48                                 codeStream.monitorexit(); 
49                         } else {
50                                 TryStatement trySub = (TryStatement) sub;
51                                 if (trySub.subRoutineCannotReturn)      {
52                                         codeStream.goto_(trySub.subRoutineStartLabel);
53                                         codeStream.recordPositionsFrom(pc, this.sourceStart);
54                                         return;
55                                 } else {
56                                         codeStream.jsr(trySub.subRoutineStartLabel);
57                                 }
58                         }
59                 }
60         }
61         codeStream.goto_(targetLabel);
62         codeStream.recordPositionsFrom(pc, this.sourceStart);
63 }
64 public void resetStateForCodeGeneration() {
65         this.targetLabel.resetStateForCodeGeneration();
66 }
67 }