1 19 20 package soot.dava.toolkits.base.finders; 21 22 import java.util.*; 23 import soot.util.*; 24 import soot.dava.internal.asg.*; 25 26 public class SwitchNode implements Comparable 27 { 28 private LinkedList preds, succs; 29 private AugmentedStmt as; 30 private int score; 31 private TreeSet indexSet; 32 private IterableSet body; 33 34 public SwitchNode( AugmentedStmt as, TreeSet indexSet, IterableSet body) 35 { 36 this.as = as; 37 this.indexSet = indexSet; 38 this.body = body; 39 40 preds = new LinkedList(); 41 succs = new LinkedList(); 42 43 score = -1; 44 } 45 46 public int get_Score() 47 { 48 if (score == -1) { 49 score = 0; 50 51 if (preds.size() < 2) { 52 53 Iterator sit = succs.iterator(); 54 while (sit.hasNext()) { 55 SwitchNode ssn = (SwitchNode) sit.next(); 56 57 int curScore = ssn.get_Score(); 58 if (score < curScore) 59 score = curScore; 60 } 61 62 score++; 63 } 64 } 65 66 return score; 67 } 68 69 public List get_Preds() 70 { 71 return preds; 72 } 73 74 public List get_Succs() 75 { 76 return succs; 77 } 78 79 public AugmentedStmt get_AugStmt() 80 { 81 return as; 82 } 83 84 public TreeSet get_IndexSet() 85 { 86 return indexSet; 87 } 88 89 public IterableSet get_Body() 90 { 91 return body; 92 } 93 94 public SwitchNode reset() 95 { 96 preds.clear(); 97 succs.clear(); 98 99 return this; 100 } 101 102 public void setup_Graph( HashMap binding) 103 { 104 Iterator rit = ((AugmentedStmt) as.bsuccs.get(0)).get_Reachers().iterator(); 105 while (rit.hasNext()) { 106 SwitchNode pred = (SwitchNode) binding.get( rit.next()); 107 108 if (pred != null) { 109 if (preds.contains( pred) == false) 110 preds.add( pred); 111 112 if (pred.succs.contains( this) == false) 113 pred.succs.add( this); 114 } 115 } 116 } 117 118 119 122 123 public int compareTo( Object o) 124 { 125 if (o == this) 126 return 0; 127 128 if (indexSet.last() instanceof String ) 129 return 1; 130 131 if (o instanceof String ) 132 return -1; 133 134 if (o instanceof Integer ) 135 return ((Integer ) indexSet.last()).intValue() - ((Integer ) o).intValue(); 136 137 if (o instanceof TreeSet) { 138 TreeSet other = (TreeSet) o; 139 140 if (other.last() instanceof String ) 141 return -1; 142 143 return ((Integer ) indexSet.last()).intValue() - ((Integer ) other.last()).intValue(); 144 } 145 146 SwitchNode other = (SwitchNode) o; 147 148 if (other.indexSet.last() instanceof String ) 149 return -1; 150 151 return ((Integer ) indexSet.last()).intValue() - ((Integer ) other.indexSet.last()).intValue(); 152 } 153 } 154 155 | Popular Tags |