001: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
002:
003: This file is part of the db4o open source object database.
004:
005: db4o is free software; you can redistribute it and/or modify it under
006: the terms of version 2 of the GNU General Public License as published
007: by the Free Software Foundation and as clarified by db4objects' GPL
008: interpretation policy, available at
009: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011: Suite 350, San Mateo, CA 94403, USA.
012:
013: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014: WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: for more details.
017:
018: You should have received a copy of the GNU General Public License along
019: with this program; if not, write to the Free Software Foundation, Inc.,
020: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
021: package EDU.purdue.cs.bloat.tree;
022:
023: import EDU.purdue.cs.bloat.cfg.*;
024:
025: /**
026: * TreeVisitor performs a traversal of a tree. It does so by having a method of
027: * every kind of node in the tree. This abstract class performs default
028: * operations for each kind of node visited. It must be subclasses to perform a
029: * more interesting traversal.
030: *
031: * @see Node
032: * @see Tree
033: *
034: * @see PrintVisitor
035: * @see ReplaceVisitor
036: *
037: */
038: public abstract class TreeVisitor {
039: public static final int FORWARD = 0;
040:
041: public static final int REVERSE = 1;
042:
043: boolean prune;
044:
045: int direction;
046:
047: public TreeVisitor() {
048: this (TreeVisitor.FORWARD);
049: }
050:
051: public TreeVisitor(final int direction) {
052: this .direction = direction;
053: }
054:
055: /**
056: * @param prune
057: * Is the tree pruned during traversal?
058: */
059: public void setPrune(final boolean prune) {
060: this .prune = prune;
061: }
062:
063: public boolean prune() {
064: return prune;
065: }
066:
067: /**
068: * @return The direction in which the tree is traversed.
069: */
070: public int direction() {
071: return direction;
072: }
073:
074: /**
075: * Returns <tt>true</tt> if the traversal traverses in the forward
076: * direction?
077: */
078: public boolean forward() {
079: return direction == TreeVisitor.FORWARD;
080: }
081:
082: public boolean reverse() {
083: return direction == TreeVisitor.REVERSE;
084: }
085:
086: public void visitFlowGraph(final FlowGraph graph) {
087: graph.visitChildren(this );
088: }
089:
090: public void visitBlock(final Block block) {
091: block.visitChildren(this );
092: }
093:
094: public void visitTree(final Tree tree) {
095: visitNode(tree);
096: }
097:
098: public void visitExprStmt(final ExprStmt stmt) {
099: visitStmt(stmt);
100: }
101:
102: public void visitIfStmt(final IfStmt stmt) {
103: visitStmt(stmt);
104: }
105:
106: public void visitIfCmpStmt(final IfCmpStmt stmt) {
107: visitIfStmt(stmt);
108: }
109:
110: public void visitIfZeroStmt(final IfZeroStmt stmt) {
111: visitIfStmt(stmt);
112: }
113:
114: public void visitInitStmt(final InitStmt stmt) {
115: visitStmt(stmt);
116: }
117:
118: public void visitGotoStmt(final GotoStmt stmt) {
119: visitStmt(stmt);
120: }
121:
122: public void visitLabelStmt(final LabelStmt stmt) {
123: visitStmt(stmt);
124: }
125:
126: public void visitMonitorStmt(final MonitorStmt stmt) {
127: visitStmt(stmt);
128: }
129:
130: public void visitPhiStmt(final PhiStmt stmt) {
131: visitStmt(stmt);
132: }
133:
134: public void visitCatchExpr(final CatchExpr expr) {
135: visitExpr(expr);
136: }
137:
138: public void visitDefExpr(final DefExpr expr) {
139: visitExpr(expr);
140: }
141:
142: public void visitStackManipStmt(final StackManipStmt stmt) {
143: visitStmt(stmt);
144: }
145:
146: public void visitPhiCatchStmt(final PhiCatchStmt stmt) {
147: visitPhiStmt(stmt);
148: }
149:
150: public void visitPhiJoinStmt(final PhiJoinStmt stmt) {
151: visitPhiStmt(stmt);
152: }
153:
154: public void visitRetStmt(final RetStmt stmt) {
155: visitStmt(stmt);
156: }
157:
158: public void visitReturnExprStmt(final ReturnExprStmt stmt) {
159: visitStmt(stmt);
160: }
161:
162: public void visitReturnStmt(final ReturnStmt stmt) {
163: visitStmt(stmt);
164: }
165:
166: public void visitAddressStoreStmt(final AddressStoreStmt stmt) {
167: visitStmt(stmt);
168: }
169:
170: public void visitStoreExpr(final StoreExpr expr) {
171: visitExpr(expr);
172: }
173:
174: public void visitJsrStmt(final JsrStmt stmt) {
175: visitStmt(stmt);
176: }
177:
178: public void visitSwitchStmt(final SwitchStmt stmt) {
179: visitStmt(stmt);
180: }
181:
182: public void visitThrowStmt(final ThrowStmt stmt) {
183: visitStmt(stmt);
184: }
185:
186: public void visitStmt(final Stmt stmt) {
187: visitNode(stmt);
188: }
189:
190: public void visitSCStmt(final SCStmt stmt) {
191: visitStmt(stmt);
192: }
193:
194: public void visitSRStmt(final SRStmt stmt) {
195: visitStmt(stmt);
196: }
197:
198: public void visitArithExpr(final ArithExpr expr) {
199: visitExpr(expr);
200: }
201:
202: public void visitArrayLengthExpr(final ArrayLengthExpr expr) {
203: visitExpr(expr);
204: }
205:
206: public void visitMemExpr(final MemExpr expr) {
207: visitDefExpr(expr);
208: }
209:
210: public void visitMemRefExpr(final MemRefExpr expr) {
211: visitMemExpr(expr);
212: }
213:
214: public void visitArrayRefExpr(final ArrayRefExpr expr) {
215: visitMemRefExpr(expr);
216: }
217:
218: public void visitCallExpr(final CallExpr expr) {
219: visitExpr(expr);
220: }
221:
222: public void visitCallMethodExpr(final CallMethodExpr expr) {
223: visitCallExpr(expr);
224: }
225:
226: public void visitCallStaticExpr(final CallStaticExpr expr) {
227: visitCallExpr(expr);
228: }
229:
230: public void visitCastExpr(final CastExpr expr) {
231: visitExpr(expr);
232: }
233:
234: public void visitConstantExpr(final ConstantExpr expr) {
235: visitExpr(expr);
236: }
237:
238: public void visitFieldExpr(final FieldExpr expr) {
239: visitMemRefExpr(expr);
240: }
241:
242: public void visitInstanceOfExpr(final InstanceOfExpr expr) {
243: visitExpr(expr);
244: }
245:
246: public void visitLocalExpr(final LocalExpr expr) {
247: visitVarExpr(expr);
248: }
249:
250: public void visitNegExpr(final NegExpr expr) {
251: visitExpr(expr);
252: }
253:
254: public void visitNewArrayExpr(final NewArrayExpr expr) {
255: visitExpr(expr);
256: }
257:
258: public void visitNewExpr(final NewExpr expr) {
259: visitExpr(expr);
260: }
261:
262: public void visitNewMultiArrayExpr(final NewMultiArrayExpr expr) {
263: visitExpr(expr);
264: }
265:
266: public void visitCheckExpr(final CheckExpr expr) {
267: visitExpr(expr);
268: }
269:
270: public void visitZeroCheckExpr(final ZeroCheckExpr expr) {
271: visitCheckExpr(expr);
272: }
273:
274: public void visitRCExpr(final RCExpr expr) {
275: visitCheckExpr(expr);
276: }
277:
278: public void visitUCExpr(final UCExpr expr) {
279: visitCheckExpr(expr);
280: }
281:
282: public void visitReturnAddressExpr(final ReturnAddressExpr expr) {
283: visitExpr(expr);
284: }
285:
286: public void visitShiftExpr(final ShiftExpr expr) {
287: visitExpr(expr);
288: }
289:
290: public void visitStackExpr(final StackExpr expr) {
291: visitVarExpr(expr);
292: }
293:
294: public void visitVarExpr(final VarExpr expr) {
295: visitMemExpr(expr);
296: }
297:
298: public void visitStaticFieldExpr(final StaticFieldExpr expr) {
299: visitMemRefExpr(expr);
300: }
301:
302: public void visitExpr(final Expr expr) {
303: visitNode(expr);
304: }
305:
306: public void visitNode(final Node node) {
307: node.visitChildren(this);
308: }
309: }
|