use of verdict.vdm.vdm_lustre.SymbolDefinition in project VERDICT by ge-high-assurance.
the class VDMInstrumentor method dec_var_const.
protected void dec_var_const(Map<String, List<String>> connection_comp_map) {
Set<String> vars = connection_comp_map.keySet();
List<SymbolDefinition> vars_dec = new ArrayList<SymbolDefinition>();
for (String var : vars) {
// Declaration global variables for instrumented links.
List<String> connections = connection_comp_map.get(var);
String id = var.replace("::", "_double_colon_");
SymbolDefinition var_dec = add_vars_assume(id, connections);
vars_dec.add(var_dec);
}
ComponentImpl compImpl = retrieve_main_cmp_impl();
// if (compImpl.getBlockImpl() == null) {
compImpl = retrieve_block_impl(compImpl);
// }
ContractSpec contractSpec = compImpl.getType().getContract();
contractSpec.getSymbol().addAll(vars_dec);
}
use of verdict.vdm.vdm_lustre.SymbolDefinition 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.SymbolDefinition in project VERDICT by ge-high-assurance.
the class VDMInstrumentor method add_vars_assume.
protected SymbolDefinition add_vars_assume(String var, List<String> connections) {
SymbolDefinition var_dec = new SymbolDefinition();
Expression var_expr = new Expression();
Stack<Expression> var_stack = new Stack<Expression>();
for (String con : connections) {
Expression expr = new Expression();
expr.setIdentifier(con);
var_stack.push(expr);
}
if (!var_stack.isEmpty()) {
var_expr = or_expr(var_stack);
}
if (var_expr == null) {
var_expr = new Expression();
var_expr.setIdentifier(var);
}
var_dec.setDefinition(var_expr);
var_dec.setName(var);
DataType dataType = new DataType();
dataType.setPlainType(PlainType.BOOL);
var_dec.setDataType(dataType);
return var_dec;
}
use of verdict.vdm.vdm_lustre.SymbolDefinition in project VERDICT by ge-high-assurance.
the class PrettyPrinter method visit.
public void visit(ContractSpec contractSpec) {
// Symbols
for (SymbolDefinition symbolDef : contractSpec.getSymbol()) {
sb.append(TAB);
sb.append("var ");
visit(symbolDef);
sb.append(";");
sb.append(NL);
}
// Assumuptions
for (ContractItem contractItem : contractSpec.getAssume()) {
sb.append(TAB).append("assume ");
visit(contractItem);
sb.append(";");
sb.append(NL);
}
sb.append(NL);
// Guarantees
for (ContractItem contractItem : contractSpec.getGuarantee()) {
sb.append(TAB).append("guarantee ");
visit(contractItem);
sb.append(";");
sb.append(NL);
}
sb.append(NL);
// Modes
for (ContractMode contractMode : contractSpec.getMode()) {
sb.append(TAB).append("mode ");
sb.append(TAB).append(" (");
sb.append(TAB).append(NL);
visit(contractMode);
sb.append(";");
sb.append(NL);
}
// Imports
for (ContractImport contractImport : contractSpec.getImport()) {
sb.append(TAB);
sb.append("import ");
visit(contractImport);
sb.append(";");
sb.append(NL);
}
}
Aggregations