KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > dava > toolkits > base > AST > ASTWalker


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2003 Jerome Miecznikowski
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */

19 /*
20    Nomair A. Naeem 08-FEB-2005
21    This analysis class has become obselete.
22    Use soot.dava.toolkits.base.AST.analysis which provides a Visitor Design
23    Pattern
24 */

25
26 package soot.dava.toolkits.base.AST;
27
28 import soot.*;
29 import soot.jimple.*;
30
31 public class ASTWalker
32 {
33     public ASTWalker( Singletons.Global g ) {}
34     public static ASTWalker v() { return G.v().soot_dava_toolkits_base_AST_ASTWalker(); }
35     
36     public void walk_stmt( ASTAnalysis a, Stmt s)
37     {
38     if (a.getAnalysisDepth() < ASTAnalysis.ANALYSE_STMTS)
39         return;
40
41     if (s instanceof DefinitionStmt) {
42         DefinitionStmt ds = (DefinitionStmt) s;
43
44         walk_value( a, ds.getRightOp());
45         walk_value( a, ds.getLeftOp());
46         a.analyseDefinitionStmt( ds);
47     }
48     else if (s instanceof ReturnStmt) {
49         ReturnStmt rs = (ReturnStmt) s;
50
51         walk_value( a, rs.getOp());
52         a.analyseReturnStmt( rs);
53     }
54     else if (s instanceof InvokeStmt) {
55         InvokeStmt is = (InvokeStmt) s;
56
57         walk_value( a, is.getInvokeExpr());
58         a.analyseInvokeStmt( is);
59     }
60     else if (s instanceof ThrowStmt) {
61         ThrowStmt ts = (ThrowStmt) s;
62
63         walk_value( a, ts.getOp());
64         a.analyseThrowStmt( ts);
65     }
66     else
67         a.analyseStmt( s);
68     }
69
70     public void walk_value( ASTAnalysis a, Value v)
71     {
72     if (a.getAnalysisDepth() < ASTAnalysis.ANALYSE_VALUES)
73         return;
74
75     if (v instanceof Expr) {
76         Expr e = (Expr) v;
77
78         if (e instanceof BinopExpr) {
79         BinopExpr be = (BinopExpr) e;
80         
81         walk_value( a, be.getOp1());
82         walk_value( a, be.getOp2());
83         a.analyseBinopExpr( be);
84         }
85         else if (e instanceof UnopExpr) {
86         UnopExpr ue = (UnopExpr) e;
87         
88         walk_value( a, ue.getOp());
89         a.analyseUnopExpr( ue);
90         }
91         else if (e instanceof NewArrayExpr) {
92         NewArrayExpr nae = (NewArrayExpr) e;
93         
94         walk_value( a, nae.getSize());
95         a.analyseNewArrayExpr( nae);
96         }
97         else if (e instanceof NewMultiArrayExpr) {
98         NewMultiArrayExpr nmae = (NewMultiArrayExpr) e;
99         
100         for (int i=0; i<nmae.getSizeCount(); i++)
101             walk_value( a, nmae.getSize( i));
102         a.analyseNewMultiArrayExpr( nmae);
103         }
104         else if (e instanceof InstanceOfExpr) {
105         InstanceOfExpr ioe = (InstanceOfExpr) e;
106         
107         walk_value( a, ioe.getOp());
108         a.analyseInstanceOfExpr( ioe);
109         }
110         else if (e instanceof InvokeExpr) {
111         InvokeExpr ie = (InvokeExpr) e;
112         
113         for (int i=0; i<ie.getArgCount(); i++)
114             walk_value( a, ie.getArg( i));
115         
116         if (ie instanceof InstanceInvokeExpr) {
117             InstanceInvokeExpr iie = (InstanceInvokeExpr) ie;
118             
119             walk_value( a, iie.getBase());
120             a.analyseInstanceInvokeExpr( iie);
121         }
122         else
123             a.analyseInvokeExpr( ie);
124         }
125         else
126         a.analyseExpr( e);
127     }
128     else if (v instanceof Ref) {
129         Ref r = (Ref) v;
130
131         if (r instanceof ArrayRef) {
132         ArrayRef ar = (ArrayRef) r;
133         
134         walk_value( a, ar.getBase());
135         walk_value( a, ar.getIndex());
136         a.analyseArrayRef( ar);
137         }
138         else if (r instanceof InstanceFieldRef) {
139         InstanceFieldRef ifr = (InstanceFieldRef) r;
140         
141         walk_value( a, ifr.getBase());
142         a.analyseInstanceFieldRef( ifr);
143         }
144         else
145         a.analyseRef( r);
146     }
147     else
148         a.analyseValue( v);
149     }
150 }
151
Popular Tags