KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > compiler > base > ast > DoStmt


1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  *
3  * This file is part of the compiler and core tools for the AspectJ(tm)
4  * programming language; see http://aspectj.org
5  *
6  * The contents of this file are subject to the Mozilla Public License
7  * Version 1.1 (the "License"); you may not use this file except in
8  * compliance with the License. You may obtain a copy of the License at
9  * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is AspectJ.
17  *
18  * The Initial Developer of the Original Code is Xerox Corporation. Portions
19  * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
20  * All Rights Reserved.
21  *
22  * Contributor(s):
23  */

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 JavaDoc;
31
32 import org.aspectj.compiler.base.bcg.CodeBuilder;
33 import org.aspectj.compiler.base.bcg.Label;
34
35 /**
36   * @grammar do {body} while (test);
37   * @child Stmt body
38   * @child Expr test
39   */

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 JavaDoc {
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     // ------------------------------
61
// INTRO from FlowCheckerPass
62

63     public void walkFlow(FlowCheckerPass w) {
64         // w.setArgs(w.getArgs());
65
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     // ------------------------------
93
// INTRO from ByteCodeCleanupPass
94

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     // ------------------------------
106
// bcg
107

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     //BEGIN: Generated from @child and @property
124
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 JavaDoc 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 JavaDoc getDefaultDisplayName() {
181         return "DoStmt()";
182     }
183
184     //END: Generated from @child and @property
185
}
186
187
188
Popular Tags