changes.
[IRC.git] / Robust / src / Analysis / SSJava / FlowNode.java
1 package Analysis.SSJava;
2
3 import java.util.HashSet;
4 import java.util.Iterator;
5 import java.util.Set;
6
7 import IR.Descriptor;
8 import IR.FieldDescriptor;
9 import IR.VarDescriptor;
10
11 public class FlowNode {
12
13   // descriptor tuple is a unique identifier of the flow node
14   private NTuple<Descriptor> descTuple;
15
16   // if the infer node represents the base type of field access,
17   // this set contains fields of the base type
18   private Set<FlowNode> fieldNodeSet;
19
20   // set true if this node is driven from a paramter
21   private boolean isParameter;
22
23   // set true if this node stores a return value
24   private boolean isReturn;
25
26   private boolean isDeclarationNode = false;
27
28   private boolean isIntermediate;
29
30   public boolean isIntermediate() {
31     return isIntermediate;
32   }
33
34   public void setIntermediate(boolean isIntermediate) {
35     this.isIntermediate = isIntermediate;
36   }
37
38   public Set<FlowNode> getFieldNodeSet() {
39     return fieldNodeSet;
40   }
41
42   private Set<FlowEdge> outEdgeSet;
43
44   public FlowNode(NTuple<Descriptor> tuple, boolean isParam) {
45
46     this.isParameter = isParam;
47
48     NTuple<Descriptor> base = null;
49     Descriptor desc = null;
50     if (tuple.size() > 1) {
51       base = tuple.subList(0, tuple.size() - 1);
52       desc = tuple.get(tuple.size() - 1);
53     } else {
54       base = tuple;
55     }
56     fieldNodeSet = new HashSet<FlowNode>();
57     descTuple = new NTuple<Descriptor>();
58     if (base != null) {
59       descTuple.addAll(base);
60     }
61     if (desc != null) {
62       descTuple.add(desc);
63     }
64     outEdgeSet = new HashSet<FlowEdge>();
65   }
66
67   public void addFieldNode(FlowNode node) {
68     fieldNodeSet.add(node);
69   }
70
71   public boolean isParameter() {
72     return isParameter;
73   }
74
75   public NTuple<Descriptor> getDescTuple() {
76     return descTuple;
77   }
78
79   public Descriptor getOwnDescriptor() {
80     return descTuple.get(descTuple.size() - 1);
81   }
82
83   public boolean isReturn() {
84     return isReturn;
85   }
86
87   public void setReturn(boolean isReturn) {
88     this.isReturn = isReturn;
89   }
90
91   public boolean isPrimitiveType() {
92     Descriptor desc = descTuple.get(descTuple.size() - 1);
93     if (desc instanceof VarDescriptor) {
94       return ((VarDescriptor) desc).getType().isPrimitive();
95     } else if (desc instanceof FieldDescriptor) {
96       return ((FieldDescriptor) desc).getType().isPrimitive();
97     }
98     return false;
99   }
100
101   public String toString() {
102     String rtr = "[FlowNode]:";
103     if (isParameter()) {
104       rtr += "param:";
105     }
106     rtr += ":" + descTuple;
107     return rtr;
108   }
109
110   public Iterator<FlowEdge> iteratorOfOutEdges() {
111     return outEdgeSet.iterator();
112   }
113
114   public void addOutEdge(FlowEdge out) {
115     outEdgeSet.add(out);
116   }
117
118   public Set<FlowEdge> getOutEdgeSet() {
119     return outEdgeSet;
120   }
121
122   public int hashCode() {
123     return 7 + descTuple.hashCode();
124   }
125
126   public boolean equals(Object obj) {
127
128     if (obj instanceof FlowNode) {
129       FlowNode in = (FlowNode) obj;
130       if (descTuple.equals(in.getDescTuple())) {
131         return true;
132       }
133     }
134
135     return false;
136
137   }
138
139   public String getID() {
140     String id = "";
141     for (int i = 0; i < descTuple.size(); i++) {
142       id += descTuple.get(i).getSymbol();
143     }
144     return id;
145   }
146
147   public String getPrettyID() {
148     String id = "<";
149     for (int i = 0; i < descTuple.size(); i++) {
150       if (i != 0) {
151         id += ",";
152       }
153       id += descTuple.get(i).getSymbol();
154     }
155     id += ">";
156     return id;
157   }
158
159   public void setDeclarationNode() {
160     isDeclarationNode = true;
161   }
162
163   public boolean isDeclaratonNode() {
164     return isDeclarationNode;
165   }
166 }