Search in sources :

Example 16 with Reference

use of org.osate.ba.declarative.Reference in project osate2 by osate.

the class AadlBaNameResolver method propertyExpressionResolver.

/**
 * Resolves the property expressions used in behavior annex.
 * @param p
 *
 * @return {@code true} if all names are resolved. {@code false} otherwise.
 */
private boolean propertyExpressionResolver(BehaviorVariable bv, Property p, PropertyExpression pe) {
    QualifiedNamedElement qne = (QualifiedNamedElement) p;
    String propertyName = "";
    boolean hasNamespace = qne.getBaNamespace() != null;
    if (hasNamespace) {
        propertyName = qne.getBaNamespace().getId() + "::";
    }
    propertyName += qne.getBaName().getId();
    boolean result = true;
    if (pe instanceof DeclarativeListValue) {
        ListValue dlv = (DeclarativeListValue) pe;
        for (PropertyExpression peInList : dlv.getOwnedListElements()) {
            result &= propertyExpressionResolver(bv, p, peInList);
        }
    } else if (pe instanceof IntegerLiteral) {
        IntegerLiteral il = (IntegerLiteral) pe;
        if (il.getUnit() != null && il.getUnit() instanceof QualifiedNamedElement) {
            result &= unitResolver(il, bv, p);
        }
    } else if (pe instanceof RealLiteral) {
        RealLiteral rl = (RealLiteral) pe;
        if (rl.getUnit() != null && rl.getUnit() instanceof QualifiedNamedElement) {
            result &= unitResolver(rl, bv, p);
        }
    } else if (pe instanceof RecordValue) {
        RecordValue rv = (RecordValue) pe;
        for (BasicPropertyAssociation bpa : rv.getOwnedFieldValues()) {
            if (bpa instanceof DeclarativeBasicPropertyAssociation) {
                DeclarativeBasicPropertyAssociation dbpa = (DeclarativeBasicPropertyAssociation) bpa;
                String basicPropertyName = dbpa.getBasicPropertyName();
                BasicProperty basicProp = getBasicPropertyResolver(bv, p, basicPropertyName);
                if (basicProp == null) {
                    _errManager.error(bv, "Property field \'" + basicPropertyName + "\' of property " + propertyName + " is not found");
                    result = false;
                }
                dbpa.setProperty(basicProp);
            }
        }
    } else if (pe instanceof RangeValue) {
        RangeValue rv = (RangeValue) pe;
        result &= propertyExpressionResolver(bv, p, rv.getMaximum());
        result &= propertyExpressionResolver(bv, p, rv.getMinimum());
    } else if (pe instanceof ReferenceValue) {
        ReferenceValue rv = (ReferenceValue) pe;
        Reference r = (Reference) (rv.getPath());
        ContainmentPathElement firstCne = Aadl2Factory.eINSTANCE.createContainmentPathElement();
        ContainmentPathElement prevCne = null;
        boolean first = true;
        Classifier context = _baParentContainer;
        for (Identifier subPath : r.getIds()) {
            ContainmentPathElement currentCne;
            if (!first) {
                currentCne = Aadl2Factory.eINSTANCE.createContainmentPathElement();
            } else {
                currentCne = firstCne;
            }
            first = false;
            NamedElement ne = Aadl2Visitors.findSubcomponentInComponent(context, subPath.getId());
            if (ne == null) {
                ne = Aadl2Visitors.findFeatureInComponent(context, subPath.getId());
            }
            if (ne == null) {
                _errManager.error(bv, "Element \'" + subPath.getId() + "\' is not found in " + context.getName() + "(property " + propertyName + ")");
                result = false;
            } else {
                currentCne.setNamedElement(ne);
                if (prevCne != null) {
                    prevCne.setPath(currentCne);
                }
                if (ne instanceof Subcomponent) {
                    Subcomponent sub = (Subcomponent) ne;
                    context = sub.getClassifier();
                } else if (ne instanceof Feature) {
                    Feature f = (Feature) ne;
                    context = f.getClassifier();
                }
            }
            prevCne = currentCne;
        }
        rv.setPath(firstCne);
    } else if (pe instanceof ClassifierValue) {
        ClassifierValue cv = (ClassifierValue) pe;
        QualifiedNamedElement classifierQne = (QualifiedNamedElement) cv.getClassifier();
        String qneClassPackageName = "";
        boolean qneClassHasNamespace = classifierQne.getBaNamespace() != null;
        if (qneClassHasNamespace) {
            qneClassPackageName = classifierQne.getBaNamespace().getId();
        }
        boolean resolved = false;
        for (PackageSection context : _contextsTab) {
            NamedElement ne = Aadl2Visitors.findElementInPackage(classifierQne.getBaName().getId(), qneClassPackageName, context);
            if (ne != null && ne instanceof Classifier) {
                cv.setClassifier((Classifier) ne);
                resolved = true;
                break;
            }
        }
        if (!resolved) {
            String cvQualifiedName = "";
            if (!qneClassPackageName.isEmpty()) {
                cvQualifiedName += qneClassPackageName + "::";
            }
            cvQualifiedName += classifierQne.getBaName().getId();
            _errManager.error(bv, "Classifier \'" + cvQualifiedName + "\' associated to property " + propertyName + " is not found");
            result = false;
        }
    }
    return result;
}
Also used : ClassifierValue(org.osate.aadl2.ClassifierValue) ReferenceValue(org.osate.aadl2.ReferenceValue) DeclarativePropertyReference(org.osate.ba.declarative.DeclarativePropertyReference) Reference(org.osate.ba.declarative.Reference) PackageSection(org.osate.aadl2.PackageSection) ListValue(org.osate.aadl2.ListValue) DeclarativeListValue(org.osate.ba.declarative.DeclarativeListValue) DeclarativeListValue(org.osate.ba.declarative.DeclarativeListValue) RecordValue(org.osate.aadl2.RecordValue) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier) DataClassifier(org.osate.aadl2.DataClassifier) ProcessorClassifier(org.osate.aadl2.ProcessorClassifier) Feature(org.osate.aadl2.Feature) ClassifierFeature(org.osate.aadl2.ClassifierFeature) RangeValue(org.osate.aadl2.RangeValue) RealLiteral(org.osate.aadl2.RealLiteral) BasicProperty(org.osate.aadl2.BasicProperty) QualifiedNamedElement(org.osate.ba.declarative.QualifiedNamedElement) Identifier(org.osate.ba.declarative.Identifier) ArrayableIdentifier(org.osate.ba.declarative.ArrayableIdentifier) Subcomponent(org.osate.aadl2.Subcomponent) PropertyExpression(org.osate.aadl2.PropertyExpression) DeclarativeBasicPropertyAssociation(org.osate.ba.declarative.DeclarativeBasicPropertyAssociation) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation) DeclarativeBasicPropertyAssociation(org.osate.ba.declarative.DeclarativeBasicPropertyAssociation) QualifiedNamedElement(org.osate.ba.declarative.QualifiedNamedElement) NamedElement(org.osate.aadl2.NamedElement) IntegerLiteral(org.osate.aadl2.IntegerLiteral) BehaviorIntegerLiteral(org.osate.ba.aadlba.BehaviorIntegerLiteral)

