1 19 20 package soot.jimple.toolkits.pointer; 21 import soot.*; 22 import soot.util.*; 23 import java.util.*; 24 25 26 class LocalTypeSet extends java.util.BitSet { 27 protected List locals; 28 protected List types; 29 30 32 public LocalTypeSet( List locals, List types ) { 33 super( locals.size() * types.size() ); 34 this.locals = locals; 35 this.types = types; 36 if( !Scene.v().hasFastHierarchy() ) { 37 Scene.v().setFastHierarchy( new FastHierarchy() ); 38 } 39 } 40 41 protected int indexOf( Local l, RefType t ) { 42 if( locals.indexOf( l ) == -1 || types.indexOf( t ) == -1 ) { 43 throw new RuntimeException ( "Invalid local or type in LocalTypeSet" ); 44 } 45 return locals.indexOf( l ) * types.size() + types.indexOf( t ); 46 } 47 48 public void killLocal( Local l ) { 49 int base = types.size() * locals.indexOf( l ); 50 for( int i = 0; i < types.size(); i++ ) { 51 clear( i + base ); 52 } 53 } 54 55 public void localCopy( Local to, Local from ) { 56 int baseTo = types.size() * locals.indexOf( to ); 57 int baseFrom = types.size() * locals.indexOf( from ); 58 for( int i = 0; i < types.size(); i++ ) { 59 if( get( i+baseFrom ) ) { 60 set( i+baseTo ); 61 } else { 62 clear( i+baseTo ); 63 } 64 } 65 } 66 67 public void clearAllBits() { 68 for( int i = 0; i < types.size() * locals.size(); i++ ) { 69 clear( i ); 70 } 71 } 72 73 public void setAllBits() { 74 for( int i = 0; i < types.size() * locals.size(); i++ ) { 75 set( i ); 76 } 77 } 78 79 public void localMustBeSubtypeOf( Local l, RefType t ) { 80 FastHierarchy fh = Scene.v().getFastHierarchy(); 81 for( Iterator it = types.iterator(); it.hasNext(); ) { 82 RefType supertype = (RefType) it.next(); 83 if( fh.canStoreType( t, supertype ) ) { 84 set( indexOf( l, supertype ) ); 85 } 86 } 87 } 88 89 public String toString(){ 90 StringBuffer sb = new StringBuffer (); 91 Iterator localsIt = locals.iterator(); 92 while (localsIt.hasNext()){ 93 Local l = (Local)localsIt.next(); 94 Iterator typesIt = types.iterator(); 95 while (typesIt.hasNext()){ 96 RefType t = (RefType)typesIt.next(); 97 int index = indexOf(l, t); 98 if (get(index)) { 100 sb.append("(("+l+","+t+") -> elim cast check) "); 101 } 102 } 103 104 } 105 return sb.toString(); 106 } 107 } 108 109 | Popular Tags |