Search in sources :

Example 6 with PrimType

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

the class SafetyValidator method checkIntervalEqStatement.

/**
 * Interval eq stmts:
 * Checks:
 * - Only primitive types supported for intervals.
 * - The interval type matches high and low parameters of interval.
 * - High and low parameters of interval are same type.
 * @param intervalEq
 */
@Check(CheckType.FAST)
public void checkIntervalEqStatement(IntervalEq intervalEq) {
    Arg arg = intervalEq.getLhs_int();
    String typeName = "";
    SafetyInterval interval = intervalEq.getInterv();
    Expr low = interval.getLow();
    Expr high = interval.getHigh();
    if (arg.getType() instanceof PrimType) {
        typeName = ((PrimType) arg.getType()).getName();
        if (typeName.equalsIgnoreCase("bool")) {
            error(arg, "Boolean intervals are not allowed. Only real or int intervals are supported.");
        }
    } else {
        error(arg, "The only types that are supported for intervals are real and int.");
    }
    // Negative values are allowed: hence the check for UnaryExpr
    if (low instanceof UnaryExpr) {
        UnaryExpr unex_low = (UnaryExpr) low;
        if (!(unex_low.getExpr() instanceof IntLitExpr) & !(unex_low.getExpr() instanceof RealLitExpr)) {
            error(low, "Only real and integer types are supported for intervals.");
        }
        if (high instanceof UnaryExpr) {
            UnaryExpr unex_high = (UnaryExpr) high;
            if (!(unex_high.getExpr() instanceof IntLitExpr) & !(unex_high.getExpr() instanceof RealLitExpr)) {
                error(high, "Only real and integer types are supported for intervals.");
            }
            testLowAndHighTypes(intervalEq, typeName, unex_low.getExpr(), unex_high.getExpr());
        } else {
            testLowAndHighTypes(intervalEq, typeName, unex_low.getExpr(), high);
        }
    } else {
        testLowAndHighTypes(intervalEq, typeName, low, high);
    }
}
Also used : RealLitExpr(com.rockwellcollins.atc.agree.agree.RealLitExpr) UnaryExpr(com.rockwellcollins.atc.agree.agree.UnaryExpr) Expr(com.rockwellcollins.atc.agree.agree.Expr) PrevExpr(com.rockwellcollins.atc.agree.agree.PrevExpr) BoolLitExpr(com.rockwellcollins.atc.agree.agree.BoolLitExpr) IntLitExpr(com.rockwellcollins.atc.agree.agree.IntLitExpr) NamedElmExpr(com.rockwellcollins.atc.agree.agree.NamedElmExpr) IntLitExpr(com.rockwellcollins.atc.agree.agree.IntLitExpr) Arg(com.rockwellcollins.atc.agree.agree.Arg) PrimType(com.rockwellcollins.atc.agree.agree.PrimType) RealLitExpr(com.rockwellcollins.atc.agree.agree.RealLitExpr) SafetyInterval(edu.umn.cs.crisys.safety.safety.SafetyInterval) UnaryExpr(com.rockwellcollins.atc.agree.agree.UnaryExpr) Check(org.eclipse.xtext.validation.Check)

Example 7 with PrimType

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

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

the class RenamingVisitor method argToString.

private String argToString(Arg arg) {
    String result = arg.getName() + " : ";
    if (arg.getType() instanceof PrimType) {
        PrimType primType = (PrimType) arg.getType();
        result += primType.getName();
        String lowLit = (primType.getLowNeg() != null) ? primType.getLowNeg() : "";
        String highLit = (primType.getHighNeg() != null) ? primType.getHighNeg() : "";
        if (primType.getRangeLow() != null) {
            result += " [" + lowLit + primType.getRangeLow() + ", " + highLit + primType.getRangeHigh() + "]";
        }
    } else {
        result += ((DoubleDotRef) arg.getType()).getElm().getName();
    }
    return result;
}
Also used : DoubleDotRef(com.rockwellcollins.atc.agree.agree.DoubleDotRef) PrimType(com.rockwellcollins.atc.agree.agree.PrimType)

