KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > dava > toolkits > base > finders > SwitchNodeGraph


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2003 Jerome Miecznikowski
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.dava.toolkits.base.finders;
21
22 import java.util.*;
23 import soot.toolkits.graph.*;
24
25 class SwitchNodeGraph implements DirectedGraph
26 {
27     private LinkedList body, heads, tails;
28     private HashMap binding;
29     
30
31     public SwitchNodeGraph( List body)
32     {
33     this.body = new LinkedList();
34     this.body.addAll( body);
35
36     binding = new HashMap();
37
38     heads = new LinkedList();
39     tails = new LinkedList();
40
41     Iterator it = body.iterator();
42     while (it.hasNext()) {
43         SwitchNode sn = (SwitchNode) it.next();
44
45         binding.put( sn.get_AugStmt().bsuccs.get(0), sn);
46         sn.reset();
47     }
48     
49     it = body.iterator();
50     while (it.hasNext())
51         ((SwitchNode) it.next()).setup_Graph( binding);
52
53     it = body.iterator();
54     while (it.hasNext()) {
55         SwitchNode sn = (SwitchNode) it.next();
56
57         if (sn.get_Preds().isEmpty())
58         heads.add( sn);
59
60         if (sn.get_Succs().isEmpty())
61         tails.add( sn);
62     }
63     }
64
65     public int size()
66     {
67     return body.size();
68     }
69
70     public List getHeads()
71     {
72     return heads;
73     }
74
75     public List getTails()
76     {
77     return tails;
78     }
79
80     public List getPredsOf( Object JavaDoc o)
81     {
82     return ((SwitchNode) o).get_Preds();
83     }
84
85     public List getSuccsOf( Object JavaDoc o)
86     {
87     return ((SwitchNode) o).get_Succs();
88     }
89
90     public Iterator iterator()
91     {
92     return body.iterator();
93     }
94
95     public List getBody()
96     {
97     return body;
98     }
99 }
100
Popular Tags