Search in sources :

Example 36 with BooleanLiteral

use of org.osate.aadl2.BooleanLiteral in project osate2 by osate.

the class OperationImpl method evaluate.

public EvaluatedProperty evaluate(EvaluationContext ctx, int depth) throws InvalidModelException {
    if (ownedPropertyExpressions.size() < 1) {
        throw new InvalidModelException(ctx.getInstanceObject(), "Property expression has no operands");
    }
    EvaluatedProperty left = ownedPropertyExpressions.get(0).evaluate(ctx, depth);
    EvaluatedProperty right = null;
    PropertyExpression arg1 = null;
    PropertyExpression arg2 = null;
    if (left.size() == 0) {
        throw new InvalidModelException(ctx.getInstanceObject(), "Argument has no value");
    }
    if (left.size() != 1 || left.first().isModal()) {
        throw new InvalidModelException(ctx.getInstanceObject(), "Argument to operation cannot be modal");
    }
    arg1 = left.first().getValue();
    if (arg1 == null) {
        throw new InvalidModelException(ctx.getInstanceObject(), "Argument missing");
    }
    // check for required arguments to operation
    switch(op) {
        case AND:
        case OR:
            if (ownedPropertyExpressions.size() < 2) {
                throw new InvalidModelException(ctx.getInstanceObject(), "Second operand missing for binary operation");
            }
            if (ownedPropertyExpressions.size() > 2) {
                throw new InvalidModelException(ctx.getInstanceObject(), "Too many operands in expression");
            }
            right = ownedPropertyExpressions.get(1).evaluate(ctx, depth);
            if (right.size() != 1 || right.first().isModal()) {
                throw new InvalidModelException(ctx.getInstanceObject(), "Argument to operation cannot be modal");
            }
            if (right.size() == 0) {
                throw new InvalidModelException(ctx.getInstanceObject(), "Argument has no value");
            }
            arg2 = right.first().getValue();
            if (arg2 == null) {
                throw new InvalidModelException(ctx.getInstanceObject(), "Argument missing");
            }
            break;
        default:
            if (ownedPropertyExpressions.size() > 1) {
                throw new InvalidModelException(ctx.getInstanceObject(), "Too many operands in expression");
            }
            break;
    }
    // check argument types
    switch(op) {
        case NOT:
            if (!(arg1 instanceof BooleanLiteral)) {
                throw new InvalidModelException(ctx.getInstanceObject(), "Argument to NOT does not evaluate to a boolean value");
            }
        // fall through!
        case AND:
        case OR:
            if (!(arg2 instanceof BooleanLiteral)) {
                throw new InvalidModelException(ctx.getInstanceObject(), "Second argument does not evaluate to a boolean value");
            }
            break;
        default:
            if (!(arg1 instanceof NumberValue)) {
                throw new InvalidModelException(ctx.getInstanceObject(), "Argument does not evaluate to a numeric value");
            }
            break;
    }
    // calculate result
    EvaluatedProperty result = null;
    switch(op) {
        case AND:
            BooleanLiteral abv = Aadl2Factory.eINSTANCE.createBooleanLiteral();
            abv.setValue(((BooleanLiteral) arg1).getValue() && ((BooleanLiteral) arg1).getValue());
            result = new EvaluatedProperty(abv);
            break;
        case OR:
            BooleanLiteral obv = Aadl2Factory.eINSTANCE.createBooleanLiteral();
            obv.setValue(((BooleanLiteral) arg1).getValue() || ((BooleanLiteral) arg1).getValue());
            result = new EvaluatedProperty(obv);
            break;
        case NOT:
            BooleanLiteral nbv = Aadl2Factory.eINSTANCE.createBooleanLiteral();
            nbv.setValue(!((BooleanLiteral) arg1).getValue());
            result = new EvaluatedProperty(nbv);
            break;
        case PLUS:
            result = left;
            break;
        case MINUS:
            result = new EvaluatedProperty(((NumberValue) arg1).cloneAndInvert());
            break;
        default:
            throw new AssertionError("Unexpected enum literal: " + getOp());
    }
    return result;
}
Also used : InvalidModelException(org.osate.aadl2.properties.InvalidModelException) NumberValue(org.osate.aadl2.NumberValue) BooleanLiteral(org.osate.aadl2.BooleanLiteral) EvaluatedProperty(org.osate.aadl2.properties.EvaluatedProperty) PropertyExpression(org.osate.aadl2.PropertyExpression)

Example 37 with BooleanLiteral

use of org.osate.aadl2.BooleanLiteral in project osate2 by osate.

