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.flow.*; 15 import org.eclipse.jdt.internal.compiler.lookup.*; 16 17 public class BreakStatement extends BranchStatement { 18 19 public BreakStatement(char[] label, int sourceStart, int e) { 20 super(label, sourceStart, e); 21 } 22 23 public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) { 24 25 28 FlowContext targetContext = (this.label == null) 30 ? flowContext.getTargetContextForDefaultBreak() 31 : flowContext.getTargetContextForBreakLabel(this.label); 32 33 if (targetContext == null) { 34 if (this.label == null) { 35 currentScope.problemReporter().invalidBreak(this); 36 } else { 37 currentScope.problemReporter().undefinedLabel(this); 38 } 39 return flowInfo; } 41 42 this.initStateIndex = 43 currentScope.methodScope().recordInitializationStates(flowInfo); 44 45 this.targetLabel = targetContext.breakLabel(); 46 FlowContext traversedContext = flowContext; 47 int subCount = 0; 48 this.subroutines = new SubRoutineStatement[5]; 49 50 do { 51 SubRoutineStatement sub; 52 if ((sub = traversedContext.subroutine()) != null) { 53 if (subCount == this.subroutines.length) { 54 System.arraycopy(this.subroutines, 0, (this.subroutines = new SubRoutineStatement[subCount*2]), 0, subCount); } 56 this.subroutines[subCount++] = sub; 57 if (sub.isSubRoutineEscaping()) { 58 break; 59 } 60 } 61 traversedContext.recordReturnFrom(flowInfo.unconditionalInits()); 62 traversedContext.recordBreakTo(targetContext); 63 64 if (traversedContext instanceof InsideSubRoutineFlowContext) { 65 ASTNode node = traversedContext.associatedNode; 66 if (node instanceof TryStatement) { 67 TryStatement tryStatement = (TryStatement) node; 68 flowInfo.addInitializationsFrom(tryStatement.subRoutineInits); } 70 } else if (traversedContext == targetContext) { 71 targetContext.recordBreakFrom(flowInfo); 73 break; 74 } 75 } while ((traversedContext = traversedContext.parent) != null); 76 77 if (subCount != this.subroutines.length) { 79 System.arraycopy(this.subroutines, 0, (this.subroutines = new SubRoutineStatement[subCount]), 0, subCount); 80 } 81 return FlowInfo.DEAD_END; 82 } 83 84 public StringBuffer printStatement(int tab, StringBuffer output) { 85 printIndent(tab, output).append("break "); if (this.label != null) output.append(this.label); 87 return output.append(';'); 88 } 89 90 public void traverse(ASTVisitor visitor, BlockScope blockscope) { 91 visitor.visit(this, blockscope); 92 visitor.endVisit(this, blockscope); 93 } 94 } 95 | Popular Tags |