1 19 20 package soot.jimple.toolkits.callgraph; 21 import soot.*; 22 import soot.jimple.*; 23 24 27 public final class Edge 28 { 29 32 private MethodOrMethodContext src; 33 public SootMethod src() { 34 if( src == null ) return null; else return src.method(); 35 } 36 public Context srcCtxt() { 37 if( src == null ) return null; else return src.context(); 38 } 39 public MethodOrMethodContext getSrc() { return src; } 40 41 44 private Unit srcUnit; 45 public Unit srcUnit() { return srcUnit; } 46 public Stmt srcStmt() { return (Stmt) srcUnit; } 47 48 49 private MethodOrMethodContext tgt; 50 public SootMethod tgt() { return tgt.method(); } 51 public Context tgtCtxt() { return tgt.context(); } 52 public MethodOrMethodContext getTgt() { return tgt; } 53 54 57 private Kind kind; 58 public Kind kind() { return kind; } 59 60 public Edge( MethodOrMethodContext src, Unit srcUnit, MethodOrMethodContext tgt, Kind kind ) { 61 this.src = src; 62 this.srcUnit = srcUnit; 63 this.tgt = tgt; 64 this.kind = kind; 65 } 66 67 public Edge( MethodOrMethodContext src, Stmt srcUnit, MethodOrMethodContext tgt ) { 68 this.kind = ieToKind( srcUnit.getInvokeExpr() ); 69 this.src = src; 70 this.srcUnit = srcUnit; 71 this.tgt = tgt; 72 } 73 74 public static Kind ieToKind( InvokeExpr ie ) { 75 if( ie instanceof VirtualInvokeExpr ) return Kind.VIRTUAL; 76 else if( ie instanceof SpecialInvokeExpr ) return Kind.SPECIAL; 77 else if( ie instanceof InterfaceInvokeExpr ) return Kind.INTERFACE; 78 else if( ie instanceof StaticInvokeExpr ) return Kind.STATIC; 79 else throw new RuntimeException (); 80 } 81 82 83 public boolean isExplicit() { 84 return kind.isExplicit(); 85 } 86 87 88 90 public boolean isInstance() { 91 return kind.isInstance(); 92 } 93 94 95 public boolean isClinit() { 96 return kind.isClinit(); 97 } 98 100 public boolean isStatic() { 101 return kind.isStatic(); 102 } 103 104 public boolean passesParameters() { 105 return kind.passesParameters(); 106 } 107 108 public int hashCode() { 109 int ret = tgt.hashCode() + kind.getNumber(); 110 if( src != null ) ret += src.hashCode(); 111 if( srcUnit != null ) ret += srcUnit.hashCode(); 112 return ret; 113 } 114 public boolean equals( Object other ) { 115 Edge o = (Edge) other; 116 if( o.src != src ) return false; 117 if( o.srcUnit != srcUnit ) return false; 118 if( o.tgt != tgt ) return false; 119 if( o.kind != kind ) return false; 120 return true; 121 } 122 123 public String toString() { 124 return kind.toString()+" edge: "+srcUnit+" in "+src+" ==> "+tgt; 125 } 126 127 private Edge nextByUnit = this; 128 private Edge prevByUnit = this; 129 private Edge nextBySrc = this; 130 private Edge prevBySrc = this; 131 private Edge nextByTgt = this; 132 private Edge prevByTgt = this; 133 void insertAfterByUnit( Edge other ) { 134 nextByUnit = other.nextByUnit; 135 nextByUnit.prevByUnit = this; 136 other.nextByUnit = this; 137 prevByUnit = other; 138 } 139 void insertAfterBySrc( Edge other ) { 140 nextBySrc = other.nextBySrc; 141 nextBySrc.prevBySrc = this; 142 other.nextBySrc = this; 143 prevBySrc = other; 144 } 145 void insertAfterByTgt( Edge other ) { 146 nextByTgt = other.nextByTgt; 147 nextByTgt.prevByTgt = this; 148 other.nextByTgt = this; 149 prevByTgt = other; 150 } 151 void insertBeforeByUnit( Edge other ) { 152 prevByUnit = other.prevByUnit; 153 prevByUnit.nextByUnit = this; 154 other.prevByUnit = this; 155 nextByUnit = other; 156 } 157 void insertBeforeBySrc( Edge other ) { 158 prevBySrc = other.prevBySrc; 159 prevBySrc.nextBySrc = this; 160 other.prevBySrc = this; 161 nextBySrc = other; 162 } 163 void insertBeforeByTgt( Edge other ) { 164 prevByTgt = other.prevByTgt; 165 prevByTgt.nextByTgt = this; 166 other.prevByTgt = this; 167 nextByTgt = other; 168 } 169 void remove() { 170 nextByUnit.prevByUnit = prevByUnit; 171 prevByUnit.nextByUnit = nextByUnit; 172 nextBySrc.prevBySrc = prevBySrc; 173 prevBySrc.nextBySrc = nextBySrc; 174 nextByTgt.prevByTgt = prevByTgt; 175 prevByTgt.nextByTgt = nextByTgt; 176 } 177 Edge nextByUnit() { 178 return nextByUnit; 179 } 180 Edge nextBySrc() { 181 return nextBySrc; 182 } 183 Edge nextByTgt() { 184 return nextByTgt; 185 } 186 Edge prevByUnit() { 187 return prevByUnit; 188 } 189 Edge prevBySrc() { 190 return prevBySrc; 191 } 192 Edge prevByTgt() { 193 return prevByTgt; 194 } 195 } 196 197 198 | Popular Tags |