KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > jimple > toolkits > annotation > purity > PurityStmtNode


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2005 Antoine Mine
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 /**
21  * Implementation of the paper "A Combined Pointer and Purity Analysis for
22  * Java Programs" by Alexandru Salcianu and Martin Rinard, within the
23  * Soot Optimization Framework.
24  *
25  * by Antoine Mine, 2005/01/24
26  */

27
28 package soot.jimple.toolkits.annotation.purity;
29 import soot.jimple.*;
30 import java.util.*;
31
32 /**
33  * A node created dynamically and attached to a statement Stmt.
34  * Can be either an inside or a load node.
35  * Two such nodes are equal if and only if they have the same inside / load
36  * flag and are attached to the same statement (we use Stmt.equal here).
37  *
38  */

39 public class PurityStmtNode implements PurityNode
40 {
41     /** Statement that created the node */
42     private Stmt id;
43
44     /** true if an inside node, false if an load node */
45     private boolean inside;
46
47     /** gives a unique id, for pretty-printing purposes */
48     private static Map nMap = new HashMap();
49     private static int n = 0;
50
51     PurityStmtNode(Stmt id, boolean inside)
52     {
53     this.id = id; this.inside = inside;
54     if (!nMap.containsKey(id)) { nMap.put(id,new Integer JavaDoc(n)); n++; }
55     }
56
57     public String JavaDoc toString()
58     {
59     if (inside) return "I_"+nMap.get(id); else return "L_"+nMap.get(id);
60     //if (inside) return "I_"+id; else return "L_"+id;
61
}
62
63     public int hashCode()
64     { return id.hashCode(); }
65     
66     public boolean equals(Object JavaDoc o)
67     {
68     if (o instanceof PurityStmtNode) {
69         PurityStmtNode oo = (PurityStmtNode)o;
70         return id.equals(oo.id) && oo.inside==inside;
71     }
72     else return false;
73     }
74
75     public boolean isInside()
76     { return inside; }
77
78     public boolean isLoad()
79     { return !inside; }
80
81     public boolean isParam()
82     { return false; }
83 }
84
Popular Tags