1 20 21 26 27 28 package soot.jimple.internal; 29 30 import soot.*; 31 import soot.jimple.*; 32 import soot.baf.*; 33 import soot.jimple.*; 34 import soot.util.*; 35 import java.util.*; 36 37 38 import soot.tagkit.*; 39 40 public abstract class AbstractInterfaceInvokeExpr extends AbstractInstanceInvokeExpr 41 implements InterfaceInvokeExpr, ConvertToBaf 42 { 43 protected AbstractInterfaceInvokeExpr(ValueBox baseBox, SootMethodRef methodRef, 44 ValueBox[] argBoxes) 45 { 46 if( methodRef.isStatic() ) throw new RuntimeException ("wrong static-ness"); 47 this.baseBox = baseBox; this.methodRef = methodRef; 48 this.argBoxes = argBoxes; 49 } 50 51 public boolean equivTo(Object o) 52 { 53 if (o instanceof AbstractInterfaceInvokeExpr) 54 { 55 AbstractInterfaceInvokeExpr ie = (AbstractInterfaceInvokeExpr)o; 56 if (!(baseBox.getValue().equivTo(ie.baseBox.getValue()) && 57 getMethod().equals(ie.getMethod()) && 58 argBoxes.length == ie.argBoxes.length)) 59 return false; 60 for (int i = 0; i < argBoxes.length; i++) 61 if (!(argBoxes[i].getValue().equivTo(ie.argBoxes[i].getValue()))) 62 return false; 63 return true; 64 } 65 return false; 66 } 67 68 69 public int equivHashCode() 70 { 71 return baseBox.getValue().equivHashCode() * 101 + getMethod().equivHashCode() * 17; 72 } 73 74 public abstract Object clone(); 75 76 public String toString() 77 { 78 StringBuffer buffer = new StringBuffer (); 79 80 buffer.append(Jimple.INTERFACEINVOKE + " " + baseBox.getValue().toString() + 81 "." + methodRef.getSignature() + "("); 82 83 for(int i = 0; i < argBoxes.length; i++) 84 { 85 if(i != 0) 86 buffer.append(", "); 87 88 buffer.append(argBoxes[i].getValue().toString()); 89 } 90 91 buffer.append(")"); 92 93 return buffer.toString(); 94 } 95 96 public void toString(UnitPrinter up) 97 { 98 up.literal(Jimple.INTERFACEINVOKE); 99 up.literal(" "); 100 baseBox.toString(up); 101 up.literal("."); 102 up.methodRef(methodRef); 103 up.literal("("); 104 105 for(int i = 0; i < argBoxes.length; i++) 106 { 107 if(i != 0) 108 up.literal(", "); 109 110 argBoxes[i].toString(up); 111 } 112 113 up.literal(")"); 114 } 115 116 117 public void apply(Switch sw) 118 { 119 ((ExprSwitch) sw).caseInterfaceInvokeExpr(this); 120 } 121 122 private static int sizeOfType(Type t) 123 { 124 if(t instanceof DoubleType || t instanceof LongType) 125 return 2; 126 else if(t instanceof VoidType) 127 return 0; 128 else 129 return 1; 130 } 131 132 private static int argCountOf(SootMethodRef m) 133 { 134 int argCount = 0; 135 Iterator typeIt = m.parameterTypes().iterator(); 136 137 while(typeIt.hasNext()) 138 { 139 Type t = (Type) typeIt.next(); 140 141 argCount += sizeOfType(t); 142 } 143 144 return argCount; 145 } 146 147 public void convertToBaf(JimpleToBafContext context, List out) 148 { 149 ((ConvertToBaf)getBase()).convertToBaf(context, out);; 150 151 for(int i = 0; i < argBoxes.length; i++) 152 { 153 ((ConvertToBaf)(argBoxes[i].getValue())).convertToBaf(context, out); 154 } 155 156 Unit u; 157 out.add(u = Baf.v().newInterfaceInvokeInst(methodRef, argCountOf(methodRef))); 158 159 Unit currentUnit = context.getCurrentUnit(); 160 161 Iterator it = currentUnit.getTags().iterator(); 162 while(it.hasNext()) { 163 u.addTag((Tag) it.next()); 164 } 165 166 } 167 } 168 169 | Popular Tags |