Search in sources :

Example 1 with EqStatement

use of com.rockwellcollins.atc.agree.agree.EqStatement 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 2 with EqStatement

use of com.rockwellcollins.atc.agree.agree.EqStatement in project AGREE by loonwerks.

the class EquationStatementHandler method rename.

@Override
public void rename(final RenameContext ctx) {
    final EqStatement bo = ctx.getBusinessObject(EqStatement.class).get();
    final String[] names = getNames(ctx);
    for (int i = 0; i < names.length; i++) {
        final String name = names[i];
        if (i < bo.getLhs().size()) {
            bo.getLhs().get(0).setName(name);
        } else {
            final Arg newArg = AgreeFactory.eINSTANCE.createArg();
            newArg.setName(name);
            final PrimType type = AgreeFactory.eINSTANCE.createPrimType();
            type.setName("bool");
            newArg.setType(type);
            bo.getLhs().add(newArg);
        }
    }
    // Remove extra names on left-hand side of equation
    while (bo.getLhs().size() > names.length) {
        bo.getLhs().remove(bo.getLhs().size() - 1);
    }
}
Also used : Arg(com.rockwellcollins.atc.agree.agree.Arg) PrimType(com.rockwellcollins.atc.agree.agree.PrimType) EqStatement(com.rockwellcollins.atc.agree.agree.EqStatement)

Example 3 with EqStatement

use of com.rockwellcollins.atc.agree.agree.EqStatement in project AGREE by loonwerks.

the class AgreeValidator method checkArg.

@Check(CheckType.FAST)
public void checkArg(Arg arg) {
    Type type = arg.getType();
    if (type instanceof PrimType) {
        PrimType primType = (PrimType) type;
        String strType = primType.getName();
        String rangeLow = primType.getRangeLow();
        String rangeHigh = primType.getRangeHigh();
        if (rangeLow != null && rangeHigh != null) {
            // this is a ranged argument. It can show up only in an equation statement
            EObject container = arg.eContainer();
            if (!(container instanceof EqStatement || container instanceof InputStatement)) {
                error(arg, "Ranged arguments can appear only in equation statements or agree_input statements");
            }
            boolean rangeLowDot = rangeLow.contains(".");
            boolean rangeHighDot = rangeHigh.contains(".");
            if (rangeLowDot != rangeHighDot) {
                error(arg, "The range intervals are of differing types");
            }
            if (strType.equals("int") && (rangeLowDot || rangeHighDot)) {
                error(arg, "Ranged variable of type 'int' contains a 'real' value in its interval");
            }
            if (strType.equals("real") && (!rangeLowDot || !rangeHighDot)) {
                error(arg, "Ranged variable of type 'real' contains an 'int' value in its interval");
            }
            float low = Float.valueOf(rangeLow);
            float high = Float.valueOf(rangeHigh);
            low *= primType.getLowNeg() == null ? 1.0 : -1.0;
            high *= primType.getHighNeg() == null ? 1.0 : -1.0;
            if (low >= high) {
                error(arg, "The low value of the interval is greater than or equal to the high end");
            }
        }
    } else if (type instanceof DoubleDotRef) {
        DoubleDotRef recType = (DoubleDotRef) type;
        NamedElement finalId = recType.getElm();
        if (!(finalId instanceof DataImplementation) && !(finalId instanceof RecordDef) && !(finalId instanceof DataType) && !(finalId instanceof EnumStatement)) {
            error(recType, "types must be record definition, array definition, data implementation, enumeration, or datatype");
        }
        if (finalId instanceof DataImplementation) {
            if (AgreeTypeSystem.typesEqual(AgreeTypeSystem.typeDefFromType(recType), AgreeTypeSystem.Prim.ErrorTypeDef)) {
                error(recType, "Data Implementations with no subcomponents must extend" + " a Base_Type that AGREE can reason about.");
                return;
            }
            if (((DataImplementation) finalId).getAllSubcomponents().size() != 0) {
                if (AgreeTypeSystem.typesEqual(AgreeTypeSystem.typeDefFromType(recType), AgreeTypeSystem.Prim.BoolTypeDef) || AgreeTypeSystem.typesEqual(AgreeTypeSystem.typeDefFromType(recType), AgreeTypeSystem.Prim.IntTypeDef) || AgreeTypeSystem.typesEqual(AgreeTypeSystem.typeDefFromType(recType), AgreeTypeSystem.Prim.RealTypeDef)) {
                    error(finalId, "Data implementations with subcomponents cannot be" + " interpreted by AGREE if they extend Base_Types");
                }
            }
            // dataImplCycleCheck(recId);
            return;
        }
        if (finalId instanceof DataType) {
            if (AgreeTypeSystem.typesEqual(AgreeTypeSystem.typeDefFromType(recType), AgreeTypeSystem.Prim.ErrorTypeDef)) {
                error(recType, "AADL Datatypes must extend" + " a Base_Type that AGREE can reason about.");
                return;
            }
        }
    }
}
Also used : DataImplementation(org.osate.aadl2.DataImplementation) PrimType(com.rockwellcollins.atc.agree.agree.PrimType) DataType(org.osate.aadl2.DataType) CheckType(org.eclipse.xtext.validation.CheckType) FeatureGroupType(org.osate.aadl2.FeatureGroupType) ComponentType(org.osate.aadl2.ComponentType) Type(com.rockwellcollins.atc.agree.agree.Type) DirectionType(org.osate.aadl2.DirectionType) EObject(org.eclipse.emf.ecore.EObject) DoubleDotRef(com.rockwellcollins.atc.agree.agree.DoubleDotRef) EnumStatement(com.rockwellcollins.atc.agree.agree.EnumStatement) PrimType(com.rockwellcollins.atc.agree.agree.PrimType) DataType(org.osate.aadl2.DataType) EqStatement(com.rockwellcollins.atc.agree.agree.EqStatement) InputStatement(com.rockwellcollins.atc.agree.agree.InputStatement) NamedElement(org.osate.aadl2.NamedElement) RecordDef(com.rockwellcollins.atc.agree.agree.RecordDef) Check(org.eclipse.xtext.validation.Check)

