1 20 21 26 27 28 29 30 31 32 package soot.grimp.internal; 33 34 import soot.*; 35 import soot.grimp.*; 36 import soot.jimple.internal.*; 37 import soot.jimple.*; 38 import soot.grimp.*; 39 import soot.jimple.internal.*; 40 import soot.util.*; 41 import java.util.*; 42 43 public class GNewInvokeExpr extends AbstractInvokeExpr 44 implements NewInvokeExpr, Precedence 45 { 46 RefType type; 47 48 public GNewInvokeExpr(RefType type, SootMethodRef methodRef, List args) 49 { 50 if( methodRef.isStatic() ) throw new RuntimeException ("wrong static-ness"); 51 52 this.methodRef = methodRef; 53 this.argBoxes = new ExprBox[args.size()]; 54 this.type = type; 55 56 for(int i = 0; i < args.size(); i++) 57 this.argBoxes[i] = Grimp.v().newExprBox((Value) args.get(i)); 58 } 59 60 67 68 public RefType getBaseType() 69 { 70 return type; 71 } 72 73 public void setBaseType(RefType type) 74 { 75 this.type = type; 76 } 77 78 public Type getType() 79 { 80 return type; 81 } 82 83 public int getPrecedence() { return 850; } 84 85 public String toString() 86 { 87 StringBuffer buffer = new StringBuffer (); 88 89 buffer.append("new " + type.toString() + "("); 90 91 for(int i = 0; i < argBoxes.length; i++) 92 { 93 if(i != 0) 94 buffer.append(", "); 95 96 buffer.append(argBoxes[i].getValue().toString()); 97 } 98 99 buffer.append(")"); 100 101 return buffer.toString(); 102 } 103 104 public void toString(UnitPrinter up) 105 { 106 up.literal("new"); 107 up.literal(" "); 108 up.type(type); 109 up.literal("("); 110 111 for(int i = 0; i < argBoxes.length; i++) 112 { 113 if(i != 0) 114 up.literal(", "); 115 116 argBoxes[i].toString(up); 117 } 118 119 up.literal(")"); 120 } 121 122 123 public List getUseBoxes() 124 { 125 List list = new ArrayList(); 126 127 for(int i = 0; i < argBoxes.length; i++) 128 { 129 list.addAll(argBoxes[i].getValue().getUseBoxes()); 130 list.add(argBoxes[i]); 131 } 132 133 return list; 134 } 135 136 public void apply(Switch sw) 137 { 138 ((GrimpValueSwitch) sw).caseNewInvokeExpr(this); 139 } 140 141 public Object clone() 142 { 143 ArrayList clonedArgs = new ArrayList(getArgCount()); 144 145 for(int i = 0; i < getArgCount(); i++) { 146 clonedArgs.add(i, Grimp.cloneIfNecessary(getArg(i))); 147 148 } 149 150 return new GNewInvokeExpr(getBaseType(), methodRef, clonedArgs); 151 } 152 public boolean equivTo(Object o) 153 { 154 if (o instanceof GNewInvokeExpr) 155 { 156 GNewInvokeExpr ie = (GNewInvokeExpr)o; 157 if (!(getMethod().equals(ie.getMethod()) && 158 argBoxes.length == ie.argBoxes.length)) 159 return false; 160 for (int i = 0; i < argBoxes.length; i++) 161 if (!(argBoxes[i].getValue().equivTo(ie.argBoxes[i].getValue()))) 162 return false; 163 if( !type.equals(ie.type) ) return false; 164 return true; 165 } 166 return false; 167 } 168 169 170 public int equivHashCode() 171 { 172 return getMethod().equivHashCode(); 173 } 174 } 175 | Popular Tags |