Search in sources :

Example 11 with NodeDef

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

the class SafetyValidator method checkFaultSpecStmt.

/**
 * Checks description string, warning if empty, and checks that the
 * fault node name is valid.
 * @param specStmt
 */
@Check(CheckType.FAST)
public void checkFaultSpecStmt(FaultStatement specStmt) {
    DoubleDotRef nodeName = specStmt.getFaultDefName();
    // Check on fault description
    if (specStmt.getStr().isEmpty()) {
        warning(specStmt, "Fault description is optional, but should " + "not be an empty string.");
    }
    // Check that the NamedElement (fault node name) is a valid node definition
    NamedElement finalNodeName = nodeName.getElm();
    if (!(finalNodeName instanceof NodeDef)) {
        error(nodeName, "The fault name must be a valid node definition.");
    }
}
Also used : NodeDef(com.rockwellcollins.atc.agree.agree.NodeDef) DoubleDotRef(com.rockwellcollins.atc.agree.agree.DoubleDotRef) NamedElement(org.osate.aadl2.NamedElement) Check(org.eclipse.xtext.validation.Check)

Example 12 with NodeDef

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

the class SafetyLinkingService method getElm.

private Element getElm(EObject context, EReference reference, String name) {
    String[] segments = name.split("::");
    if (segments.length >= 2) {
        String pkgName = String.join("::", Arrays.copyOf(segments, segments.length - 1));
        String statementName = segments[segments.length - 1];
        Namespace namespace = AadlUtil.getContainingTopLevelNamespace(context);
        PropertySet propSet = AadlUtil.findImportedPropertySet(pkgName, namespace);
        if (propSet != null) {
            Element elm = propSet.findNamedElement(statementName);
            return elm;
        }
        AadlPackage aadlPackage = AadlUtil.findImportedPackage(pkgName, namespace);
        if (aadlPackage == null) {
            for (PackageRename rename : EcoreUtil2.getAllContentsOfType(namespace.getElementRoot(), PackageRename.class)) {
                if (rename.getName() != null && pkgName.equals(rename.getName())) {
                    aadlPackage = rename.getRenamedPackage();
                }
            }
        }
        if (aadlPackage != null) {
            for (AnnexLibrary annex : AnnexUtil.getAllActualAnnexLibraries(aadlPackage, AgreePackage.eINSTANCE.getAgreeContractLibrary())) {
                AgreeContract contract = (AgreeContract) ((AgreeContractLibrary) annex).getContract();
                for (com.rockwellcollins.atc.agree.agree.SpecStatement spec : contract.getSpecs()) {
                    if (spec instanceof RecordDef) {
                        if (((RecordDef) spec).getName().equals(statementName)) {
                            return (spec);
                        }
                    } else if (spec instanceof FnDef) {
                        if (((FnDef) spec).getName().equals(statementName)) {
                            return (spec);
                        }
                    } else if (spec instanceof LibraryFnDef) {
                        if (((LibraryFnDef) spec).getName().equals(statementName)) {
                            return (spec);
                        }
                    } else if (spec instanceof NodeDef) {
                        if (((NodeDef) spec).getName().equals(statementName)) {
                            return (spec);
                        }
                    } else if (spec instanceof LinearizationDef) {
                        if (((LinearizationDef) spec).getName().equals(statementName)) {
                            return (spec);
                        }
                    } else if (spec instanceof ConstStatement) {
                        if (((ConstStatement) spec).getName().equals(statementName)) {
                            return (spec);
                        }
                    } else if (spec instanceof EnumStatement) {
                        if (((EnumStatement) spec).getName().equals(statementName)) {
                            return (spec);
                        }
                        EList<NamedID> enums = ((EnumStatement) spec).getEnums();
                        for (NamedID nid : enums) {
                            if (nid.getName().contentEquals(statementName)) {
                                return nid;
                            }
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : AgreeContract(com.rockwellcollins.atc.agree.agree.AgreeContract) AadlPackage(org.osate.aadl2.AadlPackage) LibraryFnDef(com.rockwellcollins.atc.agree.agree.LibraryFnDef) NodeDef(com.rockwellcollins.atc.agree.agree.NodeDef) Element(org.osate.aadl2.Element) LinearizationDef(com.rockwellcollins.atc.agree.agree.LinearizationDef) Namespace(org.osate.aadl2.Namespace) NamedID(com.rockwellcollins.atc.agree.agree.NamedID) FnDef(com.rockwellcollins.atc.agree.agree.FnDef) LibraryFnDef(com.rockwellcollins.atc.agree.agree.LibraryFnDef) ConstStatement(com.rockwellcollins.atc.agree.agree.ConstStatement) PackageRename(org.osate.aadl2.PackageRename) EnumStatement(com.rockwellcollins.atc.agree.agree.EnumStatement) PropertySet(org.osate.aadl2.PropertySet) AnnexLibrary(org.osate.aadl2.AnnexLibrary) RecordDef(com.rockwellcollins.atc.agree.agree.RecordDef)

Example 13 with NodeDef

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

the class AgreeASTBuilder method caseLinearizationDef.

@Override
public Expr caseLinearizationDef(LinearizationDef expr) {
    NodeDef linearization = linearizationRewriter.addLinearization(expr);
    caseNodeDef(linearization);
    return null;
}
Also used : NodeDef(com.rockwellcollins.atc.agree.agree.NodeDef)

Example 14 with NodeDef

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

the class LinearizationRewriter method generateAgreeConstraintForm.

private static NodeDef generateAgreeConstraintForm(LinearizationDef linDef, BoundingSegments segs) {
    NodeDef result = af.createNodeDef();
    result.setName(getConstraintFormName(AgreeUtils.getNodeName(linDef)));
    Arg inputArg = af.createArg();
    PrimType inputArgType = af.createPrimType();
    inputArgType.setName("real");
    inputArg.setType(inputArgType);
    inputArg.setName("inp");
    result.getArgs().add(inputArg);
    Arg outputArg = af.createArg();
    PrimType outputArgType = af.createPrimType();
    outputArgType.setName("real");
    outputArg.setType(outputArgType);
    outputArg.setName("result");
    result.getArgs().add(outputArg);
    Arg constraintArg = af.createArg();
    PrimType constraintArgType = af.createPrimType();
    constraintArgType.setName("bool");
    constraintArg.setType(constraintArgType);
    constraintArg.setName("constraint");
    result.getRets().add(constraintArg);
    NamedElmExpr inputId = af.createNamedElmExpr();
    inputId.setElm(EcoreUtil.copy(inputArg));
    RealLitExpr domainCheckLowerLit = af.createRealLitExpr();
    domainCheckLowerLit.setVal(Double.toString(segs.lower.getFirst().startX));
    BinaryExpr domainCheckLowerExpr = af.createBinaryExpr();
    domainCheckLowerExpr.setOp("<=");
    domainCheckLowerExpr.setLeft(domainCheckLowerLit);
    domainCheckLowerExpr.setRight(EcoreUtil.copy(inputId));
    RealLitExpr domainCheckUpperLit = af.createRealLitExpr();
    domainCheckUpperLit.setVal(Double.toString(segs.lower.getLast().stopX));
    BinaryExpr domainCheckUpperExpr = af.createBinaryExpr();
    domainCheckUpperExpr.setOp("<=");
    domainCheckUpperExpr.setLeft(EcoreUtil.copy(inputId));
    domainCheckUpperExpr.setRight(domainCheckUpperLit);
    BinaryExpr domainCheckExpr = af.createBinaryExpr();
    domainCheckExpr.setOp("and");
    domainCheckExpr.setLeft(domainCheckLowerExpr);
    domainCheckExpr.setRight(domainCheckUpperExpr);
    BoolLitExpr trueLitExpr = af.createBoolLitExpr();
    BooleanLiteral trueLitValue = aadlF.createBooleanLiteral();
    trueLitValue.setValue(true);
    trueLitExpr.setVal(trueLitValue);
    Expr upperBoundExpr = EcoreUtil.copy(trueLitExpr);
    for (Segment seg : segs.upper) {
        BinaryExpr andExpr = af.createBinaryExpr();
        andExpr.setOp("and");
        andExpr.setLeft(upperBoundExpr);
        andExpr.setRight(generateAgreeLinearBoundImplicationExpr(inputArg, outputArg, "<=", seg));
        upperBoundExpr = andExpr;
    }
    Expr lowerBoundExpr = EcoreUtil.copy(trueLitExpr);
    for (Segment seg : segs.lower) {
        BinaryExpr andExpr = af.createBinaryExpr();
        andExpr.setOp("and");
        andExpr.setLeft(lowerBoundExpr);
        andExpr.setRight(generateAgreeLinearBoundImplicationExpr(inputArg, outputArg, ">=", seg));
        lowerBoundExpr = andExpr;
    }
    BinaryExpr boundsCheckExpr = af.createBinaryExpr();
    boundsCheckExpr.setOp("and");
    boundsCheckExpr.setLeft(upperBoundExpr);
    boundsCheckExpr.setRight(lowerBoundExpr);
    BinaryExpr constraintExpr = af.createBinaryExpr();
    constraintExpr.setOp("and");
    constraintExpr.setLeft(domainCheckExpr);
    constraintExpr.setRight(boundsCheckExpr);
    NodeEq constraintEq = af.createNodeEq();
    constraintEq.getLhs().add(constraintArg);
    constraintEq.setExpr(constraintExpr);
    NodeBodyExpr nodeBody = af.createNodeBodyExpr();
    nodeBody.getStmts().add(constraintEq);
    result.setNodeBody(nodeBody);
    NodeLemma domainCheckLemma = af.createNodeLemma();
    domainCheckLemma.setStr(result.getName() + " domain check");
    domainCheckLemma.setExpr(EcoreUtil.copy(domainCheckExpr));
    nodeBody.getStmts().add(domainCheckLemma);
    return result;
}
Also used : BoolLitExpr(com.rockwellcollins.atc.agree.agree.BoolLitExpr) NodeDef(com.rockwellcollins.atc.agree.agree.NodeDef) NodeLemma(com.rockwellcollins.atc.agree.agree.NodeLemma) BooleanLiteral(org.osate.aadl2.BooleanLiteral) BinaryExpr(com.rockwellcollins.atc.agree.agree.BinaryExpr) NodeEq(com.rockwellcollins.atc.agree.agree.NodeEq) Segment(com.rockwellcollins.atc.agree.analysis.linearization.Linearize.Segment) NodeBodyExpr(com.rockwellcollins.atc.agree.agree.NodeBodyExpr) RealLitExpr(com.rockwellcollins.atc.agree.agree.RealLitExpr) Expr(com.rockwellcollins.atc.agree.agree.Expr) BoolLitExpr(com.rockwellcollins.atc.agree.agree.BoolLitExpr) NodeBodyExpr(com.rockwellcollins.atc.agree.agree.NodeBodyExpr) BinaryExpr(com.rockwellcollins.atc.agree.agree.BinaryExpr) NamedElmExpr(com.rockwellcollins.atc.agree.agree.NamedElmExpr) Arg(com.rockwellcollins.atc.agree.agree.Arg) PrimType(com.rockwellcollins.atc.agree.agree.PrimType) RealLitExpr(com.rockwellcollins.atc.agree.agree.RealLitExpr) NamedElmExpr(com.rockwellcollins.atc.agree.agree.NamedElmExpr)

Example 15 with NodeDef

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

the class AgreeValidator method checkNodeStmt.

@Check(CheckType.FAST)
public void checkNodeStmt(NodeStmt nodeStmt) {
    List<NamedElmExpr> dotIds = EcoreUtil2.getAllContentsOfType(nodeStmt, NamedElmExpr.class);
    for (NamedElmExpr dotId : dotIds) {
        NamedElement id = dotId.getElm();
        // restrict the elements that are single names or the last projection.
        boolean restrictedElm = true;
        if (dotId.eContainer() instanceof SelectionExpr) {
            NamedElement ne = ((SelectionExpr) dotId.eContainer()).getField();
            restrictedElm = ne == id && !(dotId.eContainer().eContainer() instanceof SelectionExpr);
        }
        if (restrictedElm && !(id instanceof Arg) && !(id instanceof ConstStatement) && !(id instanceof NodeDef) && !(id instanceof FnDef) && !(id instanceof UninterpretedFnDef) && !(id instanceof DataSubcomponent) && !(id instanceof DoubleDotRef) && !(id instanceof DataImplementation) && !(id instanceof RecordDef) && !(id instanceof NamedID)) {
            error(dotId, "Only arguments, constants, and node calls allowed within a node");
        }
    }
}
Also used : NodeDef(com.rockwellcollins.atc.agree.agree.NodeDef) DataImplementation(org.osate.aadl2.DataImplementation) SelectionExpr(com.rockwellcollins.atc.agree.agree.SelectionExpr) UninterpretedFnDef(com.rockwellcollins.atc.agree.agree.UninterpretedFnDef) NamedID(com.rockwellcollins.atc.agree.agree.NamedID) FnDef(com.rockwellcollins.atc.agree.agree.FnDef) LibraryFnDef(com.rockwellcollins.atc.agree.agree.LibraryFnDef) UninterpretedFnDef(com.rockwellcollins.atc.agree.agree.UninterpretedFnDef) ConstStatement(com.rockwellcollins.atc.agree.agree.ConstStatement) DataSubcomponent(org.osate.aadl2.DataSubcomponent) Arg(com.rockwellcollins.atc.agree.agree.Arg) DoubleDotRef(com.rockwellcollins.atc.agree.agree.DoubleDotRef) NamedElement(org.osate.aadl2.NamedElement) RecordDef(com.rockwellcollins.atc.agree.agree.RecordDef) NamedElmExpr(com.rockwellcollins.atc.agree.agree.NamedElmExpr) Check(org.eclipse.xtext.validation.Check)

Aggregations

NodeDef (com.rockwellcollins.atc.agree.agree.NodeDef)19 NamedElement (org.osate.aadl2.NamedElement)10 Arg (com.rockwellcollins.atc.agree.agree.Arg)7 Check (org.eclipse.xtext.validation.Check)7 DoubleDotRef (com.rockwellcollins.atc.agree.agree.DoubleDotRef)6 LibraryFnDef (com.rockwellcollins.atc.agree.agree.LibraryFnDef)6 FnDef (com.rockwellcollins.atc.agree.agree.FnDef)5 NamedElmExpr (com.rockwellcollins.atc.agree.agree.NamedElmExpr)5 RecordDef (com.rockwellcollins.atc.agree.agree.RecordDef)5 BoolLitExpr (com.rockwellcollins.atc.agree.agree.BoolLitExpr)4 ConstStatement (com.rockwellcollins.atc.agree.agree.ConstStatement)4 Expr (com.rockwellcollins.atc.agree.agree.Expr)4 LinearizationDef (com.rockwellcollins.atc.agree.agree.LinearizationDef)4 RealLitExpr (com.rockwellcollins.atc.agree.agree.RealLitExpr)4 UninterpretedFnDef (com.rockwellcollins.atc.agree.agree.UninterpretedFnDef)4 ArrayList (java.util.ArrayList)4 BinaryExpr (com.rockwellcollins.atc.agree.agree.BinaryExpr)3 CallExpr (com.rockwellcollins.atc.agree.agree.CallExpr)3 NodeBodyExpr (com.rockwellcollins.atc.agree.agree.NodeBodyExpr)3 EObject (org.eclipse.emf.ecore.EObject)3