Search in sources :

Example 6 with NamedElmExpr

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

the class AgreeValidator method checkEventExpr.

@Check(CheckType.FAST)
public void checkEventExpr(EventExpr event) {
    if (isInLinearizationBody(event)) {
        error(event, "'event' expressions not allowed in linearization body expressions");
        return;
    }
    Expr expr = event.getPort();
    NamedElement namedEl = null;
    if (expr instanceof NamedElmExpr) {
        namedEl = ((NamedElmExpr) expr).getElm();
    } else if (expr instanceof SelectionExpr) {
        namedEl = ((SelectionExpr) expr).getField();
    }
    if (namedEl == null || !(namedEl instanceof EventPort || namedEl instanceof EventDataPort)) {
        error(event, "Argument of event expression must be an event port or event data port");
    }
}
Also used : EnumLitExpr(com.rockwellcollins.atc.agree.agree.EnumLitExpr) IndicesExpr(com.rockwellcollins.atc.agree.agree.IndicesExpr) TimeRiseExpr(com.rockwellcollins.atc.agree.agree.TimeRiseExpr) FlatmapExpr(com.rockwellcollins.atc.agree.agree.FlatmapExpr) TimeFallExpr(com.rockwellcollins.atc.agree.agree.TimeFallExpr) RealLitExpr(com.rockwellcollins.atc.agree.agree.RealLitExpr) GetPropertyExpr(com.rockwellcollins.atc.agree.agree.GetPropertyExpr) TimeOfExpr(com.rockwellcollins.atc.agree.agree.TimeOfExpr) PrevExpr(com.rockwellcollins.atc.agree.agree.PrevExpr) FoldRightExpr(com.rockwellcollins.atc.agree.agree.FoldRightExpr) TagExpr(com.rockwellcollins.atc.agree.agree.TagExpr) EventExpr(com.rockwellcollins.atc.agree.agree.EventExpr) LatchedExpr(com.rockwellcollins.atc.agree.agree.LatchedExpr) NamedElmExpr(com.rockwellcollins.atc.agree.agree.NamedElmExpr) SelectionExpr(com.rockwellcollins.atc.agree.agree.SelectionExpr) IfThenElseExpr(com.rockwellcollins.atc.agree.agree.IfThenElseExpr) ArraySubExpr(com.rockwellcollins.atc.agree.agree.ArraySubExpr) 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) ExistsExpr(com.rockwellcollins.atc.agree.agree.ExistsExpr) FoldLeftExpr(com.rockwellcollins.atc.agree.agree.FoldLeftExpr) RecordUpdateExpr(com.rockwellcollins.atc.agree.agree.RecordUpdateExpr) ForallExpr(com.rockwellcollins.atc.agree.agree.ForallExpr) Expr(com.rockwellcollins.atc.agree.agree.Expr) ArrayUpdateExpr(com.rockwellcollins.atc.agree.agree.ArrayUpdateExpr) 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) ArrayLiteralExpr(com.rockwellcollins.atc.agree.agree.ArrayLiteralExpr) EventPort(org.osate.aadl2.EventPort) SelectionExpr(com.rockwellcollins.atc.agree.agree.SelectionExpr) EventDataPort(org.osate.aadl2.EventDataPort) NamedElement(org.osate.aadl2.NamedElement) NamedElmExpr(com.rockwellcollins.atc.agree.agree.NamedElmExpr) Check(org.eclipse.xtext.validation.Check)

Example 7 with NamedElmExpr

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

the class SafetyAnnexContentAssist method getNestedDotIDCandidates.

private List<String> getNestedDotIDCandidates(SelectionExpr id) {
    NamedElement base = ((NamedElmExpr) id).getElm();
    NamedElement namedEl = null;
    if (base instanceof Arg) {
        Type type = ((Arg) base).getType();
        DoubleDotRef elID = ((DoubleDotRef) type);
        namedEl = elID.getElm();
    } else if (base instanceof DataPort) {
        namedEl = ((DataPort) base).getDataFeatureClassifier();
    } else if (base instanceof EventDataPort) {
        namedEl = ((EventDataPort) base).getDataFeatureClassifier();
    } else if (base instanceof AadlPackage) {
        return getNestedDotIDCandidates((AadlPackage) base);
    } else {
        return new ArrayList<>();
    }
    return getNestedDotIDCandidates(namedEl);
}
Also used : DataPort(org.osate.aadl2.DataPort) EventDataPort(org.osate.aadl2.EventDataPort) Type(com.rockwellcollins.atc.agree.agree.Type) AadlPackage(org.osate.aadl2.AadlPackage) Arg(com.rockwellcollins.atc.agree.agree.Arg) DoubleDotRef(com.rockwellcollins.atc.agree.agree.DoubleDotRef) EventDataPort(org.osate.aadl2.EventDataPort) NamedElement(org.osate.aadl2.NamedElement) NamedElmExpr(com.rockwellcollins.atc.agree.agree.NamedElmExpr)

Example 8 with NamedElmExpr

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

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

the class LinearizationRewriter method generateAgreeLinearBoundImplicationExpr.

