1 19 20 25 26 27 28 29 30 31 32 package soot.coffi; 33 34 import java.io.*; 35 import soot.*; 36 37 class TypeArray 38 { 39 private Type[] types; 40 41 private TypeArray() 42 { 43 } 44 45 49 50 public static TypeArray v(int size) 51 { 52 TypeArray newArray = new TypeArray(); 53 54 newArray.types = new Type[size]; 55 56 for(int i = 0; i < size; i++) 57 newArray.types[i] = UnusuableType.v(); 58 59 return newArray; 60 } 61 62 public Type get(int index) 63 { 64 return types[index]; 65 } 66 67 public TypeArray set(int index, Type type) 68 { 69 TypeArray newArray = new TypeArray(); 70 71 newArray.types = (Type[]) types.clone(); 72 newArray.types[index] = type; 73 74 return newArray; 75 } 76 77 public boolean equals(Object obj) 78 { 79 if(obj instanceof TypeArray) 80 { 81 TypeArray other = (TypeArray) obj; 82 83 if(types.length != other.types.length) 84 return false; 85 86 for(int i = 0; i < types.length; i++) 87 if(!types[i].equals(other.types[i])) 88 return false; 89 90 return true; 91 } 92 else 93 return false; 94 } 95 96 public TypeArray merge(TypeArray otherArray) 97 { 98 TypeArray newArray = new TypeArray(); 99 100 if(types.length != otherArray.types.length) 101 throw new RuntimeException ("Merging of type arrays failed; unequal array length"); 102 103 newArray.types = new Type[types.length]; 104 105 for(int i = 0; i < types.length; i++) 106 { 107 if(types[i].equals(otherArray.types[i])) 108 newArray.types[i] = types[i]; 109 else if((types[i] instanceof ArrayType || 110 types[i] instanceof RefType) && 111 (otherArray.types[i] instanceof ArrayType 112 || otherArray.types[i] instanceof RefType)) 113 { 114 116 newArray.types[i] = RefType.v("java.lang.Object"); 117 } 118 else { 119 newArray.types[i] = UnusuableType.v(); 120 } 121 } 122 return newArray; 123 } 124 125 public void print(PrintStream out) 126 { 127 for(int i = 0; i < types.length; i++) 128 out.println(i + ": " + types[i].toString()); 129 } 130 } 131 132 133 | Popular Tags |