Example 4 with EqStatement

use of com.rockwellcollins.atc.agree.agree.EqStatement in project AGREE by loonwerks.

the class AgreeScopeProvider method getNamedElementsFromSpecs.

private Map<String, NamedElement> getNamedElementsFromSpecs(EList<SpecStatement> specs) {
    Map<String, NamedElement> nelms = new HashMap<>();
    for (SpecStatement spec : specs) {
        if (spec instanceof NamedElement) {
            nelms.put(((NamedElement) spec).getName(), (NamedElement) spec);
        }
        if (spec instanceof EqStatement) {
            EqStatement eq = (EqStatement) spec;
            ArrayList<NamedElement> nes = new ArrayList<>();
            nes.addAll(eq.getLhs());
            nelms.putAll(toNamedElementMap(nes));
        } else if (spec instanceof ConstStatement) {
            ConstStatement c = (ConstStatement) spec;
            nelms.put(c.getName(), c);
        } else if (spec instanceof InputStatement) {
            ArrayList<NamedElement> nes = new ArrayList<>();
            nes.addAll(((InputStatement) spec).getLhs());
            nelms.putAll(toNamedElementMap(nes));
        } else if (spec instanceof EnumStatement) {
            ArrayList<NamedElement> nes = new ArrayList<>();
            nes.addAll(((EnumStatement) spec).getEnums());
            nelms.putAll(toNamedElementMap(nes));
        }
    }
    return nelms;
}
Also used : ConstStatement(com.rockwellcollins.atc.agree.agree.ConstStatement) HashMap(java.util.HashMap) EnumStatement(com.rockwellcollins.atc.agree.agree.EnumStatement) ArrayList(java.util.ArrayList) SpecStatement(com.rockwellcollins.atc.agree.agree.SpecStatement) EqStatement(com.rockwellcollins.atc.agree.agree.EqStatement) InputStatement(com.rockwellcollins.atc.agree.agree.InputStatement) NamedElement(org.osate.aadl2.NamedElement)

Example 5 with EqStatement

use of com.rockwellcollins.atc.agree.agree.EqStatement in project AMASE by loonwerks.

the class SafetyScopeProvider method getNamedElementsFromSpecs.

private Set<NamedElement> getNamedElementsFromSpecs(EList<SpecStatement> agreeSpecs) {
    Set<NamedElement> nelms = new HashSet<>();
    for (SpecStatement spec : agreeSpecs) {
        if (spec instanceof NamedElement) {
            nelms.add((NamedElement) spec);
        }
        if (spec instanceof EqStatement) {
            EqStatement eq = (EqStatement) spec;
            nelms.addAll(eq.getLhs());
        } else if (spec instanceof InputStatement) {
            nelms.addAll(((InputStatement) spec).getLhs());
        } else if (spec instanceof EnumStatement) {
            nelms.addAll(((EnumStatement) spec).getEnums());
        }
    }
    return nelms;
}
Also used : EnumStatement(com.rockwellcollins.atc.agree.agree.EnumStatement) SpecStatement(com.rockwellcollins.atc.agree.agree.SpecStatement) SafetyEqStatement(edu.umn.cs.crisys.safety.safety.SafetyEqStatement) EqStatement(com.rockwellcollins.atc.agree.agree.EqStatement) InputStatement(com.rockwellcollins.atc.agree.agree.InputStatement) NamedElement(org.osate.aadl2.NamedElement) HashSet(java.util.HashSet)

Aggregations

EqStatement (com.rockwellcollins.atc.agree.agree.EqStatement)11 SpecStatement (com.rockwellcollins.atc.agree.agree.SpecStatement)7 Arg (com.rockwellcollins.atc.agree.agree.Arg)6 InputStatement (com.rockwellcollins.atc.agree.agree.InputStatement)6 ArrayList (java.util.ArrayList)5 PrimType (com.rockwellcollins.atc.agree.agree.PrimType)4 ComponentType (org.osate.aadl2.ComponentType)4 AgreeContract (com.rockwellcollins.atc.agree.agree.AgreeContract)3 AgreeContractSubclause (com.rockwellcollins.atc.agree.agree.AgreeContractSubclause)3 AssumeStatement (com.rockwellcollins.atc.agree.agree.AssumeStatement)3 ConstStatement (com.rockwellcollins.atc.agree.agree.ConstStatement)3 DoubleDotRef (com.rockwellcollins.atc.agree.agree.DoubleDotRef)3 EnumStatement (com.rockwellcollins.atc.agree.agree.EnumStatement)3 GetPropertyExpr (com.rockwellcollins.atc.agree.agree.GetPropertyExpr)3 GuaranteeStatement (com.rockwellcollins.atc.agree.agree.GuaranteeStatement)3 PropertyStatement (com.rockwellcollins.atc.agree.agree.PropertyStatement)3 ComponentImplementation (org.osate.aadl2.ComponentImplementation)3 NamedElement (org.osate.aadl2.NamedElement)3 Property (org.osate.aadl2.Property)3 ArrayLiteralExpr (com.rockwellcollins.atc.agree.agree.ArrayLiteralExpr)2