Search in sources :

Example 1 with ArrayDimension

use of org.osate.aadl2.ArrayDimension in project AGREE by loonwerks.

the class AgreeTypeSystem method getArraySize.

private static long getArraySize(ArrayDimension arrayDimension) {
    ArraySize arraySize = arrayDimension.getSize();
    long size = arraySize.getSize();
    if (size == 0) {
        ArraySizeProperty arraySizeProperty = arraySize.getSizeProperty();
        if (arraySizeProperty instanceof PropertyConstant) {
            PropertyExpression pe = ((PropertyConstant) arraySizeProperty).getConstantValue();
            size = intFromPropExp(pe).orElse((long) -1);
        }
    }
    assert size > 0;
    return size;
}
Also used : ArraySize(org.osate.aadl2.ArraySize) PropertyExpression(org.osate.aadl2.PropertyExpression) PropertyConstant(org.osate.aadl2.PropertyConstant) ArraySizeProperty(org.osate.aadl2.ArraySizeProperty)

Example 2 with ArrayDimension

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

the class BehaviorVariableImpl method createArrayDimension.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 */
public ArrayDimension createArrayDimension() {
    ArrayDimension newArrayDimension = (ArrayDimension) create(Aadl2Package.eINSTANCE.getArrayDimension());
    getArrayDimensions().add(newArrayDimension);
    return newArrayDimension;
}
Also used : ArrayDimension(org.osate.aadl2.ArrayDimension)

Example 3 with ArrayDimension

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

the class AadlBaTypeChecker method behaviorVariableCheck.

/**
 * Document: AADL Behavior Annex draft
 * Version : 0.94
 * Type : Semantic rule
 * Section : D.3 Behavior Specification
 * Object : Check semantic rule D.3.(28)
 * Keys : local variables explicitly typed valid data component classifier
 */
private boolean behaviorVariableCheck() {
    boolean result = true;
    IntegerValueConstant ivc = null;
    QualifiedNamedElement uccr;
    for (BehaviorVariable bv : _ba.getVariables()) {
        uccr = (QualifiedNamedElement) bv.getDataClassifier();
        DataClassifier dc = (DataClassifier) uniqueNamedElementReferenceResolver(uccr, TypeCheckRule.DATA_UCCR);
        _hl.addToHyperlinking(uccr.getAadlBaLocationReference(), dc);
        result &= dc != null;
        bv.setDataClassifier(dc);
        for (PropertyAssociation pa : bv.getOwnedPropertyAssociations()) {
            Property p = (Property) uniqueNamedElementReferenceResolver((QualifiedNamedElement) pa.getProperty(), TypeCheckRule.PROPERTY);
            pa.setProperty(p);
        }
        ListIterator<ArrayDimension> it = bv.getArrayDimensions().listIterator();
        while (it.hasNext()) {
            ArrayDimension tmp = it.next();
            DeclarativeArrayDimension dad = (DeclarativeArrayDimension) tmp;
            ivc = dad.getDimension();
            ivc = integerValueConstantCheck(ivc);
            result &= ivc != null;
            // integervalueConstantCheck method. So replace if needed.
            if (ivc != null) {
                it.set(integerValueConstantToArrayDimension(ivc));
            }
        }
    }
    return result;
}
Also used : QualifiedNamedElement(org.osate.ba.declarative.QualifiedNamedElement) DeclarativeArrayDimension(org.osate.ba.declarative.DeclarativeArrayDimension) PropertyAssociation(org.osate.aadl2.PropertyAssociation) DataClassifier(org.osate.aadl2.DataClassifier) BasicProperty(org.osate.aadl2.BasicProperty) Property(org.osate.aadl2.Property) ArrayDimension(org.osate.aadl2.ArrayDimension) DeclarativeArrayDimension(org.osate.ba.declarative.DeclarativeArrayDimension)

Example 4 with ArrayDimension

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

the class AadlBaNameResolver method behaviorVariableResolver.

/**
 * Resolves the behavior annex's variables.
 *
 * @return {@code true} if all names are resolved. {@code false} otherwise.
 */