Example 17 with Reference

use of org.osate.ba.declarative.Reference in project osate2 by osate.

the class AadlBaNameResolver method classifierFeaturePropertyReferenceResolver.

private boolean classifierFeaturePropertyReferenceResolver(DeclarativePropertyReference ref) {
    Reference component = ref.getReference();
    if (refResolver(component)) {
        PropertyAssociation pa = null;
        Classifier type = null;
        Identifier propertyNameId = ref.getPropertyNames().get(0).getPropertyName();
        Element el = (component.getOsateRef() != null) ? component.getOsateRef() : component.getBaRef();
        if (el instanceof PrototypeBinding) {
            PrototypeBinding pb = (PrototypeBinding) el;
            type = AadlBaUtils.getClassifier(pb, pb.getContainingClassifier());
        } else if (el instanceof ClassifierFeature) {
            ClassifierFeature cf = (ClassifierFeature) el;
            // Fetch the own property association of the classifier feature.
            pa = PropertyUtils.findPropertyAssociation(propertyNameId.getId(), cf);
            if (pa == null) {
                type = AadlBaUtils.getClassifier(cf, cf.getContainingClassifier());
            }
        } else if (el instanceof BehaviorVariable) {
            BehaviorVariable bv = (BehaviorVariable) el;
            DeclarativeBehaviorElement de = (DeclarativeBehaviorElement) bv.getDataClassifier();
            if (de.getOsateRef() instanceof Classifier) {
                type = (Classifier) de.getOsateRef();
            }
        } else // Cannot resolve or unimplemented cases.
        {
            String msg = "the type of \'" + ((NamedElement) el).getName() + "\' cannot be resolved";
            _errManager.error(el, msg);
        }
        // search within its type.
        if (pa == null && type != null) {
            pa = PropertyUtils.findPropertyAssociation(propertyNameId.getId(), type);
        }
        if (pa != null) {
            ref.getPropertyNames().get(0).setOsateRef(pa);
            propertyNameId.setOsateRef(pa);
            return propertyNameResolver(ref.getPropertyNames());
        } else {
            reportNameError(propertyNameId, propertyNameId.getId());
            return false;
        }
    } else {
        // refResolver has already reported the error.
        return false;
    }
}
Also used : DeclarativeBehaviorElement(org.osate.ba.declarative.DeclarativeBehaviorElement) Identifier(org.osate.ba.declarative.Identifier) ArrayableIdentifier(org.osate.ba.declarative.ArrayableIdentifier) BehaviorVariable(org.osate.ba.aadlba.BehaviorVariable) DeclarativePropertyReference(org.osate.ba.declarative.DeclarativePropertyReference) Reference(org.osate.ba.declarative.Reference) PropertyAssociation(org.osate.aadl2.PropertyAssociation) DeclarativeBasicPropertyAssociation(org.osate.ba.declarative.DeclarativeBasicPropertyAssociation) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement) QualifiedNamedElement(org.osate.ba.declarative.QualifiedNamedElement) DeclarativeBehaviorElement(org.osate.ba.declarative.DeclarativeBehaviorElement) NamedElement(org.osate.aadl2.NamedElement) Element(org.osate.aadl2.Element) BehaviorElement(org.osate.ba.aadlba.BehaviorElement) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier) DataClassifier(org.osate.aadl2.DataClassifier) ProcessorClassifier(org.osate.aadl2.ProcessorClassifier) PrototypeBinding(org.osate.aadl2.PrototypeBinding) QualifiedNamedElement(org.osate.ba.declarative.QualifiedNamedElement) NamedElement(org.osate.aadl2.NamedElement) ClassifierFeature(org.osate.aadl2.ClassifierFeature)

