KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > jimple > toolkits > pointer > SiteRWSet


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2003 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.toolkits.pointer;
21 import java.util.*;
22 import soot.*;
23
24 /** Represents the read or write set of a statement. */
25 public class SiteRWSet extends RWSet {
26     protected HashSet sets = new HashSet();
27     protected boolean callsNative = false;
28
29     public String JavaDoc toString() {
30         boolean empty = true;
31         final StringBuffer JavaDoc ret = new StringBuffer JavaDoc();
32         ret.append("SiteRWSet: ");
33         for( Iterator keyIt = sets.iterator(); keyIt.hasNext(); ) {
34             final Object JavaDoc key = (Object JavaDoc) keyIt.next();
35             ret.append( key.toString() );
36             empty = false;
37         }
38         if(empty) ret.append("empty");
39         return ret.toString();
40     }
41
42     public boolean getCallsNative() {
43     return callsNative;
44     }
45
46     public boolean setCallsNative() {
47     boolean ret = !callsNative;
48     callsNative = true;
49     return ret;
50     }
51
52     /** Returns an iterator over any globals read/written. */
53     public Set getGlobals() {
54     HashSet ret = new HashSet();
55     for( Iterator sIt = sets.iterator(); sIt.hasNext(); ) {
56         final RWSet s = (RWSet) sIt.next();
57         ret.addAll( s.getGlobals() );
58     }
59     return ret;
60     }
61
62     /** Returns an iterator over any fields read/written. */
63     public Set getFields() {
64     HashSet ret = new HashSet();
65     for( Iterator sIt = sets.iterator(); sIt.hasNext(); ) {
66         final RWSet s = (RWSet) sIt.next();
67         ret.addAll( s.getFields() );
68     }
69     return ret;
70     }
71
72     /** Returns a set of base objects whose field f is read/written. */
73     public PointsToSet getBaseForField( Object JavaDoc f ) {
74     Union ret = null;
75     for( Iterator sIt = sets.iterator(); sIt.hasNext(); ) {
76         final RWSet s = (RWSet) sIt.next();
77         PointsToSet os = s.getBaseForField( f );
78         if( os == null ) continue;
79         if( os.isEmpty() ) continue;
80         if( ret == null ) ret = G.v().Union_factory.newUnion();
81         ret.addAll( os );
82     }
83     return ret;
84     }
85
86     public boolean hasNonEmptyIntersection( RWSet oth ) {
87     if( sets.contains( oth ) ) return true;
88     for( Iterator sIt = sets.iterator(); sIt.hasNext(); ) {
89         final RWSet s = (RWSet) sIt.next();
90         if( oth.hasNonEmptyIntersection( s ) ) return true;
91     }
92     return false;
93     }
94
95     /** Adds the RWSet other into this set. */
96     public boolean union( RWSet other ) {
97     if( other == null ) return false;
98     boolean ret = false;
99     if( other.getCallsNative() ) ret = setCallsNative();
100     if( other.getFields().isEmpty() && other.getGlobals().isEmpty() ) return ret;
101     return sets.add( other ) | ret;
102     }
103
104     public boolean addGlobal( SootField global ) {
105     throw new RuntimeException JavaDoc( "Not implemented; try MethodRWSet" );
106     }
107     public boolean addFieldRef( PointsToSet otherBase, Object JavaDoc field ) {
108     throw new RuntimeException JavaDoc( "Not implemented; try MethodRWSet" );
109     }
110     public boolean isEquivTo( RWSet other ) {
111     if( !( other instanceof SiteRWSet ) ) return false;
112     SiteRWSet o = (SiteRWSet) other;
113     if( o.callsNative != callsNative ) return false;
114     return o.sets.equals( sets );
115     }
116 }
117
Popular Tags