Search in sources :

Example 1 with InputConstraintTypeDeterminer

use of edu.uah.rsesc.aadlsimulator.xtext.util.InputConstraintTypeDeterminer in project AGREE by loonwerks.

the class InputConstraintValidator method checkBinaryExpressionTypes.

@Check
public void checkBinaryExpressionTypes(final BinaryExpression binaryExpr) {
    final InputConstraintTypeDeterminer typeDeterminer = getTypeDeterminer();
    final ResultType leftType = typeDeterminer.determineType(binaryExpr.getLeft());
    final ResultType rightType = typeDeterminer.determineType(binaryExpr.getRight());
    if (leftType != rightType) {
        error("Both sides of a binary expression must be of the same type. Left: " + leftType + ". Right: " + rightType + ".", InputConstraintPackage.Literals.BINARY_EXPRESSION__LEFT);
    } else if (leftType == ResultType.INTEGER && binaryExpr.getOp() == Operator.DIVISION) {
        error("Integer division is not supported.", InputConstraintPackage.Literals.BINARY_EXPRESSION__LEFT);
    }
}
Also used : ResultType(edu.uah.rsesc.aadlsimulator.xtext.util.ResultType) InputConstraintTypeDeterminer(edu.uah.rsesc.aadlsimulator.xtext.util.InputConstraintTypeDeterminer) Check(org.eclipse.xtext.validation.Check)

Example 2 with InputConstraintTypeDeterminer

use of edu.uah.rsesc.aadlsimulator.xtext.util.InputConstraintTypeDeterminer in project AGREE by loonwerks.

the class InputConstraintValidator method checkIntervalTypes.

@Check
public void checkIntervalTypes(final IntervalExpression intervalExpr) {
    if (intervalExpr != null && intervalExpr != null) {
        final InputConstraintTypeDeterminer typeDeterminer = getTypeDeterminer();
        final ResultType leftType = typeDeterminer.determineType(intervalExpr.getLeft());
        final ResultType rightType = typeDeterminer.determineType(intervalExpr.getRight());
        if (leftType != rightType) {
            error("Both sides of an interval must be of the same type. Left: " + leftType + ". Right: " + rightType + ".", InputConstraintPackage.Literals.INTERVAL_EXPRESSION__LEFT);
        }
        if (!(leftType == null || leftType == ResultType.INTEGER || leftType == ResultType.REAL)) {
            error("Interval bounds must be of type integer or real. Type: " + leftType + ".", InputConstraintPackage.Literals.INTERVAL_EXPRESSION__LEFT);
        }
    }
}
Also used : ResultType(edu.uah.rsesc.aadlsimulator.xtext.util.ResultType) InputConstraintTypeDeterminer(edu.uah.rsesc.aadlsimulator.xtext.util.InputConstraintTypeDeterminer) Check(org.eclipse.xtext.validation.Check)

Aggregations

InputConstraintTypeDeterminer (edu.uah.rsesc.aadlsimulator.xtext.util.InputConstraintTypeDeterminer)2 ResultType (edu.uah.rsesc.aadlsimulator.xtext.util.ResultType)2 Check (org.eclipse.xtext.validation.Check)2