KickJava   Java API By Example, From Geeks To Geeks.

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


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.*;
22 import soot.jimple.spark.*;
23 import soot.util.*;
24 import soot.Type;
25 import soot.jimple.spark.sets.PointsToSetInternal;
26 import soot.jimple.spark.sets.EmptyPointsToSet;
27 import soot.jimple.toolkits.pointer.representations.ReferenceVariable;
28 import soot.jimple.spark.internal.TypeManager;
29
30 /** Represents every node in the pointer assignment graph.
31  * @author Ondrej Lhotak
32  */

33 public class Node implements ReferenceVariable, Numberable {
34     public final int hashCode() { return number; }
35     public final boolean equals( Object JavaDoc other ) {
36         return this == other;
37     }
38     /** Returns the declared type of this node, null for unknown. */
39     public Type getType() { return type; }
40     /** Sets the declared type of this node, null for unknown. */
41     public void setType( Type type ) {
42         if( TypeManager.isUnresolved(type) ) throw new RuntimeException JavaDoc("Unresolved type "+type );
43         this.type = type;
44     }
45     /** If this node has been merged with another, returns the new node to be
46      * used as the representative of this node; returns this if the node has
47      * not been merged. */

48     public Node getReplacement() {
49         if( replacement != replacement.replacement ) {
50             replacement = replacement.getReplacement();
51         }
52         return replacement;
53     }
54     /** Merge with the node other. */
55     public void mergeWith( Node other ) {
56         if( other.replacement != other ) {
57             throw new RuntimeException JavaDoc( "Shouldn't happen" );
58         }
59         Node myRep = getReplacement();
60         if( other == myRep ) return;
61         other.replacement = myRep;
62         if( other.p2set != p2set
63                 && other.p2set != null
64                 && !other.p2set.isEmpty() ) {
65             if( myRep.p2set == null || myRep.p2set.isEmpty() ) {
66                 myRep.p2set = other.p2set;
67             } else {
68                 myRep.p2set.mergeWith( other.p2set );
69             }
70         }
71         other.p2set = null;
72         pag.mergedWith( myRep, other );
73         if( (other instanceof VarNode)
74                 && (myRep instanceof VarNode )
75                 && ((VarNode) other).isInterProcTarget() )
76             ((VarNode) myRep).setInterProcTarget();
77     }
78     /** Returns the points-to set for this node. */
79     public PointsToSetInternal getP2Set() {
80         if( p2set != null ) {
81             if( replacement != this ) throw new RuntimeException JavaDoc(
82                     "Node "+this+" has replacement "+replacement+" but has p2set" );
83             return p2set;
84         }
85         Node rep = getReplacement();
86         if( rep == this ) {
87             return EmptyPointsToSet.v();
88         }
89         return rep.getP2Set();
90     }
91     /** Returns the points-to set for this node, makes it if necessary. */
92     public PointsToSetInternal makeP2Set() {
93         if( p2set != null ) {
94             if( replacement != this ) throw new RuntimeException JavaDoc(
95                     "Node "+this+" has replacement "+replacement+" but has p2set" );
96             return p2set;
97         }
98         Node rep = getReplacement();
99         if( rep == this ) {
100             p2set = pag.getSetFactory().newSet( type, (PAG) pag );
101         }
102         return rep.makeP2Set();
103     }
104     /** Returns the pointer assignment graph that this node is a part of. */
105     public PAG getPag() { return pag; }
106
107     /* End of public methods. */
108
109     /** Creates a new node of pointer assignment graph pag, with type type. */
110     Node( PAG pag, Type type ) {
111         if( TypeManager.isUnresolved(type) ) throw new RuntimeException JavaDoc("Unresolved type "+type );
112         this.type = type;
113         this.pag = pag;
114         replacement = this;
115     }
116
117     /* End of package methods. */
118
119     public final int getNumber() { return number; }
120     public final void setNumber( int number ) { this.number = number; }
121
122     private int number = 0;
123
124     protected Type type;
125     protected Node replacement;
126     protected PAG pag;
127     protected PointsToSetInternal p2set;
128 }
129
Popular Tags