View Javadoc

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  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"); // NOPMD by amuller on 11/16/06 4:13 PM
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      protected GNewInvokeExpr(RefType type, ExprBox[] argBoxes)
57      {
58          this.type = type;
59          this.argBoxes = argBoxes;
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()  // NOPMD by amuller on 11/16/06 4:13 PM
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     /** Returns a hash code for this object, consistent with structural equality. */
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 }