KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > jimple > internal > AbstractVirtualInvokeExpr


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 package soot.jimple.internal;
29
30 import soot.*;
31 import soot.jimple.*;
32 import soot.baf.*;
33 import soot.util.*;
34 import java.util.*;
35
36 import soot.tagkit.*;
37
38 public abstract class AbstractVirtualInvokeExpr extends AbstractInstanceInvokeExpr
39   implements VirtualInvokeExpr, ConvertToBaf
40 {
41     protected AbstractVirtualInvokeExpr(ValueBox baseBox, SootMethodRef methodRef,
42                                 ValueBox[] argBoxes)
43     {
44         if( methodRef.isStatic() ) throw new RuntimeException JavaDoc("wrong static-ness");
45         this.baseBox = baseBox; this.methodRef = methodRef;
46         this.argBoxes = argBoxes;
47     }
48
49     public boolean equivTo(Object JavaDoc o)
50     {
51         if (o instanceof AbstractVirtualInvokeExpr)
52         {
53             AbstractVirtualInvokeExpr ie = (AbstractVirtualInvokeExpr)o;
54             if (!(baseBox.getValue().equivTo(ie.baseBox.getValue()) &&
55                     getMethod().equals(ie.getMethod()) &&
56                     argBoxes.length == ie.argBoxes.length))
57                 return false;
58             for (int i = 0; i < argBoxes.length; i++)
59                 if (!(argBoxes[i].getValue().equivTo(ie.argBoxes[i].getValue())))
60                     return false;
61             return true;
62         }
63         return false;
64     }
65
66     /** Returns a hash code for this object, consistent with structural equality. */
67     public int equivHashCode()
68     {
69         return baseBox.getValue().equivHashCode() * 101 + getMethod().equivHashCode() * 17;
70     }
71
72     public abstract Object JavaDoc clone();
73
74     public void apply(Switch sw)
75     {
76         ((ExprSwitch) sw).caseVirtualInvokeExpr(this);
77     }
78     
79     public String JavaDoc toString()
80     {
81         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
82
83         buffer.append(Jimple.VIRTUALINVOKE + " " + baseBox.getValue().toString() +
84             "." + methodRef.getSignature() + "(");
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(Jimple.VIRTUALINVOKE);
102         up.literal(" ");
103         baseBox.toString(up);
104         up.literal(".");
105         up.methodRef(methodRef);
106         up.literal("(");
107         
108         for(int i = 0; i < argBoxes.length; i++)
109         {
110             if(i != 0)
111                 up.literal(", ");
112                                         
113             argBoxes[i].toString(up);
114         }
115
116         up.literal(")");
117     }
118
119     public void convertToBaf(JimpleToBafContext context, List out)
120     {
121        ((ConvertToBaf)(getBase())).convertToBaf(context, out);
122
123        for(int i = 0; i < argBoxes.length; i++)
124         {
125             ((ConvertToBaf)(argBoxes[i].getValue())).convertToBaf(context, out);
126         }
127
128        Unit u;
129        out.add(u = Baf.v().newVirtualInvokeInst(methodRef));
130
131        Unit currentUnit = context.getCurrentUnit();
132
133     Iterator it = currentUnit.getTags().iterator();
134     while(it.hasNext()) {
135         u.addTag((Tag) it.next());
136     }
137
138     }
139 }
140
Popular Tags