Search in sources :

Example 1 with ValueConstant

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

the class BehaviorVariableImpl method basicSetOwnedValueConstant.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public NotificationChain basicSetOwnedValueConstant(ValueConstant newOwnedValueConstant, NotificationChain msgs) {
    ValueConstant oldOwnedValueConstant = ownedValueConstant;
    ownedValueConstant = newOwnedValueConstant;
    if (eNotificationRequired()) {
        ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, AadlBaPackage.BEHAVIOR_VARIABLE__OWNED_VALUE_CONSTANT, oldOwnedValueConstant, newOwnedValueConstant);
        if (msgs == null)
            msgs = notification;
        else
            msgs.add(notification);
    }
    return msgs;
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) ValueConstant(org.osate.ba.aadlba.ValueConstant)

Example 2 with ValueConstant

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

the class AadlBaUtils method getTypeHolder.

/**
 * Returns the TypeHolder (data representation and component's DataClassifier
 * if any) of the given Element object.
 * <BR><BR>
 * For now, only the following objects are supported:<BR>
 * <BR>_ IterativeVariable
 * <BR>_ DataClassifier
 * <BR>_ Target
 * <BR>_ Value
 * <BR><BR>
 *
 * @param el the given Element object.
 * @param parentContainer only for AADLBA declarative objects which have no
 * parent set, yet
 * @return the type holder of the given Element object. If the given element
 * is null, it returns the default type holder object.
 * @exception UnsupportedOperationException for the unsupported types
 * or Element instances.
 * @exception DimensionException in any case of array dimension overflow.
 */
