1 20 21 package soot.dava; 22 import soot.AbstractUnitPrinter; 23 import soot.ArrayType; 24 import soot.RefType; 25 import soot.SootFieldRef; 26 import soot.SootMethodRef; 27 import soot.Type; 28 import soot.Unit; 29 import soot.jimple.IdentityRef; 30 import soot.jimple.Jimple; 31 import soot.jimple.ThisRef; 32 33 36 public class DavaUnitPrinter extends AbstractUnitPrinter { 37 public void methodRef( SootMethodRef m ) { 38 handleIndent(); 39 output.append( m.name() ); 40 } 41 public void fieldRef( SootFieldRef f ) { 42 handleIndent(); 43 output.append(f.name()); 44 } 45 public void identityRef( IdentityRef r ) { 46 handleIndent(); 47 if( r instanceof ThisRef ) { 48 literal("this"); 49 } else throw new RuntimeException (); 50 } 51 52 private boolean eatSpace = false; 53 public void literal( String s ) { 54 handleIndent(); 55 if( eatSpace && s.equals(" ") ) { 56 eatSpace = false; 57 return; 58 } 59 eatSpace = false; 60 if( false 61 || s.equals( Jimple.v().STATICINVOKE ) 62 || s.equals( Jimple.v().VIRTUALINVOKE ) 63 || s.equals( Jimple.v().INTERFACEINVOKE ) 64 ) { 65 eatSpace = true; 66 return; 67 } 68 output.append(s); 69 } 70 public void type( Type t ) { 71 handleIndent(); 72 if( t instanceof RefType ) { 73 output.append( ((RefType) t).getSootClass().getJavaStyleName() ); 74 } else if( t instanceof ArrayType ) { 75 ((ArrayType) t).toString( this ); 76 } else { 77 output.append( t.toString() ); 78 } 79 } 80 public void unitRef( Unit u, boolean branchTarget ) { 81 throw new RuntimeException ( "Dava doesn't have unit references!" ); 82 } 83 84 85 86 87 88 89 public void addNot() { 90 output.append(" !"); 91 } 92 public void addAggregatedOr() { 93 output.append(" || "); 94 } 95 public void addAggregatedAnd() { 96 output.append(" && " ); 97 } 98 public void addLeftParen() { 99 output.append(" (" ); 100 } 101 public void addRightParen() { 102 output.append(") " ); 103 } 104 105 public void printString(String s){ 106 output.append(s); 107 } 108 109 } 110 111 112 | Popular Tags |