KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > toolkits > graph > DominatorNode


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2003 Navindra Umanee <navindra@cs.mcgill.ca>
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.toolkits.graph;
21
22 import soot.*;
23 import soot.toolkits.scalar.*;
24 import soot.toolkits.graph.*;
25 import soot.jimple.*;
26 import java.util.*;
27 import soot.util.*;
28
29 /**
30  * Represents a dominator node in DominatorTree. Usually you should
31  * use DominatorTree or DominanceFrontier to obtain information on how
32  * a node relates to other nodes instead of directly using any methods
33  * provided here.
34  *
35  * @author Navindra Umanee
36  **/

37 public class DominatorNode
38 {
39     protected Object JavaDoc gode;
40     protected DominatorNode parent;
41     protected List children;
42
43     protected DominatorNode(Object JavaDoc gode)
44     {
45         this.gode = gode;
46         children = new ArrayList();
47     }
48
49     /**
50      * Sets the parent of this node in the DominatorTree. Usually
51      * called internally.
52      **/

53     public void setParent(DominatorNode parent)
54     {
55         this.parent = parent;
56     }
57
58     /**
59      * Adds a child to the internal list of children of this node in
60      * tree. Usually called internally.
61      **/

62     public boolean addChild(DominatorNode child)
63     {
64         if(children.contains(child)){
65             return false;
66         }
67         else{
68             children.add(child);
69             return true;
70         }
71     }
72
73     /**
74      * Returns the node (from the original DirectedGraph) encapsulated
75      * by this DominatorNode.
76      **/

77     public Object JavaDoc getGode()
78     {
79         return gode;
80     }
81
82     /**
83      * Returns the parent of the node in the DominatorTree.
84      **/

85     public DominatorNode getParent()
86     {
87         return parent;
88     }
89
90     /**
91      * Returns a backed list of the children of this node in the
92      * DominatorTree.
93      **/

94     public List getChildren()
95     {
96         return children;
97     }
98
99     /**
100      * Returns true if this node is the head of its DominatorTree.
101      **/

102     public boolean isHead()
103     {
104         if(parent == null)
105             return true;
106         else
107             return false;
108     }
109
110     /**
111      * Returns true if this node is a tail of its DominatorTree.
112      **/

113     public boolean isTail()
114     {
115         if(children.size() == 0)
116             return true;
117         else
118             return false;
119     }
120
121     public String JavaDoc toString()
122     {
123         // *** FIXME: Print info about parent and children
124
return gode.toString();
125     }
126 }
127
Popular Tags