1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 package org.kit.furia.fragment.soot.representation.internal;
27
28 import soot.*;
29 import org.kit.furia.fragment.soot.representation.*;
30 import soot.jimple.internal.*;
31 import soot.util.*;
32 import java.util.*;
33
34 public class FNewInvokeExpr extends AbstractInvokeExpr
35 implements NewInvokeExpr, Precedence, Qable, SpecialConstructContainer
36 {
37
38
39
40 private static final long serialVersionUID = -8425141163557597423L;
41 RefType type;
42
43 public FNewInvokeExpr(RefType type, SootMethodRef methodRef, List args)
44 {
45 if( methodRef.isStatic() ) throw new RuntimeException("wrong static-ness");
46
47 this.methodRef = methodRef;
48 this.argBoxes = new FExprBox[args.size()];
49 this.type = type;
50
51 for(int i = 0; i < args.size(); i++)
52 this.argBoxes[i] = Frimp.v().newExprBox((Value) args.get(i));
53 }
54
55
56
57
58
59
60
61
62
63 public RefType getBaseType()
64 {
65 return type;
66 }
67
68 public void setBaseType(RefType type)
69 {
70 this.type = type;
71 }
72
73 public Type getType()
74 {
75 return type;
76 }
77
78 public int getPrecedence() { return 850; }
79
80 public String toString()
81 {
82 StringBuffer buffer = new StringBuffer();
83
84 buffer.append("new " + type.toString() + "(");
85
86 for(int i = 0; i < argBoxes.length; i++)
87 {
88 if(i != 0)
89 buffer.append(", ");
90
91 buffer.append(argBoxes[i].getValue().toString());
92 }
93
94 buffer.append(")");
95
96 return buffer.toString();
97 }
98
99 public void toString(UnitPrinter up)
100 {
101 up.literal("new");
102 up.literal(" ");
103 up.type(type);
104 up.literal("(");
105
106 for(int i = 0; i < argBoxes.length; i++)
107 {
108 if(i != 0)
109 up.literal(", ");
110
111 argBoxes[i].toString(up);
112 }
113
114 up.literal(")");
115 }
116
117
118 public List getUseBoxes()
119 {
120 List list = new ArrayList();
121
122 for(int i = 0; i < argBoxes.length; i++)
123 {
124 list.addAll(argBoxes[i].getValue().getUseBoxes());
125 list.add(argBoxes[i]);
126 }
127
128 return list;
129 }
130
131 public void apply(Switch sw)
132 {
133 ((FrimpValueSwitch) sw).caseNewInvokeExpr(this);
134 }
135
136 public Object clone()
137 {
138 ArrayList clonedArgs = new ArrayList(getArgCount());
139
140 for(int i = 0; i < getArgCount(); i++) {
141 clonedArgs.add(i, Frimp.cloneIfNecessary(getArg(i)));
142
143 }
144
145 return new FNewInvokeExpr(getBaseType(), methodRef, clonedArgs);
146 }
147 public boolean equivTo(Object o)
148 {
149 if (o instanceof FNewInvokeExpr)
150 {
151 FNewInvokeExpr ie = (FNewInvokeExpr)o;
152 if (!(getMethod().equals(ie.getMethod()) &&
153 argBoxes.length == ie.argBoxes.length))
154 return false;
155 for (int i = 0; i < argBoxes.length; i++)
156 if (!(argBoxes[i].getValue().equivTo(ie.argBoxes[i].getValue())))
157 return false;
158 if( !type.equals(ie.type) ) return false;
159 return true;
160 }
161 return false;
162 }
163
164
165 public int equivHashCode()
166 {
167 return getMethod().equivHashCode();
168 }
169
170 public String toQ() throws Exception {
171 StringBuffer buffer = new StringBuffer();
172
173 buffer.append(FuriaConstructDefinitions.FURIA_fnewInvoke + "(" + Frimp.toQ(type) + "," + Frimp.toQ(methodRef));
174
175 for(int i = 0; i < argBoxes.length; i++)
176 {
177
178 buffer.append(",");
179
180 buffer.append(Frimp.toQ(argBoxes[i].getValue()));
181 }
182
183 buffer.append(")");
184
185 return buffer.toString();
186 }
187
188 public List getContainedSpecialConstructs() {
189 List res = new LinkedList();
190 res.add(type);
191 res.add(methodRef);
192 return res;
193 }
194
195 }