Search in sources :

Example 1 with TypeDef

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

the class AgreeValidator method checkSporadicStatement.

@Check(CheckType.FAST)
public void checkSporadicStatement(SporadicStatement statement) {
    Expr event = statement.getEvent();
    Expr jitter = statement.getJitter();
    Expr iat = statement.getIat();
    checkExprIsIdentifier(event);
    TypeDef eventType = AgreeTypeSystem.infer(event);
    if (!AgreeTypeSystem.typesEqual(AgreeTypeSystem.Prim.BoolTypeDef, eventType)) {
        error(event, "Expression is of type '" + eventType + "' but must be of type 'bool'");
    }
    if (jitter != null) {
        if (!(jitter instanceof RealLitExpr || isTimingConst(jitter))) {
            error(jitter, "The specified jitter must be a real literal");
        } else {
            Double val = getRealConstVal(jitter);
            if (val < 0) {
                error(jitter, "The specified jitter must be positive");
            }
        }
    }
    if (!(iat instanceof RealLitExpr || isTimingConst(iat))) {
        error(iat, "The specified interarrival time must be a real literal");
    } else {
        Double val = getRealConstVal(iat);
        if (val < 0) {
            error(iat, "The specified interarrival time must be positive");
        }
    }
}
Also used : 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) RealLitExpr(com.rockwellcollins.atc.agree.agree.RealLitExpr) Check(org.eclipse.xtext.validation.Check)

Example 2 with TypeDef

use of com.rockwellcollins.atc.agree.AgreeTypeSystem.TypeDef 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 3 with TypeDef

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

the class AgreeValidator method checkFloorCast.

@Check(CheckType.FAST)
public void checkFloorCast(FloorCast floor) {
    if (isInLinearizationBody(floor)) {
        error(floor, "'event' expressions not allowed in linearization body expressions");
        return;
    }
    checkTypeExists(floor.getExpr());
    TypeDef exprType = AgreeTypeSystem.infer(floor.getExpr());
    if (!AgreeTypeSystem.typesEqual(AgreeTypeSystem.Prim.RealTypeDef, exprType)) {
        error(floor, "Argument of floor cast is of type '" + nameOfTypeDef(exprType) + "' but must be of type 'real'");
    }
}
Also used : 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)

Example 4 with TypeDef

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

the class AgreeValidator method checkWheneverImpliesStatement.

@Check(CheckType.FAST)
public void checkWheneverImpliesStatement(WheneverImpliesStatement whenever) {
    Expr cause = whenever.getCause();
    Expr lhs = whenever.getLhs();
    Expr rhs = whenever.getRhs();
    checkExprIsIdentifier(cause);
    checkExprIsIdentifier(lhs);
    checkExprIsIdentifier(rhs);
    TypeDef type = AgreeTypeSystem.infer(cause);
    if (!AgreeTypeSystem.typesEqual(AgreeTypeSystem.Prim.BoolTypeDef, type)) {
        error(cause, "The cause of the 'whenever' statement is of type '" + type + "' " + "but must be of type 'bool'");
    }
    type = AgreeTypeSystem.infer(lhs);
    if (!AgreeTypeSystem.typesEqual(AgreeTypeSystem.Prim.BoolTypeDef, type)) {
        error(lhs, "The left hand side of the 'implies' of the 'whenever' statement is of type '" + type + "' " + "but must be of type 'bool'");
    }
    type = AgreeTypeSystem.infer(rhs);
    if (!AgreeTypeSystem.typesEqual(AgreeTypeSystem.Prim.BoolTypeDef, type)) {
        error(lhs, "The rhs hand side of the 'implies' of the 'whenever' statement is of type '" + type + "' " + "but must be of type 'bool'");
    }
}
Also used : 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)

Example 5 with TypeDef

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

RecordTypeDef (com.rockwellcollins.atc.agree.AgreeTypeSystem.RecordTypeDef)36 TypeDef (com.rockwellcollins.atc.agree.AgreeTypeSystem.TypeDef)36 ArrayTypeDef (com.rockwellcollins.atc.agree.AgreeTypeSystem.ArrayTypeDef)34 AgreeTypeSystem.nameOfTypeDef (com.rockwellcollins.atc.agree.AgreeTypeSystem.nameOfTypeDef)34 Check (org.eclipse.xtext.validation.Check)31 CallExpr (com.rockwellcollins.atc.agree.agree.CallExpr)23 ArrayLiteralExpr (com.rockwellcollins.atc.agree.agree.ArrayLiteralExpr)22 ArraySubExpr (com.rockwellcollins.atc.agree.agree.ArraySubExpr)22 ArrayUpdateExpr (com.rockwellcollins.atc.agree.agree.ArrayUpdateExpr)22 BinaryExpr (com.rockwellcollins.atc.agree.agree.BinaryExpr)22 BoolLitExpr (com.rockwellcollins.atc.agree.agree.BoolLitExpr)22 EnumLitExpr (com.rockwellcollins.atc.agree.agree.EnumLitExpr)22 EventExpr (com.rockwellcollins.atc.agree.agree.EventExpr)22 ExistsExpr (com.rockwellcollins.atc.agree.agree.ExistsExpr)22 Expr (com.rockwellcollins.atc.agree.agree.Expr)22 FlatmapExpr (com.rockwellcollins.atc.agree.agree.FlatmapExpr)22 FoldLeftExpr (com.rockwellcollins.atc.agree.agree.FoldLeftExpr)22 FoldRightExpr (com.rockwellcollins.atc.agree.agree.FoldRightExpr)22 ForallExpr (com.rockwellcollins.atc.agree.agree.ForallExpr)22 GetPropertyExpr (com.rockwellcollins.atc.agree.agree.GetPropertyExpr)22