-
Notifications
You must be signed in to change notification settings - Fork 0
/
VarBlock.java
36 lines (30 loc) · 1023 Bytes
/
VarBlock.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
import java.util.LinkedHashMap;
public class VarBlock {
LinkedHashMap<String, iObjectVariable> vars = new LinkedHashMap<>();
LinkedHashMap<Scope, VarBlock> childs = new LinkedHashMap<>();
VarBlock parent;
Scope scope;
public VarBlock(VarBlock parent, Scope scope) {
this.parent = parent;
this.scope = scope;
}
public VarBlock getChild(Scope scope) {
return childs.computeIfAbsent(scope, k -> new VarBlock(this, k));
}
public iObjectVariable declare(iClass type, String name) {
iObjectVariable obj = new iObjectVariable(scope, type, name);
vars.put(name, obj);
return obj;
}
public iObjectVariable get(String n) {
iObjectVariable v = vars.get(n);
scope.log("[varblock] getVar %s=%s", n, v);
if (v == null && parent != null)
v = parent.get(n);
return v;
}
@Override
public String toString() {
return "VarBlock" + vars;
}
}