KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > jimple > toolkits > annotation > arraycheck > ExtendedHashMutableDirectedGraph


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2000 Feng Qian
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  * Modified by the Sable Research Group and others 1997-1999.
22  * See the 'credits' file distributed with Soot for the complete list of
23  * contributors. (Soot is distributed at http://www.sable.mcgill.ca/soot)
24  */

25
26 package soot.jimple.toolkits.annotation.arraycheck;
27
28 import soot.toolkits.graph.*;
29 import java.util.*;
30
31 /**
32    add skipNode method to direct all predecessor edges to successors.
33
34    override 'addEdge' to add node if the node was not in the graph
35
36 */

37 class ExtendedHashMutableDirectedGraph extends HashMutableDirectedGraph
38 {
39     public ExtendedHashMutableDirectedGraph() {}
40     
41     /**
42        If nodes are not in the graph, add them into graph first.
43      */

44     public void addEdge (Object JavaDoc from, Object JavaDoc to)
45     {
46     if (!super.containsNode(from))
47         super.addNode(from);
48
49     if (!super.containsNode(to))
50         super.addNode(to);
51
52     super.addEdge(from, to);
53     }
54
55
56     /**
57        Add mutual edge to the graph. It should be optimized in the future.
58     */

59     public void addMutualEdge (Object JavaDoc from, Object JavaDoc to)
60     {
61     if (!super.containsNode(from))
62         super.addNode(from);
63
64     if (!super.containsNode(to))
65         super.addNode(to);
66
67     super.addEdge(from, to);
68     super.addEdge(to, from);
69     }
70
71     /**
72        Bypass the in edge to out edge. Not delete the node
73      */

74     public void skipNode(Object JavaDoc node)
75     {
76     if (!super.containsNode(node))
77         return;
78
79     Object JavaDoc[] preds = getPredsOf(node).toArray();
80     Object JavaDoc[] succs = getSuccsOf(node).toArray();
81
82     
83     for (int i=0; i<preds.length; i++)
84     {
85         for (int j=0; j<succs.length; j++)
86         {
87         if (preds[i] != succs[j])
88             super.addEdge(preds[i], succs[j]);
89         }
90     }
91
92     for (int i=0; i<preds.length; i++)
93     {
94         super.removeEdge(preds[i], node);
95     }
96
97     for (int j=0; j<succs.length; j++)
98     {
99         super.removeEdge(node, succs[j]);
100     }
101
102     super.removeNode(node);
103     }
104
105     public void mergeWith(ExtendedHashMutableDirectedGraph other)
106     {
107     List nodes = other.getNodes();
108
109     Iterator nodesIt = nodes.iterator();
110
111     while (nodesIt.hasNext())
112     {
113         Object JavaDoc node = nodesIt.next();
114
115         List succs = other.getSuccsOf(node);
116
117         Iterator succsIt = succs.iterator();
118
119         while (succsIt.hasNext())
120         {
121         Object JavaDoc succ = succsIt.next();
122         
123         this.addEdge(node, succ);
124         }
125     }
126     }
127
128     public String JavaDoc toString()
129     {
130     String JavaDoc rtn = "Graph:\n";
131
132         List nodes = super.getNodes();
133
134     Iterator nodesIt = nodes.iterator();
135
136     while (nodesIt.hasNext())
137         {
138         Object JavaDoc node = nodesIt.next();
139
140         List succs = super.getSuccsOf(node);
141
142         Iterator succsIt = succs.iterator();
143
144         while (succsIt.hasNext())
145         {
146         Object JavaDoc succ = succsIt.next();
147
148         rtn = rtn + node + "\t --- \t" + succ +"\n";
149         }
150     }
151
152     return rtn;
153     }
154 }
155
156
157
158
159
160
161
162
163
Popular Tags