116aace16f48896dbbba2b56151338d54b84b2c9
[IRC.git] / Robust / src / Analysis / SSJava / LocationInference.java
1 package Analysis.SSJava;
2
3 import java.util.ArrayList;
4 import java.util.Collections;
5 import java.util.Comparator;
6 import java.util.List;
7
8 import IR.ClassDescriptor;
9 import IR.MethodDescriptor;
10 import IR.State;
11 import IR.SymbolTable;
12 import IR.VarDescriptor;
13 import IR.Tree.BlockNode;
14 import IR.Tree.BlockStatementNode;
15 import IR.Tree.DeclarationNode;
16 import IR.Tree.Kind;
17
18 public class LocationInference {
19
20   State state;
21   SSJavaAnalysis ssjava;
22
23   List<ClassDescriptor> toanalyzeList;
24   List<MethodDescriptor> toanalyzeMethodList;
25
26   public LocationInference(SSJavaAnalysis ssjava, State state) {
27     this.ssjava = ssjava;
28     this.state = state;
29     this.toanalyzeList = new ArrayList<ClassDescriptor>();
30     this.toanalyzeMethodList = new ArrayList<MethodDescriptor>();
31   }
32
33   public void setupToAnalyze() {
34     SymbolTable classtable = state.getClassSymbolTable();
35     toanalyzeList.clear();
36     toanalyzeList.addAll(classtable.getValueSet());
37     Collections.sort(toanalyzeList, new Comparator<ClassDescriptor>() {
38       public int compare(ClassDescriptor o1, ClassDescriptor o2) {
39         return o1.getClassName().compareToIgnoreCase(o2.getClassName());
40       }
41     });
42   }
43
44   public void setupToAnalazeMethod(ClassDescriptor cd) {
45
46     SymbolTable methodtable = cd.getMethodTable();
47     toanalyzeMethodList.clear();
48     toanalyzeMethodList.addAll(methodtable.getValueSet());
49     Collections.sort(toanalyzeMethodList, new Comparator<MethodDescriptor>() {
50       public int compare(MethodDescriptor o1, MethodDescriptor o2) {
51         return o1.getSymbol().compareToIgnoreCase(o2.getSymbol());
52       }
53     });
54   }
55
56   public boolean toAnalyzeMethodIsEmpty() {
57     return toanalyzeMethodList.isEmpty();
58   }
59
60   public boolean toAnalyzeIsEmpty() {
61     return toanalyzeList.isEmpty();
62   }
63
64   public ClassDescriptor toAnalyzeNext() {
65     return toanalyzeList.remove(0);
66   }
67
68   public MethodDescriptor toAnalyzeMethodNext() {
69     return toanalyzeMethodList.remove(0);
70   }
71
72   public void inference() {
73
74     setupToAnalyze();
75
76     while (!toAnalyzeIsEmpty()) {
77       ClassDescriptor cd = toAnalyzeNext();
78
79       setupToAnalazeMethod(cd);
80       while (!toAnalyzeMethodIsEmpty()) {
81         MethodDescriptor md = toAnalyzeMethodNext();
82         if (ssjava.needTobeAnnotated(md)) {
83           if (state.SSJAVADEBUG) {
84             System.out.println("SSJAVA: Location Inference: " + md);
85           }
86           analyzeMethodBody(cd, md, null);
87         }
88       }
89     }
90
91   }
92
93   private void analyzeMethodBody(ClassDescriptor cd, MethodDescriptor md,
94       CompositeLocation constraints) {
95     BlockNode bn = state.getMethodBody(md);
96     analyzeBlockNode(md, md.getParameterTable(), bn);
97   }
98
99   private CompositeLocation analyzeBlockNode(MethodDescriptor md, SymbolTable nametable,
100       BlockNode bn) {
101
102     bn.getVarTable().setParent(nametable);
103     for (int i = 0; i < bn.size(); i++) {
104       BlockStatementNode bsn = bn.get(i);
105       analyzeBlockStatementNode(md, bn.getVarTable(), bsn);
106     }
107     return new CompositeLocation();
108
109   }
110
111   private void analyzeBlockStatementNode(MethodDescriptor md, SymbolTable nametable,
112       BlockStatementNode bsn) {
113
114     switch (bsn.kind()) {
115     case Kind.BlockExpressionNode:
116       // checkBlockExpressionNode(md,(BlockExpressionNode)bsn);
117       break;
118
119     case Kind.DeclarationNode:
120       analyzeDeclarationNode(md, nametable, (DeclarationNode) bsn);
121       break;
122
123     case Kind.IfStatementNode:
124       break;
125
126     case Kind.LoopNode:
127       break;
128
129     case Kind.ReturnNode:
130       break;
131
132     case Kind.SubBlockNode:
133       break;
134
135     case Kind.ContinueBreakNode:
136       break;
137
138     case Kind.SwitchStatementNode:
139       break;
140
141     }
142   }
143
144   private void analyzeDeclarationNode(MethodDescriptor md, SymbolTable nametable, DeclarationNode dn) {
145
146     VarDescriptor vd = dn.getVarDescriptor();
147
148   }
149
150 }