1 19 20 package soot; 21 import soot.jimple.*; 22 import java.util.*; 23 24 27 public abstract class AbstractUnitPrinter implements UnitPrinter { 28 public void setPositionTagger( AttributesUnitPrinter pt ) { 29 this.pt = pt; 30 pt.setUnitPrinter( this ); 31 } 32 public AttributesUnitPrinter getPositionTagger() { 33 return pt; 34 } 35 public void startUnit( Unit u ) { 36 handleIndent(); 37 if( pt != null ) pt.startUnit( u ); 38 } 39 public void endUnit( Unit u ) { 40 if( pt != null ) pt.endUnit( u ); 41 } 42 public void startUnitBox( UnitBox ub ) { handleIndent(); } 43 public void endUnitBox( UnitBox ub ) {} 44 public void startValueBox( ValueBox vb ) { 45 handleIndent(); 46 if( pt != null ) pt.startValueBox( vb ); 47 } 48 public void endValueBox( ValueBox vb ) { 49 if( pt != null ) pt.endValueBox( vb ); 50 } 51 52 public void noIndent() { startOfLine = false; } 53 public void incIndent() { indent = indent + " "; } 54 public void decIndent() { 55 if( indent.length() >= 4 ) indent = indent.substring(4); 56 } 57 public void setIndent(String indent) { this.indent = indent; } 58 public String getIndent() { return indent; } 59 60 public abstract void literal( String s ); 61 public abstract void type( Type t ); 62 public abstract void methodRef( SootMethodRef m ); 63 public abstract void fieldRef( SootFieldRef f ); 64 public abstract void identityRef( IdentityRef r ); 65 public abstract void unitRef( Unit u, boolean branchTarget ); 66 67 public void newline() { 68 output.append("\n"); 69 startOfLine = true; 70 if( pt != null ) pt.newline(); 71 } 72 public void local( Local l ) { 73 handleIndent(); 74 if( quotableLocals == null ) 75 initializeQuotableLocals(); 76 if( quotableLocals.contains(l.getName()) ) 77 output.append ( "'" + l.getName() + "'"); 78 else 79 output.append( l.getName() ); 80 } 81 public void constant( Constant c ) { 82 handleIndent(); 83 output.append( c.toString() ); 84 } 85 public String toString() { 86 String ret = output.toString(); 87 output = new StringBuffer (); 88 return ret; 89 } 90 public StringBuffer output() { 91 return output; 92 } 93 94 protected void handleIndent() { 95 if( startOfLine ) output.append( indent ); 96 startOfLine = false; 97 } 98 99 protected void initializeQuotableLocals() { 100 quotableLocals = new HashSet(); 101 quotableLocals.addAll (Jimple.jimpleKeywordList()); 102 } 103 104 protected boolean startOfLine = true; 105 protected String indent = " "; 106 protected StringBuffer output = new StringBuffer (); 107 protected AttributesUnitPrinter pt; 108 protected HashSet quotableLocals; 109 } 110 111 | Popular Tags |