-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLocalEnvironment.java
More file actions
32 lines (27 loc) · 915 Bytes
/
LocalEnvironment.java
File metadata and controls
32 lines (27 loc) · 915 Bytes
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
import java.util.HashMap;
import java.util.Map;
class LocalEnvironment {
public HashMap<String, String> vars = new HashMap<>(); // maps variable identifier to type
public String currentClass = "NONE";
public String retType = "Void";
public String methodName = "";
public LocalEnvironment() {
}
public LocalEnvironment(LocalEnvironment oldEnv) {
for (Map.Entry<String, String> entry : oldEnv.vars.entrySet()) {
this.vars.put(entry.getKey(), entry.getValue());
}
this.currentClass = oldEnv.currentClass;
this.retType = oldEnv.retType;
this.methodName = oldEnv.methodName;
}
public void extend(String name, String type) {
vars.put(name, type);
}
public boolean contains(String name) {
return vars.containsKey(name);
}
public String getType(String name) {
return vars.get(name);
}
}