KickJava   Java API By Example, From Geeks To Geeks.

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


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.tagkit.*;
32 import soot.jimple.*;
33 import soot.baf.*;
34 import soot.util.*;
35 import java.util.*;
36
37 import soot.tagkit.*;
38
39
40 public abstract class AbstractStaticInvokeExpr extends AbstractInvokeExpr implements StaticInvokeExpr, ConvertToBaf
41 {
42     AbstractStaticInvokeExpr(SootMethodRef methodRef, List args)
43     {
44         this(methodRef, new ValueBox[args.size()]);
45
46         for(int i = 0; i < args.size(); i++)
47             this.argBoxes[i] = Jimple.v().newImmediateBox((Value) args.get(i));
48     }
49
50     public boolean equivTo(Object JavaDoc o)
51     {
52         if (o instanceof AbstractStaticInvokeExpr)
53         {
54             AbstractStaticInvokeExpr ie = (AbstractStaticInvokeExpr)o;
55             if (!(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 getMethod().equivHashCode();
70     }
71
72     public abstract Object JavaDoc clone();
73     
74     protected AbstractStaticInvokeExpr(SootMethodRef methodRef, ValueBox[] argBoxes)
75     {
76         if( !methodRef.isStatic() ) throw new RuntimeException JavaDoc("wrong static-ness");
77         this.methodRef = methodRef; this.argBoxes = argBoxes;
78     }
79
80     public String JavaDoc toString()
81     {
82         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
83
84         buffer.append(Jimple.v().STATICINVOKE + " " + 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.v().STATICINVOKE);
102         up.literal(" ");
103         up.methodRef(methodRef);
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     public List getUseBoxes()
118     {
119         List list = new ArrayList();
120
121         for(int i = 0; i < argBoxes.length; i++)
122         {
123             list.addAll(argBoxes[i].getValue().getUseBoxes());
124             list.add(argBoxes[i]);
125         }
126
127         return list;
128     }
129
130     public void apply(Switch sw)
131     {
132         ((ExprSwitch) sw).caseStaticInvokeExpr(this);
133     }
134
135     public void convertToBaf(JimpleToBafContext context, List out)
136     {
137        for(int i = 0; i < argBoxes.length; i++)
138         {
139             ((ConvertToBaf)(argBoxes[i].getValue())).convertToBaf(context, out);
140         }
141        
142        Unit u;
143        out.add(u = Baf.v().newStaticInvokeInst(methodRef));
144
145        Unit currentUnit = context.getCurrentUnit();
146
147     Iterator it = currentUnit.getTags().iterator();
148     while(it.hasNext()) {
149         u.addTag((Tag) it.next());
150     }
151     }
152 }
153
Popular Tags