public static TypeHolder getTypeHolder(Element el, ComponentClassifier parentContainer) throws DimensionException {
    TypeHolder result = null;
    if (el instanceof IterativeVariable) {
        IterativeVariable iv = (IterativeVariable) el;
        result = getTypeHolder(iv);
        processArrayDataRepresentation(el, result, 0);
        return result;
    } else if (el instanceof DataClassifier) {
        DataClassifier dc = (DataClassifier) el;
        result = getTypeHolder(dc);
        return result;
    } else if (el instanceof ValueConstant) {
        return result = getTypeHolder((ValueConstant) el, parentContainer);
    } else if (el instanceof Target || el instanceof ValueVariable) {
        result = getTypeHolder((Value) el, parentContainer);
        // The declared variable dimension: the number of [] in the element
        // declaration.
        int declaredDim = 0;
        // The expression dimension: the number of [] in the expression.
        // Only targets and values can express dimension.
        int exprDim = 0;
        boolean hasToProcessDataRepresentation = false;
        // for/forall statement.
        if (el.eContainer() instanceof ForOrForAllStatement) {
            hasToProcessDataRepresentation = true;
        }
        // Either ElementHolder or DataComponentReference object.
        Element bindedEl = null;
        ElementHolder elHolder = null;
        if (el instanceof ElementHolder) {
            elHolder = (ElementHolder) el;
            bindedEl = elHolder.getElement();
        } else // DataComponentReference case.
        {
            DataComponentReference dcr = (DataComponentReference) el;
            elHolder = dcr.getData().get(dcr.getData().size() - 1);
        }
        bindedEl = elHolder.getElement();
        if (elHolder instanceof IndexableElement) {
            IndexableElement ie = (IndexableElement) elHolder;
            if (ie.isSetArrayIndexes()) {
                exprDim = ie.getArrayIndexes().size();
            }
        }
        // Set up the declared, expression dimension and dimension sizes.
        if (bindedEl instanceof ArrayableElement) {
            ArrayableElement ae = (ArrayableElement) bindedEl;
            if (false == ae.getArrayDimensions().isEmpty()) {
                EList<ArrayDimension> adl = ae.getArrayDimensions();
                declaredDim = adl.size();
                if (exprDim <= declaredDim) {
                    long[] ds = new long[declaredDim - exprDim];
                    for (int i = exprDim; i < declaredDim; i++) {
                        ds[i - exprDim] = adl.get(i).getSize().getSize();
                    }
                    result.setDimensionSizes(ds);
                }
            }
        }
        // or if the element is an element values of a for/forall statement.
        if (declaredDim == 0 && (exprDim > 0 || hasToProcessDataRepresentation)) {
            processArrayDataRepresentation(el, result, exprDim);
        } else {
            if (exprDim <= declaredDim) {
                result.setDimension(declaredDim - exprDim);
            } else {
                // The given type is expressed as an array in AADL standard
                // core way. We don't evaluate array behavior expressed in
                // the Data Model Annex standard as we don't want to mix up
                // the two standards.
                String msg = "mixs up AADL standard array and data model array";
                throw new DimensionException(el, msg, true);
            }
        }
        return result;
    } else if (el == null || el instanceof Abstract) {
        // returns the default type holder for untyped prototypes.
        return new TypeHolder();
    } else {
        String errorMsg = "getTypeHolder : " + el.getClass().getSimpleName() + " is not supported yet at line " + Aadl2Utils.getLocationReference(el).getLine() + ".";
        System.err.println(errorMsg);
        throw new UnsupportedOperationException(errorMsg);
    }
}
Also used : IndexableElement(org.osate.ba.aadlba.IndexableElement) IterativeVariable(org.osate.ba.aadlba.IterativeVariable) Abstract(org.osate.aadl2.Abstract) StructUnionElement(org.osate.ba.aadlba.StructUnionElement) BehaviorNamedElement(org.osate.ba.aadlba.BehaviorNamedElement) NamedElement(org.osate.aadl2.NamedElement) ArrayableElement(org.osate.aadl2.ArrayableElement) Element(org.osate.aadl2.Element) BehaviorElement(org.osate.ba.aadlba.BehaviorElement) IndexableElement(org.osate.ba.aadlba.IndexableElement) ElementHolder(org.osate.ba.aadlba.ElementHolder) PropertyElementHolder(org.osate.ba.aadlba.PropertyElementHolder) DataClassifier(org.osate.aadl2.DataClassifier) AadlString(org.osate.aadl2.AadlString) DataComponentReference(org.osate.ba.aadlba.DataComponentReference) TypeHolder(org.osate.ba.analyzers.TypeHolder) Target(org.osate.ba.aadlba.Target) ValueVariable(org.osate.ba.aadlba.ValueVariable) EList(org.eclipse.emf.common.util.EList) ValueConstant(org.osate.ba.aadlba.ValueConstant) ArrayableElement(org.osate.aadl2.ArrayableElement) ForOrForAllStatement(org.osate.ba.aadlba.ForOrForAllStatement)

Example 3 with ValueConstant

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

ValueConstant (org.osate.ba.aadlba.ValueConstant)3 ArrayList (java.util.ArrayList)1 List (java.util.List)1 BasicEList (org.eclipse.emf.common.util.BasicEList)1 EList (org.eclipse.emf.common.util.EList)1 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)1 AadlString (org.osate.aadl2.AadlString)1 Abstract (org.osate.aadl2.Abstract)1 ArrayableElement (org.osate.aadl2.ArrayableElement)1 DataClassifier (org.osate.aadl2.DataClassifier)1 Element (org.osate.aadl2.Element)1 NamedElement (org.osate.aadl2.NamedElement)1 BehaviorBooleanLiteral (org.osate.ba.aadlba.BehaviorBooleanLiteral)1 BehaviorElement (org.osate.ba.aadlba.BehaviorElement)1 BehaviorIntegerLiteral (org.osate.ba.aadlba.BehaviorIntegerLiteral)1 BehaviorNamedElement (org.osate.ba.aadlba.BehaviorNamedElement)1 BehaviorPropertyConstant (org.osate.ba.aadlba.BehaviorPropertyConstant)1 BehaviorRealLiteral (org.osate.ba.aadlba.BehaviorRealLiteral)1 BehaviorStringLiteral (org.osate.ba.aadlba.BehaviorStringLiteral)1 ClassifierFeatureHolder (org.osate.ba.aadlba.ClassifierFeatureHolder)1