KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > jimple > spark > sets > PointsToSetInternal


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.sets;
21 import soot.jimple.spark.*;
22 import soot.jimple.spark.pag.*;
23 import soot.*;
24 import java.util.*;
25
26 /** Abstract base class for implementations of points-to sets.
27  * @author Ondrej Lhotak
28  */

29 public abstract class PointsToSetInternal implements PointsToSet {
30     /** Adds contents of other minus the contents of exclude into this set;
31      * returns true if this set changed. */

32     public boolean addAll( PointsToSetInternal other,
33             final PointsToSetInternal exclude ) {
34         if( other instanceof DoublePointsToSet ) {
35             return addAll( other.getNewSet(), exclude )
36                 | addAll( other.getOldSet(), exclude );
37         } else if( other instanceof EmptyPointsToSet ) {
38             return false;
39         } else if( exclude instanceof EmptyPointsToSet ) {
40             return addAll( other, null );
41         }
42         if( !G.v().PointsToSetInternal_warnedAlready ) {
43             G.v().out.println( "Warning: using default implementation of addAll. You should implement a faster specialized implementation." );
44             G.v().out.println( "this is of type "+getClass().getName() );
45             G.v().out.println( "other is of type "+other.getClass().getName() );
46             if( exclude == null ) {
47                 G.v().out.println( "exclude is null" );
48             } else {
49                 G.v().out.println( "exclude is of type "+
50                         exclude.getClass().getName() );
51             }
52             G.v().PointsToSetInternal_warnedAlready = true;
53         }
54         return other.forall( new P2SetVisitor() {
55         public final void visit( Node n ) {
56                 if( exclude == null || !exclude.contains( n ) )
57                     returnValue = add( n ) | returnValue;
58             }
59         } );
60     }
61     /** Calls v's visit method on all nodes in this set. */
62     public abstract boolean forall( P2SetVisitor v );
63     /** Adds n to this set, returns true if n was not already in this set. */
64     public abstract boolean add( Node n );
65     /** Returns set of newly-added nodes since last call to flushNew. */
66     public PointsToSetInternal getNewSet() { return this; }
67     /** Returns set of nodes already present before last call to flushNew. */
68     public PointsToSetInternal getOldSet() { return EmptyPointsToSet.v(); }
69     /** Sets all newly-added nodes to old nodes. */
70     public void flushNew() {}
71     /** Sets all nodes to newly-added nodes. */
72     public void unFlushNew() {}
73     /** Merges other into this set. */
74     public void mergeWith( PointsToSetInternal other )
75     { addAll( other, null ); }
76     /** Returns true iff the set contains n. */
77     public abstract boolean contains( Node n );
78
79     public PointsToSetInternal( Type type ) { this.type = type; }
80
81     public boolean hasNonEmptyIntersection( PointsToSet other ) {
82         final PointsToSetInternal o = (PointsToSetInternal) other;
83         return forall( new P2SetVisitor() {
84             public void visit( Node n ) {
85                 if( o.contains( n ) ) returnValue = true;
86             }
87         } );
88     }
89     public Set possibleTypes() {
90         final HashSet ret = new HashSet();
91         forall( new P2SetVisitor() {
92             public void visit( Node n ) {
93                 Type t = n.getType();
94                 if( t instanceof RefType ) {
95                     RefType rt = (RefType) t;
96                     if( rt.getSootClass().isAbstract() ) return;
97                 }
98                 ret.add( t );
99             }
100         } );
101         return ret;
102     }
103     public Type getType() {
104         return type;
105     }
106     public void setType( Type type ) {
107         this.type = type;
108     }
109     public int size() {
110         final int[] ret = new int[1];
111         forall( new P2SetVisitor() {
112             public void visit( Node n ) {
113                 ret[0]++;
114             }
115         } );
116         return ret[0];
117     }
118     public String JavaDoc toString() {
119         final StringBuffer JavaDoc ret = new StringBuffer JavaDoc();
120         this.forall( new P2SetVisitor() {
121         public final void visit( Node n ) {
122             ret.append( ""+n+"," );
123         }} );
124         return ret.toString();
125     }
126
127     public Set possibleStringConstants() {
128         final HashSet ret = new HashSet();
129         return this.forall( new P2SetVisitor() {
130         public final void visit( Node n ) {
131             if( n instanceof StringConstantNode ) {
132                 ret.add( ((StringConstantNode)n).getString() );
133             } else {
134                 returnValue = true;
135             }
136         }} ) ? null : ret;
137     }
138     public Set possibleClassConstants() {
139         final HashSet ret = new HashSet();
140         return this.forall( new P2SetVisitor() {
141         public final void visit( Node n ) {
142             if( n instanceof ClassConstantNode ) {
143                 ret.add( ((ClassConstantNode)n).getClassConstant() );
144             } else {
145                 returnValue = true;
146             }
147         }} ) ? null : ret;
148     }
149
150     /* End of public methods. */
151     /* End of package methods. */
152
153     protected Type type;
154 }
155
156
Popular Tags