KickJava   Java API By Example, From Geeks To Geeks.

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


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.Node;
23 import soot.jimple.spark.pag.PAG;
24 import soot.jimple.spark.internal.*;
25 import soot.util.*;
26 import soot.Type;
27
28 /** Implementation of points-to set using a bit vector.
29  * @author Ondrej Lhotak
30  */

31 public final class BitPointsToSet extends PointsToSetInternal {
32     public BitPointsToSet( Type type, PAG pag ) {
33         super( type );
34         this.pag = pag;
35         bits = new BitVector( pag.getAllocNodeNumberer().size() );
36     }
37     /** Returns true if this set contains no run-time objects. */
38     public final boolean isEmpty() {
39         return empty;
40     }
41
42     private final boolean superAddAll( PointsToSetInternal other, PointsToSetInternal exclude ) {
43         boolean ret = super.addAll( other, exclude );
44         if( ret ) empty = false;
45         return ret;
46     }
47
48     private final boolean nativeAddAll( BitPointsToSet other, BitPointsToSet exclude ) {
49         BitVector mask = null;
50         TypeManager typeManager = (TypeManager) pag.getTypeManager();
51         if( !typeManager.castNeverFails( other.getType(), this.getType() ) ) {
52             mask = typeManager.get( this.getType() );
53         }
54         BitVector obits = other.bits;
55         BitVector ebits = ( exclude==null ? null : exclude.bits );
56         boolean ret = bits.orAndAndNot( obits, mask, ebits );
57         if( ret ) empty = false;
58         return ret;
59     }
60
61     /** Adds contents of other into this set, returns true if this set
62      * changed. */

63     public final boolean addAll( PointsToSetInternal other,
64             PointsToSetInternal exclude ) {
65         if( other != null && !(other instanceof BitPointsToSet) )
66             return superAddAll( other, exclude );
67         if( exclude != null && !(exclude instanceof BitPointsToSet) )
68             return superAddAll( other, exclude );
69         return nativeAddAll( (BitPointsToSet) other, (BitPointsToSet) exclude );
70     }
71     /** Calls v's visit method on all nodes in this set. */
72     public final boolean forall( P2SetVisitor v ) {
73         for( BitSetIterator it = bits.iterator(); it.hasNext(); ) {
74             v.visit( (Node) pag.getAllocNodeNumberer().get( it.next() ) );
75         }
76         return v.getReturnValue();
77     }
78     /** Adds n to this set, returns true if n was not already in this set. */
79     public final boolean add( Node n ) {
80         if( pag.getTypeManager().castNeverFails( n.getType(), type ) ) {
81             return fastAdd( n );
82         }
83         return false;
84     }
85     /** Returns true iff the set contains n. */
86     public final boolean contains( Node n ) {
87         return bits.get( n.getNumber() );
88     }
89     public static P2SetFactory getFactory() {
90         return new P2SetFactory() {
91             public PointsToSetInternal newSet( Type type, PAG pag ) {
92                 return new BitPointsToSet( type, pag );
93             }
94         };
95     }
96
97     /* End of public methods. */
98     /* End of package methods. */
99
100     private boolean fastAdd( Node n ) {
101         boolean ret = bits.set( n.getNumber() );
102         if( ret ) empty = false;
103         return ret;
104     }
105
106     private BitVector bits = null;
107     private boolean empty = true;
108     private PAG pag = null;
109 }
110
111
Popular Tags