Example 9 with PrimType

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

the class AgreeTypeSystem method typeDefFromType.

public static TypeDef typeDefFromType(Type t) {
    if (t instanceof PrimType) {
        int lowSign = ((PrimType) t).getLowNeg() == null ? 1 : -1;
        int highSign = ((PrimType) t).getHighNeg() == null ? 1 : -1;
        String lowStr = ((PrimType) t).getRangeLow();
        String highStr = ((PrimType) t).getRangeHigh();
        if (((PrimType) t).getName().equals("int")) {
            if (lowStr == null || highStr == null) {
                return Prim.IntTypeDef;
            } else {
                long low = Long.valueOf(lowStr) * lowSign;
                long high = Long.valueOf(highStr) * highSign;
                return new RangeIntTypeDef(low, high);
            }
        } else if (((PrimType) t).getName().equals("real")) {
            if (lowStr == null || highStr == null) {
                return Prim.RealTypeDef;
            } else {
                double low = Double.valueOf(lowStr) * lowSign;
                double high = Double.valueOf(highStr) * highSign;
                return new RangeRealTypeDef(low, high);
            }
        } else if (((PrimType) t).getName().equals("bool")) {
            return Prim.BoolTypeDef;
        } else {
            return Prim.ErrorTypeDef;
        }
    } else if (t instanceof ArrayType) {
        String size = ((ArrayType) t).getSize();
        TypeDef baseTypeDef = typeDefFromType(((ArrayType) t).getStem());
        return new ArrayTypeDef(baseTypeDef, Integer.parseInt(size), Optional.empty());
    } else if (t instanceof DoubleDotRef) {
        return typeDefFromNE(((DoubleDotRef) t).getElm());
    } else {
        return Prim.ErrorTypeDef;
    }
}
Also used : ArrayType(com.rockwellcollins.atc.agree.agree.ArrayType) DoubleDotRef(com.rockwellcollins.atc.agree.agree.DoubleDotRef) PrimType(com.rockwellcollins.atc.agree.agree.PrimType) AadlString(org.osate.aadl2.AadlString)

Aggregations

PrimType (com.rockwellcollins.atc.agree.agree.PrimType)9 DoubleDotRef (com.rockwellcollins.atc.agree.agree.DoubleDotRef)5 Arg (com.rockwellcollins.atc.agree.agree.Arg)4 BoolLitExpr (com.rockwellcollins.atc.agree.agree.BoolLitExpr)3 Expr (com.rockwellcollins.atc.agree.agree.Expr)3 NamedElmExpr (com.rockwellcollins.atc.agree.agree.NamedElmExpr)3 RealLitExpr (com.rockwellcollins.atc.agree.agree.RealLitExpr)3 DataImplementation (org.osate.aadl2.DataImplementation)3 BinaryExpr (com.rockwellcollins.atc.agree.agree.BinaryExpr)2 EqStatement (com.rockwellcollins.atc.agree.agree.EqStatement)2 IntLitExpr (com.rockwellcollins.atc.agree.agree.IntLitExpr)2 NodeBodyExpr (com.rockwellcollins.atc.agree.agree.NodeBodyExpr)2 NodeDef (com.rockwellcollins.atc.agree.agree.NodeDef)2 Type (com.rockwellcollins.atc.agree.agree.Type)2 UnaryExpr (com.rockwellcollins.atc.agree.agree.UnaryExpr)2 Check (org.eclipse.xtext.validation.Check)2 NamedElement (org.osate.aadl2.NamedElement)2 ArrayType (com.rockwellcollins.atc.agree.agree.ArrayType)1 CallExpr (com.rockwellcollins.atc.agree.agree.CallExpr)1 ConstStatement (com.rockwellcollins.atc.agree.agree.ConstStatement)1