KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > shimple > ShimpleTransformer


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2003 Navindra Umanee <navindra@cs.mcgill.ca>
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.shimple;
21
22 import soot.*;
23 import soot.options.Options;
24 import java.util.*;
25
26 /**
27  * Traverses all methods, in all classes from the Scene, and
28  * transforms them to Shimple. Typically used for whole-program
29  * analysis on Shimple.
30  *
31  * @author Navindra Umanee
32  **/

33 public class ShimpleTransformer extends SceneTransformer
34 {
35     public ShimpleTransformer( Singletons.Global g ) {}
36     public static ShimpleTransformer v() { return G.v().soot_shimple_ShimpleTransformer(); }
37
38     protected void internalTransform(String JavaDoc phaseName, Map options)
39     {
40         if(Options.v().verbose())
41             G.v().out.println("Transforming all classes in the Scene to Shimple...");
42
43         // *** FIXME: Add debug output to indicate which class/method is being shimplified.
44
// *** FIXME: Is ShimpleTransformer the right solution? The call graph may deem
45
// some classes unreachable.
46

47         Iterator classesIt = Scene.v().getClasses().iterator();
48         while(classesIt.hasNext()){
49             SootClass sClass = (SootClass) classesIt.next();
50             if(sClass.isPhantom()) continue;
51             
52             Iterator methodsIt = sClass.getMethods().iterator();
53             while(methodsIt.hasNext()){
54                 SootMethod method = (SootMethod) methodsIt.next();
55                 if(!method.isConcrete()) continue;
56
57                 if(method.hasActiveBody()){
58                     Body body = method.getActiveBody();
59                     ShimpleBody sBody = null;
60
61                     if(body instanceof ShimpleBody){
62                         sBody = (ShimpleBody) body;
63                         if(!sBody.isSSA())
64                             sBody.rebuild();
65                     }
66                     else{
67                         sBody = Shimple.v().newBody(body);
68                     }
69
70                     method.setActiveBody(sBody);
71                 }
72                 else{
73                     MethodSource ms = new ShimpleMethodSource(method.getSource());
74                     method.setSource(ms);
75                 }
76             }
77         }
78     }
79 }
80
Popular Tags