|
1 |
| package edu.rice.cs.dynamicjava.sourcechecker; |
|
2 |
| |
|
3 |
| import java.util.LinkedList; |
|
4 |
| import java.util.List; |
|
5 |
| |
|
6 |
| import koala.dynamicjava.interpreter.NodeProperties; |
|
7 |
| import koala.dynamicjava.interpreter.error.ExecutionError; |
|
8 |
| import koala.dynamicjava.tree.*; |
|
9 |
| import edu.rice.cs.dynamicjava.Options; |
|
10 |
| import edu.rice.cs.dynamicjava.interpreter.*; |
|
11 |
| import edu.rice.cs.plt.collect.UnindexedRelation; |
|
12 |
| import edu.rice.cs.plt.collect.Relation; |
|
13 |
| import edu.rice.cs.plt.tuple.Pair; |
|
14 |
| |
|
15 |
| public class CompilationUnitChecker { |
|
16 |
| |
|
17 |
| |
|
18 |
| private final TypeContext _context; |
|
19 |
| private final Options _opt; |
|
20 |
| |
|
21 |
0
| public CompilationUnitChecker(TypeContext context, Options opt) {
|
|
22 |
0
| _context = context;
|
|
23 |
0
| _opt = opt;
|
|
24 |
| } |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
0
| public Relation<TypeDeclaration, ClassChecker> extractDeclarations(CompilationUnit u) throws InterpreterException {
|
|
31 |
0
| TypeContext c = _context;
|
|
32 |
0
| PackageDeclaration pkg = u.getPackage();
|
|
33 |
0
| if (pkg != null) { c = c.setPackage(pkg.getName()); }
|
|
34 |
0
| List<CheckerException> errors = new LinkedList<CheckerException>();
|
|
35 |
0
| for (ImportDeclaration imp : u.getImports()) {
|
|
36 |
0
| try { c = imp.acceptVisitor(new StatementChecker(c, _opt)); }
|
|
37 |
0
| catch (ExecutionError e) { errors.add(new CheckerException(e)); }
|
|
38 |
| } |
|
39 |
0
| if (!errors.isEmpty()) { throw new CompositeException(errors); }
|
|
40 |
| |
|
41 |
0
| Relation<TypeDeclaration, ClassChecker> results = UnindexedRelation.makeLinkedHashBased();
|
|
42 |
0
| ClassLoader loader = _context.getClassLoader();
|
|
43 |
0
| for (Node decl : u.getDeclarations()) {
|
|
44 |
0
| if (decl instanceof TypeDeclaration) {
|
|
45 |
0
| ClassChecker checker = new ClassChecker(NodeProperties.getDJClass(decl), loader, c, _opt);
|
|
46 |
0
| results.add(Pair.make((TypeDeclaration) decl, checker));
|
|
47 |
| } |
|
48 |
0
| else { throw new RuntimeException("Unrecognized compilation unit declaration"); }
|
|
49 |
| } |
|
50 |
0
| return results;
|
|
51 |
| } |
|
52 |
| |
|
53 |
| } |