| 1 19 20 package soot.jimple; 21 import java.util.*; 22 import soot.*; 23 import java.io.*; 24 25 29 public class ReachingTypeDumper { 30 public ReachingTypeDumper( PointsToAnalysis pa, String output_dir ) { 31 this.pa = pa; 32 this.output_dir = output_dir; 33 } 34 public void dump() { 35 try { 36 PrintWriter file = new PrintWriter( 37 new FileOutputStream( new File(output_dir, "types") ) ); 38 for( Iterator it = Scene.v().getApplicationClasses().iterator(); 39 it.hasNext(); ) { 40 handleClass( file, (SootClass) it.next() ); 41 } 42 for( Iterator it = Scene.v().getLibraryClasses().iterator(); 43 it.hasNext(); ) { 44 handleClass( file, (SootClass) it.next() ); 45 } 46 file.close(); 47 } catch( IOException e ) { 48 throw new RuntimeException ( "Couldn't dump reaching types."+e ); 49 } 50 } 51 52 53 54 55 56 protected PointsToAnalysis pa; 57 protected String output_dir; 58 59 protected void handleClass( PrintWriter out, SootClass c ) { 60 for( Iterator mIt = c.methodIterator(); mIt.hasNext(); ) { 61 final SootMethod m = (SootMethod) mIt.next(); 62 if( !m.isConcrete() ) continue; 63 Body b = m.retrieveActiveBody(); 64 TreeSet sortedLocals = new TreeSet( new StringComparator() ); 65 sortedLocals.addAll( b.getLocals() ); 66 for( Iterator lIt = sortedLocals.iterator(); lIt.hasNext(); ) { 67 final Local l = (Local) lIt.next(); 68 out.println( "V "+m+l ); 69 if( l.getType() instanceof RefLikeType ) { 70 Set types = pa.reachingObjects( l ).possibleTypes(); 71 TreeSet sortedTypes = new TreeSet( new StringComparator() ); 72 sortedTypes.addAll( types ); 73 for( Iterator tIt = sortedTypes.iterator(); tIt.hasNext(); ) { 74 out.println( "T "+tIt.next() ); 75 } 76 } 77 } 78 } 79 } 80 class StringComparator implements Comparator { 81 public int compare( Object o1, Object o2 ) { 82 return o1.toString().compareTo( o2.toString() ); 83 } 84 } 85 } 86 87 | Popular Tags |