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
 
   9  *     IBM Corporation - initial API and implementation
 
  10  *******************************************************************************/
 
  11 package net.sourceforge.phpeclipse.internal.compiler.ast;
 
  13 import net.sourceforge.phpdt.internal.compiler.IAbstractSyntaxTreeVisitor;
 
  14 import net.sourceforge.phpdt.internal.compiler.codegen.Label;
 
  15 import net.sourceforge.phpdt.internal.compiler.flow.FlowContext;
 
  16 import net.sourceforge.phpdt.internal.compiler.flow.FlowInfo;
 
  17 import net.sourceforge.phpdt.internal.compiler.flow.LabelFlowContext;
 
  18 import net.sourceforge.phpdt.internal.compiler.lookup.BlockScope;
 
  21 public class LabeledStatement extends Statement {
 
  23         public Statement statement;
 
  25         public Label targetLabel;
 
  27         // for local variables table attributes
 
  28         int mergedInitStateIndex = -1;
 
  31          * LabeledStatement constructor comment.
 
  33         public LabeledStatement(char[] l, Statement st, int s, int e) {
 
  41         public FlowInfo analyseCode(
 
  42                 BlockScope currentScope,
 
  43                 FlowContext flowContext,
 
  46                 // need to stack a context to store explicit label, answer inits in case of normal completion merged
 
  47                 // with those relative to the exit path from break statement occurring inside the labeled statement.
 
  48                 if (statement == null) {
 
  51                         LabelFlowContext labelContext;
 
  61                                                                 (targetLabel = new Label()),
 
  64                                         .mergedWith(labelContext.initsOnBreak);
 
  65                         mergedInitStateIndex =
 
  66                                 currentScope.methodScope().recordInitializationStates(mergedInfo);
 
  71         public AstNode concreteStatement() {
 
  73                 // return statement.concreteStatement(); // for supporting nested labels:   a:b:c: someStatement (see 21912)
 
  78          * Code generation for labeled statement
 
  80          * may not need actual source positions recording
 
  82          * @param currentScope org.eclipse.jdt.internal.compiler.lookup.BlockScope
 
  83          * @param codeStream org.eclipse.jdt.internal.compiler.codegen.CodeStream
 
  85 //      public void generateCode(BlockScope currentScope, CodeStream codeStream) {
 
  87 //              int pc = codeStream.position;
 
  88 //              if (targetLabel != null) {
 
  89 //                      targetLabel.codeStream = codeStream;
 
  90 //                      if (statement != null) {
 
  91 //                              statement.generateCode(currentScope, codeStream);
 
  93 //                      targetLabel.place();
 
  95 //              // May loose some local variable initializations : affecting the local variable attributes
 
  96 //              if (mergedInitStateIndex != -1) {
 
  97 //                      codeStream.removeNotDefinitelyAssignedVariables(
 
  99 //                              mergedInitStateIndex);
 
 101 //              codeStream.recordPositionsFrom(pc, this.sourceStart);
 
 104         public void resolve(BlockScope scope) {
 
 106                 statement.resolve(scope);
 
 109         public String toString(int tab) {
 
 111                 String s = tabString(tab);
 
 112                 s += new String(label) + ": " + statement.toString(0); //$NON-NLS-1$
 
 116         public void traverse(
 
 117                 IAbstractSyntaxTreeVisitor visitor,
 
 118                 BlockScope blockScope) {
 
 120                 if (visitor.visit(this, blockScope)) {
 
 121                         statement.traverse(visitor, blockScope);
 
 123                 visitor.endVisit(this, blockScope);
 
 126         public void resetStateForCodeGeneration() {
 
 127                 if (this.targetLabel != null) { 
 
 128                         this.targetLabel.resetStateForCodeGeneration();