Example 18 with Reference

use of org.osate.ba.declarative.Reference in project osate2 by osate.

the class AadlBaTypeChecker method dispatchTriggerLogicalExpressionCheck.

private boolean dispatchTriggerLogicalExpressionCheck(DispatchTriggerLogicalExpression dtle) {
    boolean result = true;
    ElementHolder elHolder = null;
    for (DispatchConjunction dc : dtle.getDispatchConjunctions()) {
        ListIterator<DispatchTrigger> it = dc.getDispatchTriggers().listIterator();
        while (it.hasNext()) {
            Reference e = (Reference) it.next();
            elHolder = dispatchTriggerResolver(e, TypeCheckRule.DISPATCH_TRIGGER);
            if (elHolder != null) {
                it.set((DispatchTrigger) elHolder);
            } else {
                result = false;
            }
        }
    }
    return result;
}
Also used : LocationReference(org.osate.aadl2.parsesupport.LocationReference) Reference(org.osate.ba.declarative.Reference) DeclarativePropertyReference(org.osate.ba.declarative.DeclarativePropertyReference)

Example 19 with Reference

use of org.osate.ba.declarative.Reference in project osate2 by osate.

the class AadlBaTypeChecker method valueVariableCheck.

// This method checks the given object and returns a value variable
// resolved from semantic ambiguities and its data representation. On error,
// reports error and returns null.
private ValueAndTypeHolder valueVariableCheck(ValueVariable v) {
    List<ElementHolder> ehl = null;
    ValueVariable tmpResult = null;
    ActualPortHolder port;
    TypeCheckRule stopRule;
    TypeCheckRule[] checkRules;
    if (v instanceof Reference) {
        port = null;
        stopRule = TypeCheckRule.VV_STOP_RULE;
        checkRules = new TypeCheckRule[] { TypeCheckRule.VV_COMPONENT_REFERENCE_FIRST_NAME, TypeCheckRule.DATA_COMPONENT_REFERENCE_OTHER_NAMES };
    } else // NamedValue case.
    {
        NamedValue nv = (NamedValue) v;
        v = nv.getReference();
        if (nv.isCount()) {
            port = _fact.createPortCountValue();
            stopRule = TypeCheckRule.PORT_COUNT_VALUE;
        } else if (nv.isDequeue()) {
            port = _fact.createPortDequeueValue();
            stopRule = TypeCheckRule.PORT_DEQUEUE_VALUE;
        } else {
            port = _fact.createPortFreshValue();
            stopRule = TypeCheckRule.PORT_FRESH_VALUE;
        }
        port.setLocationReference(v.getLocationReference());
        checkRules = new TypeCheckRule[] { stopRule };
    }
    ehl = refResolver((Reference) v, port, stopRule, checkRules);
    if (ehl != null) {
        tmpResult = referenceToValueVariable(ehl);
        if (tmpResult instanceof PortFreshValue) {
            PortFreshValue pfv = (PortFreshValue) tmpResult;
            AadlBaVisitors.putFreshPort(_ba, pfv.getPort());
        }
        return this.getValueAndTypeHolder(tmpResult, v);
    } else {
        return null;
    }
}
Also used : LocationReference(org.osate.aadl2.parsesupport.LocationReference) Reference(org.osate.ba.declarative.Reference) DeclarativePropertyReference(org.osate.ba.declarative.DeclarativePropertyReference) NamedValue(org.osate.ba.declarative.NamedValue)

