1 11 package org.eclipse.jdt.internal.compiler.ast; 12 13 import org.eclipse.jdt.internal.compiler.ASTVisitor; 14 import org.eclipse.jdt.internal.compiler.codegen.*; 15 import org.eclipse.jdt.internal.compiler.flow.*; 16 import org.eclipse.jdt.internal.compiler.lookup.*; 17 18 public class LabeledStatement extends Statement { 19 20 public Statement statement; 21 public char[] label; 22 public BranchLabel targetLabel; 23 public int labelEnd; 24 25 int mergedInitStateIndex = -1; 27 28 31 public LabeledStatement(char[] label, Statement statement, long labelPosition, int sourceEnd) { 32 33 this.statement = statement; 34 if (statement instanceof EmptyStatement) statement.bits |= IsUsefulEmptyStatement; 36 this.label = label; 37 this.sourceStart = (int)(labelPosition >>> 32); 38 this.labelEnd = (int) labelPosition; 39 this.sourceEnd = sourceEnd; 40 } 41 42 public FlowInfo analyseCode( 43 BlockScope currentScope, 44 FlowContext flowContext, 45 FlowInfo flowInfo) { 46 47 if (statement == null) { 50 return flowInfo; 51 } else { 52 LabelFlowContext labelContext; 53 FlowInfo statementInfo, mergedInfo; 54 if (((statementInfo = statement 55 .analyseCode( 56 currentScope, 57 (labelContext = 58 new LabelFlowContext( 59 flowContext, 60 this, 61 label, 62 (targetLabel = new BranchLabel()), 63 currentScope)), 64 flowInfo)).tagBits & FlowInfo.UNREACHABLE) != 0) { 65 if ((labelContext.initsOnBreak.tagBits & FlowInfo.UNREACHABLE) == 0) { 66 mergedInfo = flowInfo.unconditionalCopy(). 68 addInitializationsFrom(labelContext.initsOnBreak); 69 } else { 70 mergedInfo = labelContext.initsOnBreak; 71 } 72 } else { 73 mergedInfo = statementInfo.mergedWith(labelContext.initsOnBreak); 74 } 75 mergedInitStateIndex = 76 currentScope.methodScope().recordInitializationStates(mergedInfo); 77 if ((this.bits & ASTNode.LabelUsed) == 0) { 78 currentScope.problemReporter().unusedLabel(this); 79 } 80 return mergedInfo; 81 } 82 } 83 84 public ASTNode concreteStatement() { 85 86 return statement; 88 } 89 90 98 public void generateCode(BlockScope currentScope, CodeStream codeStream) { 99 100 if ((bits & IsReachable) == 0) { 101 return; 102 } 103 int pc = codeStream.position; 104 if (targetLabel != null) { 105 targetLabel.initialize(codeStream); 106 if (statement != null) { 107 statement.generateCode(currentScope, codeStream); 108 } 109 targetLabel.place(); 110 } 111 if (mergedInitStateIndex != -1) { 113 codeStream.removeNotDefinitelyAssignedVariables(currentScope, mergedInitStateIndex); 114 codeStream.addDefinitelyAssignedVariables(currentScope, mergedInitStateIndex); 115 } 116 codeStream.recordPositionsFrom(pc, this.sourceStart); 117 } 118 119 public StringBuffer printStatement(int tab, StringBuffer output) { 120 121 printIndent(tab, output).append(label).append(": "); if (this.statement == null) 123 output.append(';'); 124 else 125 this.statement.printStatement(0, output); 126 return output; 127 } 128 129 public void resolve(BlockScope scope) { 130 131 if (this.statement != null) { 132 this.statement.resolve(scope); 133 } 134 } 135 136 137 public void traverse( 138 ASTVisitor visitor, 139 BlockScope blockScope) { 140 141 if (visitor.visit(this, blockScope)) { 142 if (this.statement != null) this.statement.traverse(visitor, blockScope); 143 } 144 visitor.endVisit(this, blockScope); 145 } 146 } 147 | Popular Tags |