Search in sources :

Example 1 with ClassifierValue

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

the class AadlBaNameResolver method structOrUnionOrArrayIdResolver.

// Resolves the given identifier within the property Data_Model::Element
// Names of a declared struct or union component (event if element names is
// set). If the given component is not declared as a struct or union, it
// returns false and reports error according to the hasToReport flag.
private boolean structOrUnionOrArrayIdResolver(Identifier id, DataClassifier component, boolean hasToReport) {
    boolean result = false;
    DataRepresentation rep = AadlBaUtils.getDataRepresentation(component);
    if (rep == DataRepresentation.STRUCT || rep == DataRepresentation.UNION) {
        EList<PropertyExpression> lpv = PropertyUtils.findPropertyExpression(component, DataModelProperties.ELEMENT_NAMES);
        ListValue lv = null;
        StringLiteral sl = null;
        int index1 = 0;
        int index2 = 0;
        for1: for (PropertyExpression pe : lpv) {
            lv = (ListValue) pe;
            for (PropertyExpression pex : lv.getOwnedListElements()) {
                sl = (StringLiteral) pex;
                if (id.getId().equalsIgnoreCase(sl.getValue())) {
                    result = true;
                    break for1;
                }
                index2++;
            }
            index1++;
        }
        // Binds the element name's base type.
        if (result) {
            EList<PropertyExpression> lpv2 = PropertyUtils.findPropertyExpression(component, DataModelProperties.BASE_TYPE);
            ClassifierValue cv;
            cv = (ClassifierValue) ((ListValue) lpv2.get(index1)).getOwnedListElements().get(index2);
            id.setOsateRef(cv);
        }
    } else if (rep == DataRepresentation.ARRAY) {
        EList<PropertyExpression> lpv = PropertyUtils.findPropertyExpression(component, DataModelProperties.BASE_TYPE);
        if (lpv.isEmpty() == false) {
            ClassifierValue cv;
            cv = (ClassifierValue) ((ListValue) lpv.get(0)).getOwnedListElements().get(0);
            result = identifierComponentResolver(id, cv.getClassifier(), hasToReport);
        } else {
            result = false;
        }
    }
    if (!result && hasToReport) {
        reportNameError(id, id.getId());
    }
    return result;
}
Also used : ClassifierValue(org.osate.aadl2.ClassifierValue) BasicEList(org.eclipse.emf.common.util.BasicEList) EList(org.eclipse.emf.common.util.EList) StringLiteral(org.osate.aadl2.StringLiteral) DataRepresentation(org.osate.ba.aadlba.DataRepresentation) ListValue(org.osate.aadl2.ListValue) DeclarativeListValue(org.osate.ba.declarative.DeclarativeListValue) PropertyExpression(org.osate.aadl2.PropertyExpression)

Example 2 with ClassifierValue

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

the class AadlBaUtils method getClassifier.

/**
 * Returns the given Element object's classifier.
 * If the Element object is a prototype, it will try to resolve it as
 * follow: returns the data prototype binded classifier at first withing the
 * element's parent container otherwise the constraining classifier.
 * It returns {@code null} if the prototype is not defined.
 * <BR><BR>
 * This method support instances of:<BR>
 * <BR>_Feature (port, data access, subprogram access, parameter, etc.)
 * <BR>_Subcomponent (data subcomponent, subprogram subcomponent, etc.)
 * <BR>_BehaviorVariable
 * <BR>_IterativeVariable (for/forall's iterative variable)
 * <BR>_Prototype (all excepted FeatureGroupPrototype)
 * <BR>_PrototypeBinding (all excepted FeatureGroupPrototypeBinding)
 * <BR>_ClassifierValue (struct or union data subcomponent)
 * <BR><BR>
 * If the given Element object is not one of those types, an
 * UnsupportedOperationException is thrown.
 *
 * @param el the given Element object
 * @param parentContainer the element's parent component.
 * @return the given element's classifier or {@code null} if the prototype is
 * not defined
 * @exception UnsupportedOperationException for unsupported element
 * object types.
 */
