use of verdict.vdm.vdm_lustre.Node in project VERDICT by ge-high-assurance.
the class PrettyPrinter method visit.
// @Override
public void visit(LustreProgram program) {
// ContractDeclarataions
for (Contract contract : program.getContractDeclaration()) {
visit(contract);
sb.append(NL);
}
sb.append(NL);
for (Node node : program.getNodeDeclaration()) {
if (node != null) {
visit(node);
sb.append(NL);
}
}
// for (LustreNode node : cNodes) {
// node.accept(this);
// sb.append(NL).append(NL);
// }
}
use of verdict.vdm.vdm_lustre.Node 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.Node in project VERDICT by ge-high-assurance.
the class VDM2Lustre method visit.
public void visit(Model vdm_model, LustreProgram program) {
// A) Copying Type Declaration + amend name '_Impl
for (TypeDeclaration typeDec : vdm_model.getTypeDeclaration()) {
visit(typeDec, program);
}
// Copying over Constant Declarations
for (ConstantDeclaration constDec : program.getConstantDeclaration()) {
String constName = constDec.getName();
constName = constName.replace(".", "_dot_");
constName = constName.replace("::", "_double_colon_");
constDec.setName(constName);
visit(constDec);
}
// Event Ports
for (ComponentType componentType : vdm_model.getComponentType()) {
// Collect Node with no output
Port mPort = markPort(componentType);
if (mPort == null) {
// Event Ports to Data Ports;
for (Port port : componentType.getPort()) {
// Update event_ports
visit(port, program);
}
} else {
System.out.println("Ignoring Node:" + componentType.getName());
System.out.println("Ignoring Port:" + mPort.getName());
this.marked_types.add(componentType);
this.marked_ports.add(mPort);
}
}
// B) Component Type
Node cmp_node = null;
Node impl_node = null;
String inst_cmp = "(.+)_Inst_.*";
Pattern inst_pattern = Pattern.compile(inst_cmp);
for (ComponentType componentType : vdm_model.getComponentType()) {
boolean is_declared = false;
if (!this.marked_types.contains(componentType)) {
for (ComponentImpl componentImpl : vdm_model.getComponentImpl()) {
if (componentType == componentImpl.getType()) {
impl_node = visit(componentType, true);
visit(componentImpl, impl_node);
is_declared = true;
break;
}
}
if (is_declared) {
cmp_node = visit(componentType, false);
Matcher m = inst_pattern.matcher(cmp_node.getName());
if (m.matches() == false) {
program.getNodeDeclaration().add(cmp_node);
}
program.getNodeDeclaration().add(impl_node);
} else {
cmp_node = visit(componentType, false);
program.getNodeDeclaration().add(cmp_node);
}
}
}
// Copying over Node Declarations.
for (Node node_dec : program.getNodeDeclaration()) {
visit(node_dec, program);
}
// Copy over Contract Spec.
for (Contract contract : program.getContractDeclaration()) {
visit(contract, program);
}
}
use of verdict.vdm.vdm_lustre.Node 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.Node in project VERDICT by ge-high-assurance.
the class VerdictLustreListener method exitImportedNode.
/**
* Extract an imported node declaration.
*/
@Override
public void exitImportedNode(LustreParser.ImportedNodeContext ctx) {
Node node = new Node();
node.setIsImported(true);
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.inlineContract() != null) {
node.setContract(ctx.inlineContract().spec);
}
LustreProgram program = model.getDataflowCode();
program.getNodeDeclaration().add(node);
}
Aggregations