1 19 20 package soot.jimple.spark.solver; 21 import soot.jimple.spark.*; 22 import soot.jimple.spark.pag.*; 23 import soot.jimple.spark.sets.*; 24 import soot.*; 25 import java.util.*; 26 27 31 32 public class Checker { 33 public Checker( PAG pag ) { this.pag = pag; } 34 35 public void check() { 36 for( Iterator it = pag.allocSources().iterator(); it.hasNext(); ) { 37 handleAllocNode( (AllocNode) it.next() ); 38 } 39 for( Iterator it = pag.simpleSources().iterator(); it.hasNext(); ) { 40 handleSimples( (VarNode) it.next() ); 41 } 42 for( Iterator it = pag.loadSources().iterator(); it.hasNext(); ) { 43 handleLoads( (FieldRefNode) it.next() ); 44 } 45 for( Iterator it = pag.storeSources().iterator(); it.hasNext(); ) { 46 handleStores( (VarNode) it.next() ); 47 } 48 } 49 50 51 52 53 protected void checkAll( final Node container, PointsToSetInternal nodes, 54 final Node upstream ) { 55 nodes.forall( new P2SetVisitor() { 56 public final void visit( Node n ) { 57 checkNode( container, n, upstream ); 58 } 59 } ); 60 } 61 protected void checkNode( Node container, Node n, Node upstream ) { 62 if( container.getReplacement() != container ) 63 throw new RuntimeException ( "container "+container+" is illegal" ); 64 if( upstream.getReplacement() != upstream ) 65 throw new RuntimeException ( "upstream "+upstream+" is illegal" ); 66 PointsToSetInternal p2set = container.getP2Set(); 67 FastHierarchy fh = pag.getTypeManager().getFastHierarchy(); 68 if( !p2set.contains( n ) 69 && ( fh == null || container.getType() == null || 70 fh.canStoreType( n.getType(), container.getType() ) ) ) { 71 G.v().out.println( "Check failure: "+container+" does not have "+n 72 +"; upstream is "+upstream ); 73 } 74 } 75 protected void handleAllocNode( AllocNode src ) { 76 Node[] targets = pag.allocLookup( src ); 77 for( int i = 0; i < targets.length; i++ ) { 78 checkNode( targets[i], src, src ); 79 } 80 } 81 82 protected void handleSimples( VarNode src ) { 83 PointsToSetInternal srcSet = src.getP2Set(); 84 if( srcSet.isEmpty() ) return; 85 final Node[] simpleTargets = pag.simpleLookup( src ); 86 for( int i = 0; i < simpleTargets.length; i++ ) { 87 checkAll( simpleTargets[i], srcSet, src ); 88 } 89 } 90 91 protected void handleStores( final VarNode src ) { 92 final PointsToSetInternal srcSet = src.getP2Set(); 93 if( srcSet.isEmpty() ) return; 94 Node[] storeTargets = pag.storeLookup( src ); 95 for( int i = 0; i < storeTargets.length; i++ ) { 96 final FieldRefNode fr = (FieldRefNode) storeTargets[i]; 97 final SparkField f = fr.getField(); 98 fr.getBase().getP2Set().forall( new P2SetVisitor() { 99 public final void visit( Node n ) { 100 AllocDotField nDotF = pag.makeAllocDotField( 101 (AllocNode) n, f ); 102 checkAll( nDotF, srcSet, src ); 103 } 104 } ); 105 } 106 } 107 108 protected void handleLoads( final FieldRefNode src ) { 109 final Node[] loadTargets = pag.loadLookup( src ); 110 final SparkField f = src.getField(); 111 src.getBase().getP2Set().forall( new P2SetVisitor() { 112 public final void visit( Node n ) { 113 AllocDotField nDotF = ((AllocNode)n).dot( f ); 114 if( nDotF == null ) return; 115 PointsToSetInternal set = nDotF.getP2Set(); 116 if( set.isEmpty() ) return; 117 for( int i = 0; i < loadTargets.length; i++ ) { 118 VarNode target = (VarNode) loadTargets[i]; 119 checkAll( target, set, src ); 120 } 121 } 122 } ); 123 } 124 125 protected PAG pag; 126 } 127 128 129 130 | Popular Tags |