KickJava   Java API By Example, From Geeks To Geeks.

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


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.*;
30 import soot.jimple.*;
31 import soot.util.*;
32 import java.util.*;
33
34 public abstract class AbstractInstanceOfExpr implements InstanceOfExpr
35 {
36     ValueBox opBox;
37     Type checkType;
38
39     protected AbstractInstanceOfExpr(ValueBox opBox, Type checkType)
40     {
41         this.opBox = opBox; this.checkType = checkType;
42     }
43     
44     public boolean equivTo(Object JavaDoc o)
45     {
46         if (o instanceof AbstractInstanceOfExpr)
47         {
48             AbstractInstanceOfExpr aie = (AbstractInstanceOfExpr)o;
49             return opBox.getValue().equivTo(aie.opBox.getValue()) &&
50                 checkType.equals(aie.checkType);
51         }
52         return false;
53     }
54
55     /** Returns a hash code for this object, consistent with structural equality. */
56     public int equivHashCode()
57     {
58         return opBox.getValue().equivHashCode() * 101 + checkType.hashCode() * 17;
59     }
60
61     public abstract Object JavaDoc clone();
62     
63     public String JavaDoc toString()
64     {
65         return opBox.getValue().toString() + " " + Jimple.v().INSTANCEOF + " " + checkType.toString();
66     }
67     
68     public void toString( UnitPrinter up ) {
69         opBox.toString(up);
70         up.literal(" ");
71         up.literal(Jimple.v().INSTANCEOF);
72         up.literal(" ");
73         up.type(checkType);
74     }
75
76     public Value getOp()
77     {
78         return opBox.getValue();
79     }
80
81     public void setOp(Value op)
82     {
83         opBox.setValue(op);
84     }
85
86     public ValueBox getOpBox()
87     {
88         return opBox;
89     }
90
91     public List getUseBoxes()
92     {
93         List list = new ArrayList();
94
95         list.addAll(opBox.getValue().getUseBoxes());
96         list.add(opBox);
97
98         return list;
99     }
100
101     public Type getType()
102     {
103         return BooleanType.v();
104     }
105
106     public Type getCheckType()
107     {
108         return checkType;
109     }
110
111     public void setCheckType(Type checkType)
112     {
113         this.checkType = checkType;
114     }
115
116     public void apply(Switch sw)
117     {
118         ((ExprSwitch) sw).caseInstanceOfExpr(this);
119     }
120 }
121
Popular Tags