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