Skip to content
Snippets Groups Projects
Verified Commit 0cafd422 authored by Miles Vella's avatar Miles Vella
Browse files

Remove strict scope check vor assign substitutions: it broke double function assignments

see test
parent 6cf8f0c7
No related branches found
No related tags found
No related merge requests found
Pipeline #152328 passed
......@@ -48,7 +48,7 @@ public class MachineContext extends DepthFirstAdapter {
private AOperationsMachineClause operationMachineClause;
private AAssertionsMachineClause assertionsMachineClause;
private ArrayList<LinkedHashMap<String, Node>> contextTable;
private List<Map<String, Node>> contextTable;
protected final Hashtable<Node, Node> referencesTable;
......@@ -311,7 +311,7 @@ public class MachineContext extends DepthFirstAdapter {
pExpression.apply(this);
}
for (int i = contextTable.size() - 1; i >= 0; i--) {
LinkedHashMap<String, Node> currentScope = contextTable.get(i);
Map<String, Node> currentScope = contextTable.get(i);
if (currentScope.containsKey(name)) {
this.referencesTable.put(node, currentScope.get(name));
return;
......@@ -397,7 +397,7 @@ public class MachineContext extends DepthFirstAdapter {
private void putLocalVariableIntoCurrentScope(AIdentifierExpression node) throws ScopeException {
String name = Utils.getTIdentifierListAsString(node.getIdentifier());
LinkedHashMap<String, Node> currentScope = contextTable.get(contextTable.size() - 1);
Map<String, Node> currentScope = contextTable.get(contextTable.size() - 1);
if (currentScope.containsKey(name)) {
throw new ScopeException("Duplicate Identifier: " + name);
} else {
......@@ -409,7 +409,7 @@ public class MachineContext extends DepthFirstAdapter {
public void caseAIdentifierExpression(AIdentifierExpression node) {
String name = Utils.getTIdentifierListAsString(node.getIdentifier());
for (int i = contextTable.size() - 1; i >= 0; i--) {
LinkedHashMap<String, Node> currentScope = contextTable.get(i);
Map<String, Node> currentScope = contextTable.get(i);
if (currentScope.containsKey(name)) {
this.referencesTable.put(node, currentScope.get(name));
return;
......@@ -422,7 +422,7 @@ public class MachineContext extends DepthFirstAdapter {
public void caseAPrimedIdentifierExpression(APrimedIdentifierExpression node) {
String name = Utils.getTIdentifierListAsString(node.getIdentifier());
for (int i = contextTable.size() - 1; i >= 0; i--) {
LinkedHashMap<String, Node> currentScope = contextTable.get(i);
Map<String, Node> currentScope = contextTable.get(i);
if (currentScope.containsKey(name)) {
this.referencesTable.put(node, currentScope.get(name));
return;
......@@ -596,34 +596,8 @@ public class MachineContext extends DepthFirstAdapter {
@Override
public void caseAAssignSubstitution(AAssignSubstitution node) {
ArrayList<LinkedHashMap<String, Node>> temp = contextTable;
{
List<PExpression> copy = new ArrayList<>(node.getLhsExpression());
ArrayList<LinkedHashMap<String, Node>> varTable = new ArrayList<>();
varTable.add(variables);
for (PExpression e : copy) {
if (e instanceof AFunctionExpression) {
contextTable = varTable;
((AFunctionExpression) e).getIdentifier().apply(this);
// full context table
contextTable = temp;
for (Node n : ((AFunctionExpression) e).getParameters()) {
n.apply(this);
}
} else {
contextTable = temp; // TODO outputparameter + variables
e.apply(this);
}
}
}
{
contextTable = temp;
List<PExpression> copy = new ArrayList<>(node.getRhsExpressions());
for (PExpression e : copy) {
e.apply(this);
}
}
super.caseAAssignSubstitution(node);
// TODO: check if only writable variables are written to?
}
@Override
......
......@@ -4,6 +4,8 @@ import org.junit.Ignore;
import org.junit.Test;
import static de.tlc4b.util.TestUtil.checkMachine;
import static de.tlc4b.util.TestUtil.translate;
import de.tlc4b.exceptions.ScopeException;
public class ScopeTest {
......@@ -152,4 +154,14 @@ public class ScopeTest {
checkMachine(machine);
}
@Test
public void testDoubleFunctionAssign() throws Exception {
String machine = "MACHINE test\n"
+ "VARIABLES f\n"
+ "INVARIANT f : 1..3 +-> (1..3 +-> BOOL)\n"
+ "INITIALISATION f := {}\n"
+ "OPERATIONS put(x, y, value) = SELECT x : 1..3 & y : 1..3 & value : BOOL THEN f(x)(y) := value END\n"
+ "END";
translate(machine);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment