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.phpdt.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;
20 public class LabeledStatement extends Statement {
22 public Statement statement;
26 public Label targetLabel;
28 // for local variables table attributes
29 int mergedInitStateIndex = -1;
32 * LabeledStatement constructor comment.
34 public LabeledStatement(char[] l, Statement st, int s, int e) {
42 public FlowInfo analyseCode(BlockScope currentScope,
43 FlowContext flowContext, FlowInfo flowInfo) {
45 // need to stack a context to store explicit label, answer inits in case
46 // of normal completion merged
47 // with those relative to the exit path from break statement occurring
48 // inside the labeled statement.
49 if (statement == null) {
52 LabelFlowContext labelContext;
53 FlowInfo mergedInfo = statement.analyseCode(
55 (labelContext = new LabelFlowContext(flowContext, this,
56 label, (targetLabel = new Label()), currentScope)),
57 flowInfo).mergedWith(labelContext.initsOnBreak);
58 mergedInitStateIndex = currentScope.methodScope()
59 .recordInitializationStates(mergedInfo);
64 public ASTNode concreteStatement() {
66 // return statement.concreteStatement(); // for supporting nested
67 // labels: a:b:c: someStatement (see 21912)
72 * Code generation for labeled statement
74 * may not need actual source positions recording
77 * net.sourceforge.phpdt.internal.compiler.lookup.BlockScope
79 * net.sourceforge.phpdt.internal.compiler.codegen.CodeStream
81 // public void generateCode(BlockScope currentScope, CodeStream codeStream)
84 // int pc = codeStream.position;
85 // if (targetLabel != null) {
86 // targetLabel.codeStream = codeStream;
87 // if (statement != null) {
88 // statement.generateCode(currentScope, codeStream);
90 // targetLabel.place();
92 // // May loose some local variable initializations : affecting the local
93 // variable attributes
94 // if (mergedInitStateIndex != -1) {
95 // codeStream.removeNotDefinitelyAssignedVariables(
97 // mergedInitStateIndex);
99 // codeStream.recordPositionsFrom(pc, this.sourceStart);
101 public StringBuffer printStatement(int tab, StringBuffer output) {
103 printIndent(tab, output).append(label).append(": "); //$NON-NLS-1$
104 if (this.statement == null)
107 this.statement.printStatement(0, output);
111 public void resolve(BlockScope scope) {
113 statement.resolve(scope);
116 public String toString(int tab) {
118 String s = tabString(tab);
119 s += new String(label) + ": " + statement.toString(0); //$NON-NLS-1$
123 public void traverse(ASTVisitor visitor, BlockScope blockScope) {
125 if (visitor.visit(this, blockScope)) {
126 statement.traverse(visitor, blockScope);
128 visitor.endVisit(this, blockScope);
131 public void resetStateForCodeGeneration() {
132 if (this.targetLabel != null) {
133 this.targetLabel.resetStateForCodeGeneration();