Search in sources :

Example 11 with DataClassifier

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

the class AadlBaUtils method getDataRepresentation.

/**
 * Returns the last data representation from the property stack of the given data
 * classifier or DataRepresentation.UNKNOWN if Data_Model::Data_Representation
 * property is not set or if the data classifier represents a data structure.
 *
 * @param c the given data classifier
 * @return the data representation or DataRepresentation.UNKNOWN
 */
public static DataRepresentation getDataRepresentation(DataClassifier c) {
    DataRepresentation result = null;
    if (c == null) {
        result = DataRepresentation.UNKNOWN;
    } else {
        EList<PropertyExpression> l = PropertyUtils.findPropertyExpression(c, DataModelProperties.DATA_REPRESENTATION);
        if (l.size() > 0) {
            // Fetches the last enumeration value from the inheritance stack of
            // properties.
            NamedValue nv = (NamedValue) l.get(l.size() - 1);
            String tmp = ((EnumerationLiteral) nv.getNamedValue()).getName();
            result = DataRepresentation.getByName(tmp);
            if (result == null) {
                result = DataRepresentation.UNKNOWN;
            }
        } else {
            result = DataRepresentation.UNKNOWN;
        }
    }
    return result;
}
Also used : DataRepresentation(org.osate.ba.aadlba.DataRepresentation) PropertyExpression(org.osate.aadl2.PropertyExpression) NamedValue(org.osate.aadl2.NamedValue) AadlString(org.osate.aadl2.AadlString) EnumerationLiteral(org.osate.aadl2.EnumerationLiteral)

Example 12 with DataClassifier

use of org.osate.aadl2.DataClassifier 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 13 with DataClassifier

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

the class AadlBaUtils method getDataClassifier.

/**
 * Returns the DataClassifier object associated to the given List of PrototypeBinging objects.
 *
 * @param prototypeBindings the list of PrototypeBinging object
 * @param dp the DataPrototype searched for in prototypeBindings
 * @return the DataClassifier object (null if not found)
 */
private static DataClassifier getDataClassifier(List<PrototypeBinding> prototypeBindings, DataPrototype dp) {
    for (PrototypeBinding pb : prototypeBindings) {
        if (pb instanceof ComponentPrototypeBinding && pb.getFormal().equals(dp)) {
            ComponentPrototypeBinding cpb = (ComponentPrototypeBinding) pb;
            ComponentPrototypeActual cpa = cpb.getActuals().get(cpb.getActuals().size() - 1);
            if (cpa.getSubcomponentType() instanceof DataClassifier) {
                return (DataClassifier) cpa.getSubcomponentType();
            }
        }
    }
    return null;
}
Also used : ComponentPrototypeActual(org.osate.aadl2.ComponentPrototypeActual) DataClassifier(org.osate.aadl2.DataClassifier) ComponentPrototypeBinding(org.osate.aadl2.ComponentPrototypeBinding) PrototypeBinding(org.osate.aadl2.PrototypeBinding) FeaturePrototypeBinding(org.osate.aadl2.FeaturePrototypeBinding) FeatureGroupPrototypeBinding(org.osate.aadl2.FeatureGroupPrototypeBinding) ComponentPrototypeBinding(org.osate.aadl2.ComponentPrototypeBinding)

Example 14 with DataClassifier

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

the class AadlBaUtils method prototypeBindingResolverForDataComponentReference.

/**
 * Returns the DataClassifier object associated to prototype binding in a DataComponentReference
 *
 * @param r the DataComponentRefenrence object from which the binding will be resolved
 * @param dp the DataPrototpye object that enables to identify the targeted prototype binding
 * @param parentContainer the object that contains the element binded to the
 * given DataComponentRefenrence
 * @return the DataClassifier object
 */
