Search in sources :

Example 1 with Value

use of org.osate.ba.aadlba.Value in project osate2 by osate.

the class AdaLikeDataTypeChecker method checkDefinition.

@Override
public TypeHolder checkDefinition(BehaviorElement e, Enumerator operator, TypeHolder operand1, TypeHolder operand2) {
    // Operator ** has special consistency checking.
    if (operator != BinaryNumericOperator.MULTIPLY_MULTIPLY && !conformsTo(operand1, operand2, true)) {
        reportErrorConsystency(e, operator, operand1, operand2);
        return null;
    }
    if (operator instanceof LogicalOperator) {
        if (operand1.getDataRep() == DataRepresentation.BOOLEAN) {
            return getTopLevelTypeWithoutConsistencyChecking(operand1, operand1);
        } else {
            reportErrorBinaryOperator(e, operator, operand1);
            return null;
        }
    } else if (operator instanceof RelationalOperator) {
        RelationalOperator rop = (RelationalOperator) operator;
        DataRepresentation[] expectedTypes = null;
        // Operators = and != are defined for all coherent types.
        if (rop == RelationalOperator.EQUAL || rop == RelationalOperator.NOT_EQUAL) {
            return new TypeHolder(DataRepresentation.BOOLEAN, null);
        }
        expectedTypes = _alphaNumTypes;
        if (Aadl2Utils.contains(operand1.getDataRep(), expectedTypes)) {
            return new TypeHolder(DataRepresentation.BOOLEAN, null);
        } else {
            reportErrorBinaryOperator(e, operator, operand1);
            return null;
        }
    } else if (operator instanceof BinaryAddingOperator) {
        if (Aadl2Utils.contains(operand1.getDataRep(), _numTypes)) {
            return getTopLevelTypeWithoutConsistencyChecking(operand1, operand2);
        } else {
            reportErrorBinaryOperator(e, operator, operand1);
            return null;
        }
    } else if (operator instanceof MultiplyingOperator) {
        MultiplyingOperator op = (MultiplyingOperator) operator;
        switch(op) {
            case MULTIPLY:
            case DIVIDE:
                {
                    if (Aadl2Utils.contains(operand1.getDataRep(), _numTypes)) {
                        return getTopLevelTypeWithoutConsistencyChecking(operand1, operand2);
                    } else {
                        reportErrorBinaryOperator(e, operator, operand1);
                        return null;
                    }
                }
            case MOD:
            case REM:
                {
                    if (operand1.getDataRep() == DataRepresentation.INTEGER) {
                        return getTopLevelTypeWithoutConsistencyChecking(operand1, operand2);
                    } else {
                        reportErrorBinaryOperator(e, operator, operand1);
                        return null;
                    }
                }
            default:
                return null;
        }
    } else if (operator instanceof BinaryNumericOperator) {
        // Checks operands consistency:
        if (Aadl2Utils.contains(operand1.getDataRep(), _numTypesWithoutFixed)) {
            boolean reportError = false;
            if (operand2.getDataRep() == DataRepresentation.INTEGER) {
                // Datatyped operand case : checks if operand2 is a natural.
                if (operand2.getKlass() != null) {
                    EList<org.osate.aadl2.PropertyExpression> l = PropertyUtils.findPropertyExpression(operand2.getKlass(), DataModelProperties.INTEGER_RANGE);
                    if (l.size() > 0) {
                        RangeValue rv = (RangeValue) l.get(l.size() - 1);
                        if (rv.getMinimumValue().getScaledValue() < 0) {
                            reportError = true;
                        }
                    } else {
                        reportError = true;
                    }
                } else // constant data case : checks if the constant value is not
                // negative.
                {
                    if (e instanceof Factor) {
                        Value val = ((Factor) e).getSecondValue();
                        // PropertyConstants and warns PropertyValues.
                        if (val instanceof BehaviorPropertyConstant) {
                            BehaviorPropertyConstant bpc = (BehaviorPropertyConstant) val;
                            org.osate.aadl2.PropertyConstant pc = bpc.getProperty();
                            org.osate.aadl2.IntegerLiteral intLit = (org.osate.aadl2.IntegerLiteral) pc.getConstantValue();
                            if (intLit.getValue() < 0) {
                                reportError = true;
                            }
                        } else if (val instanceof PropertyReference) // PropertyValue case : its value can only be evaluated at
                        // runtime so raises a warning.
                        {
                            _errManager.warning(e, "Cannot evaluate if the exponent" + " is a natural");
                        }
                    }
                }
            } else {
                reportError = true;
            }
            if (reportError) {
                _errManager.error(e, "exponent must be of type natural, found " + operand2.toString());
                return null;
            } else {
                return operand1;
            }
        } else {
            reportErrorConsystency(e, operator, operand1, operand2);
            return null;
        }
    } else {
        String errorMsg = "operator : " + operator.getName() + " is not supported.";
        System.err.println(errorMsg);
        throw new UnsupportedOperationException(errorMsg);
    }
}
Also used : RelationalOperator(org.osate.ba.aadlba.RelationalOperator) LogicalOperator(org.osate.ba.aadlba.LogicalOperator) RangeValue(org.osate.aadl2.RangeValue) PropertyReference(org.osate.ba.aadlba.PropertyReference) BehaviorPropertyConstant(org.osate.ba.aadlba.BehaviorPropertyConstant) Factor(org.osate.ba.aadlba.Factor) BinaryAddingOperator(org.osate.ba.aadlba.BinaryAddingOperator) RangeValue(org.osate.aadl2.RangeValue) Value(org.osate.ba.aadlba.Value) MultiplyingOperator(org.osate.ba.aadlba.MultiplyingOperator) BinaryNumericOperator(org.osate.ba.aadlba.BinaryNumericOperator)

