KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.*;
25 import soot.Type;
26
27 /** HashSet implementation of points-to set.
28  * @author Ondrej Lhotak
29  */

30 public final class HashPointsToSet extends PointsToSetInternal {
31     public HashPointsToSet( Type type, PAG pag ) {
32         super( type );
33         this.pag = pag;
34     }
35     /** Returns true if this set contains no run-time objects. */
36     public final boolean isEmpty() {
37         return s.isEmpty();
38     }
39     /** Adds contents of other into this set, returns true if this set
40      * changed. */

41     public final boolean addAll( final PointsToSetInternal other,
42             final PointsToSetInternal exclude ) {
43         if( other instanceof HashPointsToSet
44         && exclude == null
45         && ( pag.getTypeManager().getFastHierarchy() == null ||
46             type == null || type.equals( other.type ) ) ) {
47             return s.addAll( ((HashPointsToSet) other).s );
48         } else {
49             return super.addAll( other, exclude );
50         }
51     }
52     /** Calls v's visit method on all nodes in this set. */
53     public final boolean forall( P2SetVisitor v ) {
54         for( Iterator it = new ArrayList(s).iterator(); it.hasNext(); ) {
55             v.visit( (Node) it.next() );
56         }
57         return v.getReturnValue();
58     }
59     /** Adds n to this set, returns true if n was not already in this set. */
60     public final boolean add( Node n ) {
61         if( pag.getTypeManager().castNeverFails( n.getType(), type ) ) {
62
63             return s.add( n );
64         }
65         return false;
66     }
67     /** Returns true iff the set contains n. */
68     public final boolean contains( Node n ) {
69         return s.contains( n );
70     }
71     public static P2SetFactory getFactory() {
72         return new P2SetFactory() {
73             public PointsToSetInternal newSet( Type type, PAG pag ) {
74                 return new HashPointsToSet( type, pag );
75             }
76         };
77     }
78
79     /* End of public methods. */
80     /* End of package methods. */
81
82     private HashSet s = new HashSet(4);
83     private PAG pag = null;
84 }
85
86
Popular Tags