private boolean behaviorVariableResolver() {
    boolean result = true;
    QualifiedNamedElement uccr;
    // classifier reference exists.
    for (BehaviorVariable v : _ba.getVariables()) {
        uccr = (QualifiedNamedElement) v.getDataClassifier();
        result &= qualifiedNamedElementResolver(uccr, true);
        for (ArrayDimension tmp : v.getArrayDimensions()) {
            IntegerValueConstant ivc = ((DeclarativeArrayDimension) tmp).getDimension();
            result &= integerValueConstantResolver(ivc);
        }
        List<PropertyAssociation> paList = v.getOwnedPropertyAssociations();
        List<PropertyAssociation> paPropertyNotFound = new ArrayList<PropertyAssociation>();
        Set<PropertyAssociation> paPropertyValueError = new HashSet<PropertyAssociation>();
        for (PropertyAssociation pa : paList) {
            QualifiedNamedElement p = (QualifiedNamedElement) pa.getProperty();
            boolean valid = qualifiedNamedElementResolver(p, false);
            if (valid) {
                for (ModalPropertyValue mpv : pa.getOwnedValues()) {
                    result &= propertyExpressionResolver(v, p, mpv.getOwnedValue());
                    paPropertyValueError.add(pa);
                }
            }
            if (!valid) {
                paPropertyNotFound.add(pa);
            }
            result &= valid;
        }
        StringBuilder msg = new StringBuilder();
        if (paPropertyNotFound.size() > 1) {
            msg.append("Properties ");
        } else {
            msg.append("Property ");
        }
        boolean first = true;
        for (PropertyAssociation paToRemove : paPropertyNotFound) {
            QualifiedNamedElement p = (QualifiedNamedElement) paToRemove.getProperty();
            StringBuilder qualifiedName = new StringBuilder();
            if (p.getBaNamespace() != null) {
                qualifiedName.append(p.getBaNamespace().getId());
                qualifiedName.append("::");
            }
            qualifiedName.append(p.getBaName().getId());
            if (first) {
                msg.append("\'" + qualifiedName + "\' ");
            } else {
                msg.append(" and \'" + qualifiedName + "\' ");
            }
            first = false;
        }
        paList.removeAll(paPropertyNotFound);
        paList.removeAll(paPropertyValueError);
        if (paPropertyNotFound.size() > 0) {
            msg.append("not found");
            _errManager.error(v, msg.toString());
        }
    }
    return result;
}
Also used : ModalPropertyValue(org.osate.aadl2.ModalPropertyValue) BehaviorVariable(org.osate.ba.aadlba.BehaviorVariable) PropertyAssociation(org.osate.aadl2.PropertyAssociation) DeclarativeBasicPropertyAssociation(org.osate.ba.declarative.DeclarativeBasicPropertyAssociation) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation) ArrayList(java.util.ArrayList) QualifiedNamedElement(org.osate.ba.declarative.QualifiedNamedElement) DeclarativeArrayDimension(org.osate.ba.declarative.DeclarativeArrayDimension) IntegerValueConstant(org.osate.ba.aadlba.IntegerValueConstant) ArrayDimension(org.osate.aadl2.ArrayDimension) DeclarativeArrayDimension(org.osate.ba.declarative.DeclarativeArrayDimension) HashSet(java.util.HashSet)

Example 5 with ArrayDimension

use of org.osate.aadl2.ArrayDimension 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)

Aggregations

ArrayDimension (org.osate.aadl2.ArrayDimension)25 ArraySize (org.osate.aadl2.ArraySize)12 Feature (org.osate.aadl2.Feature)7 Property (org.osate.aadl2.Property)6 PropertyAssociation (org.osate.aadl2.PropertyAssociation)6 Subcomponent (org.osate.aadl2.Subcomponent)6 AadlString (org.osate.aadl2.AadlString)5 PropertyConstant (org.osate.aadl2.PropertyConstant)5 PropertyExpression (org.osate.aadl2.PropertyExpression)5 ArraySizeProperty (org.osate.aadl2.ArraySizeProperty)4 ArrayableElement (org.osate.aadl2.ArrayableElement)4 NamedElement (org.osate.aadl2.NamedElement)4 DeclarativeArrayDimension (org.osate.ba.declarative.DeclarativeArrayDimension)4 QualifiedNamedElement (org.osate.ba.declarative.QualifiedNamedElement)4 ArrayList (java.util.ArrayList)3 EList (org.eclipse.emf.common.util.EList)3 AbstractNamedValue (org.osate.aadl2.AbstractNamedValue)3 DirectedFeature (org.osate.aadl2.DirectedFeature)3 NamedValue (org.osate.aadl2.NamedValue)3 List (java.util.List)2