KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > jimple > PointerStmtSwitch


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2003 Ondrej Lhotak
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 package soot.jimple;
21 import soot.*;
22
23 public abstract class PointerStmtSwitch extends AbstractStmtSwitch {
24     Stmt statement;
25
26     /** A statement of the form l = constant; */
27     protected abstract void caseAssignConstStmt( Value dest, Constant c );
28
29     /** A statement of the form l = v; */
30     protected abstract void caseCopyStmt( Local dest, Local src );
31
32     /** A statement of the form l = (cl) v; */
33     protected void caseCastStmt( Local dest, Local src, CastExpr c ) {
34     // default is to just ignore the cast
35
caseCopyStmt( dest, src );
36     }
37     /** An identity statement assigning a parameter to a local. */
38     protected abstract void caseIdentityStmt( Local dest, IdentityRef src );
39
40     /** A statement of the form l1 = l2.f; */
41     protected abstract void caseLoadStmt( Local dest, InstanceFieldRef src );
42
43     /** A statement of the form l1.f = l2; */
44     protected abstract void caseStoreStmt( InstanceFieldRef dest, Local src );
45
46     /** A statement of the form l1 = l2[i]; */
47     protected abstract void caseArrayLoadStmt( Local dest, ArrayRef src );
48     /** A statement of the form l1[i] = l2; */
49     protected abstract void caseArrayStoreStmt( ArrayRef dest, Local src );
50     /** A statement of the form l = cl.f; */
51     protected abstract void caseGlobalLoadStmt( Local dest, StaticFieldRef src );
52     /** A statement of the form cl.f = l; */
53     protected abstract void caseGlobalStoreStmt( StaticFieldRef dest, Local src );
54     /** A return statement. e is null if a non-reference type is returned. */
55     protected abstract void caseReturnStmt( Local val );
56     /** A return statement returning a constant. */
57     protected void caseReturnConstStmt( Constant val ) {
58     // default is uninteresting
59
caseUninterestingStmt( statement );
60     }
61     /** Any type of new statement (NewStmt, NewArrayStmt, NewMultiArrayStmt) */
62     protected abstract void caseAnyNewStmt( Local dest, Expr e );
63     /** A new statement */
64     protected void caseNewStmt( Local dest, NewExpr e ) {
65     caseAnyNewStmt( dest, e );
66     }
67     /** A newarray statement */
68     protected void caseNewArrayStmt( Local dest, NewArrayExpr e ) {
69     caseAnyNewStmt( dest, e );
70     }
71     /** A anewarray statement */
72     protected void caseNewMultiArrayStmt( Local dest, NewMultiArrayExpr e ) {
73     caseAnyNewStmt( dest, e );
74     }
75     /** A method invocation. dest is null if there is no reference type return value. */
76     protected abstract void caseInvokeStmt( Local dest, InvokeExpr e );
77     /** A throw statement */
78     protected void caseThrowStmt( Local thrownException ) {
79     caseUninterestingStmt(statement);
80     }
81     /** A catch statement */
82     protected void caseCatchStmt( Local dest, CaughtExceptionRef cer ) {
83     caseUninterestingStmt(statement);
84     }
85     /** Any other statement */
86     protected void caseUninterestingStmt( Stmt s ) {};
87
88     public final void caseAssignStmt( AssignStmt s ) {
89     statement = s;
90     Value lhs = s.getLeftOp();
91     Value rhs = s.getRightOp();
92     if( ! (lhs.getType() instanceof RefType)
93     && ! (lhs.getType() instanceof ArrayType) ) {
94         if( rhs instanceof InvokeExpr ) {
95         caseInvokeStmt( null, (InvokeExpr) rhs );
96         return;
97         }
98         caseUninterestingStmt( s );
99         return;
100     }
101     if( rhs instanceof InvokeExpr ) {
102         caseInvokeStmt( (Local) lhs, (InvokeExpr) rhs );
103         return;
104     }
105     if( lhs instanceof Local ) {
106         if( rhs instanceof Local ) {
107         caseCopyStmt( (Local) lhs, (Local) rhs );
108         } else if( rhs instanceof InstanceFieldRef ) {
109         caseLoadStmt( (Local) lhs, (InstanceFieldRef) rhs );
110         } else if( rhs instanceof ArrayRef ) {
111         caseArrayLoadStmt( (Local) lhs, (ArrayRef) rhs );
112         } else if( rhs instanceof StaticFieldRef ) {
113         caseGlobalLoadStmt( (Local) lhs, (StaticFieldRef) rhs );
114         } else if( rhs instanceof NewExpr ) {
115         caseNewStmt( (Local) lhs, (NewExpr) rhs );
116         } else if( rhs instanceof NewArrayExpr ) {
117         caseNewArrayStmt( (Local) lhs, (NewArrayExpr) rhs );
118         } else if( rhs instanceof NewMultiArrayExpr ) {
119         caseNewMultiArrayStmt( (Local) lhs, (NewMultiArrayExpr) rhs );
120         } else if( rhs instanceof CastExpr ) {
121         CastExpr r = (CastExpr) rhs;
122         Value rv = r.getOp();
123         if( rv instanceof Constant ) {
124             caseAssignConstStmt( lhs, (Constant) rv );
125         } else {
126             caseCastStmt( (Local) lhs, (Local) rv, r );
127         }
128         } else if( rhs instanceof Constant ) {
129         caseAssignConstStmt( lhs, (Constant) rhs );
130         } else throw new RuntimeException JavaDoc( "unhandled stmt "+s );
131     } else if( lhs instanceof InstanceFieldRef ) {
132         if( rhs instanceof Local ) {
133         caseStoreStmt( (InstanceFieldRef) lhs, (Local) rhs );
134         } else if( rhs instanceof Constant ) {
135         caseAssignConstStmt( lhs, (Constant) rhs );
136         } else throw new RuntimeException JavaDoc( "unhandled stmt "+s );
137     } else if( lhs instanceof ArrayRef ) {
138         if( rhs instanceof Local ) {
139         caseArrayStoreStmt( (ArrayRef) lhs, (Local) rhs );
140         } else if( rhs instanceof Constant ) {
141         caseAssignConstStmt( lhs, (Constant) rhs );
142         } else throw new RuntimeException JavaDoc( "unhandled stmt "+s );
143     } else if( lhs instanceof StaticFieldRef ) {
144         if( rhs instanceof Local ) {
145         caseGlobalStoreStmt( (StaticFieldRef) lhs, (Local) rhs );
146         } else if( rhs instanceof Constant ) {
147         caseAssignConstStmt( lhs, (Constant) rhs );
148         } else throw new RuntimeException JavaDoc( "unhandled stmt "+s );
149     } else if( rhs instanceof Constant ) {
150         caseAssignConstStmt( lhs, (Constant) rhs );
151     } else throw new RuntimeException JavaDoc( "unhandled stmt "+s );
152     }
153     public final void caseReturnStmt(ReturnStmt s) {
154     statement = s;
155     Value op = s.getOp();
156     if( op.getType() instanceof RefType
157     || op.getType() instanceof ArrayType ) {
158         if( op instanceof Constant ) {
159         caseReturnConstStmt( (Constant) op );
160         } else {
161         caseReturnStmt( (Local) op );
162         }
163     } else {
164         caseReturnStmt( (Local) null );
165     }
166     }
167     public final void caseReturnVoidStmt(ReturnVoidStmt s) {
168     statement = s;
169     caseReturnStmt( (Local) null );
170     }
171     public final void caseInvokeStmt(InvokeStmt s) {
172     statement = s;
173     caseInvokeStmt( null, (InvokeExpr) s.getInvokeExpr() );
174     }
175     public final void caseIdentityStmt(IdentityStmt s) {
176     statement = s;
177     Value lhs = s.getLeftOp();
178     Value rhs = s.getRightOp();
179     if( !( lhs.getType() instanceof RefType )
180     && !(lhs.getType() instanceof ArrayType ) ) {
181          caseUninterestingStmt( s );
182          return;
183     }
184     Local llhs = (Local) lhs;
185     if( rhs instanceof CaughtExceptionRef ) {
186         caseCatchStmt( llhs, (CaughtExceptionRef) rhs );
187     } else {
188         IdentityRef rrhs = (IdentityRef) rhs;
189         caseIdentityStmt( llhs, rrhs );
190     }
191     }
192     public final void caseThrowStmt( ThrowStmt s) {
193     statement = s;
194     caseThrowStmt( (Local) s.getOp() );
195     }
196 }
197
198
Popular Tags