Search in sources :

Example 11 with SelectionExpr

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

Example 12 with SelectionExpr

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

Example 13 with SelectionExpr

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

the class AgreeValidator method isTimingConst.

/**
 * Is a given expression a usable timing constant
 *
 * Determine whether the given expression is a constant that may be a
 * statically evaluated such that can be used to set the timing model
 *
 * @param expr
 * @return true if acceptable timing constant, false otherwise
 */
protected boolean isTimingConst(Expr expr) {
    if (expr instanceof SelectionExpr) {
        SelectionExpr id = (SelectionExpr) expr;
        NamedElement finalId = id.getField();
        return (finalId instanceof ConstStatement);
    } else if (expr instanceof EnumLitExpr) {
        return true;
    }
    return false;
}
Also used : ConstStatement(com.rockwellcollins.atc.agree.agree.ConstStatement) EnumLitExpr(com.rockwellcollins.atc.agree.agree.EnumLitExpr) SelectionExpr(com.rockwellcollins.atc.agree.agree.SelectionExpr) NamedElement(org.osate.aadl2.NamedElement)

Aggregations

SelectionExpr (com.rockwellcollins.atc.agree.agree.SelectionExpr)13 NamedElmExpr (com.rockwellcollins.atc.agree.agree.NamedElmExpr)7 NamedElement (org.osate.aadl2.NamedElement)7 BinaryExpr (com.rockwellcollins.atc.agree.agree.BinaryExpr)6 IntLitExpr (com.rockwellcollins.atc.agree.agree.IntLitExpr)6 UnaryExpr (com.rockwellcollins.atc.agree.agree.UnaryExpr)6 ConstStatement (com.rockwellcollins.atc.agree.agree.ConstStatement)5 EnumLitExpr (com.rockwellcollins.atc.agree.agree.EnumLitExpr)5 RealLitExpr (com.rockwellcollins.atc.agree.agree.RealLitExpr)5 EObject (org.eclipse.emf.ecore.EObject)5 BoolLitExpr (com.rockwellcollins.atc.agree.agree.BoolLitExpr)4 CallExpr (com.rockwellcollins.atc.agree.agree.CallExpr)4 EventExpr (com.rockwellcollins.atc.agree.agree.EventExpr)4 Expr (com.rockwellcollins.atc.agree.agree.Expr)4 IfThenElseExpr (com.rockwellcollins.atc.agree.agree.IfThenElseExpr)4 NodeBodyExpr (com.rockwellcollins.atc.agree.agree.NodeBodyExpr)4 PreExpr (com.rockwellcollins.atc.agree.agree.PreExpr)4 RecordLitExpr (com.rockwellcollins.atc.agree.agree.RecordLitExpr)4 Check (org.eclipse.xtext.validation.Check)4 ArrayLiteralExpr (com.rockwellcollins.atc.agree.agree.ArrayLiteralExpr)3