KickJava   Java API By Example, From Geeks To Geeks.

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


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 StmtRWSet extends RWSet {
26     protected Object JavaDoc field;
27     protected PointsToSet base;
28     protected boolean callsNative = false;
29
30     public String JavaDoc toString() {
31         return "[Field: "+field+base+"]\n";
32     }
33
34     public boolean getCallsNative() {
35     return callsNative;
36     }
37
38     public boolean setCallsNative() {
39     boolean ret = !callsNative;
40     callsNative = true;
41     return ret;
42     }
43
44     /** Returns an iterator over any globals read/written. */
45     public Set getGlobals() {
46     if( base == null ) {
47         HashSet ret = new HashSet();
48         ret.add( field );
49         return ret;
50     }
51     return Collections.EMPTY_SET;
52     }
53
54     /** Returns an iterator over any fields read/written. */
55     public Set getFields() {
56     if( base != null ) {
57         HashSet ret = new HashSet();
58         ret.add( field );
59         return ret;
60     }
61     return Collections.EMPTY_SET;
62     }
63
64     /** Returns a set of base objects whose field f is read/written. */
65     public PointsToSet getBaseForField( Object JavaDoc f ) {
66     if( field.equals( f ) ) return base;
67     return null;
68     }
69
70     public boolean hasNonEmptyIntersection( RWSet other ) {
71     if( field == null ) return false;
72     if( other instanceof StmtRWSet ) {
73         StmtRWSet o = (StmtRWSet) other;
74         if( !field.equals( o.field ) ) return false;
75         if( base == null ) return o.base == null;
76         return Union.hasNonEmptyIntersection( base, o.base );
77     } else if( other instanceof MethodRWSet ) {
78         MethodRWSet o = (MethodRWSet) other;
79         if( base == null ) return other.getGlobals().contains( field );
80         return Union.hasNonEmptyIntersection( base,
81                     other.getBaseForField( field ) );
82     } else {
83         return other.hasNonEmptyIntersection( this );
84     }
85     }
86
87     /** Adds the RWSet other into this set. */
88     public boolean union( RWSet other ) {
89     throw new RuntimeException JavaDoc( "Can't do that" );
90     }
91
92     public boolean addGlobal( SootField global ) {
93     if( field != null || base != null )
94         throw new RuntimeException JavaDoc( "Can't do that" );
95     field = global;
96     return true;
97     }
98     public boolean addFieldRef( PointsToSet otherBase, Object JavaDoc field ) {
99     if( this.field != null || base != null )
100         throw new RuntimeException JavaDoc( "Can't do that" );
101     this.field = field;
102     base = otherBase;
103     return true;
104     }
105     public boolean isEquivTo( RWSet other ) {
106     if( !( other instanceof StmtRWSet ) ) return false;
107     StmtRWSet o = (StmtRWSet) other;
108     if( callsNative != o.callsNative ) return false;
109     if( !field.equals( o.field ) ) return false;
110     if( base instanceof FullObjectSet && o.base instanceof FullObjectSet ) return true;
111     if( base != o.base ) return false;
112     return true;
113     }
114 }
115
Popular Tags