1 19 20 25 26 27 package soot.jimple.toolkits.typing.integer; 28 29 import soot.*; 30 import soot.jimple.*; 31 import soot.util.*; 32 import java.util.*; 33 34 39 public class ClassHierarchy 40 { 41 public ClassHierarchy( Singletons.Global g ) 42 { 43 typeNodeMap.put(BooleanType.v(), BOOLEAN); 44 typeNodeMap.put(ByteType.v(), BYTE); 45 typeNodeMap.put(ShortType.v(), SHORT); 46 typeNodeMap.put(CharType.v(), CHAR); 47 typeNodeMap.put(IntType.v(), INT); 48 } 49 50 public static ClassHierarchy v() { return G.v().soot_jimple_toolkits_typing_integer_ClassHierarchy(); } 51 public final TypeNode BOOLEAN = new TypeNode(0, BooleanType.v()); 52 public final TypeNode BYTE = new TypeNode(1, ByteType.v()); 53 public final TypeNode SHORT = new TypeNode(2, ShortType.v()); 54 public final TypeNode CHAR = new TypeNode(3, CharType.v()); 55 public final TypeNode INT = new TypeNode(4, IntType.v()); 56 public final TypeNode TOP = new TypeNode(5, null); 57 public final TypeNode R0_1 = new TypeNode(6, null); 58 public final TypeNode R0_127 = new TypeNode(7, null); 59 public final TypeNode R0_32767 = new TypeNode(8, null); 60 61 private final TypeNode[] typeNodes = 62 { 63 BOOLEAN, BYTE, SHORT, CHAR, INT, TOP, R0_1, R0_127, R0_32767, 64 }; 65 66 private final boolean[][] ancestors_1 = 67 { 68 { false, false, false, false, false, true, false, false, false, }, 69 { false, false, true, false, true, true, false, false, false, }, 70 { false, false, false, false, true, true, false, false, false, }, 71 { false, false, false, false, true, true, false, false, false, }, 72 { false, false, false, false, false, true, false, false, false, }, 73 { false, false, false, false, false, false, false, false, false, }, 74 { true, true, true, true, true, true, false, true, true, }, 75 { false, true, true, true, true, true, false, false, true, }, 76 { false, false, true, true, true, true, false, false, false, }, 77 }; 78 79 private final boolean[][] ancestors_2 = 80 { 81 { false, true, true, true, true, false, false, true, true, }, 82 { false, false, true, false, true, false, false, false, false, }, 83 { false, false, false, false, true, false, false, false, false, }, 84 { false, false, false, false, true, false, false, false, false, }, 85 { false, false, false, false, false, false, false, false, false, }, 86 { }, 87 { }, 88 { false, true, true, true, true, false, false, false, true, }, 89 { false, false, true, true, true, false, false, false, false, }, 90 }; 91 92 private final boolean[][] descendants_1 = 93 { 94 { false, false, false, false, false, false, true, false, false, }, 95 { false, false, false, false, false, false, true, true, false, }, 96 { false, true, false, false, false, false, true, true, true, }, 97 { false, false, false, false, false, false, true, true, true, }, 98 { false, true, true, true, false, false, true, true, true, }, 99 { true, true, true, true, true, false, true, true, true, }, 100 { false, false, false, false, false, false, false, false, false, }, 101 { false, false, false, false, false, false, true, false, false, }, 102 { false, false, false, false, false, false, true, true, false, }, 103 }; 104 105 private final boolean[][] descendants_2 = 106 { 107 { false, false, false, false, false, false, false, false, false, }, 108 { true, false, false, false, false, false, false, true, false, }, 109 { true, true, false, false, false, false, false, true, true, }, 110 { true, false, false, false, false, false, false, true, true, }, 111 { true, true, true, true, false, false, false, true, true, }, 112 { }, 113 { }, 114 { true, false, false, false, false, false, false, false, false, }, 115 { true, false, false, false, false, false, false, true, false, }, 116 }; 117 118 private final TypeNode[][] lca_1 = 119 { 120 { BOOLEAN, TOP, TOP, TOP, TOP, TOP, BOOLEAN, TOP, TOP, }, 121 { TOP, BYTE, SHORT, INT, INT, TOP, BYTE, BYTE, SHORT, }, 122 { TOP, SHORT, SHORT, INT, INT, TOP, SHORT, SHORT, SHORT, }, 123 { TOP, INT, INT, CHAR, INT, TOP, CHAR, CHAR, CHAR, }, 124 { TOP, INT, INT, INT, INT, TOP, INT, INT, INT, }, 125 { TOP, TOP, TOP, TOP, TOP, TOP, TOP, TOP, TOP, }, 126 { BOOLEAN, BYTE, SHORT, CHAR, INT, TOP, R0_1, R0_127, R0_32767, }, 127 { TOP, BYTE, SHORT, CHAR, INT, TOP, R0_127, R0_127, R0_32767, }, 128 { TOP, SHORT, SHORT, CHAR, INT, TOP, R0_32767, R0_32767, R0_32767, }, 129 }; 130 131 private final TypeNode[][] lca_2 = 132 { 133 { BOOLEAN, BYTE, SHORT, CHAR, INT, null, null, R0_127, R0_32767, }, 134 { BYTE, BYTE, SHORT, INT, INT, null, null, BYTE, SHORT, }, 135 { SHORT, SHORT, SHORT, INT, INT, null, null, SHORT, SHORT, }, 136 { CHAR, INT, INT, CHAR, INT, null, null, CHAR, CHAR, }, 137 { INT, INT, INT, INT, INT, null, null, INT, INT, }, 138 { }, 139 { }, 140 { R0_127, BYTE, SHORT, CHAR, INT, null, null, R0_127, R0_32767, }, 141 { R0_32767, SHORT, SHORT, CHAR, INT, null, null, R0_32767, R0_32767, }, 142 }; 143 144 private final TypeNode[][] gcd_1 = 145 { 146 { BOOLEAN, R0_1, R0_1, R0_1, R0_1, BOOLEAN, R0_1, R0_1, R0_1, }, 147 { R0_1, BYTE, BYTE, R0_127, BYTE, BYTE, R0_1, R0_127, R0_127, }, 148 { R0_1, BYTE, SHORT, R0_32767, SHORT, SHORT, R0_1, R0_127, R0_32767, }, 149 { R0_1, R0_127, R0_32767, CHAR, CHAR, CHAR, R0_1, R0_127, R0_32767, }, 150 { R0_1, BYTE, SHORT, CHAR, INT, INT, R0_1, R0_127, R0_32767, }, 151 { BOOLEAN, BYTE, SHORT, CHAR, INT, TOP, R0_1, R0_127, R0_32767, }, 152 { R0_1, R0_1, R0_1, R0_1, R0_1, R0_1, R0_1, R0_1, R0_1, }, 153 { R0_1, R0_127, R0_127, R0_127, R0_127, R0_127, R0_1, R0_127, R0_127, }, 154 { R0_1, R0_127, R0_32767, R0_32767, R0_32767, R0_32767, R0_1, R0_127, R0_32767, }, 155 }; 156 157 private final TypeNode[][] gcd_2 = 158 { 159 { BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, null, null, BOOLEAN, BOOLEAN, }, 160 { BOOLEAN, BYTE, BYTE, R0_127, BYTE, null, null, R0_127, R0_127, }, 161 { BOOLEAN, BYTE, SHORT, R0_32767, SHORT, null, null, R0_127, R0_32767, }, 162 { BOOLEAN, R0_127, R0_32767, CHAR, CHAR, null, null, R0_127, R0_32767, }, 163 { BOOLEAN, BYTE, SHORT, CHAR, INT, null, null, R0_127, R0_32767, }, 164 { }, 165 { }, 166 { BOOLEAN, R0_127, R0_127, R0_127, R0_127, null, null, R0_127, R0_127, }, 167 { BOOLEAN, R0_127, R0_32767, R0_32767, R0_32767, null, null, R0_127, R0_32767, }, 168 }; 169 170 171 private final HashMap typeNodeMap = new HashMap(); 172 173 174 public TypeNode typeNode(Type type) 175 { 176 if(type == null || !(type instanceof PrimType || type instanceof RefType)) 177 { 178 throw new InternalTypingException(); 179 } 180 181 TypeNode typeNode = (TypeNode) typeNodeMap.get(type); 182 183 if(typeNode == null) 184 { 185 throw new InternalTypingException(); 186 } 187 188 return typeNode; 189 } 190 191 public boolean hasAncestor_1(int t1, int t2) 192 { 193 return ancestors_1[t1][t2]; 194 } 195 196 public boolean hasAncestor_2(int t1, int t2) 197 { 198 return ancestors_2[t1][t2]; 199 } 200 201 public boolean hasDescendant_1(int t1, int t2) 202 { 203 return descendants_1[t1][t2]; 204 } 205 206 public boolean hasDescendant_2(int t1, int t2) 207 { 208 return descendants_2[t1][t2]; 209 } 210 211 public TypeNode lca_1(int t1, int t2) 212 { 213 return lca_1[t1][t2]; 214 } 215 216 private int convert(int n) 217 { 218 switch(n) 219 { 220 case 5: return 4; 221 case 6: return 0; 222 default: return n; 223 } 224 } 225 226 public TypeNode lca_2(int t1, int t2) 227 { 228 return lca_2[convert(t1)][convert(t2)]; 229 } 230 231 public TypeNode gcd_1(int t1, int t2) 232 { 233 return gcd_1[t1][t2]; 234 } 235 236 public TypeNode gcd_2(int t1, int t2) 237 { 238 return gcd_2[convert(t1)][convert(t2)]; 239 } 240 } 241 | Popular Tags |