Search in sources :

Example 1 with SymbolDefinition

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);
        }
    }
}
Also used : Expression(verdict.vdm.vdm_lustre.Expression) ContractItem(verdict.vdm.vdm_lustre.ContractItem) ArrayList(java.util.ArrayList) ContractSpec(verdict.vdm.vdm_lustre.ContractSpec) ComponentImpl(verdict.vdm.vdm_model.ComponentImpl) SymbolDefinition(verdict.vdm.vdm_lustre.SymbolDefinition) HashSet(java.util.HashSet)

Example 2 with SymbolDefinition

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;
}
Also used : EnumLitExpr(com.rockwellcollins.atc.agree.agree.EnumLitExpr) RealLitExpr(com.rockwellcollins.atc.agree.agree.RealLitExpr) EventExpr(com.rockwellcollins.atc.agree.agree.EventExpr) NamedElmExpr(com.rockwellcollins.atc.agree.agree.NamedElmExpr) SelectionExpr(com.rockwellcollins.atc.agree.agree.SelectionExpr) IfThenElseExpr(com.rockwellcollins.atc.agree.agree.IfThenElseExpr) PreExpr(com.rockwellcollins.atc.agree.agree.PreExpr) RecordLitExpr(com.rockwellcollins.atc.agree.agree.RecordLitExpr) BinaryExpr(com.rockwellcollins.atc.agree.agree.BinaryExpr) UnaryExpr(com.rockwellcollins.atc.agree.agree.UnaryExpr) Expr(com.rockwellcollins.atc.agree.agree.Expr) BoolLitExpr(com.rockwellcollins.atc.agree.agree.BoolLitExpr) NodeBodyExpr(com.rockwellcollins.atc.agree.agree.NodeBodyExpr) IntLitExpr(com.rockwellcollins.atc.agree.agree.IntLitExpr) CallExpr(com.rockwellcollins.atc.agree.agree.CallExpr) PropertyExpression(org.osate.aadl2.PropertyExpression) Expression(verdict.vdm.vdm_lustre.Expression) Arg(com.rockwellcollins.atc.agree.agree.Arg) SymbolDefinition(verdict.vdm.vdm_lustre.SymbolDefinition)

Example 3 with SymbolDefinition

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;
}
Also used : ConstStatementImpl(com.rockwellcollins.atc.agree.agree.impl.ConstStatementImpl) ConstantDeclaration(verdict.vdm.vdm_lustre.ConstantDeclaration) SystemType(org.osate.aadl2.SystemType) ComponentImpl(verdict.vdm.vdm_model.ComponentImpl) ContractItem(verdict.vdm.vdm_lustre.ContractItem) EObject(org.eclipse.emf.ecore.EObject) DefaultAnnexSubclause(org.osate.aadl2.DefaultAnnexSubclause) AssertStatementImpl(com.rockwellcollins.atc.agree.agree.impl.AssertStatementImpl) SymbolDefinition(verdict.vdm.vdm_lustre.SymbolDefinition) NodeBody(verdict.vdm.vdm_lustre.NodeBody) AgreeContract(com.rockwellcollins.atc.agree.agree.AgreeContract) EqStatementImpl(com.rockwellcollins.atc.agree.agree.impl.EqStatementImpl) GuaranteeStatement(com.rockwellcollins.atc.agree.agree.GuaranteeStatement) ComponentType(verdict.vdm.vdm_model.ComponentType) AssumeStatement(com.rockwellcollins.atc.agree.agree.AssumeStatement) NodeBody(verdict.vdm.vdm_lustre.NodeBody) SpecStatement(com.rockwellcollins.atc.agree.agree.SpecStatement) AgreeContractSubclause(com.rockwellcollins.atc.agree.agree.AgreeContractSubclause) NodeEquation(verdict.vdm.vdm_lustre.NodeEquation) PropertyExpression(org.osate.aadl2.PropertyExpression) Expression(verdict.vdm.vdm_lustre.Expression) LustreProgram(verdict.vdm.vdm_lustre.LustreProgram) SystemImplementation(org.osate.aadl2.SystemImplementation) EqStatement(com.rockwellcollins.atc.agree.agree.EqStatement) AssignStatementImpl(com.rockwellcollins.atc.agree.agree.impl.AssignStatementImpl) AnnexSubclause(org.osate.aadl2.AnnexSubclause) DefaultAnnexSubclause(org.osate.aadl2.DefaultAnnexSubclause)

Example 4 with SymbolDefinition

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);
    }
}
Also used : SymbolDefinition(verdict.vdm.vdm_lustre.SymbolDefinition)

Example 5 with SymbolDefinition

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);
}
Also used : Pattern(java.util.regex.Pattern) Expression(verdict.vdm.vdm_lustre.Expression) ContractItem(verdict.vdm.vdm_lustre.ContractItem) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) DataType(verdict.vdm.vdm_data.DataType) SymbolDefinition(verdict.vdm.vdm_lustre.SymbolDefinition)

Aggregations

SymbolDefinition (verdict.vdm.vdm_lustre.SymbolDefinition)9 ContractItem (verdict.vdm.vdm_lustre.ContractItem)5 Expression (verdict.vdm.vdm_lustre.Expression)5 ArrayList (java.util.ArrayList)3 ComponentImpl (verdict.vdm.vdm_model.ComponentImpl)3 PropertyExpression (org.osate.aadl2.PropertyExpression)2 ContractImport (verdict.vdm.vdm_lustre.ContractImport)2 ContractMode (verdict.vdm.vdm_lustre.ContractMode)2 ContractSpec (verdict.vdm.vdm_lustre.ContractSpec)2 AgreeContract (com.rockwellcollins.atc.agree.agree.AgreeContract)1 AgreeContractSubclause (com.rockwellcollins.atc.agree.agree.AgreeContractSubclause)1 Arg (com.rockwellcollins.atc.agree.agree.Arg)1 AssumeStatement (com.rockwellcollins.atc.agree.agree.AssumeStatement)1 BinaryExpr (com.rockwellcollins.atc.agree.agree.BinaryExpr)1 BoolLitExpr (com.rockwellcollins.atc.agree.agree.BoolLitExpr)1 CallExpr (com.rockwellcollins.atc.agree.agree.CallExpr)1 EnumLitExpr (com.rockwellcollins.atc.agree.agree.EnumLitExpr)1 EqStatement (com.rockwellcollins.atc.agree.agree.EqStatement)1 EventExpr (com.rockwellcollins.atc.agree.agree.EventExpr)1 Expr (com.rockwellcollins.atc.agree.agree.Expr)1