public static Classifier getClassifier(Element el, Classifier parentContainer) {
    Classifier result = null;
    if (el instanceof Feature) {
        Feature f = (Feature) el;
        if (el instanceof FeatureGroup) {
            org.osate.aadl2.FeatureType ft = ((FeatureGroup) el).getFeatureType();
            if (ft != null) {
                if (ft instanceof FeatureGroupType) {
                    result = (FeatureGroupType) ft;
                } else // FeatureGroupPrototype case
                {
                    result = getClassifier((FeatureGroupPrototype) ft, parentContainer);
                }
            }
        } else {
            // Feature case.
            result = f.getClassifier();
            // Feature without classifier returns null.
            if (result == null && f.getPrototype() != null) {
                result = prototypeResolver(f.getPrototype(), parentContainer);
            }
        }
    } else if (el instanceof Subcomponent) {
        Subcomponent sub = (Subcomponent) el;
        if (el instanceof SubprogramGroupSubcomponent) {
            result = ((SubprogramGroupSubcomponent) el).getClassifier();
        } else {
            // Subcomponent case.
            result = sub.getClassifier();
            // Subcomponent without classifier returns null.
            if (result == null && sub.getPrototype() != null) {
                result = prototypeResolver(sub.getPrototype(), parentContainer);
            }
        }
    } else if (el instanceof BehaviorVariable) {
        // Local variable case (BehaviorVariable).
        BehaviorVariable bv = (BehaviorVariable) el;
        result = bv.getDataClassifier();
    } else if (el instanceof IterativeVariable) {
        // Iterative variable case.
        result = ((IterativeVariable) el).getDataClassifier();
    } else if (el instanceof Prototype) {
        result = prototypeResolver((Prototype) el, parentContainer);
    } else if (el instanceof PrototypeBinding) {
        // Prototype binding case.
        result = prototypeBindingResolver((PrototypeBinding) el);
    } else if (el instanceof ClassifierValue) {
        // struct or union member case (ClassifierValue).
        result = ((ClassifierValue) el).getClassifier();
    } else if (el instanceof StructUnionElement) {
        return ((StructUnionElement) el).getDataClassifier();
    } else {
        // Reports error.
        String errorMsg = "getClassifier : " + el.getClass().getSimpleName() + " is not supported yet.";
        System.err.println(errorMsg);
        throw new UnsupportedOperationException(errorMsg);
    }
    return result;
}
Also used : IterativeVariable(org.osate.ba.aadlba.IterativeVariable) FeatureGroup(org.osate.aadl2.FeatureGroup) Prototype(org.osate.aadl2.Prototype) DataPrototype(org.osate.aadl2.DataPrototype) FeatureGroupPrototype(org.osate.aadl2.FeatureGroupPrototype) FeaturePrototype(org.osate.aadl2.FeaturePrototype) ComponentPrototype(org.osate.aadl2.ComponentPrototype) ClassifierValue(org.osate.aadl2.ClassifierValue) BehaviorVariable(org.osate.ba.aadlba.BehaviorVariable) FeatureGroupType(org.osate.aadl2.FeatureGroupType) SubprogramGroupSubcomponent(org.osate.aadl2.SubprogramGroupSubcomponent) 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) AadlString(org.osate.aadl2.AadlString) StructUnionElement(org.osate.ba.aadlba.StructUnionElement) Feature(org.osate.aadl2.Feature) AbstractFeature(org.osate.aadl2.AbstractFeature) DirectedFeature(org.osate.aadl2.DirectedFeature) FeatureGroupPrototype(org.osate.aadl2.FeatureGroupPrototype) 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) PrototypeBinding(org.osate.aadl2.PrototypeBinding) FeaturePrototypeBinding(org.osate.aadl2.FeaturePrototypeBinding) FeatureGroupPrototypeBinding(org.osate.aadl2.FeatureGroupPrototypeBinding) ComponentPrototypeBinding(org.osate.aadl2.ComponentPrototypeBinding)

Example 3 with ClassifierValue

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

the class AadlBaUtils method getBaseType.

/**
 * Returns the last value of the base type property of the given component or
 * {@code null} if the base type property is not set.
 *
 * @param component the given component
 * @return the last value of the base type property or {@code null}
 */
public static ClassifierValue getBaseType(Classifier component) {
    PropertyExpression pe;
    EList<PropertyExpression> le;
    Element el;
    EList<PropertyExpression> lpe = PropertyUtils.findPropertyExpression(component, DataModelProperties.BASE_TYPE);
    if (lpe != null && (!lpe.isEmpty())) {
        pe = lpe.get(lpe.size() - 1);
        // Syntax with ()
        if (pe instanceof ListValue) {
            le = ((ListValue) pe).getOwnedListElements();
            if (le != null && (!le.isEmpty())) {
                el = le.get(le.size() - 1);
                if (el instanceof ClassifierValue) {
                    return (ClassifierValue) el;
                }
            }
        } else // Syntax without ()
        if (pe instanceof ClassifierValue) {
            return (ClassifierValue) pe;
        }
    }
    return null;
}
Also used : ClassifierValue(org.osate.aadl2.ClassifierValue) 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) ListValue(org.osate.aadl2.ListValue) PropertyExpression(org.osate.aadl2.PropertyExpression)

Example 4 with ClassifierValue

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

Example 5 with ClassifierValue

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

the class ModelingProperties method getImplementedAs.

public static Optional<Classifier> getImplementedAs(NamedElement lookupContext, Optional<Mode> mode) {
    Property property = getImplementedAs_Property(lookupContext);
    try {
        PropertyExpression value = CodeGenUtil.lookupProperty(property, lookupContext, mode);
        PropertyExpression resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode);
        return Optional.of(((ClassifierValue) resolved).getClassifier());
    } catch (PropertyNotPresentException e) {
        return Optional.empty();
    }
}
Also used : PropertyNotPresentException(org.osate.aadl2.properties.PropertyNotPresentException) PropertyExpression(org.osate.aadl2.PropertyExpression) Property(org.osate.aadl2.Property)

Aggregations

ClassifierValue (org.osate.aadl2.ClassifierValue)36 PropertyExpression (org.osate.aadl2.PropertyExpression)36 ListValue (org.osate.aadl2.ListValue)28 Property (org.osate.aadl2.Property)26 PropertyNotPresentException (org.osate.aadl2.properties.PropertyNotPresentException)21 Classifier (org.osate.aadl2.Classifier)15 IntegerLiteral (org.osate.aadl2.IntegerLiteral)15 StringLiteral (org.osate.aadl2.StringLiteral)12 RangeValue (org.osate.aadl2.RangeValue)11 RecordValue (org.osate.aadl2.RecordValue)11 BasicPropertyAssociation (org.osate.aadl2.BasicPropertyAssociation)10 ContainmentPathElement (org.osate.aadl2.ContainmentPathElement)10 NamedValue (org.osate.aadl2.NamedValue)10 RealLiteral (org.osate.aadl2.RealLiteral)10 BasicProperty (org.osate.aadl2.BasicProperty)9 BooleanLiteral (org.osate.aadl2.BooleanLiteral)9 ComponentClassifier (org.osate.aadl2.ComponentClassifier)9 PropertyConstant (org.osate.aadl2.PropertyConstant)9 ReferenceValue (org.osate.aadl2.ReferenceValue)9 EObject (org.eclipse.emf.ecore.EObject)8