Search in sources :

Example 1 with PropertyReference

use of org.osate.ba.aadlba.PropertyReference 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 PropertyReference

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

the class AadlBaParserVisitor method cloneValueConstant.

private ValueConstant cloneValueConstant(ValueConstant sourceValueConstant) {
    ValueConstant targetValueConstant = null;
    /*
		 * value_constant ::=
		 * boolean_literal
		 * | numeric_literal
		 * | string_literal
		 * | property_constant
		 * | property_reference
		 */
    if (sourceValueConstant instanceof BehaviorBooleanLiteral) {
        BehaviorBooleanLiteral sourceBbl = (BehaviorBooleanLiteral) sourceValueConstant;
        BehaviorBooleanLiteral targetBbl = _baFact.createBehaviorBooleanLiteral();
        targetBbl.setValue(sourceBbl.getValue());
        targetValueConstant = targetBbl;
    } else if (sourceValueConstant instanceof BehaviorRealLiteral) {
        BehaviorRealLiteral sourceBrl = (BehaviorRealLiteral) sourceValueConstant;
        BehaviorRealLiteral targetBrl = _baFact.createBehaviorRealLiteral();
        targetBrl.setValue(sourceBrl.getValue());
        targetBrl.setUnit(sourceBrl.getUnit());
        targetValueConstant = targetBrl;
    } else if (sourceValueConstant instanceof BehaviorIntegerLiteral) {
        BehaviorIntegerLiteral sourceIl = (BehaviorIntegerLiteral) sourceValueConstant;
        BehaviorIntegerLiteral targetIl = _baFact.createBehaviorIntegerLiteral();
        targetIl.setValue(sourceIl.getValue());
        targetIl.setUnit(sourceIl.getUnit());
        targetValueConstant = targetIl;
    } else if (sourceValueConstant instanceof BehaviorStringLiteral) {
        BehaviorStringLiteral sourceBsl = (BehaviorStringLiteral) sourceValueConstant;
        BehaviorStringLiteral targetBsl = _baFact.createBehaviorStringLiteral();
        targetBsl.setValue(sourceBsl.getValue());
        targetValueConstant = targetBsl;
    } else if (sourceValueConstant instanceof BehaviorPropertyConstant) {
        BehaviorPropertyConstant sourceBpc = (BehaviorPropertyConstant) sourceValueConstant;
        BehaviorPropertyConstant targetBpc = _baFact.createBehaviorPropertyConstant();
        targetBpc.setProperty(sourceBpc.getProperty());
        targetBpc.setPropertySet(sourceBpc.getPropertySet());
        targetValueConstant = targetBpc;
    } else if (sourceValueConstant instanceof PropertyReference) {
        PropertyReference sourcePr = (PropertyReference) sourceValueConstant;
        List<PropertyNameHolder> sourceProperties = sourcePr.getProperties();
        if (sourceValueConstant instanceof ClassifierFeaturePropertyReference) {
            ClassifierFeaturePropertyReference sourceCfpr = (ClassifierFeaturePropertyReference) sourceValueConstant;
            ClassifierFeaturePropertyReference targetCfpr = _baFact.createClassifierFeaturePropertyReference();
            targetCfpr.setComponent((ClassifierFeatureHolder) cloneHolder(sourceCfpr.getComponent()));
            targetCfpr.getProperties().addAll(clonePropertyNameHolderList(sourceProperties));
            targetValueConstant = targetCfpr;
        } else if (sourceValueConstant instanceof ClassifierPropertyReference) {
            ClassifierPropertyReference sourceCpr = (ClassifierPropertyReference) sourceValueConstant;
            ClassifierPropertyReference targetCpr = _baFact.createClassifierPropertyReference();
            targetCpr.setClassifier(sourceCpr.getClassifier());
            targetCpr.getProperties().addAll(clonePropertyNameHolderList(sourceProperties));
            targetValueConstant = targetCpr;
        } else if (sourceValueConstant instanceof PropertySetPropertyReference) {
            PropertySetPropertyReference sourcePspr = (PropertySetPropertyReference) sourceValueConstant;
            PropertySetPropertyReference targetPspr = _baFact.createPropertySetPropertyReference();
            targetPspr.setPropertySet(sourcePspr.getPropertySet());
            targetPspr.getProperties().addAll(clonePropertyNameHolderList(sourceProperties));
            targetValueConstant = targetPspr;
        }
    }
    targetValueConstant.setLocationReference(sourceValueConstant.getLocationReference());
    return targetValueConstant;
}
Also used : PropertyReference(org.osate.ba.aadlba.PropertyReference) DeclarativePropertyReference(org.osate.ba.declarative.DeclarativePropertyReference) PropertySetPropertyReference(org.osate.ba.aadlba.PropertySetPropertyReference) ClassifierFeaturePropertyReference(org.osate.ba.aadlba.ClassifierFeaturePropertyReference) ClassifierPropertyReference(org.osate.ba.aadlba.ClassifierPropertyReference) BehaviorPropertyConstant(org.osate.ba.aadlba.BehaviorPropertyConstant) ClassifierFeaturePropertyReference(org.osate.ba.aadlba.ClassifierFeaturePropertyReference) BehaviorStringLiteral(org.osate.ba.aadlba.BehaviorStringLiteral) ClassifierPropertyReference(org.osate.ba.aadlba.ClassifierPropertyReference) BehaviorRealLiteral(org.osate.ba.aadlba.BehaviorRealLiteral) ValueConstant(org.osate.ba.aadlba.ValueConstant) BehaviorBooleanLiteral(org.osate.ba.aadlba.BehaviorBooleanLiteral) ArrayList(java.util.ArrayList) List(java.util.List) BasicEList(org.eclipse.emf.common.util.BasicEList) ClassifierFeatureHolder(org.osate.ba.aadlba.ClassifierFeatureHolder) PropertySetPropertyReference(org.osate.ba.aadlba.PropertySetPropertyReference) BehaviorIntegerLiteral(org.osate.ba.aadlba.BehaviorIntegerLiteral)

Aggregations

BehaviorPropertyConstant (org.osate.ba.aadlba.BehaviorPropertyConstant)2 PropertyReference (org.osate.ba.aadlba.PropertyReference)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 BasicEList (org.eclipse.emf.common.util.BasicEList)1 RangeValue (org.osate.aadl2.RangeValue)1 BehaviorBooleanLiteral (org.osate.ba.aadlba.BehaviorBooleanLiteral)1 BehaviorIntegerLiteral (org.osate.ba.aadlba.BehaviorIntegerLiteral)1 BehaviorRealLiteral (org.osate.ba.aadlba.BehaviorRealLiteral)1 BehaviorStringLiteral (org.osate.ba.aadlba.BehaviorStringLiteral)1 BinaryAddingOperator (org.osate.ba.aadlba.BinaryAddingOperator)1 BinaryNumericOperator (org.osate.ba.aadlba.BinaryNumericOperator)1 ClassifierFeatureHolder (org.osate.ba.aadlba.ClassifierFeatureHolder)1 ClassifierFeaturePropertyReference (org.osate.ba.aadlba.ClassifierFeaturePropertyReference)1 ClassifierPropertyReference (org.osate.ba.aadlba.ClassifierPropertyReference)1 Factor (org.osate.ba.aadlba.Factor)1 LogicalOperator (org.osate.ba.aadlba.LogicalOperator)1 MultiplyingOperator (org.osate.ba.aadlba.MultiplyingOperator)1 PropertySetPropertyReference (org.osate.ba.aadlba.PropertySetPropertyReference)1 RelationalOperator (org.osate.ba.aadlba.RelationalOperator)1