KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > jimple > ParameterRef


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 1997-1999 Raja Vallee-Rai
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */

19
20 /*
21  * Modified by the Sable Research Group and others 1997-1999.
22  * See the 'credits' file distributed with Soot for the complete list of
23  * contributors. (Soot is distributed at http://www.sable.mcgill.ca/soot)
24  */

25
26
27
28
29
30 package soot.jimple;
31
32 import soot.*;
33 import soot.util.*;
34 import java.util.*;
35
36 /** <code>ParameterRef</code> objects are used by <code>Body</code>
37  * objects to refer to the parameter slots on method entry. <br>
38  *
39  * For instance, in an instance method, the first statement will
40  * often be <code> this := @parameter0; </code> */

41 public class ParameterRef implements IdentityRef
42 {
43     int n;
44     Type paramType;
45
46     /** Constructs a ParameterRef object of the specified type, representing the specified parameter number. */
47     public ParameterRef(Type paramType, int number)
48     {
49         this.n = number;
50         this.paramType = paramType;
51     }
52
53     public boolean equivTo(Object JavaDoc o)
54     {
55         if (o instanceof ParameterRef)
56         {
57             return n == ((ParameterRef)o).n &&
58                 paramType.equals(((ParameterRef)o).paramType);
59         }
60         return false;
61     }
62
63     public int equivHashCode()
64     {
65         return n * 101 + paramType.hashCode() * 17;
66     }
67     
68     /** Create a new ParameterRef object with the same paramType and number. */
69     public Object JavaDoc clone()
70     {
71         return new ParameterRef(paramType, n);
72     }
73     
74     /** Converts the given ParameterRef into a String i.e. <code>@parameter0: .int</code>. */
75     public String JavaDoc toString()
76     {
77         return "@parameter" + n + ": " + paramType;
78     }
79     
80     public void toString( UnitPrinter up )
81     {
82         up.identityRef(this);
83     }
84
85     /** Returns the index of this ParameterRef. */
86     public int getIndex()
87     {
88         return n;
89     }
90
91     /** Sets the index of this ParameterRef. */
92     public void setIndex(int index)
93     {
94         n = index;
95     }
96
97     public List getUseBoxes()
98     {
99         return AbstractUnit.emptyList;
100     }
101
102     /** Returns the type of this ParameterRef. */
103     public Type getType()
104     {
105         return paramType;
106     }
107
108     /** Used with RefSwitch. */
109     public void apply(Switch sw)
110     {
111         ((RefSwitch) sw).caseParameterRef(this);
112     }
113 }
114
Popular Tags