KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 1999 Patrick Lam
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 package soot.jimple.internal;
28
29 import soot.tagkit.*;
30 import soot.*;
31 import soot.jimple.*;
32 import soot.baf.*;
33 import soot.util.*;
34 import java.util.*;
35
36 public class JimpleLocal implements Local, ConvertToBaf
37 {
38     String JavaDoc name;
39     Type type;
40
41     int fixedHashCode;
42     boolean isHashCodeChosen;
43
44     /** Constructs a JimpleLocal of the given name and type. */
45     public JimpleLocal(String JavaDoc name, Type t)
46     {
47         this.name = name;
48         this.type = t;
49         Scene.v().getLocalNumberer().add( this );
50     }
51
52     /** Returns true if the given object is structurally equal to this one. */
53     public boolean equivTo(Object JavaDoc o)
54     {
55         return this.equals( o );
56     }
57
58     /** Returns a hash code for this object, consistent with structural equality. */
59     public int equivHashCode()
60     {
61         return name.hashCode() * 101 + type.hashCode() * 17;
62     }
63
64     /** Returns a clone of the current JimpleLocal. */
65     public Object JavaDoc clone()
66     {
67         return new JimpleLocal(name, type);
68     }
69
70     /** Returns the name of this object. */
71     public String JavaDoc getName()
72     {
73         return name;
74     }
75
76     /** Sets the name of this object as given. */
77     public void setName(String JavaDoc name)
78     {
79         this.name = name;
80     }
81
82     /** Returns a hashCode consistent with object equality. */
83     public int hashCode()
84     {
85         if(!isHashCodeChosen)
86         {
87             // Set the hash code for this object
88

89             if(name != null & type != null)
90                 fixedHashCode = name.hashCode() + 19 * type.hashCode();
91             else if(name != null)
92                 fixedHashCode = name.hashCode();
93             else if(type != null)
94                 fixedHashCode = type.hashCode();
95             else
96                 fixedHashCode = 1;
97                 
98             isHashCodeChosen = true;
99         }
100         
101         return fixedHashCode;
102     }
103     
104     /** Returns the type of this local. */
105     public Type getType()
106     {
107         return type;
108     }
109
110     /** Sets the type of this local. */
111     public void setType(Type t)
112     {
113         this.type = t;
114     }
115
116     public String JavaDoc toString()
117     {
118         return getName();
119     }
120     
121     public void toString(UnitPrinter up) {
122         up.local(this);
123     }
124
125     public List getUseBoxes()
126     {
127         return AbstractUnit.emptyList;
128     }
129
130     public void apply(Switch sw)
131     {
132         ((JimpleValueSwitch) sw).caseLocal(this);
133     }
134
135     public void convertToBaf(JimpleToBafContext context, List out)
136     {
137     Unit u = Baf.v().newLoadInst(getType(),context.getBafLocalOfJimpleLocal(this));
138         out.add(u);
139     Iterator it = context.getCurrentUnit().getTags().iterator();
140     while(it.hasNext()) {
141         u.addTag((Tag) it.next());
142     }
143     }
144     public final int getNumber() { return number; }
145     public final void setNumber( int number ) { this.number = number; }
146
147     private int number = 0;
148 }
149
150
Popular Tags