KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > grimp > internal > GNewInvokeExpr


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 1999 Patrick Lam
3  * Copyright (C) 2004 Ondrej Lhotak
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */

20
21 /*
22  * Modified by the Sable Research Group and others 1997-1999.
23  * See the 'credits' file distributed with Soot for the complete list of
24  * contributors. (Soot is distributed at http://www.sable.mcgill.ca/soot)
25  */

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 JavaDoc("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     /*
61     protected GNewInvokeExpr(RefType type, ExprBox[] argBoxes)
62     {
63         this.type = type;
64         this.argBoxes = argBoxes;
65     }
66     */

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 JavaDoc toString()
86     {
87         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
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 JavaDoc 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 JavaDoc 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     /** Returns a hash code for this object, consistent with structural equality. */
170     public int equivHashCode()
171     {
172         return getMethod().equivHashCode();
173     }
174 }
175
Popular Tags