Example 2 with Value

use of org.osate.ba.aadlba.Value in project osate2 by osate.

the class AadlBaUtils method isOnlyOneValue.

/**
 * If the given value expression is composed of an single value, it returns
 * this value otherwise {@code null}. Recursive method.
 *
 * @param ve the given value expression
 * @return the value or {@code null}
 */
public static Value isOnlyOneValue(ValueExpression ve) {
    Relation firstRelation = ve.getRelations().get(0);
    SimpleExpression firstSE = firstRelation.getFirstExpression();
    Term firstTerm = firstSE.getTerms().get(0);
    Factor firstFactor = firstTerm.getFactors().get(0);
    Value firstValue = firstFactor.getFirstValue();
    if (ve.getRelations().size() == 1) {
        if (firstRelation.getSecondExpression() == null) {
            if (firstSE.getTerms().size() == 1) {
                if (firstTerm.getFactors().size() == 1) {
                    if (firstFactor.getSecondValue() == null) {
                        // Recursive case.
                        if (firstValue instanceof ValueExpression) {
                            return isOnlyOneValue((ValueExpression) firstValue);
                        } else {
                            return firstValue;
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : Relation(org.osate.ba.aadlba.Relation) Factor(org.osate.ba.aadlba.Factor) ValueExpression(org.osate.ba.aadlba.ValueExpression) ListValue(org.osate.aadl2.ListValue) PortFreshValue(org.osate.ba.aadlba.PortFreshValue) IntegerValue(org.osate.ba.aadlba.IntegerValue) ClassifierValue(org.osate.aadl2.ClassifierValue) NamedValue(org.osate.aadl2.NamedValue) PortCountValue(org.osate.ba.aadlba.PortCountValue) ModalPropertyValue(org.osate.aadl2.ModalPropertyValue) Value(org.osate.ba.aadlba.Value) Term(org.osate.ba.aadlba.Term) SimpleExpression(org.osate.ba.aadlba.SimpleExpression)

Example 3 with Value

use of org.osate.ba.aadlba.Value in project osate2 by osate.

the class AadlBaParserVisitor method visitInteger_value.

/**
 * {@inheritDoc}
 * <p/>
 * The default implementation returns the result of calling
 * {@link #visitChildren} on {@code ctx}.
 */
@Override
public T visitInteger_value(@NotNull AadlBaParser.Integer_valueContext ctx) {
    visitChildren(ctx);
    Value result = null;
    if (ctx.integer_value_constant() != null) {
        result = ctx.integer_value_constant().result;
    } else {
        result = ctx.value_variable().result;
    }
    ctx.result = (IntegerValue) result;
    return null;
}
Also used : ListValue(org.osate.aadl2.ListValue) IntegerValue(org.osate.ba.aadlba.IntegerValue) NamedValue(org.osate.ba.declarative.NamedValue) ClassifierValue(org.osate.aadl2.ClassifierValue) RangeValue(org.osate.aadl2.RangeValue) RecordValue(org.osate.aadl2.RecordValue) DeclarativeReferenceValue(org.osate.ba.declarative.DeclarativeReferenceValue) DeclarativeClassifierValue(org.osate.ba.declarative.DeclarativeClassifierValue) ReferenceValue(org.osate.aadl2.ReferenceValue) ModalPropertyValue(org.osate.aadl2.ModalPropertyValue) Value(org.osate.ba.aadlba.Value)

Example 4 with Value

use of org.osate.ba.aadlba.Value in project osate2 by osate.

the class AadlBaParserVisitor method visitFactor.

/**
 * {@inheritDoc}
 * <p/>
 * The default implementation returns the result of calling
 * {@link #visitChildren} on {@code ctx}.
 */
@Override
public T visitFactor(@NotNull AadlBaParser.FactorContext ctx) {
    visitChildren(ctx);
    ctx.result = _baFact.createFactor();
    Iterator<Value_constant_or_variableContext> it = ctx.value_constant_or_variable().iterator();
    Value tmpValue = it.next().result;
    ctx.result.setFirstValue(tmpValue);
    ctx.result.setLocationReference(tmpValue.getLocationReference());
    if (ctx.binary_numeric_operator() != null) {
        ctx.result.setBinaryNumericOperator(ctx.binary_numeric_operator().result);
        ctx.result.setSecondValue(it.next().result);
    } else if (ctx.unary_numeric_operator() != null) {
        ctx.result.setUnaryNumericOperator(ctx.unary_numeric_operator().result);
    } else if (ctx.unary_boolean_operator() != null) {
        ctx.result.setUnaryBooleanOperator(ctx.unary_boolean_operator().result);
    }
    return null;
}
Also used : Value_constant_or_variableContext(org.osate.ba.parser.AadlBaParser.Value_constant_or_variableContext) ListValue(org.osate.aadl2.ListValue) IntegerValue(org.osate.ba.aadlba.IntegerValue) NamedValue(org.osate.ba.declarative.NamedValue) ClassifierValue(org.osate.aadl2.ClassifierValue) RangeValue(org.osate.aadl2.RangeValue) RecordValue(org.osate.aadl2.RecordValue) DeclarativeReferenceValue(org.osate.ba.declarative.DeclarativeReferenceValue) DeclarativeClassifierValue(org.osate.ba.declarative.DeclarativeClassifierValue) ReferenceValue(org.osate.aadl2.ReferenceValue) ModalPropertyValue(org.osate.aadl2.ModalPropertyValue) Value(org.osate.ba.aadlba.Value)

Example 5 with Value

use of org.osate.ba.aadlba.Value in project osate2 by osate.

the class AadlBaNameResolver method valueExpressionResolver.

private boolean valueExpressionResolver(ValueExpression expr) {
    boolean result = true;
    int seNb = 0;
    SimpleExpression se;
    Value v;
    int vNb = 0;
    // Iterates over relations.
    for (Relation r : expr.getRelations()) {
        se = r.getFirstExpression();
        // Treats simple expression(s).
        do {
            // Iterates over Terms.
            for (Term t : se.getTerms()) {
                // Iterate over Factors.
                for (Factor f : t.getFactors()) {
                    v = f.getFirstValue();
                    // Treats value(s).
                    do {
                        result &= valueResolver(v);
                        v = f.getSecondValue();
                        vNb++;
                    } while (v != null && vNb != 2);
                    vNb = 0;
                }
            // End of for factors.
            }
            // End of for terms.
            se = r.getSecondExpression();
            seNb++;
        } while (se != null && seNb != 2);
        seNb = 0;
    }
    return result;
}
Also used : Relation(org.osate.ba.aadlba.Relation) Factor(org.osate.ba.aadlba.Factor) ListValue(org.osate.aadl2.ListValue) IntegerValue(org.osate.ba.aadlba.IntegerValue) NamedValue(org.osate.ba.declarative.NamedValue) NumberValue(org.osate.aadl2.NumberValue) ClassifierValue(org.osate.aadl2.ClassifierValue) RangeValue(org.osate.aadl2.RangeValue) RecordValue(org.osate.aadl2.RecordValue) ReferenceValue(org.osate.aadl2.ReferenceValue) DeclarativeListValue(org.osate.ba.declarative.DeclarativeListValue) ModalPropertyValue(org.osate.aadl2.ModalPropertyValue) Value(org.osate.ba.aadlba.Value) Term(org.osate.ba.aadlba.Term) SimpleExpression(org.osate.ba.aadlba.SimpleExpression)

Aggregations

Value (org.osate.ba.aadlba.Value)7 ClassifierValue (org.osate.aadl2.ClassifierValue)4 ListValue (org.osate.aadl2.ListValue)4 ModalPropertyValue (org.osate.aadl2.ModalPropertyValue)4 RangeValue (org.osate.aadl2.RangeValue)4 IntegerValue (org.osate.ba.aadlba.IntegerValue)4 RecordValue (org.osate.aadl2.RecordValue)3 ReferenceValue (org.osate.aadl2.ReferenceValue)3 Factor (org.osate.ba.aadlba.Factor)3 NamedValue (org.osate.ba.declarative.NamedValue)3 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)2 Relation (org.osate.ba.aadlba.Relation)2 SimpleExpression (org.osate.ba.aadlba.SimpleExpression)2 Term (org.osate.ba.aadlba.Term)2 DeclarativeClassifierValue (org.osate.ba.declarative.DeclarativeClassifierValue)2 DeclarativeReferenceValue (org.osate.ba.declarative.DeclarativeReferenceValue)2 NamedValue (org.osate.aadl2.NamedValue)1 NumberValue (org.osate.aadl2.NumberValue)1 BehaviorPropertyConstant (org.osate.ba.aadlba.BehaviorPropertyConstant)1 BinaryAddingOperator (org.osate.ba.aadlba.BinaryAddingOperator)1