-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctionDirectory.java
More file actions
37 lines (30 loc) · 1.02 KB
/
FunctionDirectory.java
File metadata and controls
37 lines (30 loc) · 1.02 KB
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
import java.util.*;
public class FunctionDirectory {
private Map<String, FunctionInfo> dir;
public String currentFunction = "global";
public FunctionDirectory() {
dir = new HashMap<>();
dir.put("global", new FunctionInfo("void"));
}
public boolean addFunction(String name, String returnType) {
if (dir.containsKey(name))
return false;
dir.put(name, new FunctionInfo(returnType));
return true;
}
public boolean addVariableToCurrent(String name, String type, int address) {
FunctionInfo func = dir.get(currentFunction);
if (func == null)
return false;
return func.addVariable(name, new VariableInfo(type, address, currentFunction));
}
public FunctionInfo getFunction(String name) {
return dir.get(name);
}
public void setCurrentFunction(String name) {
currentFunction = name;
}
public Set<String> getFunctionNames() {
return Collections.unmodifiableSet(dir.keySet());
}
}