Skip to content
Snippets Groups Projects
Commit 90b00f59 authored by Nathan PERIER's avatar Nathan PERIER
Browse files

Added variable definitions to the context

parent dcff8851
No related branches found
No related tags found
No related merge requests found
package fr.insarennes.nperier.minichamo.parsing;
import fr.insarennes.nperier.minichamo.language.assignement.VariableDef;
import fr.insarennes.nperier.minichamo.language.typing.Type;
import java.util.HashMap;
......@@ -8,17 +9,20 @@ import java.util.Map;
public class Context {
private final Map<String, Type> userTypes;
private final Map<String, VariableDef> variables;
public Context() {
userTypes = new HashMap<>();
variables = new HashMap<>();
}
private Context(Map<String, Type> ut) {
private Context(Map<String, Type> ut, Map<String, VariableDef> vars) {
userTypes = new HashMap<>(ut);
variables = new HashMap<>(vars);
}
public Context duplicate() {
return new Context(userTypes);
return new Context(userTypes, variables);
}
public boolean hasUserType(String typename) {
......@@ -36,4 +40,19 @@ public class Context {
return userTypes.get(typename);
}
public boolean hasVariable(String varname) {
return variables.containsKey(varname);
}
public VariableDef getVariable(String varname) {
return variables.get(varname);
}
public void addVariable(VariableDef var) {
String name = var.getName();
if(!"()".equals(name) && !name.startsWith("_")) {
variables.put(name, var);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment