Search in sources :

Example 11 with NamedElmExpr

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

the class AgreeValidator method evaluateIndexExpr.

// TODO: This is really minimal -- need to create a proper AGREE static expression evaluation infrastructure
private BigInteger evaluateIndexExpr(Expr expr) {
    BigInteger result = null;
    if (expr instanceof IntLitExpr) {
        return new BigInteger(((IntLitExpr) expr).getVal());
    } else if (expr instanceof UnaryExpr) {
        UnaryExpr unaryExpr = (UnaryExpr) expr;
        BigInteger val = evaluateIndexExpr(unaryExpr.getExpr());
        if ("-".equals(unaryExpr.getOp()) && val != null) {
            return val.negate();
        }
    } else if (expr instanceof BinaryExpr) {
        BinaryExpr binaryExpr = (BinaryExpr) expr;
        BigInteger leftVal = evaluateIndexExpr(binaryExpr.getLeft());
        BigInteger rightVal = evaluateIndexExpr(binaryExpr.getRight());
        if (leftVal != null && rightVal != null) {
            if ("+".equals(binaryExpr.getOp())) {
                return leftVal.add(rightVal);
            } else if ("-".equals(binaryExpr.getOp())) {
                return leftVal.subtract(rightVal);
            } else if ("*".equals(binaryExpr.getOp())) {
                return leftVal.multiply(rightVal);
            } else if ("/".equals(binaryExpr.getOp()) || "div".equals(binaryExpr.getOp())) {
                return leftVal.divide(rightVal);
            } else if ("mod".equals(binaryExpr.getOp())) {
                return leftVal.mod(rightVal);
            }
        }
    } else if (expr instanceof NamedElmExpr) {
        return evaluateIndexNamedElement(((NamedElmExpr) expr).getElm());
    } else if (expr instanceof SelectionExpr) {
        return evaluateIndexNamedElement(((SelectionExpr) expr).getField());
    }
    return result;
}
Also used : IntLitExpr(com.rockwellcollins.atc.agree.agree.IntLitExpr) BinaryExpr(com.rockwellcollins.atc.agree.agree.BinaryExpr) BigInteger(java.math.BigInteger) SelectionExpr(com.rockwellcollins.atc.agree.agree.SelectionExpr) UnaryExpr(com.rockwellcollins.atc.agree.agree.UnaryExpr) NamedElmExpr(com.rockwellcollins.atc.agree.agree.NamedElmExpr)

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