use of verdict.vdm.vdm_lustre.ContractItem in project VERDICT by ge-high-assurance.
the class VerdictLustreListener method exitGuarantee.
/**
* Extract a guarantee contract item.
*/
@Override
public void exitGuarantee(LustreParser.GuaranteeContext ctx) {
ctx.item = new ContractItem();
if (ctx.STRING() != null) {
ctx.item.setName(ctx.STRING().getText());
}
ctx.item.setExpression(ctx.expr().expression);
}
use of verdict.vdm.vdm_lustre.ContractItem in project VERDICT by ge-high-assurance.
the class VDM2Lustre method visit.
public void visit(ContractSpec contractSpec) {
for (SymbolDefinition symbol : contractSpec.getSymbol()) {
DataType data_type = symbol.getDataType();
String user_defined_type = data_type.getUserDefinedType();
if (user_defined_type != null) {
user_defined_type = user_defined_type.replace(".", "_dot_");
user_defined_type = user_defined_type.replace("::", "_double_colon_");
boolean implemented_type = typeDeclarations.containsKey(user_defined_type);
if (implemented_type) {
data_type.setUserDefinedType(user_defined_type);
}
}
Expression expr = symbol.getDefinition();
expr = visitExpression(expr);
symbol.setDefinition(expr);
recordLiteral(expr);
}
String mbas_fml = "((.+):(.+):(.+))|((.+):Formula$)";
Pattern fml_pattern = Pattern.compile(mbas_fml);
List<ContractItem> mbas_guarantee = new ArrayList<ContractItem>();
// guarantee
for (ContractItem contractItem : contractSpec.getGuarantee()) {
if (contractItem.getName() != null) {
Matcher m = fml_pattern.matcher(contractItem.getName());
if (m.find()) {
mbas_guarantee.add(contractItem);
} else {
// Normal Formula
visit(contractItem);
}
} else {
visit(contractItem);
}
}
// remove MBAS guarantee
contractSpec.getGuarantee().removeAll(mbas_guarantee);
}
use of verdict.vdm.vdm_lustre.ContractItem 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.ContractItem in project VERDICT by ge-high-assurance.
the class VDMLustre2Kind2 method visit.
/**
* Translate VDM model contract specification to Kind 2 Lustre contract body.
*
* @param modelSpec the VDM model contract spec
* @return the Kind 2 Lustre contract body builder
*/
private static ContractBodyBuilder visit(ContractSpec modelSpec) {
ContractBodyBuilder cbb = new ContractBodyBuilder();
for (ContractImport contractImport : modelSpec.getImport()) {
cbb.importContract(contractImport.getContractId(), contractImport.getInputArgument().stream().map(input -> (IdExpr) visit(input)).collect(Collectors.toList()), contractImport.getOutputArgument().stream().map(output -> (IdExpr) visit(output)).collect(Collectors.toList()));
}
for (SymbolDefinition symbol : modelSpec.getSymbol()) {
if (symbol.isIsConstant() != null && symbol.isIsConstant()) {
if (symbol.getDataType() != null) {
if (symbol.getDefinition() != null) {
cbb.createConstant(symbol.getName(), visit(symbol.getDataType()), visit(symbol.getDefinition()));
} else {
cbb.createConstant(symbol.getName(), visit(symbol.getDataType()));
}
} else {
cbb.createConstant(symbol.getName(), visit(symbol.getDefinition()));
}
} else {
cbb.createVarDef(symbol.getName(), visit(symbol.getDataType()), visit(symbol.getDefinition()));
}
}
for (ContractItem assumption : modelSpec.getWeaklyassume()) {
cbb.weaklyAssume(assumption.getName(), visit(assumption.getExpression()));
}
for (ContractItem assumption : modelSpec.getAssume()) {
cbb.assume(assumption.getName(), visit(assumption.getExpression()));
}
for (ContractItem guarantee : modelSpec.getGuarantee()) {
cbb.guarantee(guarantee.getName(), visit(guarantee.getExpression()));
}
for (ContractMode mode : modelSpec.getMode()) {
ModeBuilder mb = new ModeBuilder(mode.getName());
for (ContractItem require : mode.getRequire()) {
mb.require(require.getName(), visit(require.getExpression()));
}
for (ContractItem ensure : mode.getEnsure()) {
mb.ensure(ensure.getName(), visit(ensure.getExpression()));
}
cbb.addMode(mb);
}
return cbb;
}
use of verdict.vdm.vdm_lustre.ContractItem in project VERDICT by ge-high-assurance.
the class VerdictLustreListener method exitAssume.
/**
* Extract an assume contract item.
*/
@Override
public void exitAssume(LustreParser.AssumeContext ctx) {
ctx.item = new ContractItem();
ctx.item.setExpression(ctx.expr().expression);
}
Aggregations