Search in sources :

Example 1 with ElementHolder

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

the class AadlBaUtils method isSameTarget.

/**
 * Compare the given Target objects.<BR><BR>
 *
 * This comparator is base on name and not on object's hash number, meaning
 * that two different Target instances with the same name are
 * considered as equals.
 *
 * This comparator doesn't support array indexes comparison, meaning that two
 * target instances with the same name and different array indexes
 * are considered as equals.
 * <BR><BR>
 *
 * @param tar0 the first name
 * @param tar1 the second name
 * @return {@code true} if the given Target objects are the same.
 * Otherwise returns {@code false}
 */
public static boolean isSameTarget(Target tar0, Target tar1) {
    if (tar0 instanceof ElementHolder && tar1 instanceof DataComponentReference || tar1 instanceof ElementHolder && tar0 instanceof DataComponentReference) {
        return false;
    } else {
        if (tar0 instanceof ElementHolder && tar1 instanceof ElementHolder) {
            return isSameElementHolder((ElementHolder) tar0, (ElementHolder) tar1);
        } else {
            EList<DataHolder> dhl0 = ((DataComponentReference) tar0).getData();
            EList<DataHolder> dhl1 = ((DataComponentReference) tar1).getData();
            if (dhl0.size() == dhl1.size()) {
                ListIterator<DataHolder> it1 = dhl1.listIterator();
                DataHolder dh1 = null;
                boolean result = true;
                for (DataHolder dh0 : dhl0) {
                    dh1 = it1.next();
                    result &= isSameElementHolder(dh0, dh1);
                }
                return result;
            } else {
                return false;
            }
        }
    }
}
Also used : DataHolder(org.osate.ba.aadlba.DataHolder) ElementHolder(org.osate.ba.aadlba.ElementHolder) PropertyElementHolder(org.osate.ba.aadlba.PropertyElementHolder) DataComponentReference(org.osate.ba.aadlba.DataComponentReference)

Example 2 with ElementHolder

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

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

the class AadlBaUtils method getAccessRight.

/**
 * If the given Target object is a DataAccessHolder object or a
 * DataComponentReference object which the last element is a DataAccessHolder
 * object, it returns the data access right or "unknown" if the default
 * data access right is not set.
 *
 * @see org.osate.utils.internal.Aadl2Utils#getAccessRight
 * @param tar the given Target object
 * @return the data access right or "unknown"
 */
public static String getAccessRight(Target tar) {
    ElementHolder el = null;
    if (// The other ElementHolders.
    tar instanceof ElementHolder) {
        el = (ElementHolder) tar;
    } else // Data component reference.
    {
        EList<DataHolder> dhl = ((DataComponentReference) tar).getData();
        el = dhl.get(dhl.size() - 1);
    }
    if (el instanceof DataAccessHolder || el instanceof DataAccessPrototypeHolder || el instanceof FeaturePrototypeHolder) {
        return Aadl2Utils.getAccessRight(el.getElement());
    } else {
        return "unknown";
    }
}
Also used : DataAccessHolder(org.osate.ba.aadlba.DataAccessHolder) DataHolder(org.osate.ba.aadlba.DataHolder) DataAccessPrototypeHolder(org.osate.ba.aadlba.DataAccessPrototypeHolder) FeaturePrototypeHolder(org.osate.ba.aadlba.FeaturePrototypeHolder) ElementHolder(org.osate.ba.aadlba.ElementHolder) PropertyElementHolder(org.osate.ba.aadlba.PropertyElementHolder) DataComponentReference(org.osate.ba.aadlba.DataComponentReference)

Example 4 with ElementHolder

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

the class AadlBaTextPositionResolver method resolveBehaviorAnnexElementAt.

private TextPositionInfo resolveBehaviorAnnexElementAt(int offset) {
    Element e = this.getLinkedElement(offset);
    if (e == null)
        return new TextPositionInfo(null, 0, 0);
    AadlBaLocationReference loc = this.getSourceOffsetElement(offset);
    TextPositionInfo positionInfo;
    if (e instanceof ElementHolder) {
        ElementHolder beh = (ElementHolder) e;
        positionInfo = new TextPositionInfo(beh.getElement(), loc.getOffset(), loc.getLength());
    } else {
        positionInfo = new TextPositionInfo(e, loc.getOffset(), loc.getLength());
    }
    return positionInfo;
}
Also used : AadlBaLocationReference(org.osate.ba.utils.AadlBaLocationReference) TextPositionInfo(org.osate.annexsupport.TextPositionInfo) Element(org.osate.aadl2.Element) ElementHolder(org.osate.ba.aadlba.ElementHolder)

Example 5 with ElementHolder

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

the class AadlBaTextPositionResolver method resolveBehaviorAnnexCrossReferencedElementAt.

private TextPositionInfo resolveBehaviorAnnexCrossReferencedElementAt(int offset) {
    Element e = this.getLinkedElement(offset);
    if (e == null)
        return new TextPositionInfo(null, offset, 0);
    AadlBaLocationReference loc = this.getSourceOffsetElement(offset);
    TextPositionInfo positionInfo;
    if (e instanceof ElementHolder) {
        ElementHolder beh = (ElementHolder) e;
        positionInfo = new TextPositionInfo(beh.getElement(), loc.getOffset(), loc.getLength());
    } else {
        positionInfo = new TextPositionInfo(e, loc.getOffset(), loc.getLength());
    }
    return positionInfo;
}
Also used : AadlBaLocationReference(org.osate.ba.utils.AadlBaLocationReference) TextPositionInfo(org.osate.annexsupport.TextPositionInfo) Element(org.osate.aadl2.Element) ElementHolder(org.osate.ba.aadlba.ElementHolder)

Aggregations

ElementHolder (org.osate.ba.aadlba.ElementHolder)9 PropertyElementHolder (org.osate.ba.aadlba.PropertyElementHolder)7 Element (org.osate.aadl2.Element)6 DataComponentReference (org.osate.ba.aadlba.DataComponentReference)6 DataClassifier (org.osate.aadl2.DataClassifier)4 NamedElement (org.osate.aadl2.NamedElement)4 BehaviorElement (org.osate.ba.aadlba.BehaviorElement)4 DataHolder (org.osate.ba.aadlba.DataHolder)4 IndexableElement (org.osate.ba.aadlba.IndexableElement)4 ArrayableElement (org.osate.aadl2.ArrayableElement)3 BehaviorNamedElement (org.osate.ba.aadlba.BehaviorNamedElement)3 DataAccessPrototypeHolder (org.osate.ba.aadlba.DataAccessPrototypeHolder)3 FeaturePrototypeHolder (org.osate.ba.aadlba.FeaturePrototypeHolder)3 StructUnionElement (org.osate.ba.aadlba.StructUnionElement)3 Abstract (org.osate.aadl2.Abstract)2 Classifier (org.osate.aadl2.Classifier)2 ComponentClassifier (org.osate.aadl2.ComponentClassifier)2 ProcessClassifier (org.osate.aadl2.ProcessClassifier)2 ProcessorClassifier (org.osate.aadl2.ProcessorClassifier)2 SubprogramClassifier (org.osate.aadl2.SubprogramClassifier)2