use of verdict.vdm.vdm_lustre.ContractSpec 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.ContractSpec in project VERDICT by ge-high-assurance.
the class VerdictLustreListener method exitContractSpec.
/**
* Extract a contract spec.
*/
@Override
public void exitContractSpec(LustreParser.ContractSpecContext ctx) {
ctx.spec = new ContractSpec();
ctx.symbol().forEach(symbol -> ctx.spec.getSymbol().add(symbol.def));
ctx.assume().forEach(assume -> ctx.spec.getAssume().add(assume.item));
ctx.guarantee().forEach(guarantee -> ctx.spec.getGuarantee().add(guarantee.item));
ctx.contractMode().forEach(contractMode -> ctx.spec.getMode().add(contractMode.mode));
ctx.contractImport().forEach(contractImport -> ctx.spec.getImport().add(contractImport.imprt));
}
use of verdict.vdm.vdm_lustre.ContractSpec in project VERDICT by ge-high-assurance.
the class VerdictLustreListener method exitNode.
/**
* Extract a node declaration.
*/
@Override
public void exitNode(LustreParser.NodeContext ctx) {
Node node = new Node();
if ("function".equals(ctx.nodeType.getText())) {
node.setIsFunction(true);
}
node.setName(ctx.ID().getText());
if (ctx.input != null) {
node.getInputParameter().addAll(ctx.input.nodeParameters);
}
if (ctx.output != null) {
node.getOutputParameter().addAll(ctx.output.nodeParameters);
}
if (ctx.nodeBody() != null) {
node.setBody(ctx.nodeBody().body);
}
if (ctx.inlineContract() != null) {
node.setContract(ctx.inlineContract().spec);
}
if (!ctx.importedContract().isEmpty()) {
if (node.getContract() == null) {
node.setContract(new ContractSpec());
}
final ContractSpec spec = node.getContract();
ctx.importedContract().forEach(importedContract -> spec.getImport().add(importedContract.imprt));
}
LustreProgram program = model.getDataflowCode();
program.getNodeDeclaration().add(node);
}
use of verdict.vdm.vdm_lustre.ContractSpec in project VERDICT by ge-high-assurance.
the class PrettyPrinter method visit.
// @Override
public void visit(Contract contract) {
sb.append("contract ").append(contract.getName());
sb.append(" (").append(NL);
for (NodeParameter param : contract.getInputParameter()) {
visit(param);
}
sb.append(")").append(NL);
sb.append("returns (").append(NL);
for (NodeParameter param : contract.getInputParameter()) {
visit(param);
}
sb.append(");").append(NL);
// Specifications
sb.append("let").append(NL);
for (ContractSpec contractSpec : contract.getSpecification()) {
visit(contractSpec);
}
sb.append("tel");
sb.append(NL);
}
use of verdict.vdm.vdm_lustre.ContractSpec in project VERDICT by ge-high-assurance.
the class PrettyPrinter method visit.
public void visit(Node node) {
sb.append("node ");
// if (node.isIsImported()) {
sb.append("imported ");
// }
sb.append(node.getName());
sb.append("(");
sb.append(NL);
for (NodeParameter param : node.getInputParameter()) {
visit(param);
}
sb.append(")");
sb.append(NL);
sb.append("returns (");
sb.append(NL);
for (NodeParameter param : node.getOutputParameter()) {
visit(param);
}
sb.append(");");
sb.append(NL);
ContractSpec contractSpec = node.getContract();
if (contractSpec != null) {
sb.append("(*@contract ");
visit(contractSpec);
sb.append("*)");
// sb.append(NL);
}
// if (node.isIsFunction()) {
NodeBody nodeBody = node.getBody();
if (nodeBody != null) {
// sb.append("{");
sb.append(NL);
visit(nodeBody);
// sb.append("}");
sb.append(NL);
}
// }
}
Aggregations