KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > jimple > spark > pag > VarNode


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2002 Ondrej Lhotak
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 package soot.jimple.spark.pag;
21 import soot.jimple.spark.*;
22 import soot.*;
23 import java.util.*;
24
25 /** Represents a simple variable node (Green) in the pointer assignment graph.
26  * @author Ondrej Lhotak
27  */

28 public abstract class VarNode extends ValNode implements Comparable JavaDoc {
29     public Context context() { return null; }
30     /** Returns all field ref nodes having this node as their base. */
31     public Collection getAllFieldRefs() {
32     if( fields == null ) return Collections.EMPTY_LIST;
33     return fields.values();
34     }
35     /** Returns the field ref node having this node as its base,
36      * and field as its field; null if nonexistent. */

37     public FieldRefNode dot( SparkField field )
38     { return fields == null ? null : (FieldRefNode) fields.get( field ); }
39     public int compareTo( Object JavaDoc o ) {
40     VarNode other = (VarNode) o;
41         if( other.finishingNumber == finishingNumber && other != this ) {
42             G.v().out.println( "This is: "+this+" with id "+getNumber()+" and number "+finishingNumber );
43             G.v().out.println( "Other is: "+other+" with id "+other.getNumber()+" and number "+other.finishingNumber );
44             throw new RuntimeException JavaDoc("Comparison error" );
45         }
46     return other.finishingNumber - finishingNumber;
47     }
48     public void setFinishingNumber( int i ) {
49         finishingNumber = i;
50         if( i > pag.maxFinishNumber ) pag.maxFinishNumber = i;
51     }
52     /** Returns the underlying variable that this node represents. */
53     public Object JavaDoc getVariable() {
54         return variable;
55     }
56
57     /** Designates this node as the potential target of a interprocedural
58      * assignment edge which may be added during on-the-fly call graph
59      * updating. */

60     public void setInterProcTarget() {
61         interProcTarget = true;
62     }
63     /** Returns true if this node is the potential target of a interprocedural
64      * assignment edge which may be added during on-the-fly call graph
65      * updating. */

66     public boolean isInterProcTarget() {
67         return interProcTarget;
68     }
69
70     /** Designates this node as the potential source of a interprocedural
71      * assignment edge which may be added during on-the-fly call graph
72      * updating. */

73     public void setInterProcSource() {
74         interProcSource = true;
75     }
76     /** Returns true if this node is the potential source of a interprocedural
77      * assignment edge which may be added during on-the-fly call graph
78      * updating. */

79     public boolean isInterProcSource() {
80         return interProcSource;
81     }
82
83     /* End of public methods. */
84
85     VarNode( PAG pag, Object JavaDoc variable, Type t ) {
86     super( pag, t );
87     if( !(t instanceof RefLikeType) || t instanceof AnySubType ) {
88         throw new RuntimeException JavaDoc( "Attempt to create VarNode of type "+t );
89     }
90     this.variable = variable;
91         pag.getVarNodeNumberer().add(this);
92         setFinishingNumber( ++pag.maxFinishNumber );
93     }
94     /** Registers a frn as having this node as its base. */
95     void addField( FieldRefNode frn, SparkField field ) {
96     if( fields == null ) fields = new HashMap();
97     fields.put( field, frn );
98     }
99
100     /* End of package methods. */
101
102     protected Object JavaDoc variable;
103     protected Map fields;
104     protected int finishingNumber = 0;
105     protected boolean interProcTarget = false;
106     protected boolean interProcSource = false;
107     protected int numDerefs = 0;
108 }
109
110
Popular Tags