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.*;
15 import net.sourceforge.phpdt.internal.compiler.flow.*;
16 import net.sourceforge.phpdt.internal.compiler.lookup.*;
18 public class LabeledStatement extends Statement {
20 public Statement statement;
22 public Label targetLabel;
24 // for local variables table attributes
25 int mergedInitStateIndex = -1;
28 * LabeledStatement constructor comment.
30 public LabeledStatement(char[] l, Statement st, int s, int e) {
38 public FlowInfo analyseCode(
39 BlockScope currentScope,
40 FlowContext flowContext,
43 // need to stack a context to store explicit label, answer inits in case of normal completion merged
44 // with those relative to the exit path from break statement occurring inside the labeled statement.
45 if (statement == null) {
48 LabelFlowContext labelContext;
58 (targetLabel = new Label()),
61 .mergedWith(labelContext.initsOnBreak);
62 mergedInitStateIndex =
63 currentScope.methodScope().recordInitializationStates(mergedInfo);
68 public AstNode concreteStatement() {
70 return statement.concreteStatement();
74 * Code generation for labeled statement
76 * may not need actual source positions recording
78 * @param currentScope org.eclipse.jdt.internal.compiler.lookup.BlockScope
79 * @param codeStream org.eclipse.jdt.internal.compiler.codegen.CodeStream
81 public void generateCode(BlockScope currentScope, CodeStream codeStream) {
83 int pc = codeStream.position;
84 if (targetLabel != null) {
85 targetLabel.codeStream = codeStream;
86 if (statement != null) {
87 statement.generateCode(currentScope, codeStream);
91 // May loose some local variable initializations : affecting the local variable attributes
92 if (mergedInitStateIndex != -1) {
93 codeStream.removeNotDefinitelyAssignedVariables(
95 mergedInitStateIndex);
97 codeStream.recordPositionsFrom(pc, this.sourceStart);
100 public void resolve(BlockScope scope) {
102 statement.resolve(scope);
105 public String toString(int tab) {
107 String s = tabString(tab);
108 s += new String(label) + ": " + statement.toString(0); //$NON-NLS-1$
112 public void traverse(
113 IAbstractSyntaxTreeVisitor visitor,
114 BlockScope blockScope) {
116 if (visitor.visit(this, blockScope)) {
117 statement.traverse(visitor, blockScope);
119 visitor.endVisit(this, blockScope);
122 public void resetStateForCodeGeneration() {
124 this.targetLabel.resetStateForCodeGeneration();