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 public class DoStmt extends TestStmt { 41 42 public boolean isBreakable() { return true; } 43 public boolean isContinuable() { return true; } 44 45 public void unparse(CodeWriter writer) throws IOException { 46 writer.writeKeyword("do"); 47 writer.requiredSpace(); 48 writer.write(body); 49 writer.writeKeyword("while"); 50 writer.requiredSpace(); 51 writer.parenExpr(test); 52 writer.closeStmt(); 53 } 54 55 public void checkSpec() { 56 body.requireStmt(); 57 super.checkSpec(); 58 } 59 60 63 public void walkFlow(FlowCheckerPass w) { 64 FlowCheckerPass.Set enteringPossiblyAssigned = w.popPossiblyAssigned(); 66 w.enterContext(this); 67 w.process(getBody()); 68 w.leaveContext(); 69 FlowCheckerPass.Vars v = w.getVars(); 70 FlowCheckerPass.Vars cv = w.getContinueVars(this); 71 FlowCheckerPass.Vars bv = w.getBreakVars(this); 72 boolean bodyLive = w.isLive(); 73 74 w.setVars(v.join(cv)); 75 w.processBoolean(getTest()); 76 FlowCheckerPass.Vars p = w.getVars(); 77 FlowCheckerPass.Vars tv = p.getTrue(); 78 FlowCheckerPass.Vars fv = p.getFalse(); 79 80 FlowCheckerPass.Set loopPossiblyAssigned = w.popPossiblyAssigned(); 81 82 w.checkLoopingFinals(this, loopPossiblyAssigned.inter(enteringPossiblyAssigned), tv); 83 w.mergePossiblyAssigned(enteringPossiblyAssigned); 84 w.mergePossiblyAssigned(loopPossiblyAssigned); 85 86 w.setLive(w.isBroken(this) || 87 (! getTest().isConstantTrue() && 88 (bodyLive || w.isContinued(this)))); 89 w.setVars(fv.join(bv)); 90 } 91 92 95 public void walkCleanup(ByteCodeCleanupPass w) { 96 w.enterContext(this); 97 w.process(getBody()); 98 w.leaveContext(); 99 100 w.setLive(w.isBroken(this) 101 || (! getTest().isConstantTrue() 102 && (w.isLive() || w.isContinued(this)))); 103 } 104 105 108 protected void cgStmt(CodeBuilder cb) { 109 Label startLab = cb.genLabel(); 110 Label testLab = cb.genLabel(); 111 Label endLab = cb.genLabel(); 112 113 cb.emitLabel(startLab); 114 cb.enterNonWindingContext(this, endLab, testLab); 115 getBody().cgTop(cb); 116 cb.leaveContext(); 117 118 cb.emitLabel(testLab); 119 getTest().cgTest(cb, startLab, endLab); 120 cb.emitLabel(endLab); 121 } 122 123 protected Stmt body; 125 public Stmt getBody() { return body; } 126 public void setBody(Stmt _body) { 127 if (_body != null) _body.setParent(this); 128 body = _body; 129 } 130 131 protected Expr test; 132 public Expr getTest() { return test; } 133 public void setTest(Expr _test) { 134 if (_test != null) _test.setParent(this); 135 test = _test; 136 } 137 138 public DoStmt(SourceLocation location, Stmt _body, Expr _test) { 139 super(location); 140 setBody(_body); 141 setTest(_test); 142 } 143 protected DoStmt(SourceLocation source) { 144 super(source); 145 } 146 147 public ASTObject copyWalk(CopyWalker walker) { 148 DoStmt ret = new DoStmt(getSourceLocation()); 149 ret.preCopy(walker, this); 150 if (body != null) ret.setBody( (Stmt)walker.process(body) ); 151 if (test != null) ret.setTest( (Expr)walker.process(test) ); 152 return ret; 153 } 154 155 public ASTObject getChildAt(int childIndex) { 156 switch(childIndex) { 157 case 0: return body; 158 case 1: return test; 159 default: return super.getChildAt(childIndex); 160 } 161 } 162 public String getChildNameAt(int childIndex) { 163 switch(childIndex) { 164 case 0: return "body"; 165 case 1: return "test"; 166 default: return super.getChildNameAt(childIndex); 167 } 168 } 169 public void setChildAt(int childIndex, ASTObject child) { 170 switch(childIndex) { 171 case 0: setBody((Stmt)child); return; 172 case 1: setTest((Expr)child); return; 173 default: super.setChildAt(childIndex, child); return; 174 } 175 } 176 public int getChildCount() { 177 return 2; 178 } 179 180 public String getDefaultDisplayName() { 181 return "DoStmt()"; 182 } 183 184 } 186 187 188 | Popular Tags |