1 19 20 package soot; 21 22 import soot.util.*; 23 import java.util.*; 24 25 27 public class RadioScenePack extends ScenePack 28 { 29 public RadioScenePack(String name) { 30 super(name); 31 } 32 33 protected void internalApply() 34 { 35 LinkedList enableds = new LinkedList(); 36 37 for( Iterator tIt = this.iterator(); tIt.hasNext(); ) { 38 39 final Transform t = (Transform) tIt.next(); 40 Map opts = PhaseOptions.v().getPhaseOptions( t ); 41 if( !PhaseOptions.getBoolean( opts, "enabled" ) ) continue; 42 enableds.add( t ); 43 } 44 if( enableds.size() == 0 ) { 45 G.v().out.println( "Exactly one phase in the pack "+getPhaseName()+ 46 " must be enabled. Currently, none of them are." ); 47 throw new CompilationDeathException( CompilationDeathException.COMPILATION_ABORTED ); 48 } 49 if( enableds.size() > 1 ) { 50 G.v().out.println( "Only one phase in the pack "+getPhaseName()+ 51 " may be enabled. The following are enabled currently: " ); 52 for( Iterator tIt = enableds.iterator(); tIt.hasNext(); ) { 53 final Transform t = (Transform) tIt.next(); 54 G.v().out.println( " "+t.getPhaseName() ); 55 } 56 throw new CompilationDeathException( CompilationDeathException.COMPILATION_ABORTED ); 57 } 58 for( Iterator tIt = enableds.iterator(); tIt.hasNext(); ) { 59 final Transform t = (Transform) tIt.next(); 60 t.apply(); 61 } 62 } 63 64 public void add(Transform t) { 65 super.add(t); 66 checkEnabled(t); 67 } 68 public void insertAfter(Transform t, String phaseName) { 69 super.insertAfter(t, phaseName); 70 checkEnabled(t); 71 } 72 public void insertBefore(Transform t, String phaseName) { 73 super.insertBefore(t, phaseName); 74 checkEnabled(t); 75 } 76 private void checkEnabled(Transform t) { 77 Map options = PhaseOptions.v().getPhaseOptions(t); 78 if( PhaseOptions.v().getBoolean( options, "enabled" ) ) { 79 PhaseOptions.v().setPhaseOption( t, "enabled:true" ); 81 } 82 } 83 } 84 | Popular Tags |