KickJava   Java API By Example, From Geeks To Geeks.

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


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