use of verdict.vdm.vdm_lustre.SymbolDefinition in project VERDICT by ge-high-assurance.
the class VDMInstrumentor method dec_var_asmp_const.
/*
* Declare and Define weak assumptions for the blame assignment.
*/
protected void dec_var_asmp_const(Map<String, List<String>> connection_comp_map, boolean blame_assignment, boolean link_level) {
Set<String> vars = connection_comp_map.keySet();
List<SymbolDefinition> vars_dec = new ArrayList<SymbolDefinition>();
// String default_var = null;
Set<String> var_links = new HashSet<String>();
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);
if (!connections.isEmpty()) {
vars_dec.add(var_dec);
var_links.addAll(connections);
}
}
String[] vars_assumption = new String[vars.size()];
vars_assumption = vars.toArray(vars_assumption);
Expression assume_expr = null;
if (link_level) {
String[] links = new String[var_links.size()];
links = var_links.toArray(links);
assume_expr = add_assume_amo(links);
} else {
assume_expr = add_assume_amo(vars_assumption);
}
// Adding Xor assumption for components.
ComponentImpl compImpl = retrieve_main_cmp_impl();
if (compImpl != null) {
if (compImpl.getBlockImpl() == null) {
compImpl = retrieve_block_impl(compImpl);
}
ContractSpec contractSpec = compImpl.getType().getContract();
ContractItem assume_item = new ContractItem();
if (assume_expr != null) {
assume_item.setExpression(assume_expr);
contractSpec.getAssume().add(assume_item);
}
if (blame_assignment == false && contractSpec != null) {
contractSpec.getSymbol().addAll(vars_dec);
}
}
}
use of verdict.vdm.vdm_lustre.SymbolDefinition in project VERDICT by ge-high-assurance.
the class Agree2Vdm method translateEqStatement.
// method to map agree statements of the type EqStatement
// that have the form: 'eq' Arg (',' Arg)* '=' Expr ';'
// and create corresponding "SymbolDefinition" for the "ContractSpec" in the vdm model
private SymbolDefinition translateEqStatement(EqStatement eqStmt, Model model, HashSet<String> dataTypeDecl, HashSet<String> nodeDecl) {
SymbolDefinition symbDef = new verdict.vdm.vdm_lustre.SymbolDefinition();
// get the right side/expression
Expr agreeExpr = eqStmt.getExpr();
Expression vdmExpression = getVdmExpressionFromAgreeExpression(agreeExpr, dataTypeDecl, nodeDecl, model);
// get left side of the equation
EList<Arg> lhsArgs = eqStmt.getLhs();
for (Arg lhsArg : lhsArgs) {
// left side has the variable names along with their types
// set the id
symbDef.setName(lhsArg.getName());
symbDef.setDataType(getVdmTypeFromAgreeType(lhsArg.getType(), dataTypeDecl, model));
// set the expression as the value/definition for each variable on the left
symbDef.setDefinition(vdmExpression);
}
return symbDef;
}
use of verdict.vdm.vdm_lustre.SymbolDefinition in project VERDICT by ge-high-assurance.
the class Agree2Vdm method translateAgreeAnnex.
private Model translateAgreeAnnex(List<SystemType> systemTypes, List<SystemImplementation> systemImpls, Model model, HashSet<String> dataTypeDecl, HashSet<String> nodeDecl) {
LustreProgram lustreProgram = new LustreProgram();
// Initializing the lustre program in the VDM
model.setDataflowCode(lustreProgram);
// System.out.println("Processing "+systemTypes.size()+" SystemTypes for agree annexes");
for (SystemType sysType : systemTypes) {
// unpacking sysType
for (AnnexSubclause annex : sysType.getOwnedAnnexSubclauses()) {
if (annex.getName().equalsIgnoreCase("agree")) {
// annex is of type DefaultAnnexSubclause
DefaultAnnexSubclause ddASC = (DefaultAnnexSubclause) annex;
// AnnexSubclause aSC = ddASC.getParsedAnnexSubclause();
AgreeContractSubclause agreeAnnex = (AgreeContractSubclause) ddASC.getParsedAnnexSubclause();
// populating agree contracts in the vdm component type -- SHOULD ADD THIS CODE TO AADL2VDM
verdict.vdm.vdm_lustre.ContractSpec contractSpec = new verdict.vdm.vdm_lustre.ContractSpec();
EList<EObject> annexContents = agreeAnnex.eContents();
if (annexContents.isEmpty()) {
System.out.println("Empty Agree Annex.");
}
for (EObject clause : annexContents) {
// mapping to AgreeContractclause
AgreeContract agreeContract = (AgreeContract) clause;
// getting specStatements
EList<SpecStatement> specStatements = agreeContract.getSpecs();
for (SpecStatement specStatement : specStatements) {
if (specStatement instanceof EqStatement) {
EqStatement eqStmt = (EqStatement) specStatement;
// translate EqStatement in Agree to SymbolDefinition in vdm
SymbolDefinition symbDef = translateEqStatement(eqStmt, model, dataTypeDecl, nodeDecl);
// Add agree variable/symbol definition to the contractSpec in vdm
contractSpec.getSymbol().add(symbDef);
} else if (specStatement instanceof GuaranteeStatement) {
GuaranteeStatement guaranteeStmt = (GuaranteeStatement) specStatement;
ContractItem contractItem = translateGuaranteeStatement(guaranteeStmt, dataTypeDecl, nodeDecl, model);
contractSpec.getGuarantee().add(contractItem);
} else if (specStatement instanceof AssumeStatement) {
AssumeStatement assumeStmt = (AssumeStatement) specStatement;
ContractItem contractItem = translateAssumeStatement(assumeStmt, dataTypeDecl, nodeDecl, model);
contractSpec.getAssume().add(contractItem);
} else {
if (!(specStatement instanceof ConstStatementImpl)) {
System.out.println("Element not recognizable" + clause.eContents().toString());
}
}
}
}
if (contractSpec != null) {
List<ComponentType> vdmComponentTypes = model.getComponentType();
for (ComponentType vdmComponentType : vdmComponentTypes) {
// populating agree contract details in the corresponding componentType instance in vdm
if (vdmComponentType.getName().equalsIgnoreCase(sysType.getName())) {
vdmComponentType.setContract(contractSpec);
}
}
// populating agree contract details in the componentType instance in vdm
// packComponent.setContract(contractSpec);
}
}
}
// End of unpacking sysType
}
for (SystemImplementation sysImpl : systemImpls) {
// unpacking sysType
for (AnnexSubclause annex : sysImpl.getOwnedAnnexSubclauses()) {
if (annex.getName().equalsIgnoreCase("agree")) {
// annex is of type DefaultAnnexSubclause
DefaultAnnexSubclause ddASC = (DefaultAnnexSubclause) annex;
// AnnexSubclause aSC = ddASC.getParsedAnnexSubclause();
AgreeContractSubclause agreeAnnex = (AgreeContractSubclause) ddASC.getParsedAnnexSubclause();
// populating agree contracts in the vdm node body for component implementation type
verdict.vdm.vdm_lustre.NodeBody nodeBody = new verdict.vdm.vdm_lustre.NodeBody();
;
EList<EObject> annexContents = agreeAnnex.eContents();
if (annexContents.isEmpty()) {
System.out.println("Empty Agree Annex.");
}
for (EObject clause : annexContents) {
// mapping to AgreeContractclause
AgreeContract agreeContract = (AgreeContract) clause;
// getting specStatements
EList<SpecStatement> specStatements = agreeContract.getSpecs();
for (SpecStatement specStatement : specStatements) {
if (specStatement instanceof ConstStatementImpl) {
ConstStatementImpl constStmtImpl = (ConstStatementImpl) specStatement;
ConstantDeclaration constDecl = translateConstStatementImpl(constStmtImpl, dataTypeDecl, nodeDecl, model);
nodeBody.getConstantDeclaration().add(constDecl);
} else if (specStatement instanceof EqStatementImpl) {
EqStatementImpl eqStmtImpl = (EqStatementImpl) specStatement;
nodeBody = translateEqStatementImpl(eqStmtImpl, dataTypeDecl, nodeDecl, model, nodeBody);
} else if (specStatement instanceof AssignStatementImpl) {
AssignStatementImpl assignStmtImpl = (AssignStatementImpl) specStatement;
NodeEquation nodeEquation = translateAssignStatementImpl(assignStmtImpl, dataTypeDecl, nodeDecl, model);
nodeBody.getEquation().add(nodeEquation);
} else if (specStatement instanceof AssertStatementImpl) {
AssertStatementImpl assertStmtImpl = (AssertStatementImpl) specStatement;
Expression assertion = translateAssertStatementImpl(assertStmtImpl, dataTypeDecl, nodeDecl, model);
nodeBody.getAssertion().add(assertion);
} else {
System.out.println("Element not recognizable" + clause.eContents().toString());
}
}
}
List<ComponentImpl> vdmComponentImpls = model.getComponentImpl();
for (ComponentImpl vdmComponentImpl : vdmComponentImpls) {
// populating agree contract details in the corresponding componentImplType instance in vdm
if (vdmComponentImpl.getName().equalsIgnoreCase(sysImpl.getName())) {
vdmComponentImpl.setDataflowImpl(nodeBody);
}
}
}
}
}
return model;
}
use of verdict.vdm.vdm_lustre.SymbolDefinition in project VERDICT by ge-high-assurance.
the class VerdictLustreListener method exitSymbol.
/**
* Extract a symbol definition.
*/
@Override
public void exitSymbol(LustreParser.SymbolContext ctx) {
ctx.def = new SymbolDefinition();
if ("const".equals(ctx.keyword.getText())) {
ctx.def.setIsConstant(true);
}
ctx.def.setName(ctx.ID().getText());
if (ctx.type() != null) {
ctx.def.setDataType(ctx.type().dataType);
}
if (ctx.expr() != null) {
ctx.def.setDefinition(ctx.expr().expression);
}
}
use of verdict.vdm.vdm_lustre.SymbolDefinition 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);
}
Aggregations