Search in sources :

Example 1 with ArrayTypeDef

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

Example 2 with ArrayTypeDef

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

the class AgreeValidator method checkArrayUpdateExpr.

@Check(CheckType.FAST)
public void checkArrayUpdateExpr(ArrayUpdateExpr arrup) {
    List<Expr> exprs = arrup.getValueExprs();
    Expr arrExpr = arrup.getArray();
    checkTypeExists(arrExpr);
    TypeDef arrType = AgreeTypeSystem.infer(arrExpr);
    if (arrType instanceof ArrayTypeDef) {
        TypeDef t = ((ArrayTypeDef) arrType).stemType;
        TypeDef elmType = AgreeTypeSystem.infer(exprs.get(0));
        if (!AgreeTypeSystem.typesEqual(elmType, t)) {
            error(exprs.get(0), "type of element must be " + nameOfTypeDef(elmType) + ", but has type " + nameOfTypeDef(t));
        }
    } else {
        error(arrExpr, "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) Check(org.eclipse.xtext.validation.Check)

Aggregations

ArrayTypeDef (com.rockwellcollins.atc.agree.AgreeTypeSystem.ArrayTypeDef)2 RecordTypeDef (com.rockwellcollins.atc.agree.AgreeTypeSystem.RecordTypeDef)2 TypeDef (com.rockwellcollins.atc.agree.AgreeTypeSystem.TypeDef)2 AgreeTypeSystem.nameOfTypeDef (com.rockwellcollins.atc.agree.AgreeTypeSystem.nameOfTypeDef)2 ArrayLiteralExpr (com.rockwellcollins.atc.agree.agree.ArrayLiteralExpr)2 ArraySubExpr (com.rockwellcollins.atc.agree.agree.ArraySubExpr)2 ArrayUpdateExpr (com.rockwellcollins.atc.agree.agree.ArrayUpdateExpr)2 BinaryExpr (com.rockwellcollins.atc.agree.agree.BinaryExpr)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 Expr (com.rockwellcollins.atc.agree.agree.Expr)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 IfThenElseExpr (com.rockwellcollins.atc.agree.agree.IfThenElseExpr)2