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

further simplications in BAstCreator

parent f9bcb08b
No related branches found
No related tags found
No related merge requests found
Pipeline #148230 passed
...@@ -347,56 +347,36 @@ public class BAstCreator extends BuiltInOPs implements TranslationGlobals, BBuil ...@@ -347,56 +347,36 @@ public class BAstCreator extends BuiltInOPs implements TranslationGlobals, BBuil
if (conEval != null && conEval.getConstantAssignments().containsKey(con) && bConstants.contains(con)) { if (conEval != null && conEval.getConstantAssignments().containsKey(con) && bConstants.contains(con)) {
ValueObj v = conEval.getConstantAssignments().get(con); ValueObj v = conEval.getConstantAssignments().get(con);
TLAType t = v.getType(); TLAType t = v.getType();
boolean isEnum = false;
if (t instanceof SetType) {
TLAType sub = ((SetType) t).getSubType();
if (sub instanceof EnumType) {
EnumType en = (EnumType) sub;
SetEnumValue set = (SetEnumValue) v.getValue();
if (set.elems.size() == en.modelvalues.size()) {
isEnum = true;
}
}
}
AEqualPredicate equal = new AEqualPredicate(); AEqualPredicate equal = new AEqualPredicate();
if (isEnum) {
equal.setLeft(createIdentifierNode(con)); equal.setLeft(createIdentifierNode(con));
if (t instanceof SetType && ((SetType) t).getSubType() instanceof EnumType
&& ((SetEnumValue) v.getValue()).elems.size() == ((EnumType) ((SetType) t).getSubType()).modelvalues.size()) {
// isEnum = true
equal.setRight(createIdentifierNode(((SetType) t).getSubType().toString())); equal.setRight(createIdentifierNode(((SetType) t).getSubType().toString()));
} else { } else {
equal.setLeft(createIdentifierNode(con)); equal.setRight(createTLCValue(v.getValue()));
Value tlcValue = v.getValue();
equal.setRight(createTLCValue(tlcValue));
} }
propertiesList.add(equal); propertiesList.add(equal);
} else { } else {
AMemberPredicate member = new AMemberPredicate();
member.setLeft(createIdentifierNode(con));
TLAType t = (TLAType) con.getToolObject(TYPE_ID); TLAType t = (TLAType) con.getToolObject(TYPE_ID);
member.setRight(t.getBNode()); propertiesList.add(new AMemberPredicate(createIdentifierNode(con), t.getBNode()));
propertiesList.add(member);
} }
} }
if (conEval != null) { if (conEval != null) {
for (Entry<OpDeclNode, OpDefNode> entry : conEval.getConstantOverrides().entrySet()) { for (Entry<OpDeclNode, OpDefNode> entry : conEval.getConstantOverrides().entrySet()) {
OpDeclNode con = entry.getKey(); OpDeclNode con = entry.getKey();
OpDefNode generatedDef = entry.getValue(); OpDefNode def = entry.getValue(); // generated def
OpDefNode def;
try { try {
OpApplNode opApplNode = (OpApplNode) generatedDef.getBody(); OpApplNode opApplNode = (OpApplNode) def.getBody();
if (opApplNode.getKind() == UserDefinedOpKind) { if (opApplNode.getKind() == UserDefinedOpKind) {
def = (OpDefNode) opApplNode.getOperator(); def = (OpDefNode) opApplNode.getOperator();
} else {
def = generatedDef;
} }
} catch (ClassCastException e) { } catch (ClassCastException e) {
def = generatedDef; // ignore
} }
propertiesList.add(new AEqualPredicate(createIdentifierNode(con), visitExprNodeExpression(def.getBody())));
AEqualPredicate equal = new AEqualPredicate();
equal.setLeft(createIdentifierNode(con));
equal.setRight(visitExprNodeExpression(def.getBody()));
propertiesList.add(equal);
} }
} }
...@@ -405,24 +385,19 @@ public class BAstCreator extends BuiltInOPs implements TranslationGlobals, BBuil ...@@ -405,24 +385,19 @@ public class BAstCreator extends BuiltInOPs implements TranslationGlobals, BBuil
for (AssumeNode assumeNode : assumes) { for (AssumeNode assumeNode : assumes) {
ThmOrAssumpDefNode def = assumeNode.getDef(); ThmOrAssumpDefNode def = assumeNode.getDef();
if (def != null) { if (def != null) {
ALabelPredicate aLabelPredicate = new ALabelPredicate(new TPragmaIdOrString(def.getName().toString()), assertionList.add(new ALabelPredicate(
createPositionedNode(visitAssumeNode(assumeNode), assumeNode)); new TPragmaIdOrString(def.getName().toString()),
assertionList.add(aLabelPredicate); createPositionedNode(visitAssumeNode(assumeNode), assumeNode)));
} else { } else {
propertiesList.add(visitAssumeNode(assumeNode)); propertiesList.add(visitAssumeNode(assumeNode));
} }
} }
if (!propertiesList.isEmpty()) { if (!propertiesList.isEmpty()) {
APropertiesMachineClause propertiesClause = new APropertiesMachineClause(); machineClauseList.add(new APropertiesMachineClause(createConjunction(propertiesList)));
propertiesClause.setPredicates(createConjunction(propertiesList));
machineClauseList.add(propertiesClause);
} }
if (!assertionList.isEmpty()) { if (!assertionList.isEmpty()) {
AAssertionsMachineClause assertionClause = new AAssertionsMachineClause(); machineClauseList.add(new AAssertionsMachineClause(assertionList));
assertionClause.setPredicates(assertionList);
machineClauseList.add(assertionClause);
} }
} }
private List<PPredicate> evalRecursiveFunctions() { private List<PPredicate> evalRecursiveFunctions() {
...@@ -507,12 +482,7 @@ public class BAstCreator extends BuiltInOPs implements TranslationGlobals, BBuil ...@@ -507,12 +482,7 @@ public class BAstCreator extends BuiltInOPs implements TranslationGlobals, BBuil
List<PPredicate> predList = new ArrayList<>(); List<PPredicate> predList = new ArrayList<>();
for (OpDeclNode var : vars) { for (OpDeclNode var : vars) {
TLAType varType = (TLAType) var.getToolObject(TYPE_ID); TLAType varType = (TLAType) var.getToolObject(TYPE_ID);
predList.add(new AMemberPredicate(createIdentifierNode(var), varType.getBNode()));
AMemberPredicate member = new AMemberPredicate();
member.setLeft(createIdentifierNode(var));
member.setRight(varType.getBNode());
predList.add(member);
} }
for (OpDefNode def : specAnalyser.getInvariants()) { for (OpDefNode def : specAnalyser.getInvariants()) {
...@@ -528,7 +498,6 @@ public class BAstCreator extends BuiltInOPs implements TranslationGlobals, BBuil ...@@ -528,7 +498,6 @@ public class BAstCreator extends BuiltInOPs implements TranslationGlobals, BBuil
defExpr.setDefLiteral(new TIdentifierLiteral(getName(def))); defExpr.setDefLiteral(new TIdentifierLiteral(getName(def)));
predList.add(new AEqualPredicate(defExpr, new ABooleanTrueExpression())); predList.add(new AEqualPredicate(defExpr, new ABooleanTrueExpression()));
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment