Refactored packagename to net.sourceforge.phpdt.internal.compiler.ast
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / ast / LabeledStatement.java
index 1cfa5a5..7070de7 100644 (file)
@@ -1,23 +1,23 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2001, 2002 International Business Machines Corp. and others.
+ * Copyright (c) 2000, 2003 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials 
- * are made available under the terms of the Common Public License v0.5 
+ * are made available under the terms of the Common Public License v1.0
  * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v05.html
+ * http://www.eclipse.org/legal/cpl-v10.html
  * 
  * Contributors:
  *     IBM Corporation - initial API and implementation
- ******************************************************************************/
+ *******************************************************************************/
 package net.sourceforge.phpdt.internal.compiler.ast;
 
-import net.sourceforge.phpdt.internal.compiler.IAbstractSyntaxTreeVisitor;
-import net.sourceforge.phpdt.internal.compiler.codegen.CodeStream;
+import net.sourceforge.phpdt.internal.compiler.ASTVisitor;
 import net.sourceforge.phpdt.internal.compiler.codegen.Label;
 import net.sourceforge.phpdt.internal.compiler.flow.FlowContext;
 import net.sourceforge.phpdt.internal.compiler.flow.FlowInfo;
 import net.sourceforge.phpdt.internal.compiler.flow.LabelFlowContext;
 import net.sourceforge.phpdt.internal.compiler.lookup.BlockScope;
 
+
 public class LabeledStatement extends Statement {
        
        public Statement statement;
@@ -68,9 +68,10 @@ public class LabeledStatement extends Statement {
                }
        }
        
-       public AstNode concreteStatement() {
+       public ASTNode concreteStatement() {
                
-               return statement.concreteStatement();
+               // return statement.concreteStatement(); // for supporting nested labels:   a:b:c: someStatement (see 21912)
+               return statement;
        }
        
        /**
@@ -78,28 +79,36 @@ public class LabeledStatement extends Statement {
         *
         * may not need actual source positions recording
         *
-        * @param currentScope org.eclipse.jdt.internal.compiler.lookup.BlockScope
-        * @param codeStream org.eclipse.jdt.internal.compiler.codegen.CodeStream
+        * @param currentScope net.sourceforge.phpdt.internal.compiler.lookup.BlockScope
+        * @param codeStream net.sourceforge.phpdt.internal.compiler.codegen.CodeStream
         */
-       public void generateCode(BlockScope currentScope, CodeStream codeStream) {
-               
-               int pc = codeStream.position;
-               if (targetLabel != null) {
-                       targetLabel.codeStream = codeStream;
-                       if (statement != null) {
-                               statement.generateCode(currentScope, codeStream);
-                       }
-                       targetLabel.place();
-               }
-               // May loose some local variable initializations : affecting the local variable attributes
-               if (mergedInitStateIndex != -1) {
-                       codeStream.removeNotDefinitelyAssignedVariables(
-                               currentScope,
-                               mergedInitStateIndex);
-               }
-               codeStream.recordPositionsFrom(pc, this.sourceStart);
+//     public void generateCode(BlockScope currentScope, CodeStream codeStream) {
+//             
+//             int pc = codeStream.position;
+//             if (targetLabel != null) {
+//                     targetLabel.codeStream = codeStream;
+//                     if (statement != null) {
+//                             statement.generateCode(currentScope, codeStream);
+//                     }
+//                     targetLabel.place();
+//             }
+//             // May loose some local variable initializations : affecting the local variable attributes
+//             if (mergedInitStateIndex != -1) {
+//                     codeStream.removeNotDefinitelyAssignedVariables(
+//                             currentScope,
+//                             mergedInitStateIndex);
+//             }
+//             codeStream.recordPositionsFrom(pc, this.sourceStart);
+//     }
+       public StringBuffer printStatement(int tab, StringBuffer output) {
+
+               printIndent(tab, output).append(label).append(": "); //$NON-NLS-1$
+               if (this.statement == null) 
+                       output.append(';');
+               else 
+                       this.statement.printStatement(0, output); 
+               return output;
        }
-       
        public void resolve(BlockScope scope) {
                
                statement.resolve(scope);
@@ -113,7 +122,7 @@ public class LabeledStatement extends Statement {
        }
 
        public void traverse(
-               IAbstractSyntaxTreeVisitor visitor,
+           ASTVisitor visitor,
                BlockScope blockScope) {
 
                if (visitor.visit(this, blockScope)) {
@@ -123,7 +132,8 @@ public class LabeledStatement extends Statement {
        }
 
        public void resetStateForCodeGeneration() {
-
-               this.targetLabel.resetStateForCodeGeneration();
+               if (this.targetLabel != null) { 
+                       this.targetLabel.resetStateForCodeGeneration();
+               }
        }
-}
\ No newline at end of file
+}