private static Expr generateAgreeLinearBoundImplicationExpr(Arg inputArg, Arg resultArg, String relop, Segment seg) {
    RealLitExpr inputMinExpr = af.createRealLitExpr();
    inputMinExpr.setVal(Double.toString(seg.startX));
    RealLitExpr inputMaxExpr = af.createRealLitExpr();
    inputMaxExpr.setVal(Double.toString(seg.stopX));
    RealLitExpr resultOriginExpr = af.createRealLitExpr();
    resultOriginExpr.setVal(Double.toString(seg.startY));
    RealLitExpr resultSlopeExpr = af.createRealLitExpr();
    resultSlopeExpr.setVal(Double.toString((seg.stopY - seg.startY) / (seg.stopX - seg.startX)));
    NamedElmExpr inputId = af.createNamedElmExpr();
    inputId.setElm(EcoreUtil.copy(inputArg));
    NamedElmExpr resultId = af.createNamedElmExpr();
    resultId.setElm(EcoreUtil.copy(resultArg));
    // =======
    // 
    // NestedDotID resultId = af.createNestedDotID();
    // resultId.setBase(EcoreUtil.copy(resultArg));
    // >>>>>>> origin/develop
    BinaryExpr rangeMinExpr = af.createBinaryExpr();
    rangeMinExpr.setOp(">=");
    rangeMinExpr.setLeft(EcoreUtil.copy(inputId));
    rangeMinExpr.setRight(EcoreUtil.copy(inputMinExpr));
    BinaryExpr rangeMaxExpr = af.createBinaryExpr();
    rangeMaxExpr.setOp("<=");
    rangeMaxExpr.setLeft(EcoreUtil.copy(inputId));
    rangeMaxExpr.setRight(EcoreUtil.copy(inputMaxExpr));
    BinaryExpr rangeExpr = af.createBinaryExpr();
    rangeExpr.setOp("and");
    rangeExpr.setLeft(EcoreUtil.copy(rangeMinExpr));
    rangeExpr.setRight(EcoreUtil.copy(rangeMaxExpr));
    BinaryExpr shiftExpr = af.createBinaryExpr();
    shiftExpr.setOp("-");
    shiftExpr.setLeft(EcoreUtil.copy(inputId));
    shiftExpr.setRight(EcoreUtil.copy(inputMinExpr));
    BinaryExpr multiplyExpr = af.createBinaryExpr();
    multiplyExpr.setOp("*");
    multiplyExpr.setLeft(EcoreUtil.copy(resultSlopeExpr));
    multiplyExpr.setRight(shiftExpr);
    BinaryExpr additionExpr = af.createBinaryExpr();
    additionExpr.setOp("+");
    additionExpr.setLeft(EcoreUtil.copy(resultOriginExpr));
    additionExpr.setRight(multiplyExpr);
    BinaryExpr linearBoundExpr = af.createBinaryExpr();
    linearBoundExpr.setOp(relop);
    linearBoundExpr.setLeft(EcoreUtil.copy(resultId));
    linearBoundExpr.setRight(additionExpr);
    BinaryExpr result = af.createBinaryExpr();
    result.setOp("=>");
    result.setLeft(rangeExpr);
    result.setRight(linearBoundExpr);
    return result;
}
Also used : BinaryExpr(com.rockwellcollins.atc.agree.agree.BinaryExpr) RealLitExpr(com.rockwellcollins.atc.agree.agree.RealLitExpr) NamedElmExpr(com.rockwellcollins.atc.agree.agree.NamedElmExpr)

Example 10 with NamedElmExpr

use of com.rockwellcollins.atc.agree.agree.NamedElmExpr 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

NamedElmExpr (com.rockwellcollins.atc.agree.agree.NamedElmExpr)11 BinaryExpr (com.rockwellcollins.atc.agree.agree.BinaryExpr)7 SelectionExpr (com.rockwellcollins.atc.agree.agree.SelectionExpr)7 NamedElement (org.osate.aadl2.NamedElement)7 RealLitExpr (com.rockwellcollins.atc.agree.agree.RealLitExpr)6 Arg (com.rockwellcollins.atc.agree.agree.Arg)5 BoolLitExpr (com.rockwellcollins.atc.agree.agree.BoolLitExpr)5 Expr (com.rockwellcollins.atc.agree.agree.Expr)5 IntLitExpr (com.rockwellcollins.atc.agree.agree.IntLitExpr)5 NodeBodyExpr (com.rockwellcollins.atc.agree.agree.NodeBodyExpr)5 UnaryExpr (com.rockwellcollins.atc.agree.agree.UnaryExpr)5 EventDataPort (org.osate.aadl2.EventDataPort)5 CallExpr (com.rockwellcollins.atc.agree.agree.CallExpr)4 DoubleDotRef (com.rockwellcollins.atc.agree.agree.DoubleDotRef)4 EnumLitExpr (com.rockwellcollins.atc.agree.agree.EnumLitExpr)4 EventExpr (com.rockwellcollins.atc.agree.agree.EventExpr)4 IfThenElseExpr (com.rockwellcollins.atc.agree.agree.IfThenElseExpr)4 PreExpr (com.rockwellcollins.atc.agree.agree.PreExpr)4 RecordLitExpr (com.rockwellcollins.atc.agree.agree.RecordLitExpr)4 Check (org.eclipse.xtext.validation.Check)4