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.ASTVisitor;
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 net.sourceforge.phpdt.internal.compiler.lookup.BlockScope
83 * @param codeStream net.sourceforge.phpdt.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);
103 public StringBuffer printStatement(int tab, StringBuffer output) {
105 printIndent(tab, output).append(label).append(": "); //$NON-NLS-1$
106 if (this.statement == null)
109 this.statement.printStatement(0, output);
112 public void resolve(BlockScope scope) {
114 statement.resolve(scope);
117 public String toString(int tab) {
119 String s = tabString(tab);
120 s += new String(label) + ": " + statement.toString(0); //$NON-NLS-1$
124 public void traverse(
126 BlockScope blockScope) {
128 if (visitor.visit(this, blockScope)) {
129 statement.traverse(visitor, blockScope);
131 visitor.endVisit(this, blockScope);
134 public void resetStateForCodeGeneration() {
135 if (this.targetLabel != null) {
136 this.targetLabel.resetStateForCodeGeneration();