Aggregations

Reference (org.osate.ba.declarative.Reference)19 DeclarativePropertyReference (org.osate.ba.declarative.DeclarativePropertyReference)16 LocationReference (org.osate.aadl2.parsesupport.LocationReference)7 QualifiedNamedElement (org.osate.ba.declarative.QualifiedNamedElement)6 NamedElement (org.osate.aadl2.NamedElement)5 ArrayableIdentifier (org.osate.ba.declarative.ArrayableIdentifier)5 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)4 ContainmentPathElement (org.osate.aadl2.ContainmentPathElement)4 DataClassifier (org.osate.aadl2.DataClassifier)4 Element (org.osate.aadl2.Element)4 BehaviorElement (org.osate.ba.aadlba.BehaviorElement)4 Identifier (org.osate.ba.declarative.Identifier)4 Classifier (org.osate.aadl2.Classifier)3 ComponentClassifier (org.osate.aadl2.ComponentClassifier)3 ProcessorClassifier (org.osate.aadl2.ProcessorClassifier)3 BasicPropertyAssociation (org.osate.aadl2.BasicPropertyAssociation)2 ClassifierFeature (org.osate.aadl2.ClassifierFeature)2 ClassifierValue (org.osate.aadl2.ClassifierValue)2 Feature (org.osate.aadl2.Feature)2 PropertyAssociation (org.osate.aadl2.PropertyAssociation)2