use of verdict.vdm.vdm_lustre.Expression in project VERDICT by ge-high-assurance.
the class VDM2Lustre method recordLiteral.
public void recordLiteral(Expression expr) {
if (expr != null) {
RecordLiteral recordLiteral = expr.getRecordLiteral();
if (recordLiteral != null) {
String identifier = recordLiteral.getRecordType();
identifier = identifier.replace(".", "_dot_");
identifier = identifier.replace("::", "_double_colon_");
recordLiteral.setRecordType(identifier);
for (FieldDefinition fieldDef : recordLiteral.getFieldDefinition()) {
expr = fieldDef.getFieldValue();
recordLiteral(expr);
}
} else {
BinaryOperation op = expr.getEqual();
if (op == null) {
op = expr.getNotEqual();
if (op == null) {
op = expr.getAnd();
if (op == null) {
op = expr.getImplies();
}
}
}
if (op != null) {
Expression lhs_expr = op.getLhsOperand();
recordLiteral(lhs_expr);
Expression rhs_expr = op.getRhsOperand();
recordLiteral(rhs_expr);
}
Expression not_expr = expr.getNot();
if (not_expr != null) {
recordLiteral(not_expr);
} else {
Expression pre_expr = expr.getPre();
recordLiteral(pre_expr);
}
NodeCall nodeCall = expr.getCall();
if (nodeCall != null) {
for (Expression arg : nodeCall.getArgument()) {
recordLiteral(arg);
}
}
}
}
}
use of verdict.vdm.vdm_lustre.Expression in project VERDICT by ge-high-assurance.
the class VDM2Lustre method visit.
// 1) Node signature +/- contract
// a) Imported Node (Contract, no Implementation)
// b) Node Impl
// c) Node Impl + contract
// d) @TODO: no Contract, no Implementation -- (*@contract gurantee true*)
public Node visit(ComponentType componentType, boolean is_implemented) {
Node node = new Node();
String identifier = componentType.getName();
// Replace dot identifier to support lustre naming compliance
identifier = identifier.replace(".", "_dot_");
identifier = identifier.replace("::", "_double_colon_");
if (is_implemented) {
identifier += "_dot_Impl";
} else {
// Imported Node
node.setIsImported(true);
// System.out.println("Imported Nodes:" +identifier );
}
node.setName(identifier);
for (Port port : componentType.getPort()) {
if (port.isEvent() != null && port.isEvent()) {
this.eventDeclarations.put(port.getName(), port.getType());
}
visit(port, node);
}
// + Contract (Optional)
ContractSpec contractSpec = componentType.getContract();
if (is_implemented == false && contractSpec == null) {
// Rename output renaming to avoid Duplicate.
// List<NodeParameter> node_parameters = node.getOutputParameter();
// for (NodeParameter instrumented_param : node_parameters) {
// String param_identifier = instrumented_param.getName();
// instrumented_param.setName(param_identifier + "_intrumented");
// }
ContractItem true_guarantee_item = new ContractItem();
Expression true_expr = new Expression();
Boolean true_lit = Boolean.TRUE;
true_expr.setBoolLiteral(true_lit);
true_guarantee_item.setExpression(true_expr);
contractSpec = new ContractSpec();
contractSpec.getGuarantee().add(true_guarantee_item);
componentType.setContract(contractSpec);
}
if (contractSpec != null) {
visit(contractSpec);
if (contractSpec.getGuarantee().size() != 0) {
node.setContract(contractSpec);
this.eventDeclarations.clear();
}
}
return node;
}
use of verdict.vdm.vdm_lustre.Expression in project VERDICT by ge-high-assurance.
the class VDM2Lustre method visit.
public void visit(ContractItem contractItem) {
Expression expr = contractItem.getExpression();
expr = visitExpression(expr);
contractItem.setExpression(expr);
recordLiteral(expr);
}
use of verdict.vdm.vdm_lustre.Expression in project VERDICT by ge-high-assurance.
the class VDMInstrumentor method xor_expr.
protected Expression xor_expr(String i_id, String j_id) {
Expression amo_expr = new Expression();
Expression expr_i = new Expression();
expr_i.setIdentifier(i_id);
Expression expr_j = new Expression();
expr_j.setIdentifier(j_id);
Expression notexpr_i = new Expression();
notexpr_i.setNot(expr_i);
Expression notexpr_j = new Expression();
notexpr_j.setNot(expr_j);
BinaryOperation or_op = new BinaryOperation();
or_op.setLhsOperand(notexpr_i);
or_op.setRhsOperand(notexpr_j);
amo_expr.setOr(or_op);
return amo_expr;
}
use of verdict.vdm.vdm_lustre.Expression in project VERDICT by ge-high-assurance.
the class VDMInstrumentor method and_expr.
protected Expression and_expr(Stack<Expression> expr_stack) {
while (expr_stack.size() > 1) {
Expression left_expr = expr_stack.pop();
Expression right_expr = expr_stack.pop();
BinaryOperation and_op = new BinaryOperation();
and_op.setLhsOperand(left_expr);
and_op.setRhsOperand(right_expr);
Expression and_expr = new Expression();
and_expr.setAnd(and_op);
expr_stack.push(and_expr);
}
return expr_stack.pop();
}
Aggregations