Search in sources :

Example 1 with ArraySubExpr

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

the class AgreeASTBuilder method caseArraySubExpr.

@Override
public Expr caseArraySubExpr(ArraySubExpr expr) {
    // Note: AADL/AGREE arrays are indexed starting at 1, JKind arrays are indexed starting at zero
    Expr index = new BinaryExpr(doSwitch(expr.getIndex()), BinaryOp.MINUS, new IntExpr(1));
    Expr array = doSwitch(expr.getExpr());
    return new ArrayAccessExpr(array, index);
}
Also used : EnumLitExpr(com.rockwellcollins.atc.agree.agree.EnumLitExpr) IndicesExpr(com.rockwellcollins.atc.agree.agree.IndicesExpr) TimeRiseExpr(com.rockwellcollins.atc.agree.agree.TimeRiseExpr) RecordAccessExpr(jkind.lustre.RecordAccessExpr) 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) Expr(jkind.lustre.Expr) CastExpr(jkind.lustre.CastExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) TimeOfExpr(com.rockwellcollins.atc.agree.agree.TimeOfExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) RealExpr(jkind.lustre.RealExpr) ArrayExpr(jkind.lustre.ArrayExpr) PrevExpr(com.rockwellcollins.atc.agree.agree.PrevExpr) IdExpr(jkind.lustre.IdExpr) TimeExpr(com.rockwellcollins.atc.agree.agree.TimeExpr) 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) FunctionCallExpr(jkind.lustre.FunctionCallExpr) SelectionExpr(com.rockwellcollins.atc.agree.agree.SelectionExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) TupleExpr(jkind.lustre.TupleExpr) UnaryExpr(jkind.lustre.UnaryExpr) ArraySubExpr(com.rockwellcollins.atc.agree.agree.ArraySubExpr) IntExpr(jkind.lustre.IntExpr) PreExpr(com.rockwellcollins.atc.agree.agree.PreExpr) RecordLitExpr(com.rockwellcollins.atc.agree.agree.RecordLitExpr) 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) ArrayAccessExpr(jkind.lustre.ArrayAccessExpr) 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) ArrayAccessExpr(jkind.lustre.ArrayAccessExpr) BinaryExpr(jkind.lustre.BinaryExpr) IntExpr(jkind.lustre.IntExpr)

Example 2 with ArraySubExpr

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

the class AgreeValidator method checkArraySubExpr.

@Check(CheckType.FAST)
public void checkArraySubExpr(ArraySubExpr asub) {
    Expr arrExp = asub.getExpr();
    checkTypeExists(arrExp);
    TypeDef arrType = AgreeTypeSystem.infer(arrExp);
    Expr index = asub.getIndex();
    checkTypeExists(index);
    TypeDef indexType = AgreeTypeSystem.infer(index);
    if (!AgreeTypeSystem.typesEqual(indexType, AgreeTypeSystem.Prim.IntTypeDef)) {
        error(index, "index must be an int");
    }
    if (arrType instanceof ArrayTypeDef) {
        ArrayTypeDef arrayTypeDef = (ArrayTypeDef) arrType;
        int arraySize = arrayTypeDef.size;
        BigInteger indexValue = evaluateIndexExpr(index);
        if (indexValue != null) {
            if (!(indexValue.compareTo(BigInteger.ONE) >= 0 && indexValue.compareTo(BigInteger.valueOf(arraySize)) <= 0)) {
                error(index, "Index value " + indexValue + " is out of array bounds [1 .. " + arraySize + "]");
            }
        } else {
            warning(index, "Could not statically compute array index value");
        }
    } else {
        error(arrExp, "expression must evaluate to an array");
    }
}
Also used : ArrayTypeDef(com.rockwellcollins.atc.agree.AgreeTypeSystem.ArrayTypeDef) 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) AgreeTypeSystem.nameOfTypeDef(com.rockwellcollins.atc.agree.AgreeTypeSystem.nameOfTypeDef) ArrayTypeDef(com.rockwellcollins.atc.agree.AgreeTypeSystem.ArrayTypeDef) RecordTypeDef(com.rockwellcollins.atc.agree.AgreeTypeSystem.RecordTypeDef) TypeDef(com.rockwellcollins.atc.agree.AgreeTypeSystem.TypeDef) BigInteger(java.math.BigInteger) Check(org.eclipse.xtext.validation.Check)

Aggregations

ArrayLiteralExpr (com.rockwellcollins.atc.agree.agree.ArrayLiteralExpr)2 ArraySubExpr (com.rockwellcollins.atc.agree.agree.ArraySubExpr)2 ArrayUpdateExpr (com.rockwellcollins.atc.agree.agree.ArrayUpdateExpr)2 BoolLitExpr (com.rockwellcollins.atc.agree.agree.BoolLitExpr)2 CallExpr (com.rockwellcollins.atc.agree.agree.CallExpr)2 EnumLitExpr (com.rockwellcollins.atc.agree.agree.EnumLitExpr)2 EventExpr (com.rockwellcollins.atc.agree.agree.EventExpr)2 ExistsExpr (com.rockwellcollins.atc.agree.agree.ExistsExpr)2 FlatmapExpr (com.rockwellcollins.atc.agree.agree.FlatmapExpr)2 FoldLeftExpr (com.rockwellcollins.atc.agree.agree.FoldLeftExpr)2 FoldRightExpr (com.rockwellcollins.atc.agree.agree.FoldRightExpr)2 ForallExpr (com.rockwellcollins.atc.agree.agree.ForallExpr)2 GetPropertyExpr (com.rockwellcollins.atc.agree.agree.GetPropertyExpr)2 IndicesExpr (com.rockwellcollins.atc.agree.agree.IndicesExpr)2 IntLitExpr (com.rockwellcollins.atc.agree.agree.IntLitExpr)2 LatchedExpr (com.rockwellcollins.atc.agree.agree.LatchedExpr)2 NamedElmExpr (com.rockwellcollins.atc.agree.agree.NamedElmExpr)2 NodeBodyExpr (com.rockwellcollins.atc.agree.agree.NodeBodyExpr)2 PreExpr (com.rockwellcollins.atc.agree.agree.PreExpr)2 PrevExpr (com.rockwellcollins.atc.agree.agree.PrevExpr)2