This commit was manufactured by cvs2svn to create tag 'buildscript'.
[IRC.git] /
1 package IR;
2 import java.util.*;
3
4 public class Virtual {
5     State state;
6     Hashtable methodnumber;
7     Hashtable classmethodcount;
8       
9     public int getMethodNumber(MethodDescriptor md) {
10         return ((Integer)methodnumber.get(md)).intValue();
11     }
12
13     public int getMethodCount(ClassDescriptor md) {
14         return ((Integer)classmethodcount.get(md)).intValue();
15     }
16
17     public Virtual(State state) {
18         this.state=state;
19         methodnumber=new Hashtable();
20         classmethodcount=new Hashtable();
21         doAnalysis();
22     }
23
24     private void doAnalysis() {
25         Iterator classit=state.getClassSymbolTable().getDescriptorsIterator();
26         while(classit.hasNext()) {
27             ClassDescriptor cd=(ClassDescriptor)classit.next();
28             numberMethods(cd);
29         }
30     }
31
32     private int numberMethods(ClassDescriptor cd) {
33         if (classmethodcount.containsKey(cd))
34             return ((Integer)classmethodcount.get(cd)).intValue();
35         ClassDescriptor superdesc=cd.getSuperDesc();
36         int start=0;
37         if (superdesc!=null)
38             start=numberMethods(superdesc);
39         for(Iterator it=cd.getMethods();it.hasNext();) {
40             MethodDescriptor md=(MethodDescriptor)it.next();
41             if (md.isStatic()||md.getReturnType()==null)
42                 continue;
43             if (superdesc!=null) {
44                 Set possiblematches=superdesc.getMethodTable().getSet(md.getSymbol());
45                 boolean foundmatch=false;
46                 for(Iterator matchit=possiblematches.iterator();matchit.hasNext();) {
47                     MethodDescriptor matchmd=(MethodDescriptor)matchit.next();
48                     if (md.matches(matchmd)) {
49                         int num=((Integer)methodnumber.get(matchmd)).intValue();
50                         methodnumber.put(md, new Integer(num));
51                         foundmatch=true;
52                         break;
53                     }
54                 }
55                 if (!foundmatch)
56                     methodnumber.put(md, new Integer(start++));
57             } else {
58                 methodnumber.put(md, new Integer(start++));
59             }
60         }
61         classmethodcount.put(cd, new Integer(start));
62         return start;
63     }
64 }
65