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  
27  
28  
29  
30  
31  
32  package org.kit.furia.fragment.soot.representation.internal;
33  
34  import soot.*;
35  import org.kit.furia.fragment.soot.representation.*;
36  import soot.jimple.internal.*;
37  import java.util.*;
38  
39  public class FVirtualInvokeExpr extends AbstractVirtualInvokeExpr
40      implements Precedence, Qable, SpecialConstructContainer
41  {
42      /**
43  	 * 
44  	 */
45  	private static final long serialVersionUID = -6455352440041113825L;
46  
47  	public FVirtualInvokeExpr(Value base, SootMethodRef methodRef, List args)
48      {
49          super(Frimp.v().newObjExprBox(base), methodRef,
50                new ValueBox[args.size()]);
51  
52          for(int i = 0; i < args.size(); i++)
53              this.argBoxes[i] = Frimp.v().newExprBox((Value) args.get(i));
54      }
55  
56  
57      public int getPrecedence() { return 950; }
58  
59      private String toString(Value op, String opString, String rightString)
60      {
61          String leftOp = opString;
62  
63          if (getBase() instanceof Precedence && 
64              ((Precedence)getBase()).getPrecedence() < getPrecedence()) 
65              leftOp = "(" + leftOp + ")";
66          return leftOp + rightString;
67      }
68  
69      public String toString()
70      {
71          StringBuffer buffer = new StringBuffer();
72  
73          buffer.append("." + methodRef.getSignature() + "(");
74  
75          for(int i = 0; i < argBoxes.length; i++)
76          {
77              if(i != 0)
78                  buffer.append(", ");
79  
80              buffer.append(argBoxes[i].getValue().toString());
81          }
82  
83          buffer.append(")");
84  
85          return toString(getBase(), getBase().toString(), 
86                          buffer.toString());
87      }
88  
89      public void toString(UnitPrinter up)
90      {
91          if( PrecedenceTest.needsBrackets( baseBox, this ) ) up.literal("(");
92          baseBox.toString(up);
93          if( PrecedenceTest.needsBrackets( baseBox, this ) ) up.literal(")");
94          up.literal(".");
95          up.methodRef(methodRef);
96          up.literal("(");
97  
98          for(int i = 0; i < argBoxes.length; i++)
99          {
100             if(i != 0)
101                 up.literal(", ");
102 
103             argBoxes[i].toString(up);
104         }
105 
106         up.literal(")");
107     }
108 
109     
110     public Object clone()  // NOPMD by amuller on 11/16/06 4:22 PM
111     {
112         ArrayList clonedArgs = new ArrayList(getArgCount());
113 
114         for(int i = 0; i < getArgCount(); i++) {
115             clonedArgs.add(i, Frimp.cloneIfNecessary(getArg(i)));
116         }
117         
118         return new  FVirtualInvokeExpr(Frimp.cloneIfNecessary(getBase()), methodRef, 
119             clonedArgs);
120     }
121     
122     public String toQ() throws Exception {
123 		
124 		StringBuffer buffer = new StringBuffer();
125 
126         buffer.append(FuriaConstructDefinitions.FURIA_fvirtualInvokeExpr + "(" + Frimp.toQ(methodRef ));
127 
128         for(int i = 0; i < argBoxes.length; i++)
129         {
130             
131             buffer.append(",");
132 
133             buffer.append(Frimp.toQ(argBoxes[i].getValue()));
134         }
135 
136         buffer.append(")");
137 
138         return buffer.toString(); 
139 
140 	}
141     
142     public List getContainedSpecialConstructs() {
143 		List res = new LinkedList();
144 		res.add(methodRef);
145 		return res;
146 	}
147 
148 }
149