1 19 20 package soot.jimple.spark.sets; 21 import soot.jimple.spark.*; 22 import soot.jimple.spark.pag.Node; 23 import soot.jimple.spark.pag.PAG; 24 import soot.jimple.spark.internal.*; 25 import soot.util.*; 26 import soot.Type; 27 28 31 public final class BitPointsToSet extends PointsToSetInternal { 32 public BitPointsToSet( Type type, PAG pag ) { 33 super( type ); 34 this.pag = pag; 35 bits = new BitVector( pag.getAllocNodeNumberer().size() ); 36 } 37 38 public final boolean isEmpty() { 39 return empty; 40 } 41 42 private final boolean superAddAll( PointsToSetInternal other, PointsToSetInternal exclude ) { 43 boolean ret = super.addAll( other, exclude ); 44 if( ret ) empty = false; 45 return ret; 46 } 47 48 private final boolean nativeAddAll( BitPointsToSet other, BitPointsToSet exclude ) { 49 BitVector mask = null; 50 TypeManager typeManager = (TypeManager) pag.getTypeManager(); 51 if( !typeManager.castNeverFails( other.getType(), this.getType() ) ) { 52 mask = typeManager.get( this.getType() ); 53 } 54 BitVector obits = other.bits; 55 BitVector ebits = ( exclude==null ? null : exclude.bits ); 56 boolean ret = bits.orAndAndNot( obits, mask, ebits ); 57 if( ret ) empty = false; 58 return ret; 59 } 60 61 63 public final boolean addAll( PointsToSetInternal other, 64 PointsToSetInternal exclude ) { 65 if( other != null && !(other instanceof BitPointsToSet) ) 66 return superAddAll( other, exclude ); 67 if( exclude != null && !(exclude instanceof BitPointsToSet) ) 68 return superAddAll( other, exclude ); 69 return nativeAddAll( (BitPointsToSet) other, (BitPointsToSet) exclude ); 70 } 71 72 public final boolean forall( P2SetVisitor v ) { 73 for( BitSetIterator it = bits.iterator(); it.hasNext(); ) { 74 v.visit( (Node) pag.getAllocNodeNumberer().get( it.next() ) ); 75 } 76 return v.getReturnValue(); 77 } 78 79 public final boolean add( Node n ) { 80 if( pag.getTypeManager().castNeverFails( n.getType(), type ) ) { 81 return fastAdd( n ); 82 } 83 return false; 84 } 85 86 public final boolean contains( Node n ) { 87 return bits.get( n.getNumber() ); 88 } 89 public static P2SetFactory getFactory() { 90 return new P2SetFactory() { 91 public PointsToSetInternal newSet( Type type, PAG pag ) { 92 return new BitPointsToSet( type, pag ); 93 } 94 }; 95 } 96 97 98 99 100 private boolean fastAdd( Node n ) { 101 boolean ret = bits.set( n.getNumber() ); 102 if( ret ) empty = false; 103 return ret; 104 } 105 106 private BitVector bits = null; 107 private boolean empty = true; 108 private PAG pag = null; 109 } 110 111 | Popular Tags |