Skip to content
Snippets Groups Projects
Commit 468a4d4c authored by hansen's avatar hansen
Browse files

external definitions files are now supported

parent a4f6b584
Branches
Tags
No related merge requests found
Showing
with 306 additions and 123 deletions
...@@ -5,6 +5,7 @@ import java.io.IOException; ...@@ -5,6 +5,7 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import de.be4.classicalb.core.parser.BParser; import de.be4.classicalb.core.parser.BParser;
import de.be4.classicalb.core.parser.analysis.prolog.RecursiveMachineLoader;
import de.be4.classicalb.core.parser.exceptions.BException; import de.be4.classicalb.core.parser.exceptions.BException;
import de.be4.classicalb.core.parser.node.APredicateParseUnit; import de.be4.classicalb.core.parser.node.APredicateParseUnit;
import de.be4.classicalb.core.parser.node.PPredicate; import de.be4.classicalb.core.parser.node.PPredicate;
...@@ -68,6 +69,10 @@ public class Translator { ...@@ -68,6 +69,10 @@ public class Translator {
BParser parser = new BParser(machineName); BParser parser = new BParser(machineName);
start = parser.parseFile(machineFile, false); start = parser.parseFile(machineFile, false);
// Definitions of definitions files are injected in the ast of the main machine
final RecursiveMachineLoader rml = new RecursiveMachineLoader(
machineFile.getParent(), parser.getContentProvider());
rml.loadAllMachines(machineFile, start, null, parser.getDefinitions(), parser.getPragmas());
if(constantSetup!= null){ if(constantSetup!= null){
BParser con = new BParser(); BParser con = new BParser();
...@@ -93,10 +98,10 @@ public class Translator { ...@@ -93,10 +98,10 @@ public class Translator {
} }
public void translate() { public void translate() {
new DefinitionsEliminator(start);
new NotSupportedConstructs(start); new NotSupportedConstructs(start);
new DefinitionsEliminator(start);
MachineContext machineContext = new MachineContext(machineName, start, MachineContext machineContext = new MachineContext(machineName, start,
ltlFormula, constantsSetup); ltlFormula, constantsSetup);
this.machineName = machineContext.getMachineName(); this.machineName = machineContext.getMachineName();
......
...@@ -101,7 +101,6 @@ public class MachineContext extends DepthFirstAdapter { ...@@ -101,7 +101,6 @@ public class MachineContext extends DepthFirstAdapter {
private AConstantsMachineClause constantsMachineClause; private AConstantsMachineClause constantsMachineClause;
private ADefinitionsMachineClause definitionMachineClause; private ADefinitionsMachineClause definitionMachineClause;
private APropertiesMachineClause propertiesMachineClause; private APropertiesMachineClause propertiesMachineClause;
private AVariablesMachineClause variablesMachineClause;
private AInvariantMachineClause invariantMachineClause; private AInvariantMachineClause invariantMachineClause;
private AInitialisationMachineClause initialisationMachineClause; private AInitialisationMachineClause initialisationMachineClause;
private AOperationsMachineClause operationMachineClause; private AOperationsMachineClause operationMachineClause;
...@@ -437,8 +436,6 @@ public class MachineContext extends DepthFirstAdapter { ...@@ -437,8 +436,6 @@ public class MachineContext extends DepthFirstAdapter {
} }
} }
// TODO import, include, ..
@Override @Override
public void caseASetsContextClause(ASetsContextClause node) { public void caseASetsContextClause(ASetsContextClause node) {
this.setsMachineClause = node; this.setsMachineClause = node;
...@@ -490,7 +487,19 @@ public class MachineContext extends DepthFirstAdapter { ...@@ -490,7 +487,19 @@ public class MachineContext extends DepthFirstAdapter {
@Override @Override
public void caseAVariablesMachineClause(AVariablesMachineClause node) { public void caseAVariablesMachineClause(AVariablesMachineClause node) {
this.variablesMachineClause = node; List<PExpression> copy = new ArrayList<PExpression>(
node.getIdentifiers());
for (PExpression e : copy) {
AIdentifierExpression v = (AIdentifierExpression) e;
String name = Utils.getIdentifierAsString(v.getIdentifier());
exist(v.getIdentifier());
variables.put(name, v);
}
}
@Override
public void caseAConcreteVariablesMachineClause(
AConcreteVariablesMachineClause node) {
List<PExpression> copy = new ArrayList<PExpression>( List<PExpression> copy = new ArrayList<PExpression>(
node.getIdentifiers()); node.getIdentifiers());
for (PExpression e : copy) { for (PExpression e : copy) {
...@@ -724,8 +733,6 @@ public class MachineContext extends DepthFirstAdapter { ...@@ -724,8 +733,6 @@ public class MachineContext extends DepthFirstAdapter {
@Override @Override
public void caseAAssignSubstitution(AAssignSubstitution node) { public void caseAAssignSubstitution(AAssignSubstitution node) {
// TODO maybe give better feedback to the user, e.g. cannot assign a
// value to constant 'c'
ArrayList<LinkedHashMap<String, Node>> temp = contextTable; ArrayList<LinkedHashMap<String, Node>> temp = contextTable;
{ {
List<PExpression> copy = new ArrayList<PExpression>( List<PExpression> copy = new ArrayList<PExpression>(
...@@ -788,10 +795,7 @@ public class MachineContext extends DepthFirstAdapter { ...@@ -788,10 +795,7 @@ public class MachineContext extends DepthFirstAdapter {
if (node.getName() != null) { if (node.getName() != null) {
AIdentifierExpression op = (AIdentifierExpression) node.getName(); AIdentifierExpression op = (AIdentifierExpression) node.getName();
String name = Utils.getIdentifierAsString(op.getIdentifier()); String name = Utils.getIdentifierAsString(op.getIdentifier());
Node o = operations.get(name); // TODO operation Node o = operations.get(name);
// of an
// external
// machine
if (o != null) { if (o != null) {
this.referencesTable.put(op, o); this.referencesTable.put(op, o);
} else { } else {
...@@ -1060,10 +1064,6 @@ public class MachineContext extends DepthFirstAdapter { ...@@ -1060,10 +1064,6 @@ public class MachineContext extends DepthFirstAdapter {
this.propertiesMachineClause = propertiesMachineClause; this.propertiesMachineClause = propertiesMachineClause;
} }
public AVariablesMachineClause getVariablesMachineClause() {
return variablesMachineClause;
}
public AInvariantMachineClause getInvariantMachineClause() { public AInvariantMachineClause getInvariantMachineClause() {
return invariantMachineClause; return invariantMachineClause;
} }
......
...@@ -2,7 +2,14 @@ package de.tlc4b.analysis; ...@@ -2,7 +2,14 @@ package de.tlc4b.analysis;
import de.be4.classicalb.core.parser.analysis.DepthFirstAdapter; import de.be4.classicalb.core.parser.analysis.DepthFirstAdapter;
import de.be4.classicalb.core.parser.node.ACaseSubstitution; import de.be4.classicalb.core.parser.node.ACaseSubstitution;
import de.be4.classicalb.core.parser.node.AExtendsMachineClause;
import de.be4.classicalb.core.parser.node.AImportsMachineClause;
import de.be4.classicalb.core.parser.node.AIncludesMachineClause;
import de.be4.classicalb.core.parser.node.APromotesMachineClause;
import de.be4.classicalb.core.parser.node.ARefinesModelClause;
import de.be4.classicalb.core.parser.node.ASeesModelClause;
import de.be4.classicalb.core.parser.node.ASequenceSubstitution; import de.be4.classicalb.core.parser.node.ASequenceSubstitution;
import de.be4.classicalb.core.parser.node.AUsesMachineClause;
import de.be4.classicalb.core.parser.node.AWhileSubstitution; import de.be4.classicalb.core.parser.node.AWhileSubstitution;
import de.be4.classicalb.core.parser.node.Start; import de.be4.classicalb.core.parser.node.Start;
import de.tlc4b.exceptions.NotSupportedException; import de.tlc4b.exceptions.NotSupportedException;
...@@ -13,20 +20,54 @@ public class NotSupportedConstructs extends DepthFirstAdapter{ ...@@ -13,20 +20,54 @@ public class NotSupportedConstructs extends DepthFirstAdapter{
start.apply(this); start.apply(this);
} }
public void inAWhileSubstitution(AWhileSubstitution node) public void inARefinesModelClause(ARefinesModelClause node) {
{ throw new NotSupportedException(
throw new NotSupportedException("While substitutions are currently not supported."); "Refines clause is currently not supported.");
} }
public void inACaseSubstitution(ACaseSubstitution node) public void inAUsesMachineClause(AUsesMachineClause node) {
{ throw new NotSupportedException(
throw new NotSupportedException("Case substitutions are currently not supported."); "USES clause is currently not supported.");
} }
public void inASequenceSubstitution(ASequenceSubstitution node) public void inAPromotesMachineClause(APromotesMachineClause node) {
{ throw new NotSupportedException(
throw new NotSupportedException("Sequence substitutions ';' are currently not supported."); "Promotes clause is currently not supported.");
} }
public void inASeesModelClause(ASeesModelClause node) {
throw new NotSupportedException(
"Sees clause is currently not supported.");
}
public void inAIncludesMachineClause(AIncludesMachineClause node) {
throw new NotSupportedException(
"INCLUDES clause is currently not supported.");
}
public void inAExtendsMachineClause(AExtendsMachineClause node) {
throw new NotSupportedException(
"EXTENDS clause is currently not supported.");
}
public void inAImportsMachineClause(AImportsMachineClause node) {
throw new NotSupportedException(
"IMPORTS clause is currently not supported.");
}
public void inAWhileSubstitution(AWhileSubstitution node) {
throw new NotSupportedException(
"While substitutions are currently not supported.");
}
public void inACaseSubstitution(ACaseSubstitution node) {
throw new NotSupportedException(
"Case substitutions are currently not supported.");
}
public void inASequenceSubstitution(ASequenceSubstitution node) {
throw new NotSupportedException(
"Sequence substitutions ';' are currently not supported.");
}
} }
...@@ -5,12 +5,14 @@ import java.util.Hashtable; ...@@ -5,12 +5,14 @@ import java.util.Hashtable;
import de.be4.classicalb.core.parser.analysis.DepthFirstAdapter; import de.be4.classicalb.core.parser.analysis.DepthFirstAdapter;
import de.be4.classicalb.core.parser.node.AConvertBoolExpression; import de.be4.classicalb.core.parser.node.AConvertBoolExpression;
import de.be4.classicalb.core.parser.node.ADomainExpression;
import de.be4.classicalb.core.parser.node.AMinusOrSetSubtractExpression; import de.be4.classicalb.core.parser.node.AMinusOrSetSubtractExpression;
import de.be4.classicalb.core.parser.node.AMultOrCartExpression; import de.be4.classicalb.core.parser.node.AMultOrCartExpression;
import de.be4.classicalb.core.parser.node.Node; import de.be4.classicalb.core.parser.node.Node;
import de.be4.classicalb.core.parser.node.Start; import de.be4.classicalb.core.parser.node.Start;
import de.tlc4b.analysis.typerestriction.TypeRestrictor; import de.tlc4b.analysis.typerestriction.TypeRestrictor;
import de.tlc4b.btypes.BType; import de.tlc4b.btypes.BType;
import de.tlc4b.btypes.FunctionType;
import de.tlc4b.btypes.IntegerType; import de.tlc4b.btypes.IntegerType;
public class PrecedenceCollector extends DepthFirstAdapter { public class PrecedenceCollector extends DepthFirstAdapter {
...@@ -58,7 +60,9 @@ public class PrecedenceCollector extends DepthFirstAdapter { ...@@ -58,7 +60,9 @@ public class PrecedenceCollector extends DepthFirstAdapter {
put("AAddExpression", 10, 10, true); put("AAddExpression", 10, 10, true);
put("AModuloExpression", 10, 11, true); put("AModuloExpression", 10, 11, true);
put("AUnaryMinusExpression", 12, 12, false);
put("AConcatExpression", 13, 13, true); put("AConcatExpression", 13, 13, true);
put("ADivExpression", 13, 13, false);
} }
...@@ -144,6 +148,25 @@ public class PrecedenceCollector extends DepthFirstAdapter { ...@@ -144,6 +148,25 @@ public class PrecedenceCollector extends DepthFirstAdapter {
} }
} }
@Override
public void inADomainExpression(ADomainExpression node) {
BType type = typechecker.getType(node.getExpression());
Precedence p;
if (type instanceof FunctionType) {
// Function
p = new Precedence("ADomainExpression", 9, 9, false);
precedenceTable.put(node, p);
Precedence parent = precedenceTable.get(node.parent());
if (Precedence.makeBrackets(p, parent)) {
brackets.add(node);
}
}
}
@Override @Override
public void inAMinusOrSetSubtractExpression( public void inAMinusOrSetSubtractExpression(
AMinusOrSetSubtractExpression node) { AMinusOrSetSubtractExpression node) {
......
...@@ -10,6 +10,7 @@ import java.util.Map.Entry; ...@@ -10,6 +10,7 @@ import java.util.Map.Entry;
import de.be4.classicalb.core.parser.Utils; import de.be4.classicalb.core.parser.Utils;
import de.be4.classicalb.core.parser.analysis.DepthFirstAdapter; import de.be4.classicalb.core.parser.analysis.DepthFirstAdapter;
import de.be4.classicalb.core.parser.node.AAnySubstitution;
import de.be4.classicalb.core.parser.node.AComprehensionSetExpression; import de.be4.classicalb.core.parser.node.AComprehensionSetExpression;
import de.be4.classicalb.core.parser.node.ADefinitionsMachineClause; import de.be4.classicalb.core.parser.node.ADefinitionsMachineClause;
import de.be4.classicalb.core.parser.node.AExistsPredicate; import de.be4.classicalb.core.parser.node.AExistsPredicate;
...@@ -19,11 +20,13 @@ import de.be4.classicalb.core.parser.node.AGeneralProductExpression; ...@@ -19,11 +20,13 @@ import de.be4.classicalb.core.parser.node.AGeneralProductExpression;
import de.be4.classicalb.core.parser.node.AGeneralSumExpression; import de.be4.classicalb.core.parser.node.AGeneralSumExpression;
import de.be4.classicalb.core.parser.node.AIdentifierExpression; import de.be4.classicalb.core.parser.node.AIdentifierExpression;
import de.be4.classicalb.core.parser.node.ALambdaExpression; import de.be4.classicalb.core.parser.node.ALambdaExpression;
import de.be4.classicalb.core.parser.node.ALetSubstitution;
import de.be4.classicalb.core.parser.node.AOperation; import de.be4.classicalb.core.parser.node.AOperation;
import de.be4.classicalb.core.parser.node.APredicateDefinitionDefinition; import de.be4.classicalb.core.parser.node.APredicateDefinitionDefinition;
import de.be4.classicalb.core.parser.node.AQuantifiedIntersectionExpression; import de.be4.classicalb.core.parser.node.AQuantifiedIntersectionExpression;
import de.be4.classicalb.core.parser.node.AQuantifiedUnionExpression; import de.be4.classicalb.core.parser.node.AQuantifiedUnionExpression;
import de.be4.classicalb.core.parser.node.ASubstitutionDefinitionDefinition; import de.be4.classicalb.core.parser.node.ASubstitutionDefinitionDefinition;
import de.be4.classicalb.core.parser.node.AVarSubstitution;
import de.be4.classicalb.core.parser.node.Node; import de.be4.classicalb.core.parser.node.Node;
import de.be4.classicalb.core.parser.node.PDefinition; import de.be4.classicalb.core.parser.node.PDefinition;
import de.be4.classicalb.core.parser.node.PExpression; import de.be4.classicalb.core.parser.node.PExpression;
...@@ -341,6 +344,52 @@ public class Renamer extends DepthFirstAdapter { ...@@ -341,6 +344,52 @@ public class Renamer extends DepthFirstAdapter {
localContexts.add(context); localContexts.add(context);
} }
@Override
public void caseAAnySubstitution(AAnySubstitution node) {
List<PExpression> list = new ArrayList<PExpression>();
list.addAll(node.getIdentifiers());
evalBoundedVariables(node, list);
List<PExpression> copy = new ArrayList<PExpression>(
node.getIdentifiers());
for (PExpression e : copy) {
e.apply(this);
}
node.getWhere().apply(this);
node.getThen().apply(this);
removeLastContext();
}
@Override
public void caseALetSubstitution(ALetSubstitution node) {
List<PExpression> list = new ArrayList<PExpression>();
list.addAll(node.getIdentifiers());
evalBoundedVariables(node, list);
List<PExpression> copy = new ArrayList<PExpression>(
node.getIdentifiers());
for (PExpression e : copy) {
e.apply(this);
}
node.getPredicate().apply(this);
node.getSubstitution().apply(this);
removeLastContext();
}
@Override
public void caseAVarSubstitution(AVarSubstitution node) {
List<PExpression> list = new ArrayList<PExpression>();
list.addAll(node.getIdentifiers());
evalBoundedVariables(node, list);
List<PExpression> copy = new ArrayList<PExpression>(
node.getIdentifiers());
for (PExpression e : copy) {
e.apply(this);
}
node.getSubstitution().apply(this);
removeLastContext();
}
public void removeLastContext() { public void removeLastContext() {
localContexts.remove(localContexts.size() - 1); localContexts.remove(localContexts.size() - 1);
} }
......
...@@ -143,6 +143,8 @@ public final class StandardMadules { ...@@ -143,6 +143,8 @@ public final class StandardMadules {
public static final String REL_SEQUENCE_SIZE = "RelSeqSize"; public static final String REL_SEQUENCE_SIZE = "RelSeqSize";
public static final String IS_REL_SEQUENCE = "isRelSeq"; public static final String IS_REL_SEQUENCE = "isRelSeq";
public static final String REL_SEQUENCE_SET = "RelSeqSet"; public static final String REL_SEQUENCE_SET = "RelSeqSet";
public static final String REL_SET_OF_SEQUENCES = "RelSeq";
public static final String REL_SET_OF_NON_EMPTY_SEQUENCES = "RelSeq1";
public static final String IS_REL_SEQUENCE_1 = "isRelSeq1"; public static final String IS_REL_SEQUENCE_1 = "isRelSeq1";
public static final String REL_SEQUENCE_1_SET = "RelSeqSet1"; public static final String REL_SEQUENCE_1_SET = "RelSeqSet1";
public static final String REL_INJECTIVE_SEQUENCE = "RelISeq"; public static final String REL_INJECTIVE_SEQUENCE = "RelISeq";
......
...@@ -57,6 +57,7 @@ public class Typechecker extends DepthFirstAdapter implements ITypechecker { ...@@ -57,6 +57,7 @@ public class Typechecker extends DepthFirstAdapter implements ITypechecker {
c.getTree().apply(this); c.getTree().apply(this);
checkLTLFormulas(); checkLTLFormulas();
checkConstantsSetup();
} }
private void checkLTLFormulas() { private void checkLTLFormulas() {
...@@ -76,6 +77,23 @@ public class Typechecker extends DepthFirstAdapter implements ITypechecker { ...@@ -76,6 +77,23 @@ public class Typechecker extends DepthFirstAdapter implements ITypechecker {
} }
private void checkConstantsSetup() {
PPredicate p = machineContext.getConstantsSetup();
if (p != null) {
setType(p, BoolType.getInstance());
p.apply(this);
for (Entry<String, Node> entry : machineContext.getConstants()
.entrySet()) {
String c = entry.getKey();
Node n = entry.getValue();
if (getType(n).isUntyped()) {
throw new TypeErrorException("Can not infer type of constant '"
+ c + "': " + getType(n));
}
}
}
}
@Override @Override
public void caseAPredicateParseUnit(APredicateParseUnit node) { public void caseAPredicateParseUnit(APredicateParseUnit node) {
setType(node.getPredicate(), BoolType.getInstance()); setType(node.getPredicate(), BoolType.getInstance());
...@@ -198,6 +216,18 @@ public class Typechecker extends DepthFirstAdapter implements ITypechecker { ...@@ -198,6 +216,18 @@ public class Typechecker extends DepthFirstAdapter implements ITypechecker {
} }
} }
@Override
public void caseAConcreteVariablesMachineClause(AConcreteVariablesMachineClause node) {
List<PExpression> copy = new ArrayList<PExpression>(
node.getIdentifiers());
for (PExpression e : copy) {
AIdentifierExpression v = (AIdentifierExpression) e;
UntypedType u = new UntypedType();
setType(v, u);
}
}
/** /**
* Definitions * Definitions
*/ */
......
...@@ -4,6 +4,7 @@ import java.util.Hashtable; ...@@ -4,6 +4,7 @@ import java.util.Hashtable;
import de.be4.classicalb.core.parser.analysis.DepthFirstAdapter; import de.be4.classicalb.core.parser.analysis.DepthFirstAdapter;
import de.be4.classicalb.core.parser.node.AConstraintsMachineClause; import de.be4.classicalb.core.parser.node.AConstraintsMachineClause;
import de.be4.classicalb.core.parser.node.ADefinitionsMachineClause;
import de.be4.classicalb.core.parser.node.AExpressionDefinitionDefinition; import de.be4.classicalb.core.parser.node.AExpressionDefinitionDefinition;
import de.be4.classicalb.core.parser.node.AInitialisationMachineClause; import de.be4.classicalb.core.parser.node.AInitialisationMachineClause;
import de.be4.classicalb.core.parser.node.AInvariantMachineClause; import de.be4.classicalb.core.parser.node.AInvariantMachineClause;
...@@ -26,16 +27,25 @@ import de.be4.classicalb.core.parser.node.Start; ...@@ -26,16 +27,25 @@ import de.be4.classicalb.core.parser.node.Start;
public class DefinitionCollector extends DepthFirstAdapter { public class DefinitionCollector extends DepthFirstAdapter {
private Hashtable<String, PDefinition> definitionsTable; private Hashtable<String, PDefinition> definitionsTable;
private ADefinitionsMachineClause definitionsMachineClause;
public Hashtable<String, PDefinition> getDefinitions(){ public Hashtable<String, PDefinition> getDefinitions(){
return new Hashtable<String, PDefinition>(definitionsTable); return new Hashtable<String, PDefinition>(definitionsTable);
} }
public ADefinitionsMachineClause getDefinitionsMachineClause(){
return this.definitionsMachineClause;
}
public DefinitionCollector(Start tree) { public DefinitionCollector(Start tree) {
definitionsTable = new Hashtable<String, PDefinition>(); definitionsTable = new Hashtable<String, PDefinition>();
tree.apply(this); tree.apply(this);
} }
@Override
public void inADefinitionsMachineClause(ADefinitionsMachineClause node) {
this.definitionsMachineClause = node;
}
@Override @Override
public void caseAPredicateDefinitionDefinition( public void caseAPredicateDefinitionDefinition(
......
...@@ -63,16 +63,26 @@ public class DefinitionsEliminator extends DepthFirstAdapter { ...@@ -63,16 +63,26 @@ public class DefinitionsEliminator extends DepthFirstAdapter {
List<PDefinition> copy = new ArrayList<PDefinition>( List<PDefinition> copy = new ArrayList<PDefinition>(
node.getDefinitions()); node.getDefinitions());
for (PDefinition e : copy) { for (PDefinition e : copy) {
if (e instanceof AExpressionDefinitionDefinition) {
String name = ((AExpressionDefinitionDefinition) e).getName()
.getText().toString();
if (name.startsWith("ASSERT_LTL") || name.startsWith("scope_")
|| name.startsWith("SET_PREF_")
|| name.startsWith("ANIMATION_FUNCTION"))
continue;
}
e.apply(this); e.apply(this);
} }
for (PDefinition e : copy) { for (PDefinition e : copy) {
if (e instanceof AExpressionDefinitionDefinition) { if (e instanceof AExpressionDefinitionDefinition) {
String name = ((AExpressionDefinitionDefinition) e).getName() String name = ((AExpressionDefinitionDefinition) e).getName()
.getText().toString(); .getText().toString();
if (name.startsWith("ASSERT_LTL") || name.startsWith("scope_")|| name.startsWith("SET_PREF_")) if (name.startsWith("ASSERT_LTL") || name.startsWith("scope_")
|| name.startsWith("SET_PREF_"))
continue; continue;
} else if (e instanceof APredicateDefinitionDefinition) { } else if (e instanceof APredicateDefinitionDefinition) {
String name = ((APredicateDefinitionDefinition) e).getName().getText().toString(); String name = ((APredicateDefinitionDefinition) e).getName()
.getText().toString();
if (name.equals("GOAL")) if (name.equals("GOAL"))
continue; continue;
} }
...@@ -124,7 +134,6 @@ public class DefinitionsEliminator extends DepthFirstAdapter { ...@@ -124,7 +134,6 @@ public class DefinitionsEliminator extends DepthFirstAdapter {
context.put(paramName, node.getParameters().get(i)); context.put(paramName, node.getParameters().get(i));
} }
contextStack.add(context); contextStack.add(context);
clone.getRhs().apply(this); clone.getRhs().apply(this);
node.replaceBy(clone.getRhs()); node.replaceBy(clone.getRhs());
contextStack.remove(context); contextStack.remove(context);
...@@ -154,7 +163,6 @@ public class DefinitionsEliminator extends DepthFirstAdapter { ...@@ -154,7 +163,6 @@ public class DefinitionsEliminator extends DepthFirstAdapter {
clone.getRhs().apply(this); clone.getRhs().apply(this);
node.replaceBy(clone.getRhs()); node.replaceBy(clone.getRhs());
contextStack.remove(context); contextStack.remove(context);
} }
......
...@@ -198,6 +198,7 @@ public class TypeRestrictor extends DepthFirstAdapter { ...@@ -198,6 +198,7 @@ public class TypeRestrictor extends DepthFirstAdapter {
if (list.contains(r_left) if (list.contains(r_left)
&& isAConstantExpression(right, list, ignoreList)) { && isAConstantExpression(right, list, ignoreList)) {
right.apply(this);
ArrayList<PExpression> element = new ArrayList<PExpression>(); ArrayList<PExpression> element = new ArrayList<PExpression>();
element.add(right); element.add(right);
if (machineContext.getVariables().values().contains(r_left)) { if (machineContext.getVariables().values().contains(r_left)) {
...@@ -207,9 +208,10 @@ public class TypeRestrictor extends DepthFirstAdapter { ...@@ -207,9 +208,10 @@ public class TypeRestrictor extends DepthFirstAdapter {
removedNodes.add(n); removedNodes.add(n);
} }
if (list.contains(r_right) if (list.contains(r_right)
&& isAConstantExpression(right, list, ignoreList)) { && isAConstantExpression(left, list, ignoreList)) {
left.apply(this);
ArrayList<PExpression> element = new ArrayList<PExpression>(); ArrayList<PExpression> element = new ArrayList<PExpression>();
element.add(right); element.add(left);
if (machineContext.getVariables().values().contains(r_right)) { if (machineContext.getVariables().values().contains(r_right)) {
r_right = variablesHashTable.get(r_right); r_right = variablesHashTable.get(r_right);
} }
...@@ -256,6 +258,7 @@ public class TypeRestrictor extends DepthFirstAdapter { ...@@ -256,6 +258,7 @@ public class TypeRestrictor extends DepthFirstAdapter {
if (list.contains(r_left) if (list.contains(r_left)
&& isAConstantExpression(right, list, ignoreList)) { && isAConstantExpression(right, list, ignoreList)) {
right.apply(this);
if (machineContext.getVariables().values().contains(r_left)) { if (machineContext.getVariables().values().contains(r_left)) {
r_left = variablesHashTable.get(r_left); r_left = variablesHashTable.get(r_left);
} }
...@@ -268,10 +271,8 @@ public class TypeRestrictor extends DepthFirstAdapter { ...@@ -268,10 +271,8 @@ public class TypeRestrictor extends DepthFirstAdapter {
if (n instanceof AConjunctPredicate) { if (n instanceof AConjunctPredicate) {
Node left = ((AConjunctPredicate) n).getLeft(); Node left = ((AConjunctPredicate) n).getLeft();
Node right = ((AConjunctPredicate) n).getRight(); Node right = ((AConjunctPredicate) n).getRight();
analysePredicate(left, list, analysePredicate(left, list, ignoreList);
ignoreList); analysePredicate(right, list, ignoreList);
analysePredicate(right, list,
ignoreList);
if (removedNodes.contains(left) && removedNodes.contains(right)) { if (removedNodes.contains(left) && removedNodes.contains(right)) {
removedNodes.add(n); removedNodes.add(n);
} }
...@@ -474,6 +475,7 @@ public class TypeRestrictor extends DepthFirstAdapter { ...@@ -474,6 +475,7 @@ public class TypeRestrictor extends DepthFirstAdapter {
node.getIdentifiers())); node.getIdentifiers()));
} }
@Override @Override
public void inALetSubstitution(ALetSubstitution node) { public void inALetSubstitution(ALetSubstitution node) {
HashSet<Node> list = new HashSet<Node>(); HashSet<Node> list = new HashSet<Node>();
......
...@@ -1715,7 +1715,8 @@ public class TLAPrinter extends DepthFirstAdapter { ...@@ -1715,7 +1715,8 @@ public class TLAPrinter extends DepthFirstAdapter {
tlaModuleString.append("]"); tlaModuleString.append("]");
} else { } else {
if (node.parent() instanceof AMemberPredicate if (node.parent() instanceof AMemberPredicate
&& !typeRestrictor.isARemovedNode(node.parent())) { && !typeRestrictor.isARemovedNode(node.parent())
&& !this.tlaModule.getInitPredicates().contains(node.parent())) {
tlaModuleString.append(REL_TOTAL_FUNCTION_ELEMENT_OF); tlaModuleString.append(REL_TOTAL_FUNCTION_ELEMENT_OF);
} else { } else {
tlaModuleString.append(REL_TOTAL_FUNCTION); tlaModuleString.append(REL_TOTAL_FUNCTION);
...@@ -1732,8 +1733,7 @@ public class TLAPrinter extends DepthFirstAdapter { ...@@ -1732,8 +1733,7 @@ public class TLAPrinter extends DepthFirstAdapter {
Node parent = node.parent(); Node parent = node.parent();
if (parent instanceof AMemberPredicate if (parent instanceof AMemberPredicate
&& !typeRestrictor.isARemovedNode(parent) && !typeRestrictor.isARemovedNode(parent)
// && !this.tlaModule.getInitPredicates().contains(parent) && !this.tlaModule.getInitPredicates().contains(parent)) {
) {
return true; return true;
} else { } else {
String clazz = parent.getClass().getName(); String clazz = parent.getClass().getName();
...@@ -1883,9 +1883,7 @@ public class TLAPrinter extends DepthFirstAdapter { ...@@ -1883,9 +1883,7 @@ public class TLAPrinter extends DepthFirstAdapter {
} }
tlaModuleString.append(")"); tlaModuleString.append(")");
return; return;
} }
tlaModuleString.append("{"); tlaModuleString.append("{");
{ {
List<PExpression> copy = new ArrayList<PExpression>( List<PExpression> copy = new ArrayList<PExpression>(
...@@ -2461,32 +2459,14 @@ public class TLAPrinter extends DepthFirstAdapter { ...@@ -2461,32 +2459,14 @@ public class TLAPrinter extends DepthFirstAdapter {
public void caseASeqExpression(ASeqExpression node) { public void caseASeqExpression(ASeqExpression node) {
SetType set = (SetType) typechecker.getType(node); SetType set = (SetType) typechecker.getType(node);
if (set.getSubtype() instanceof SetType) { if (set.getSubtype() instanceof SetType) {
if (node.parent() instanceof AMemberPredicate) { tlaModuleString.append(REL_SET_OF_SEQUENCES);
AMemberPredicate member = (AMemberPredicate) node.parent();
tlaModuleString.append(REL_SEQUENCE_SET);
tlaModuleString.append("(");
member.getLeft().apply(this);
tlaModuleString.append(", ");
node.getExpression().apply(this);
tlaModuleString.append(")");
} else if (node.parent() instanceof ANotMemberPredicate) {
ANotMemberPredicate member = (ANotMemberPredicate) node
.parent();
tlaModuleString.append(REL_SEQUENCE_SET);
tlaModuleString.append("(");
member.getLeft().apply(this);
tlaModuleString.append(", ");
node.getExpression().apply(this);
tlaModuleString.append(")");
}
} else { } else {
tlaModuleString.append("Seq"); tlaModuleString.append("Seq");
}
tlaModuleString.append("("); tlaModuleString.append("(");
node.getExpression().apply(this); node.getExpression().apply(this);
tlaModuleString.append(")"); tlaModuleString.append(")");
} }
}
@Override @Override
public void caseASizeExpression(ASizeExpression node) { public void caseASizeExpression(ASizeExpression node) {
...@@ -2593,32 +2573,14 @@ public class TLAPrinter extends DepthFirstAdapter { ...@@ -2593,32 +2573,14 @@ public class TLAPrinter extends DepthFirstAdapter {
public void caseASeq1Expression(ASeq1Expression node) { public void caseASeq1Expression(ASeq1Expression node) {
SetType set = (SetType) typechecker.getType(node); SetType set = (SetType) typechecker.getType(node);
if (set.getSubtype() instanceof SetType) { if (set.getSubtype() instanceof SetType) {
if (node.parent() instanceof AMemberPredicate) { tlaModuleString.append(REL_SET_OF_NON_EMPTY_SEQUENCES);
AMemberPredicate member = (AMemberPredicate) node.parent();
tlaModuleString.append(REL_SEQUENCE_1_SET);
tlaModuleString.append("(");
member.getLeft().apply(this);
tlaModuleString.append(", ");
node.getExpression().apply(this);
tlaModuleString.append(")");
} else if (node.parent() instanceof ANotMemberPredicate) {
ANotMemberPredicate member = (ANotMemberPredicate) node
.parent();
tlaModuleString.append(REL_SEQUENCE_1_SET);
tlaModuleString.append("(");
member.getLeft().apply(this);
tlaModuleString.append(", ");
node.getExpression().apply(this);
tlaModuleString.append(")");
}
} else { } else {
tlaModuleString.append(SEQUENCE_1); tlaModuleString.append(SEQUENCE_1);
}
tlaModuleString.append("("); tlaModuleString.append("(");
node.getExpression().apply(this); node.getExpression().apply(this);
tlaModuleString.append(")"); tlaModuleString.append(")");
} }
}
@Override @Override
public void caseALastExpression(ALastExpression node) { public void caseALastExpression(ALastExpression node) {
......
...@@ -10,6 +10,7 @@ import java.util.Map.Entry; ...@@ -10,6 +10,7 @@ import java.util.Map.Entry;
import de.be4.classicalb.core.parser.analysis.DepthFirstAdapter; import de.be4.classicalb.core.parser.analysis.DepthFirstAdapter;
import de.be4.classicalb.core.parser.node.AAssertionsMachineClause; import de.be4.classicalb.core.parser.node.AAssertionsMachineClause;
import de.be4.classicalb.core.parser.node.AConcreteVariablesMachineClause;
import de.be4.classicalb.core.parser.node.AConstraintsMachineClause; import de.be4.classicalb.core.parser.node.AConstraintsMachineClause;
import de.be4.classicalb.core.parser.node.ADefinitionsMachineClause; import de.be4.classicalb.core.parser.node.ADefinitionsMachineClause;
import de.be4.classicalb.core.parser.node.AEnumeratedSetSet; import de.be4.classicalb.core.parser.node.AEnumeratedSetSet;
...@@ -239,7 +240,8 @@ public class Generator extends DepthFirstAdapter { ...@@ -239,7 +240,8 @@ public class Generator extends DepthFirstAdapter {
return; return;
LinkedHashMap<Node, Node> conValueTable = constantsEvaluator LinkedHashMap<Node, Node> conValueTable = constantsEvaluator
.getValueOfIdentifierMap(); .getValueOfIdentifierMap();
Iterator<Entry<Node, Node>> iterator = conValueTable.entrySet().iterator(); Iterator<Entry<Node, Node>> iterator = conValueTable.entrySet()
.iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
Entry<Node, Node> entry = iterator.next(); Entry<Node, Node> entry = iterator.next();
AIdentifierExpression con = (AIdentifierExpression) entry.getKey(); AIdentifierExpression con = (AIdentifierExpression) entry.getKey();
...@@ -259,7 +261,7 @@ public class Generator extends DepthFirstAdapter { ...@@ -259,7 +261,7 @@ public class Generator extends DepthFirstAdapter {
Node propertiesPerdicate = machineContext.getPropertiesMachineClause() Node propertiesPerdicate = machineContext.getPropertiesMachineClause()
.getPredicates(); .getPredicates();
if (remainingConstants.size() != 0) { if (remainingConstants.size() > 0) {
boolean init = false; boolean init = false;
int numberOfIteratedConstants = 0; int numberOfIteratedConstants = 0;
...@@ -302,8 +304,11 @@ public class Generator extends DepthFirstAdapter { ...@@ -302,8 +304,11 @@ public class Generator extends DepthFirstAdapter {
} }
} else { } else {
tlaModule.assumes.addAll(constantsEvaluator.getPropertiesList()); if (machineContext.getConstantsSetup() == null){
// tlaModule.addAssume(propertiesPerdicate); tlaModule.assumes
.addAll(constantsEvaluator.getPropertiesList());
}
tlaModule.addAssume(propertiesPerdicate);
} }
} }
...@@ -324,6 +329,15 @@ public class Generator extends DepthFirstAdapter { ...@@ -324,6 +329,15 @@ public class Generator extends DepthFirstAdapter {
} }
} }
@Override
public void caseAConcreteVariablesMachineClause(AConcreteVariablesMachineClause node) {
List<PExpression> copy = new ArrayList<PExpression>(
node.getIdentifiers());
for (PExpression e : copy) {
this.tlaModule.variables.add(e);
}
}
@Override @Override
public void inAAssertionsMachineClause(AAssertionsMachineClause node) { public void inAAssertionsMachineClause(AAssertionsMachineClause node) {
List<PPredicate> copy = new ArrayList<PPredicate>(node.getPredicates()); List<PPredicate> copy = new ArrayList<PPredicate>(node.getPredicates());
......
...@@ -6,11 +6,23 @@ IsRelSeq(x, S) == \A n \in 1..Cardinality(x): RelCall(x,n) \in S ...@@ -6,11 +6,23 @@ IsRelSeq(x, S) == \A n \in 1..Cardinality(x): RelCall(x,n) \in S
RelSeqSet(x, S) == IF IsRelSeq(x,S) THEN {x} ELSE {} RelSeqSet(x, S) == IF IsRelSeq(x,S) THEN {x} ELSE {}
RelSeq(S) == {p \in SUBSET(Nat \times S):
LET d == {q[1] : q \in p}
IN /\ Cardinality(p) = Cardinality(d)
/\ d = 1..Cardinality(d)}
IsRelSeq1(x, S) == x # {} /\ IsRelSeq(x, S) IsRelSeq1(x, S) == x # {} /\ IsRelSeq(x, S)
\* Testing if x is a non-empty sequence with elements of the set S \* Testing if x is a non-empty sequence with elements of the set S
RelSeqSet1(x, S) == IF IsRelSeq1(x,S) THEN {x} ELSE {} RelSeqSet1(x, S) == IF IsRelSeq1(x,S) THEN {x} ELSE {}
RelSeq1(S) == {p \in SUBSET(Nat \times S):
LET d == {q[1] : q \in p}
IN /\ Cardinality(p) > 0
/\ Cardinality(p) = Cardinality(d)
/\ d = 1..Cardinality(d)}
LOCAL ISeq(S) == UNION { {x \in [(1..n) -> S]: Cardinality(Range(x)) = Cardinality(DOMAIN x)} LOCAL ISeq(S) == UNION { {x \in [(1..n) -> S]: Cardinality(Range(x)) = Cardinality(DOMAIN x)}
: n \in 0..Cardinality(S)} : n \in 0..Cardinality(S)}
......
...@@ -42,5 +42,12 @@ public class SpecialTest { ...@@ -42,5 +42,12 @@ public class SpecialTest {
} }
@Test
public void testDefinitionsLoad() throws Exception {
String[] a = new String[] {
"./src/test/resources/special/LoadDefinitions.mch"};
assertEquals(NoError, test(a));
}
} }
package testing; package testing;
import static de.tlc4b.tlc.TLCResults.TLCResult.NoError; import static de.tlc4b.tlc.TLCResults.TLCResult.NoError;
import static de.tlc4b.util.TestUtil.test;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -28,9 +28,11 @@ public class Testing2 extends AbstractParseMachineTest{ ...@@ -28,9 +28,11 @@ public class Testing2 extends AbstractParseMachineTest{
@Test @Test
public void testRunTLC() throws Exception { public void testRunTLC() throws Exception {
String[] a = new String[] {machine.getPath()}; String[] a = new String[] {
machine.getPath()};
TLC4B.main(a); TLC4B.main(a);
//TLC4B.test(a,false); //TLC4B.test(a,false);
//test(a);
} }
@Config @Config
......
...@@ -10,6 +10,11 @@ PROPERTIES ...@@ -10,6 +10,11 @@ PROPERTIES
& {} : seq({1+0}) & {} : seq({1+0})
& {} : seq({}) & {} : seq({})
& {x,y| x : 1..10 & y : {3}} : seq({3})
& {} \/ {} : seq({1})
& {x,y| x : 1..10 & y : {3}} : seq1({3})
& {} \/ {} /: seq1({1})
/* Set of sequences */ /* Set of sequences */
& {(1+0,1)} : seq1({1}) & {(1+0,1)} : seq1({1})
......
DEFINITIONS
d3 == 3;
d4 == 4;
\ No newline at end of file
MACHINE LoadDefinitions
DEFINITIONS
"Definitions.def";
d1 == 1;
d2 == 2;
PROPERTIES
d1+ d2 = d3 & d4 = d3 + d1
END
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment