bug fix. analyzeMethod of buildgraph has wrong FlatMethod parameter.
[IRC.git] / Robust / src / Analysis / CallGraph / JavaCallGraph.java
1 package Analysis.CallGraph;
2 import IR.State;
3 import IR.Flat.FlatMethod;
4 import IR.Flat.FlatNode;
5 import IR.Flat.FlatCall;
6 import IR.Flat.FKind;
7 import IR.Descriptor;
8 import IR.ClassDescriptor;
9 import IR.MethodDescriptor;
10 import IR.TaskDescriptor;
11 import IR.TypeDescriptor;
12 import IR.TypeUtil;
13 import java.util.*;
14 import java.io.*;
15
16 public class JavaCallGraph extends CallGraph {
17   TypeUtil tu;
18   public JavaCallGraph(State state, TypeUtil tu) {
19     this.state=state;
20     mapVirtual2ImplementationSet = new Hashtable();
21     mapCaller2CalleeSet          = new Hashtable();
22     mapCallee2CallerSet          = new Hashtable();
23     this.tu=tu;
24     buildVirtualMap();
25     buildGraph();
26   }
27
28   //Work our way down from main
29   private void buildGraph() {
30     MethodDescriptor main=tu.getMain();
31     HashSet tovisit=new HashSet();
32     HashSet discovered=new HashSet();
33     tovisit.add(main);
34     discovered.add(main);
35     while(!tovisit.isEmpty()) {
36       MethodDescriptor md=(MethodDescriptor)tovisit.iterator().next();
37       tovisit.remove(md);
38       FlatMethod fm=state.getMethodFlat(md);
39       analyzeMethod(md, fm);
40       for(Iterator<FlatNode> fnit=fm.getNodeSet().iterator();fnit.hasNext();) {
41         FlatNode fn=fnit.next();
42         if (fn.kind()==FKind.FlatCall) {
43           FlatCall fcall=(FlatCall)fn;
44           Set callees=fcall.getThis()==null?getMethods(fcall.getMethod()):getMethods(fcall.getMethod(),fcall.getThis().getType());
45           for(Iterator mdit=callees.iterator();mdit.hasNext();) {
46             MethodDescriptor callee=(MethodDescriptor)mdit.next();
47             if (!discovered.contains(callee)) {
48               discovered.add(callee);
49               tovisit.add(callee);
50             }
51           }
52         }
53       }
54     }
55   }
56 }