KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > EquivalentValue


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2000 Patrick Lam
3  * extended 2002 Florian Loitsch
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;
29 import java.util.*;
30 import soot.util.*;
31
32 /**
33  * Encapsulates the Value class, but uses EquivTo for equality comparisons.
34  * Also uses equivHashCode as its hash code. */

35 public class EquivalentValue implements Value {
36     Value e;
37     public EquivalentValue(Value e) { this.e = e; }
38     public boolean equals(Object JavaDoc o)
39     {
40         if (o instanceof EquivalentValue)
41             o = ((EquivalentValue)o).e;
42         return e.equivTo(o);
43     }
44
45     /**
46      * compares the encapsulated value with <code>v</code>, using
47      * <code>equivTo</code>
48      **/

49     public boolean equivToValue(Value v) {
50       return e.equivTo(v);
51     }
52
53     /**
54      * compares the encapsulated value with <code>v</code>, using
55      * <code>equals</code>
56      **/

57     public boolean equalsToValue(Value v) {
58       return e.equals(v);
59     }
60
61     /**
62      * returns the deepest Value stored in <code>this</code>. If the
63      * immediate stored value is an EquivalentValue its deepest value is
64      * returned.
65      **/

66     public Value getDeepestValue() {
67       Value deepest = e;
68       while (e instanceof EquivalentValue)
69         deepest = ((EquivalentValue)deepest).getValue();
70       return deepest;
71     }
72
73     public int hashCode() { return e.equivHashCode(); }
74     public String JavaDoc toString() { return e.toString(); }
75     public Value getValue() { return e; }
76
77     /*********************************/
78     /* implement the Value-interface */
79     /*********************************/
80     public List getUseBoxes() {
81       return e.getUseBoxes();
82     }
83
84     public Type getType() {
85       return e.getType();
86     }
87
88     public Object JavaDoc clone() {
89       EquivalentValue equiVal = new EquivalentValue((Value)e.clone());
90       return equiVal;
91     }
92
93     public boolean equivTo(Object JavaDoc o) {
94       return e.equivTo(o);
95     }
96
97     public int equivHashCode() {
98       return e.equivHashCode();
99     }
100
101     public void apply(Switch sw) {
102       e.apply(sw);
103     }
104     public void toString( UnitPrinter up ) {
105         e.toString(up);
106     }
107 }
108
Popular Tags