Skip to content
Snippets Groups Projects
Commit f9bcb08b authored by Jan Gruteser's avatar Jan Gruteser
Browse files

simplify definition and clause creation

parent 5068f69b
No related branches found
No related tags found
No related merge requests found
Pipeline #148226 passed
...@@ -175,37 +175,33 @@ public class BAstCreator extends BuiltInOPs implements TranslationGlobals, BBuil ...@@ -175,37 +175,33 @@ public class BAstCreator extends BuiltInOPs implements TranslationGlobals, BBuil
} else { } else {
DebugUtils.printVeryVerboseMsg("Not creating unused B DEFINITION for " + def.getName() + " " + def); DebugUtils.printVeryVerboseMsg("Not creating unused B DEFINITION for " + def.getName() + " " + def);
} }
} }
Set<EXTERNAL_FUNCTIONS> set = usedExternalFunctions.getUsedExternalFunctions(); Set<EXTERNAL_FUNCTIONS> set = usedExternalFunctions.getUsedExternalFunctions();
List<PDefinition> defs = new ArrayList<>(createDefinitionsForExternalFunctions(set)); List<PDefinition> defs = new ArrayList<>(createDefinitionsForExternalFunctions(set));
for (OpDefNode opDefNode : bDefs) { for (OpDefNode opDefNode : bDefs) {
List<PExpression> list = new ArrayList<>(); List<PExpression> params = Arrays.stream(opDefNode.getParams())
for (int i = 0; i < opDefNode.getParams().length; i++) { .map(this::createIdentifierNode).collect(Collectors.toList());
FormalParamNode p = opDefNode.getParams()[i];
list.add(createIdentifierNode(p));
}
// TLAType type = (TLAType) opDefNode.getToolObject(TYPE_ID); // TLAType type = (TLAType) opDefNode.getToolObject(TYPE_ID);
// if (opDefNode.level == 2 || type instanceof BoolType) { // if (opDefNode.level == 2 || type instanceof BoolType) {
PDefinition definition;
if (predicateVsExpression.getDefinitionType(opDefNode) == DefinitionType.PREDICATE) { if (predicateVsExpression.getDefinitionType(opDefNode) == DefinitionType.PREDICATE) {
APredicateDefinitionDefinition d = new APredicateDefinitionDefinition(); definition = new APredicateDefinitionDefinition(
d.setName(new TDefLiteralPredicate(getName(opDefNode))); new TDefLiteralPredicate(getName(opDefNode)),
d.setParameters(list); params,
d.setRhs(visitExprNodePredicate(opDefNode.getBody())); visitExprNodePredicate(opDefNode.getBody())
defs.add(createPositionedNode(d,opDefNode)); );
DebugUtils.printVeryVerboseMsg("Creating Predicate DEFINITION " + getName(opDefNode));
} else { } else {
AExpressionDefinitionDefinition d = new AExpressionDefinitionDefinition(); definition = new AExpressionDefinitionDefinition(
d.setName(new TIdentifierLiteral(getName(opDefNode))); new TIdentifierLiteral(getName(opDefNode)),
// System.out.println("Creating Expression DEFINITION " + getName(opDefNode)); params,
// TODO: these definitions have no position info in the definition_decl term nor at the top-level body visitExprNodeExpression(opDefNode.getBody())
);
d.setParameters(list); DebugUtils.printVeryVerboseMsg("Creating Expression DEFINITION " + getName(opDefNode));
d.setRhs(visitExprNodeExpression(opDefNode.getBody()));
defs.add(createPositionedNode(d,opDefNode));
} }
defs.add(createPositionedNode(definition, opDefNode));
} }
if (!defs.isEmpty()) { if (!defs.isEmpty()) {
...@@ -273,15 +269,8 @@ public class BAstCreator extends BuiltInOPs implements TranslationGlobals, BBuil ...@@ -273,15 +269,8 @@ public class BAstCreator extends BuiltInOPs implements TranslationGlobals, BBuil
OpDeclNode[] vars = moduleNode.getVariableDecls(); OpDeclNode[] vars = moduleNode.getVariableDecls();
if (vars.length == 0) if (vars.length == 0)
return; return;
List<PExpression> varList = new ArrayList<>(); List<PExpression> varList = Arrays.stream(vars).map(this::createIdentifierNode).collect(Collectors.toList());
for (OpDeclNode var : vars) { List<PPredicate> predList = specAnalyser.getInits().stream().map(this::visitExprNodePredicate).collect(Collectors.toList());
varList.add(createIdentifierNode(var));
}
List<PPredicate> predList = new ArrayList<>();
for (ExprNode node : specAnalyser.getInits()) {
predList.add(visitExprNodePredicate(node));
}
if (predList.isEmpty()) { if (predList.isEmpty()) {
throw new IllegalStateException("Could not find a definition of Init."); throw new IllegalStateException("Could not find a definition of Init.");
} }
...@@ -325,23 +314,16 @@ public class BAstCreator extends BuiltInOPs implements TranslationGlobals, BBuil ...@@ -325,23 +314,16 @@ public class BAstCreator extends BuiltInOPs implements TranslationGlobals, BBuil
} }
private void createConstantsClause() { private void createConstantsClause() {
List<OpDeclNode> bConstants; List<OpDeclNode> bConstants = conEval != null ? conEval.getbConstantList() : Arrays.asList(moduleNode.getConstantDecls());
if (conEval != null) {
bConstants = conEval.getbConstantList();
} else {
bConstants = Arrays.asList(moduleNode.getConstantDecls());
}
List<PExpression> constantsList = new ArrayList<>(); List<PExpression> constantsList = new ArrayList<>();
for (OpDeclNode opDeclNode : bConstants) { for (OpDeclNode opDeclNode : bConstants) {
AIdentifierExpression id = createPositionedNode(createIdentifierNode(getName(opDeclNode)), opDeclNode); AIdentifierExpression id = createPositionedNode(createIdentifierNode(getName(opDeclNode)), opDeclNode);
constantsList.add(id); constantsList.add(id);
TLAType type = (TLAType) opDeclNode.getToolObject(TYPE_ID); types.put(id, (TLAType) opDeclNode.getToolObject(TYPE_ID));
types.put(id, type);
} }
if (!constantsList.isEmpty()) { if (!constantsList.isEmpty()) {
AConstantsMachineClause constantsClause = new AConstantsMachineClause(constantsList); machineClauseList.add(new AConstantsMachineClause(constantsList));
machineClauseList.add(constantsClause);
} }
} }
...@@ -551,10 +533,8 @@ public class BAstCreator extends BuiltInOPs implements TranslationGlobals, BBuil ...@@ -551,10 +533,8 @@ public class BAstCreator extends BuiltInOPs implements TranslationGlobals, BBuil
} }
if (!predList.isEmpty()) { if (!predList.isEmpty()) {
AInvariantMachineClause invClause = new AInvariantMachineClause(createConjunction(predList)); machineClauseList.add(new AInvariantMachineClause(createConjunction(predList)));
machineClauseList.add(invClause);
} }
} }
private PPredicate visitAssumeNode(AssumeNode assumeNode) { private PPredicate visitAssumeNode(AssumeNode assumeNode) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment