01: /* Soot - a J*va Optimization Framework
02: * Copyright (C) 1997-1999 Raja Vallee-Rai
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or (at your option) any later version.
08: *
09: * 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: package soot.jimple;
27:
28: import soot.*;
29: import soot.util.*;
30: import java.util.*;
31:
32: /** <code>ParameterRef</code> objects are used by <code>Body</code>
33: * objects to refer to the parameter slots on method entry. <br>
34: *
35: * For instance, in an instance method, the first statement will
36: * often be <code> this := @parameter0; </code> */
37: public class ParameterRef implements IdentityRef {
38: int n;
39: Type paramType;
40:
41: /** Constructs a ParameterRef object of the specified type, representing the specified parameter number. */
42: public ParameterRef(Type paramType, int number) {
43: this .n = number;
44: this .paramType = paramType;
45: }
46:
47: public boolean equivTo(Object o) {
48: if (o instanceof ParameterRef) {
49: return n == ((ParameterRef) o).n
50: && paramType.equals(((ParameterRef) o).paramType);
51: }
52: return false;
53: }
54:
55: public int equivHashCode() {
56: return n * 101 + paramType.hashCode() * 17;
57: }
58:
59: /** Create a new ParameterRef object with the same paramType and number. */
60: public Object clone() {
61: return new ParameterRef(paramType, n);
62: }
63:
64: /** Converts the given ParameterRef into a String i.e. <code>@parameter0: .int</code>. */
65: public String toString() {
66: return "@parameter" + n + ": " + paramType;
67: }
68:
69: public void toString(UnitPrinter up) {
70: up.identityRef(this );
71: }
72:
73: /** Returns the index of this ParameterRef. */
74: public int getIndex() {
75: return n;
76: }
77:
78: /** Sets the index of this ParameterRef. */
79: public void setIndex(int index) {
80: n = index;
81: }
82:
83: public List getUseBoxes() {
84: return AbstractUnit.emptyList;
85: }
86:
87: /** Returns the type of this ParameterRef. */
88: public Type getType() {
89: return paramType;
90: }
91:
92: /** Used with RefSwitch. */
93: public void apply(Switch sw) {
94: ((RefSwitch) sw).caseParameterRef(this);
95: }
96: }
|