private static DataClassifier prototypeBindingResolverForDataComponentReference(DataComponentReference r, DataPrototype dp, NamedElement parentContainer) {
    if (r.getData().size() > 1) {
        DataHolder h = r.getData().get(r.getData().size() - 2);
        NamedElement parent = h.getElement();
        if (parent instanceof Classifier) {
            Classifier c = (Classifier) parent;
            return getDataClassifier(c.getOwnedPrototypeBindings(), dp);
        }
        if (parent instanceof Subcomponent) {
            Subcomponent s = (Subcomponent) parent;
            return getDataClassifier(s.getOwnedPrototypeBindings(), dp);
        } else if (parent instanceof DataAccess) {
            DataAccess da = (DataAccess) parent;
            DataSubcomponentType parentDst = da.getDataFeatureClassifier();
            Classifier c = (Classifier) parentDst;
            DataClassifier matchedPrototype = getDataClassifier(c.getOwnedPrototypeBindings(), dp);
            if (matchedPrototype == null) {
                if (parentContainer instanceof ComponentType) {
                    ComponentType ct = (ComponentType) parentContainer;
                    for (Feature f : ct.getOwnedFeatures()) {
                        if (f instanceof DataAccess && f.getName().equals(parent.getName())) {
                            DataAccess containerDa = (DataAccess) f;
                            DataSubcomponentType containerDst = containerDa.getDataFeatureClassifier();
                            Classifier c2 = (Classifier) containerDst;
                            return getDataClassifier(c2.getOwnedPrototypeBindings(), dp);
                        }
                    }
                }
            }
        } else if (parent instanceof DataPort) {
            DataPort dataport = (DataPort) parent;
            DataSubcomponentType parentDst = dataport.getDataFeatureClassifier();
            Classifier c = (Classifier) parentDst;
            DataClassifier matchedPrototype = getDataClassifier(c.getOwnedPrototypeBindings(), dp);
            if (matchedPrototype == null) {
                if (parentContainer instanceof ComponentType) {
                    ComponentType ct = (ComponentType) parentContainer;
                    for (Feature f : ct.getOwnedFeatures()) {
                        if (f instanceof DataPort && f.getName().equals(parent.getName())) {
                            DataPort containerDp = (DataPort) f;
                            DataSubcomponentType containerDst = containerDp.getDataFeatureClassifier();
                            Classifier c2 = (Classifier) containerDst;
                            return getDataClassifier(c2.getOwnedPrototypeBindings(), dp);
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : DataPort(org.osate.aadl2.DataPort) EventDataPort(org.osate.aadl2.EventDataPort) DataSubcomponentType(org.osate.aadl2.DataSubcomponentType) ComponentType(org.osate.aadl2.ComponentType) DataHolder(org.osate.ba.aadlba.DataHolder) Subcomponent(org.osate.aadl2.Subcomponent) SubprogramSubcomponent(org.osate.aadl2.SubprogramSubcomponent) SubprogramGroupSubcomponent(org.osate.aadl2.SubprogramGroupSubcomponent) SystemSubcomponent(org.osate.aadl2.SystemSubcomponent) DataSubcomponent(org.osate.aadl2.DataSubcomponent) SubprogramClassifier(org.osate.aadl2.SubprogramClassifier) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier) ProcessClassifier(org.osate.aadl2.ProcessClassifier) DataClassifier(org.osate.aadl2.DataClassifier) ProcessorClassifier(org.osate.aadl2.ProcessorClassifier) DataClassifier(org.osate.aadl2.DataClassifier) BehaviorNamedElement(org.osate.ba.aadlba.BehaviorNamedElement) NamedElement(org.osate.aadl2.NamedElement) Feature(org.osate.aadl2.Feature) AbstractFeature(org.osate.aadl2.AbstractFeature) DirectedFeature(org.osate.aadl2.DirectedFeature) DataAccess(org.osate.aadl2.DataAccess)

Example 15 with DataClassifier

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

the class AadlBaUtils method processArrayDataRepresentation.

// Evaluates the array behavior of the given type in the Data Model Annex
// standard way. Set up dimension and dimension sizes of the given
// TypeHolder object.
// The given expression dimension is used as an dimension offset.
private static void processArrayDataRepresentation(Element el, TypeHolder type, int exprDim) throws DimensionException {
    // Treats only type declared as an array. Otherwise returns.
    if (type.getDataRep() == DataRepresentation.ARRAY) {
        // Fetches the array element data type.
        ClassifierValue cv = AadlBaUtils.getBaseType(type.getKlass());
        if (cv != null && cv.getClassifier() instanceof DataClassifier) {
            DataClassifier dc = (DataClassifier) cv.getClassifier();
            type.setKlass(dc);
            type.setDataRep(AadlBaUtils.getDataRepresentation(dc));
        } else {
            type.setKlass(null);
        }
        EList<PropertyExpression> pel = PropertyUtils.findPropertyExpression(type.getKlass(), DataModelProperties.DIMENSION);
        int declareDimBT = 0;
        long[] declareDimSizeBT;
        if (false == pel.isEmpty()) {
            // pel has only one element, according to AADL core standard.
            PropertyExpression pe = pel.get(pel.size() - 1);
            if (pe instanceof ListValue) {
                ListValue lv = (ListValue) pe;
                EList<PropertyExpression> lve = lv.getOwnedListElements();
                declareDimBT = lve.size();
                if (declareDimBT >= exprDim) {
                    declareDimSizeBT = new long[declareDimBT - exprDim];
                    for (int i = exprDim; i < declareDimBT; i++) {
                        IntegerLiteral il = (IntegerLiteral) lve.get(i);
                        declareDimSizeBT[i - exprDim] = il.getValue();
                    }
                    type.setDimension(declareDimBT - exprDim);
                    type.setDimensionSizes(declareDimSizeBT);
                } else {
                    String msg = "must be an array but is resolved as " + type.getKlass().getQualifiedName();
                    throw new DimensionException(el, msg, false);
                }
            }
        } else {
            // Returning -1 and null means that the expression is declared as an
            // array but the dimension property is not set.
            type.setDimension(-1);
            type.setDimensionSizes(null);
            return;
        // String msg = "is declared as an array but the dimension property is not set" ;
        // throw new DimensionException(el, msg, true) ;
        }
    } else {
        return;
    }
}
Also used : ClassifierValue(org.osate.aadl2.ClassifierValue) ListValue(org.osate.aadl2.ListValue) PropertyExpression(org.osate.aadl2.PropertyExpression) DataClassifier(org.osate.aadl2.DataClassifier) AadlString(org.osate.aadl2.AadlString) IntegerLiteral(org.osate.aadl2.IntegerLiteral) BehaviorIntegerLiteral(org.osate.ba.aadlba.BehaviorIntegerLiteral)

Aggregations

DataClassifier (org.osate.aadl2.DataClassifier)22 NamedElement (org.osate.aadl2.NamedElement)8 ProcessorClassifier (org.osate.aadl2.ProcessorClassifier)7 Classifier (org.osate.aadl2.Classifier)6 ComponentClassifier (org.osate.aadl2.ComponentClassifier)6 Element (org.osate.aadl2.Element)6 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)5 Feature (org.osate.aadl2.Feature)5 AadlString (org.osate.aadl2.AadlString)4 AbstractFeature (org.osate.aadl2.AbstractFeature)4 PropertyExpression (org.osate.aadl2.PropertyExpression)4 BehaviorNamedElement (org.osate.ba.aadlba.BehaviorNamedElement)4 QualifiedNamedElement (org.osate.ba.declarative.QualifiedNamedElement)4 ListValue (org.osate.aadl2.ListValue)3 ProcessClassifier (org.osate.aadl2.ProcessClassifier)3 SubprogramClassifier (org.osate.aadl2.SubprogramClassifier)3 BehaviorElement (org.osate.ba.aadlba.BehaviorElement)3 BehaviorVariable (org.osate.ba.aadlba.BehaviorVariable)3 DataComponentReference (org.osate.ba.aadlba.DataComponentReference)3 ElementHolder (org.osate.ba.aadlba.ElementHolder)3