-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.java
executable file
·98 lines (75 loc) · 2.54 KB
/
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import syntaxtree.*;
import java.io.*;
import java.util.LinkedHashMap;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
class OffsetMapData {
Integer offset;
String className;
OffsetMapData(Integer offset, String className) {
this.offset = offset;
this.className = className;
}
}
class OffsetMaps { // Essentially a Pair class
public String className;
public Map<String,OffsetMapData> variableOffsets;
public Map<String,OffsetMapData> methodOffsets;
public int totalVarOffset;
public int totalMethodOffset;
OffsetMaps(String className)
{
this.variableOffsets = new LinkedHashMap<String,OffsetMapData>();
this.methodOffsets = new LinkedHashMap<String,OffsetMapData>();
this.totalMethodOffset = 0;
this.totalVarOffset = 0;
this.className = className;
}
}
class Main {
public static void main (String [] args){
if(args.length == 0){
System.err.println("Usage: java Main [options] <inputFile1> <inputFile2> ... <inputFileN>\nUse --help for more info.");
System.exit(1);
}
FileInputStream fis = null;
for(int i = 0; i < args.length; i++ ) {
Map<String, Map<String, List<Argument>>> classToMethods = new HashMap<String, Map<String, List<Argument>>>();
Map<String, Map<String, String>> scopeToVars = new HashMap<String, Map<String, String>>();
Map<String, String> inheritanceChain = new HashMap<String, String>();
Map<String, OffsetMaps> classToOffsetMap = new LinkedHashMap<String, OffsetMaps>();
boolean found_error = false;
try{
System.out.println("\nChecking file: " + args[i]);
fis = new FileInputStream(args[i]);
MiniJavaParser parser = new MiniJavaParser(fis);
MainVisitor mainVis = new MainVisitor(classToMethods, scopeToVars, inheritanceChain, classToOffsetMap);
ClassDefVisitor classDefVis = new ClassDefVisitor(classToMethods, scopeToVars, inheritanceChain);
Goal root = parser.Goal();
root.accept(classDefVis, null);
root.accept(mainVis, null);
IntermediateCodeVisitor intermediateCodeVis = new IntermediateCodeVisitor(args[i], classToOffsetMap, scopeToVars, inheritanceChain, classToMethods);
root.accept(intermediateCodeVis, null);
//System.out.println("\n");
}
catch(Exception ex) {
System.out.println("Exception Encountered in file: " + args[i] + "\n\t" + ex + "\n");
found_error = true;
}
finally{
if(found_error)
System.out.println();
try{
if(fis != null)
{
fis.close();
}
}
catch(IOException ex){
System.err.println("\t" + ex.getMessage());
}
}
}
}
}