0655c5faccdfcb84418236e2c816c742ee40043e
[IRC.git] / Robust / src / Analysis / SSJava / FlowGraph.java
1 package Analysis.SSJava;
2
3 import java.io.BufferedWriter;
4 import java.io.FileWriter;
5 import java.io.IOException;
6 import java.util.HashMap;
7 import java.util.HashSet;
8 import java.util.Iterator;
9 import java.util.Map;
10 import java.util.Set;
11
12 import IR.ClassDescriptor;
13 import IR.Descriptor;
14 import IR.FieldDescriptor;
15 import IR.MethodDescriptor;
16 import IR.NameDescriptor;
17 import IR.VarDescriptor;
18
19 public class FlowGraph {
20
21   MethodDescriptor md;
22
23   Set<FlowNode> nodeSet;
24
25   Set<FlowNode> returnNodeSet;
26   FlowNode thisVarNode;
27
28   Map<FlowNode, Set<FlowEdge>> mapFlowNodeToOutEdgeSet;
29
30   Map<NTuple<Location>, FlowNode> mapLocTupleToFlowNode;
31   Map<FlowNode, NTuple<Location>> mapFlowNodeToLocTuple;
32
33   // maps the composite representation of field/var descriptors to infer nodes
34   Map<NTuple<Descriptor>, FlowNode> mapDescTupleToInferNode;
35
36   // maps a paramter descriptor to its index
37   Map<Descriptor, Integer> mapParamDescToIdx;
38
39   // DS for the lattice generation
40   Map<Integer, FlowNode> mapIdxToFlowNode;
41
42   public static int interseed = 0;
43
44   boolean debug = true;
45
46   public FlowGraph(MethodDescriptor md, Map<Descriptor, Integer> mapParamDescToIdx) {
47     this.md = md;
48     this.mapFlowNodeToLocTuple = new HashMap<FlowNode, NTuple<Location>>();
49     this.mapLocTupleToFlowNode = new HashMap<NTuple<Location>, FlowNode>();
50     this.nodeSet = new HashSet<FlowNode>();
51     this.mapDescTupleToInferNode = new HashMap<NTuple<Descriptor>, FlowNode>();
52     this.mapParamDescToIdx = new HashMap<Descriptor, Integer>();
53     this.mapParamDescToIdx.putAll(mapParamDescToIdx);
54     this.returnNodeSet = new HashSet<FlowNode>();
55     this.mapIdxToFlowNode = new HashMap<Integer, FlowNode>();
56     this.mapFlowNodeToOutEdgeSet = new HashMap<FlowNode, Set<FlowEdge>>();
57
58     if (!md.isStatic()) {
59       // create a node for 'this' varialbe
60       // NTuple<Descriptor> thisDescTuple = new NTuple<Descriptor>();
61       // thisDescTuple.add(md.getThis());
62
63       NTuple<Descriptor> thisVarTuple = new NTuple<Descriptor>();
64       thisVarTuple.add(md.getThis());
65       FlowNode thisNode = createNewFlowNode(thisVarTuple);
66       thisNode.setSkeleton(true);
67       thisVarNode = thisNode;
68     }
69
70     setupMapIdxToDesc();
71
72   }
73
74   public Map<NTuple<Descriptor>, FlowNode> getMapDescTupleToInferNode() {
75     return mapDescTupleToInferNode;
76   }
77
78   public void setMapDescTupleToInferNode(Map<NTuple<Descriptor>, FlowNode> in) {
79     this.mapDescTupleToInferNode.putAll(in);
80   }
81
82   public Map<NTuple<Location>, FlowNode> getMapLocTupleToFlowNode() {
83     return mapLocTupleToFlowNode;
84   }
85
86   public void setMapLocTupleToFlowNode(Map<NTuple<Location>, FlowNode> in) {
87     this.mapLocTupleToFlowNode.putAll(in);
88   }
89
90   public void setNodeSet(Set<FlowNode> in) {
91     this.nodeSet.addAll(in);
92   }
93
94   public void setReturnNodeSet(Set<FlowNode> in) {
95     this.returnNodeSet.addAll(in);
96   }
97
98   public void setThisVarNode(FlowNode thisVarNode) {
99     this.thisVarNode = thisVarNode;
100   }
101
102   public Map<Descriptor, Integer> getMapParamDescToIdx() {
103     return mapParamDescToIdx;
104   }
105
106   public FlowNode createIntermediateNode() {
107     NTuple<Descriptor> tuple = new NTuple<Descriptor>();
108     Descriptor interDesc = new InterDescriptor(LocationInference.INTERLOC + interseed);
109     tuple.add(interDesc);
110     interseed++;
111
112     FlowNode newNode = new FlowNode(tuple);
113     newNode.setIntermediate(true);
114
115     mapDescTupleToInferNode.put(tuple, newNode);
116     nodeSet.add(newNode);
117
118     System.out.println("create new intermediate node= " + newNode);
119
120     return newNode;
121   }
122
123   private void setupMapIdxToDesc() {
124
125     Set<Descriptor> descSet = mapParamDescToIdx.keySet();
126     for (Iterator iterator = descSet.iterator(); iterator.hasNext();) {
127       Descriptor paramDesc = (Descriptor) iterator.next();
128       int idx = mapParamDescToIdx.get(paramDesc);
129       NTuple<Descriptor> descTuple = new NTuple<Descriptor>();
130       descTuple.add(paramDesc);
131       FlowNode paramNode = getFlowNode(descTuple);
132       mapIdxToFlowNode.put(idx, paramNode);
133       paramNode.setSkeleton(true);
134     }
135
136   }
137
138   public int getNumParameters() {
139     return mapIdxToFlowNode.keySet().size();
140   }
141
142   public FlowNode getParamFlowNode(int idx) {
143     return mapIdxToFlowNode.get(idx);
144   }
145
146   public Set<FlowNode> getNodeSet() {
147     return nodeSet;
148   }
149
150   public MethodDescriptor getMethodDescriptor() {
151     return md;
152   }
153
154   public boolean isParamDesc(Descriptor desc) {
155
156     if (mapParamDescToIdx.containsKey(desc)) {
157       int idx = mapParamDescToIdx.get(desc);
158       if (!md.isStatic() && idx == 0) {
159         return false;
160       }
161       return true;
162     }
163
164     return false;
165   }
166
167   public boolean hasEdge(NTuple<Descriptor> fromDescTuple, NTuple<Descriptor> toDescTuple) {
168
169     FlowNode fromNode = mapDescTupleToInferNode.get(fromDescTuple);
170     FlowNode toNode = mapDescTupleToInferNode.get(toDescTuple);
171
172     Set<FlowEdge> fromNodeOutEdgeSet = getOutEdgeSet(fromNode);
173     for (Iterator iterator = fromNodeOutEdgeSet.iterator(); iterator.hasNext();) {
174       FlowEdge flowEdge = (FlowEdge) iterator.next();
175       if (flowEdge.getDst().equals(toNode)) {
176         return true;
177       } else {
178         if (hasEdge(flowEdge.getDst().getDescTuple(), toDescTuple)) {
179           return true;
180         }
181       }
182     }
183
184     return false;
185   }
186
187   public Set<FlowEdge> getOutEdgeSet(FlowNode node) {
188     if (!mapFlowNodeToOutEdgeSet.containsKey(node)) {
189       mapFlowNodeToOutEdgeSet.put(node, new HashSet<FlowEdge>());
190     }
191     return mapFlowNodeToOutEdgeSet.get(node);
192   }
193
194   public void addValueFlowEdge(NTuple<Descriptor> fromDescTuple, NTuple<Descriptor> toDescTuple) {
195
196     FlowNode fromNode = getFlowNode(fromDescTuple);
197     FlowNode toNode = getFlowNode(toDescTuple);
198
199     System.out.println("create an edge from " + fromNode + " to " + toNode);
200
201     int fromTupleSize = fromDescTuple.size();
202     NTuple<Descriptor> curFromTuple = new NTuple<Descriptor>();
203     for (int i = 0; i < fromTupleSize; i++) {
204       Descriptor desc = fromDescTuple.get(i);
205       curFromTuple.add(desc);
206       int toTupleSize = toDescTuple.size();
207       NTuple<Descriptor> curToTuple = new NTuple<Descriptor>();
208       for (int k = 0; k < toTupleSize; k++) {
209         Descriptor toDesc = toDescTuple.get(k);
210         curToTuple.add(toDesc);
211         addFlowEdge(getFlowNode(curFromTuple), getFlowNode(curToTuple), fromDescTuple, toDescTuple);
212       }
213     }
214
215     // int fromTupleSize = fromDescTuple.size();
216     // NTuple<Descriptor> curTuple = new NTuple<Descriptor>();
217     // for (int i = 0; i < fromTupleSize; i++) {
218     // Descriptor desc = fromDescTuple.get(i);
219     // curTuple.add(desc);
220     // addFlowEdge(getFlowNode(curTuple), toNode, fromDescTuple, toDescTuple);
221     // }
222     //
223     // int toTupleSize = toDescTuple.size();
224     // curTuple = new NTuple<Descriptor>();
225     // for (int i = 0; i < toTupleSize; i++) {
226     // Descriptor desc = toDescTuple.get(i);
227     // curTuple.add(desc);
228     // addFlowEdge(fromNode, getFlowNode(curTuple), fromDescTuple, toDescTuple);
229     // }
230
231   }
232
233   private void addFlowEdge(FlowNode fromNode, FlowNode toNode, NTuple<Descriptor> initTuple,
234       NTuple<Descriptor> endTuple) {
235
236     FlowEdge edge = new FlowEdge(fromNode, toNode, initTuple, endTuple);
237     addOutEdge(fromNode, edge);
238
239     // System.out.println("add a new edge=" + edge);
240   }
241
242   private void addOutEdge(FlowNode fromNode, FlowEdge edge) {
243     if (!mapFlowNodeToOutEdgeSet.containsKey(fromNode)) {
244       mapFlowNodeToOutEdgeSet.put(fromNode, new HashSet<FlowEdge>());
245     }
246     mapFlowNodeToOutEdgeSet.get(fromNode).add(edge);
247   }
248
249   public FlowNode getFlowNode(NTuple<Descriptor> descTuple) {
250     if (!mapDescTupleToInferNode.containsKey(descTuple)) {
251       FlowNode node = createNewFlowNode(descTuple);
252       mapDescTupleToInferNode.put(descTuple, node);
253     }
254     return mapDescTupleToInferNode.get(descTuple);
255   }
256
257   public FlowNode getThisVarNode() {
258     return thisVarNode;
259   }
260
261   public FlowNode createNewFlowNode(NTuple<Descriptor> tuple) {
262
263     if (!mapDescTupleToInferNode.containsKey(tuple)) {
264       FlowNode node = new FlowNode(tuple);
265       mapDescTupleToInferNode.put(tuple, node);
266       nodeSet.add(node);
267
268       mapLocTupleToFlowNode.put(getLocationTuple(node), node);
269
270       if (tuple.size() > 1) {
271         NTuple<Descriptor> baseTuple = tuple.subList(0, tuple.size() - 1);
272         getFlowNode(baseTuple).addFieldNode(node);
273       }
274
275       // System.out.println("Creating new node=" + node);
276       return node;
277     } else {
278       return mapDescTupleToInferNode.get(tuple);
279     }
280
281   }
282
283   public void addReturnFlowNode(NTuple<Descriptor> tuple) {
284
285     if (!mapDescTupleToInferNode.containsKey(tuple)) {
286       createNewFlowNode(tuple);
287     }
288
289     FlowNode node = mapDescTupleToInferNode.get(tuple);
290     node.setReturn(true);
291
292     returnNodeSet.add(node);
293   }
294
295   public Set<FlowNode> getReturnNodeSet() {
296     return returnNodeSet;
297   }
298
299   public Set<FlowNode> getLocalReachFlowNodeSetFrom(FlowNode fn) {
300     Set<FlowNode> set = new HashSet<FlowNode>();
301     recurLocalReachFlowNodeSet(fn, set);
302     return set;
303   }
304
305   private void recurLocalReachFlowNodeSet(FlowNode fn, Set<FlowNode> visited) {
306
307     Set<FlowEdge> outEdgeSet = getOutEdgeSet(fn);
308     for (Iterator iterator = outEdgeSet.iterator(); iterator.hasNext();) {
309       FlowEdge edge = (FlowEdge) iterator.next();
310       FlowNode dstNode = edge.getDst();
311
312       if (!visited.contains(dstNode)) {
313         visited.add(dstNode);
314         recurLocalReachFlowNodeSet(dstNode, visited);
315       }
316     }
317
318   }
319
320   private void getReachFlowNodeSetFrom(FlowNode fn, Set<FlowNode> visited) {
321
322     Set<FlowEdge> outEdgeSet = getOutEdgeSet(fn);
323     for (Iterator iterator = outEdgeSet.iterator(); iterator.hasNext();) {
324       FlowEdge edge = (FlowEdge) iterator.next();
325
326       if (fn.equals(getFlowNode(edge.getInitTuple()))) {
327         FlowNode dstNode = getFlowNode(edge.getEndTuple());
328         if (!visited.contains(dstNode)) {
329           visited.add(dstNode);
330           getReachFlowNodeSetFrom(dstNode, visited);
331         }
332       }
333     }
334
335   }
336
337   public Set<FlowNode> getReachFlowNodeSetFrom(FlowNode fn) {
338     Set<FlowNode> set = new HashSet<FlowNode>();
339     getReachFlowNodeSetFrom(fn, set);
340     return set;
341   }
342
343   // private void getReachFlowNodeSetFrom(FlowNode fn, Set<FlowNode> visited) {
344   //
345   // for (Iterator iterator = fn.getOutEdgeSet().iterator();
346   // iterator.hasNext();) {
347   // FlowEdge edge = (FlowEdge) iterator.next();
348   //
349   // if (fn.equals(getFlowNode(edge.getInitTuple()))) {
350   //
351   // FlowNode dstNode = getFlowNode(edge.getEndTuple());
352   //
353   // if (!visited.contains(dstNode)) {
354   // visited.add(dstNode);
355   // getReachFlowNodeSetFrom(dstNode, visited);
356   // }
357   // }
358   // }
359   //
360   // }
361
362   public Set<NTuple<Location>> getReachableFlowTupleSet(Set<NTuple<Location>> visited, FlowNode fn) {
363
364     Set<FlowEdge> outEdgeSet = getOutEdgeSet(fn);
365
366     for (Iterator iterator = outEdgeSet.iterator(); iterator.hasNext();) {
367       FlowEdge edge = (FlowEdge) iterator.next();
368
369       if (fn.getDescTuple().equals(edge.getInitTuple())) {
370         FlowNode dstNode = getFlowNode(edge.getEndTuple());
371         NTuple<Location> dstTuple = getLocationTuple(dstNode);
372
373         if (!visited.contains(dstTuple)) {
374           visited.add(dstTuple);
375           visited.addAll(getReachableFlowTupleSet(visited, dstNode));
376         }
377
378       }
379     }
380     return visited;
381   }
382
383   public NTuple<Location> getLocationTuple(NTuple<Descriptor> descTuple) {
384     return getLocationTuple(getFlowNode(descTuple));
385   }
386
387   public NTuple<Location> getLocationTuple(FlowNode fn) {
388
389     if (!mapFlowNodeToLocTuple.containsKey(fn)) {
390       NTuple<Descriptor> descTuple = fn.getDescTuple();
391       NTuple<Location> locTuple = new NTuple<Location>();
392       ClassDescriptor cd = null;
393
394       Descriptor localDesc = fn.getDescTuple().get(0);
395
396       if (fn.isIntermediate()) {
397         Location interLoc = new Location(md, localDesc.getSymbol());
398         interLoc.setLocDescriptor(localDesc);
399         locTuple.add(interLoc);
400       } else if (localDesc.getSymbol().equals(LocationInference.TOPLOC)) {
401         Location topLoc = new Location(md, Location.TOP);
402         topLoc.setLocDescriptor(LocationInference.TOPDESC);
403         locTuple.add(topLoc);
404       } else if (localDesc.getSymbol().equals(LocationInference.GLOBALLOC)) {
405         Location globalLoc = new Location(md, LocationInference.GLOBALLOC);
406         globalLoc.setLocDescriptor(LocationInference.GLOBALDESC);
407         locTuple.add(globalLoc);
408       } else {
409         // normal case
410         for (int i = 0; i < descTuple.size(); i++) {
411           Descriptor curDesc = descTuple.get(i);
412           Location loc;
413           if (i == 0) {
414             loc = new Location(md, curDesc.getSymbol());
415             loc.setLocDescriptor(curDesc);
416             cd = ((VarDescriptor) curDesc).getType().getClassDesc();
417           } else {
418             loc = new Location(cd, curDesc.getSymbol());
419             loc.setLocDescriptor(curDesc);
420
421             if (curDesc instanceof FieldDescriptor) {
422               cd = ((FieldDescriptor) curDesc).getType().getClassDesc();
423             } else {
424               cd = ((LocationDescriptor) curDesc).getEnclosingClassDesc();
425             }
426
427           }
428           locTuple.add(loc);
429         }
430       }
431
432       mapFlowNodeToLocTuple.put(fn, locTuple);
433     }
434     return mapFlowNodeToLocTuple.get(fn);
435   }
436
437   public Set<FlowNode> getIncomingFlowNodeSet(FlowNode node) {
438     Set<FlowNode> set = new HashSet<FlowNode>();
439     getIncomingFlowNodeSet(node, set);
440     return set;
441   }
442
443   public void getIncomingFlowNodeSet(FlowNode node, Set<FlowNode> visited) {
444
445     for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) {
446       FlowNode curNode = (FlowNode) iterator.next();
447       Set<FlowEdge> edgeSet = getOutEdgeSet(curNode);
448
449       for (Iterator iterator2 = edgeSet.iterator(); iterator2.hasNext();) {
450         FlowEdge flowEdge = (FlowEdge) iterator2.next();
451
452         if (node.equals(getFlowNode(flowEdge.getEndTuple()))) {
453           FlowNode incomingNode = getFlowNode(flowEdge.getInitTuple());
454
455           if (!visited.contains(incomingNode)) {
456             visited.add(incomingNode);
457             getIncomingFlowNodeSet(incomingNode, visited);
458           }
459         }
460       }
461     }
462
463   }
464
465   public Set<NTuple<Location>> getIncomingFlowTupleSet(FlowNode fn) {
466
467     NTuple<Descriptor> dstTuple = fn.getDescTuple();
468
469     Set<NTuple<Location>> set = new HashSet<NTuple<Location>>();
470
471     ClassDescriptor cd = null;
472
473     for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) {
474       FlowNode node = (FlowNode) iterator.next();
475
476       Set<FlowEdge> edgeSet = getOutEdgeSet(node);
477       for (Iterator iterator2 = edgeSet.iterator(); iterator2.hasNext();) {
478         FlowEdge flowEdge = (FlowEdge) iterator2.next();
479         if (dstTuple.equals(flowEdge.getEndTuple())) {
480           NTuple<Descriptor> initTuple = flowEdge.getInitTuple();
481           NTuple<Location> locTuple = new NTuple<Location>();
482           for (int i = 0; i < initTuple.size(); i++) {
483             Descriptor d = initTuple.get(i);
484             Location loc;
485             if (i == 0) {
486               loc = new Location(md, d.getSymbol());
487               cd = ((VarDescriptor) d).getType().getClassDesc();
488             } else {
489               loc = new Location(cd, d.getSymbol());
490               cd = ((FieldDescriptor) d).getType().getClassDesc();
491             }
492             locTuple.add(loc);
493           }
494           set.add(locTuple);
495         }
496       }
497     }
498     return set;
499   }
500
501   public boolean isParameter(NTuple<Descriptor> tuple) {
502     // return true if a descriptor tuple is started with a parameter descriptor
503     Descriptor firstIdxDesc = tuple.get(0);
504     return mapParamDescToIdx.containsKey(firstIdxDesc);
505   }
506
507   public FlowGraph clone() {
508     FlowGraph clone = new FlowGraph(md, mapParamDescToIdx);
509
510     clone.setNodeSet(getNodeSet());
511     clone.setMapLocTupleToFlowNode(getMapLocTupleToFlowNode());
512     clone.setMapFlowNodeToLocTuple(getMapFlowNodeToLocTuple());
513     clone.setMapDescTupleToInferNode(getMapDescTupleToInferNode());
514
515     clone.setMapFlowNodeToOutEdgeSet(getMapFlowNodeToOutEdgeSet());
516     clone.setReturnNodeSet(getReturnNodeSet());
517     clone.setThisVarNode(getThisVarNode());
518
519     return clone;
520   }
521
522   public Map<FlowNode, NTuple<Location>> getMapFlowNodeToLocTuple() {
523     return mapFlowNodeToLocTuple;
524   }
525
526   public void setMapFlowNodeToLocTuple(Map<FlowNode, NTuple<Location>> in) {
527     this.mapFlowNodeToLocTuple.putAll(in);
528   }
529
530   public Map<FlowNode, Set<FlowEdge>> getMapFlowNodeToOutEdgeSet() {
531     return mapFlowNodeToOutEdgeSet;
532   }
533
534   public void setMapFlowNodeToOutEdgeSet(Map<FlowNode, Set<FlowEdge>> inMap) {
535     Set<FlowNode> keySet = inMap.keySet();
536     for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
537       FlowNode key = (FlowNode) iterator.next();
538       Set<FlowEdge> newEdgeSet = new HashSet<FlowEdge>();
539       newEdgeSet.addAll(inMap.get(key));
540       mapFlowNodeToOutEdgeSet.put(key, newEdgeSet);
541     }
542   }
543
544   private void drawEdges(FlowNode node, BufferedWriter bw, Set<FlowNode> addedNodeSet,
545       Set<FlowEdge> addedEdgeSet) throws IOException {
546
547     Set<FlowEdge> edgeSet = getOutEdgeSet(node);
548
549     for (Iterator<FlowEdge> iterator = edgeSet.iterator(); iterator.hasNext();) {
550       FlowEdge flowEdge = iterator.next();
551
552       FlowNode u = flowEdge.getSrc();
553       FlowNode v = flowEdge.getDst();
554
555       if (u.getDescTuple().equals(flowEdge.getInitTuple())
556           && v.getDescTuple().equals(flowEdge.getEndTuple())) {
557         // only draw an edge of the actual value flow
558
559         if (!addedEdgeSet.contains(flowEdge)) {
560
561           if (!addedNodeSet.contains(u)) {
562             drawNode(u, bw);
563             addedNodeSet.add(u);
564           }
565           if (!addedNodeSet.contains(v)) {
566             drawNode(v, bw);
567             addedNodeSet.add(v);
568           }
569
570           bw.write("" + u.getID() + " -> " + v.getID() + ";\n");
571           addedEdgeSet.add(flowEdge);
572         }
573       }
574
575     }
576
577   }
578
579   private void drawNode(FlowNode node, BufferedWriter bw) throws IOException {
580     bw.write(node.getID() + " [label=\"" + node.getPrettyID() + "\"]" + ";\n");
581   }
582
583   public void writeGraph() throws java.io.IOException {
584     writeGraph("");
585   }
586
587   public void writeGraph(String suffix) throws java.io.IOException {
588
589     String graphName = "flowgraph_" + md.toString() + suffix;
590     graphName = graphName.replaceAll("[\\W]", "");
591
592     BufferedWriter bw = new BufferedWriter(new FileWriter(graphName + ".dot"));
593     bw.write("digraph " + graphName + " {\n");
594     bw.write("compound=true;\n");
595
596     // then visit every flow node
597
598     Iterator<FlowNode> iter = nodeSet.iterator();
599
600     Set<FlowEdge> addedEdgeSet = new HashSet<FlowEdge>();
601     Set<FlowNode> addedNodeSet = new HashSet<FlowNode>();
602
603     while (iter.hasNext()) {
604       FlowNode node = iter.next();
605
606       if (node.getDescTuple().size() == 1) {
607         // here, we just care about the local variable
608         if (node.getFieldNodeSet().size() > 0) {
609           drawSubgraph(node, bw, addedEdgeSet);
610         }
611       }
612       drawEdges(node, bw, addedNodeSet, addedEdgeSet);
613
614     }
615
616     bw.write("}\n");
617     bw.close();
618
619   }
620
621   public boolean constainsNode(FlowNode node) {
622     return nodeSet.contains(node);
623   }
624
625   private void drawSubgraph(FlowNode node, BufferedWriter bw, Set<FlowEdge> addedSet)
626       throws IOException {
627
628     bw.write("subgraph cluster_" + node.getID() + "{\n");
629     bw.write("label=\"" + node.getPrettyID() + "\";\n");
630
631     Set<FlowNode> fieldNodeSet = node.getFieldNodeSet();
632     for (Iterator iterator = fieldNodeSet.iterator(); iterator.hasNext();) {
633       FlowNode fieldNode = (FlowNode) iterator.next();
634       if (fieldNode.getFieldNodeSet().size() > 0) {
635         drawSubgraph(fieldNode, bw, addedSet);
636       } else {
637         Descriptor desc = fieldNode.getDescTuple().getLastElement();
638         if (desc instanceof VarDescriptor) {
639           VarDescriptor varDesc = (VarDescriptor) desc;
640           if (varDesc.getType().isPrimitive()) {
641             bw.write(fieldNode.getID() + " [label=\"" + fieldNode.getPrettyID() + "\"];\n");
642           }
643         } else if (desc instanceof FieldDescriptor) {
644           FieldDescriptor fieldDesc = (FieldDescriptor) desc;
645           if (fieldDesc.getType().isPrimitive()) {
646             bw.write(fieldNode.getID() + " [label=\"" + fieldNode.getPrettyID() + "\"];\n");
647           }
648         }
649       }
650     }
651
652     bw.write("}\n");
653   }
654 }