the class Arinc653 method getSystemPartition.

public static Optional<Boolean> getSystemPartition(NamedElement lookupContext, Optional<Mode> mode) {
    Property property = getSystemPartition_Property(lookupContext);
    try {
        PropertyExpression value = CodeGenUtil.lookupProperty(property, lookupContext, mode);
        PropertyExpression resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode);
        return Optional.of(((BooleanLiteral) resolved).getValue());
    } catch (PropertyNotPresentException e) {
        return Optional.empty();
    }
}
Also used : PropertyNotPresentException(org.osate.aadl2.properties.PropertyNotPresentException) PropertyExpression(org.osate.aadl2.PropertyExpression) Property(org.osate.aadl2.Property)

Example 38 with BooleanLiteral

use of org.osate.aadl2.BooleanLiteral in project osate2 by osate.

the class CodeGenerationProperties method getReturnParameter.

public static Optional<Boolean> getReturnParameter(NamedElement lookupContext, Optional<Mode> mode) {
    Property property = getReturnParameter_Property(lookupContext);
    try {
        PropertyExpression value = CodeGenUtil.lookupProperty(property, lookupContext, mode);
        PropertyExpression resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode);
        return Optional.of(((BooleanLiteral) resolved).getValue());
    } catch (PropertyNotPresentException e) {
        return Optional.empty();
    }
}
Also used : PropertyNotPresentException(org.osate.aadl2.properties.PropertyNotPresentException) PropertyExpression(org.osate.aadl2.PropertyExpression) Property(org.osate.aadl2.Property)

Example 39 with BooleanLiteral

use of org.osate.aadl2.BooleanLiteral in project osate2 by osate.

the class Sei method getBroadcastProtocol.

public static Optional<Boolean> getBroadcastProtocol(NamedElement lookupContext, Optional<Mode> mode) {
    Property property = getBroadcastProtocol_Property(lookupContext);
    try {
        PropertyExpression value = CodeGenUtil.lookupProperty(property, lookupContext, mode);
        PropertyExpression resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode);
        return Optional.of(((BooleanLiteral) resolved).getValue());
    } catch (PropertyNotPresentException e) {
        return Optional.empty();
    }
}
Also used : PropertyNotPresentException(org.osate.aadl2.properties.PropertyNotPresentException) PropertyExpression(org.osate.aadl2.PropertyExpression) Property(org.osate.aadl2.Property)

Example 40 with BooleanLiteral

use of org.osate.aadl2.BooleanLiteral in project osate2 by osate.

the class Sei method getIsPartition.

public static Optional<Boolean> getIsPartition(NamedElement lookupContext, Optional<Mode> mode) {
    Property property = getIsPartition_Property(lookupContext);
    try {
        PropertyExpression value = CodeGenUtil.lookupProperty(property, lookupContext, mode);
        PropertyExpression resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode);
        return Optional.of(((BooleanLiteral) resolved).getValue());
    } catch (PropertyNotPresentException e) {
        return Optional.empty();
    }
}
Also used : PropertyNotPresentException(org.osate.aadl2.properties.PropertyNotPresentException) PropertyExpression(org.osate.aadl2.PropertyExpression) Property(org.osate.aadl2.Property)

Aggregations

BooleanLiteral (org.osate.aadl2.BooleanLiteral)29 PropertyExpression (org.osate.aadl2.PropertyExpression)19 StringLiteral (org.osate.aadl2.StringLiteral)18 IntegerLiteral (org.osate.aadl2.IntegerLiteral)17 RealLiteral (org.osate.aadl2.RealLiteral)17 Property (org.osate.aadl2.Property)16 NamedValue (org.osate.aadl2.NamedValue)12 RangeValue (org.osate.aadl2.RangeValue)11 RecordValue (org.osate.aadl2.RecordValue)11 PropertyNotPresentException (org.osate.aadl2.properties.PropertyNotPresentException)11 EPackage (org.eclipse.emf.ecore.EPackage)10 Action (org.eclipse.xtext.Action)10 Parameter (org.eclipse.xtext.Parameter)10 ParserRule (org.eclipse.xtext.ParserRule)10 ClassifierValue (org.osate.aadl2.ClassifierValue)10 ListValue (org.osate.aadl2.ListValue)10 ReferenceValue (org.osate.aadl2.ReferenceValue)10 ContainmentPathElement (org.osate.aadl2.ContainmentPathElement)9 PropertyAssociation (org.osate.aadl2.PropertyAssociation)9 BasicPropertyAssociation (org.osate.aadl2.BasicPropertyAssociation)8