1 24 25 package org.aspectj.compiler.base.ast; 26 27 import org.aspectj.compiler.base.*; 28 import org.aspectj.compiler.base.JavaCompiler; 29 import org.aspectj.compiler.base.CodeWriter; 30 import java.io.IOException ; 31 32 import org.aspectj.compiler.base.bcg.CodeBuilder; 33 import org.aspectj.compiler.base.bcg.Label; 34 35 40 41 public class LabeledStmt extends Stmt { 42 43 public void unparse(CodeWriter writer) throws IOException { 44 writer.write(label); 45 writer.write(": "); 46 writer.write(stmt); 47 } 48 49 public void requireStmt() { 50 this.showError("labeled statement not allowed here"); 51 } 52 53 public void checkSpec() { 54 if (!(stmt instanceof LabeledStmt)) { 55 stmt.requireStmt(); 56 } 57 super.checkSpec(); 58 } 59 60 63 public void walkFlow(FlowCheckerPass w) { 64 if (w.isLabelUsed(getLabel())) { 65 showError("duplicate definition of label " + getLabel()); 66 } 67 w.enterContext(this); 68 w.process(getStmt()); 69 w.leaveContext(); 70 w.setLive(w.isLive() || w.isBroken(this)); 71 w.setVars(w.getVars().join(w.getBreakVars(this))); 72 } 73 74 77 public void walkCleanup(ByteCodeCleanupPass w) { 78 w.enterContext(this); 79 w.process(getStmt()); 80 w.leaveContext(); 81 w.setLive(w.isLive() || w.isBroken(this)); 82 } 83 84 public ASTObject postCleanup(ByteCodeCleanupPass walker) { 86 if (getStmt() instanceof EmptyStmt) { 87 return getStmt(); 88 } else { 89 return this; 90 } 91 } 92 93 96 protected void cgStmt(CodeBuilder cb) { 97 Label endLab = cb.genLabel(); 98 cb.enterNonWindingContext(this, endLab, null); 99 stmt.cgTop(cb); 100 cb.leaveContext(); 101 cb.emitLabel(endLab); 102 } 103 104 107 111 protected String label; 113 public String getLabel() { return label; } 114 public void setLabel(String _label) { label = _label; } 115 116 protected Stmt stmt; 117 public Stmt getStmt() { return stmt; } 118 public void setStmt(Stmt _stmt) { 119 if (_stmt != null) _stmt.setParent(this); 120 stmt = _stmt; 121 } 122 123 public LabeledStmt(SourceLocation location, String _label, Stmt _stmt) { 124 super(location); 125 setLabel(_label); 126 setStmt(_stmt); 127 } 128 protected LabeledStmt(SourceLocation source) { 129 super(source); 130 } 131 132 public ASTObject copyWalk(CopyWalker walker) { 133 LabeledStmt ret = new LabeledStmt(getSourceLocation()); 134 ret.preCopy(walker, this); 135 ret.label = label; 136 if (stmt != null) ret.setStmt( (Stmt)walker.process(stmt) ); 137 return ret; 138 } 139 140 public ASTObject getChildAt(int childIndex) { 141 switch(childIndex) { 142 case 0: return stmt; 143 default: return super.getChildAt(childIndex); 144 } 145 } 146 public String getChildNameAt(int childIndex) { 147 switch(childIndex) { 148 case 0: return "stmt"; 149 default: return super.getChildNameAt(childIndex); 150 } 151 } 152 public void setChildAt(int childIndex, ASTObject child) { 153 switch(childIndex) { 154 case 0: setStmt((Stmt)child); return; 155 default: super.setChildAt(childIndex, child); return; 156 } 157 } 158 public int getChildCount() { 159 return 1; 160 } 161 162 public String getDefaultDisplayName() { 163 return "LabeledStmt(label: "+label+")"; 164 } 165 166 } 168 169 170 | Popular Tags |