KickJava   Java API By Example, From Geeks To Geeks.

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


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 soot.*;
22 import soot.util.*;
23 import java.util.*;
24
25 /** Represents a set of (local,type) pairs using a bit-vector. */
26 class LocalTypeSet extends java.util.BitSet JavaDoc {
27     protected List locals;
28     protected List types;
29
30     /** Constructs a new empty set given a list of all locals and types that may
31      * ever be in the set. */

32     public LocalTypeSet( List locals, List types ) {
33     super( locals.size() * types.size() );
34     this.locals = locals;
35     this.types = types;
36     if( !Scene.v().hasFastHierarchy() ) {
37         Scene.v().setFastHierarchy( new FastHierarchy() );
38     }
39     }
40     /** Returns the number of the bit corresponding to the pair (l,t). */
41     protected int indexOf( Local l, RefType t ) {
42     if( locals.indexOf( l ) == -1 || types.indexOf( t ) == -1 ) {
43         throw new RuntimeException JavaDoc( "Invalid local or type in LocalTypeSet" );
44     }
45     return locals.indexOf( l ) * types.size() + types.indexOf( t );
46     }
47     /** Removes all pairs corresponding to local l from the set. */
48     public void killLocal( Local l ) {
49     int base = types.size() * locals.indexOf( l );
50     for( int i = 0; i < types.size(); i++ ) {
51         clear( i + base );
52     }
53     }
54     /** For each pair (from,t), adds a pair (to,t). */
55     public void localCopy( Local to, Local from ) {
56     int baseTo = types.size() * locals.indexOf( to );
57     int baseFrom = types.size() * locals.indexOf( from );
58     for( int i = 0; i < types.size(); i++ ) {
59         if( get( i+baseFrom ) ) {
60         set( i+baseTo );
61         } else {
62         clear( i+baseTo );
63         }
64     }
65     }
66     /** Empties the set. */
67     public void clearAllBits() {
68     for( int i = 0; i < types.size() * locals.size(); i++ ) {
69         clear( i );
70     }
71     }
72     /** Fills the set to contain all possible (local,type) pairs. */
73     public void setAllBits() {
74     for( int i = 0; i < types.size() * locals.size(); i++ ) {
75         set( i );
76     }
77     }
78     /** Adds to the set all pairs (l,type) where type is any supertype of t. */
79     public void localMustBeSubtypeOf( Local l, RefType t ) {
80     FastHierarchy fh = Scene.v().getFastHierarchy();
81     for( Iterator it = types.iterator(); it.hasNext(); ) {
82         RefType supertype = (RefType) it.next();
83         if( fh.canStoreType( t, supertype ) ) {
84         set( indexOf( l, supertype ) );
85         }
86     }
87     }
88
89     public String JavaDoc toString(){
90         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
91         Iterator localsIt = locals.iterator();
92         while (localsIt.hasNext()){
93             Local l = (Local)localsIt.next();
94             Iterator typesIt = types.iterator();
95             while (typesIt.hasNext()){
96                 RefType t = (RefType)typesIt.next();
97                 int index = indexOf(l, t);
98                 //G.v().out.println("for: "+l+" and type: "+t+" at: "+index);
99
if (get(index)) {
100                     sb.append("(("+l+","+t+") -> elim cast check) ");
101                 }
102             }
103             
104         }
105         return sb.toString();
106     }
107 }
108
109
Popular Tags