switch to spaces only..
[IRC.git] / Robust / src / IR / Flat / FieldShadow.java
1 package IR.Flat;
2 import IR.*;
3 import java.util.*;
4
5 public class FieldShadow {
6   public static void handleFieldShadow(State state) {
7     Iterator classit=state.getClassSymbolTable().getDescriptorsIterator();
8     HashMap<ClassDescriptor, HashMap<String,Integer>> namemap=new HashMap<ClassDescriptor,HashMap<String, Integer>>();
9     while(classit.hasNext()) {
10       ClassDescriptor cd=(ClassDescriptor)classit.next();
11       handleClass(cd, state, namemap);
12     }
13   }
14
15   private static void handleClass(ClassDescriptor cd, State state, HashMap<ClassDescriptor, HashMap<String, Integer>> namemap) {
16     if (cd.getSuperDesc()!=null&&!namemap.containsKey(cd.getSuperDesc()))
17       handleClass(cd.getSuperDesc(), state, namemap);
18
19     Iterator it_sifs = cd.getSuperInterfaces();
20     while(it_sifs.hasNext()) {
21       ClassDescriptor sif = (ClassDescriptor)it_sifs.next();
22       if (!namemap.containsKey(sif))
23         handleClass(sif, state, namemap);
24     }
25
26     HashMap<String, Integer> supermap=cd.getSuperDesc()!=null?namemap.get(cd.getSuperDesc()):new HashMap<String, Integer>();
27
28     Vector<HashMap<String, Integer>> superifmaps = new Vector<HashMap<String, Integer>>();
29     it_sifs = cd.getSuperInterfaces();
30     while(it_sifs.hasNext()) {
31       ClassDescriptor sif = (ClassDescriptor)it_sifs.next();
32       superifmaps.addElement(namemap.get(sif));
33     }
34
35     HashMap<String, Integer> fieldmap=new HashMap<String, Integer>();
36     namemap.put(cd, fieldmap);
37
38     for(Iterator fieldit=cd.getFields(); fieldit.hasNext(); ) {
39       FieldDescriptor fd=(FieldDescriptor)fieldit.next();
40       if (supermap.containsKey(fd.getSymbol())) {
41         Integer oldint=supermap.get(fd.getSymbol());
42         int newint=oldint.intValue()+1;
43         fieldmap.put(fd.getSymbol(), new Integer(newint));
44         fd.changeSafeSymbol(newint);
45       } else {
46         // the fields in interfaces are defaultely static & final, so do not need to
47         // check them, they will always have the interface name as prefix
48         fieldmap.put(fd.getSymbol(), new Integer(0));
49       }
50     }
51   }
52 }