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
9 * IBM Corporation - initial API and implementation
10 ******************************************************************************/
11 package net.sourceforge.phpdt.internal.compiler.ast;
13 import net.sourceforge.phpdt.internal.compiler.IAbstractSyntaxTreeVisitor;
14 import net.sourceforge.phpdt.internal.compiler.codegen.CodeStream;
15 import net.sourceforge.phpdt.internal.compiler.codegen.Label;
16 import net.sourceforge.phpdt.internal.compiler.flow.FlowContext;
17 import net.sourceforge.phpdt.internal.compiler.flow.FlowInfo;
18 import net.sourceforge.phpdt.internal.compiler.flow.LabelFlowContext;
19 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();
77 * Code generation for labeled statement
79 * may not need actual source positions recording
81 * @param currentScope org.eclipse.jdt.internal.compiler.lookup.BlockScope
82 * @param codeStream org.eclipse.jdt.internal.compiler.codegen.CodeStream
84 public void generateCode(BlockScope currentScope, CodeStream codeStream) {
86 int pc = codeStream.position;
87 if (targetLabel != null) {
88 targetLabel.codeStream = codeStream;
89 if (statement != null) {
90 statement.generateCode(currentScope, codeStream);
94 // May loose some local variable initializations : affecting the local variable attributes
95 if (mergedInitStateIndex != -1) {
96 codeStream.removeNotDefinitelyAssignedVariables(
98 mergedInitStateIndex);
100 codeStream.recordPositionsFrom(pc, this.sourceStart);
103 public void resolve(BlockScope scope) {
105 statement.resolve(scope);
108 public String toString(int tab) {
110 String s = tabString(tab);
111 s += new String(label) + ": " + statement.toString(0); //$NON-NLS-1$
115 public void traverse(
116 IAbstractSyntaxTreeVisitor visitor,
117 BlockScope blockScope) {
119 if (visitor.visit(this, blockScope)) {
120 statement.traverse(visitor, blockScope);
122 visitor.endVisit(this, blockScope);
125 public void resetStateForCodeGeneration() {
127 this.targetLabel.resetStateForCodeGeneration();