Search in sources :

Example 1 with Annex

use of org.sireum.hamr.ir.Annex in project osate-plugin by sireum.

the class Visitor method processDataType.

public org.sireum.hamr.ir.Component processDataType(DataClassifier f) {
    final String name = f.getQualifiedName();
    if (datamap.containsKey(name)) {
        return datamap.get(name);
    }
    if (f.getExtended() != null) {
        Classifier c = f.getExtended();
        String parentName = c.getQualifiedName();
    // TODO: add extended classifier name to AIR nodes
    // System.out.println(parentName + " >> " + name);
    }
    /*
		 * need to use 'getAll...' in order to pickup properties inherited from parent
		 * since DataClassifier is coming from the declarative model (i.e. isn't flattened)
		 * javadoc for method:
		 * A list of the property associations. Property associations from
		 * an ancestor component classifier will appear before those of any
		 * descendents.
		 */
    List<PropertyAssociation> allProperties = VisitorUtil.toIList(f.getAllPropertyAssociations());
    List<org.sireum.hamr.ir.Component> subComponents = VisitorUtil.iList();
    if (f instanceof DataTypeImpl) {
    // do nothing as component types can't have subcomponents
    } else if (f instanceof DataImplementation) {
        final DataImplementation di = (DataImplementation) f;
        // the properties from the data component's type are not inherited by
        // the data component's implementation in the declarative model.
        // Add the data component type's properties before the data component
        // implemention's properties
        allProperties = VisitorUtil.addAll(di.getType().getAllPropertyAssociations(), allProperties);
        for (Subcomponent subcom : di.getAllSubcomponents()) {
            if (!(subcom instanceof DataSubcomponent)) {
                throw new RuntimeException("Unexpected data subcomponent: " + subcom.getFullName() + " of type " + subcom.getClass().getSimpleName() + " from " + f.getFullName());
            }
            DataSubcomponent dsc = (DataSubcomponent) subcom;
            final org.sireum.hamr.ir.Name subName = factory.name(VisitorUtil.toIList(dsc.getName()), VisitorUtil.buildPosInfo(dsc));
            final List<org.sireum.hamr.ir.Property> fProperties = dsc.getOwnedPropertyAssociations().stream().map(op -> buildProperty(op, VisitorUtil.iList())).collect(Collectors.toList());
            DataClassifier sct = null;
            if (dsc.getDataSubcomponentType() instanceof DataClassifier) {
                sct = (DataClassifier) dsc.getDataSubcomponentType();
            } else {
                if (dsc.getDataSubcomponentType() != null) {
                    String mesg = "Expecting a DataClassifier for " + dsc.qualifiedName() + " but found something of type " + dsc.getDataSubcomponentType().getClass().getSimpleName() + (dsc.getDataSubcomponentType().hasName() ? " whose name is " + dsc.getDataSubcomponentType().getQualifiedName() : "") + ". This can happen when your model has multiple copies of the same resource.";
                    throw new RuntimeException(mesg);
                }
            }
            if (sct != null) {
                final org.sireum.hamr.ir.Component c = processDataType(sct);
                final List<org.sireum.hamr.ir.Property> cProps = VisitorUtil.addAll(VisitorUtil.isz2IList(c.properties()), fProperties);
                final AadlASTJavaFactory.ComponentCategory category = AadlASTJavaFactory.ComponentCategory.valueOf(c.category().name());
                final org.sireum.hamr.ir.Classifier classifier = c.classifier().nonEmpty() ? c.classifier().get() : null;
                final org.sireum.hamr.ir.Component sub = factory.component(subName, category, classifier, VisitorUtil.isz2IList(c.features()), VisitorUtil.isz2IList(c.subComponents()), VisitorUtil.isz2IList(c.connections()), VisitorUtil.isz2IList(c.connectionInstances()), cProps, VisitorUtil.isz2IList(c.flows()), VisitorUtil.isz2IList(c.modes()), VisitorUtil.isz2IList(c.annexes()), VisitorUtil.getUriFragment(sct));
                subComponents = VisitorUtil.add(subComponents, sub);
            } else {
                // type not specified for subcomponent/field
                final org.sireum.hamr.ir.Component sub = // name
                factory.component(// name
                subName, // category
                AadlASTJavaFactory.ComponentCategory.Data, // classifier
                null, // features
                VisitorUtil.iList(), // subComponents
                VisitorUtil.iList(), // connections
                VisitorUtil.iList(), // connectionInstances
                VisitorUtil.iList(), // properties
                fProperties, // flows
                VisitorUtil.iList(), // modes
                VisitorUtil.iList(), // annexes
                VisitorUtil.iList(), "");
                subComponents = VisitorUtil.add(subComponents, sub);
            }
        }
    } else {
        throw new RuntimeException("Unexpected data type: " + f);
    }
    // NOTE there may be multiple properties associations with the same name if, e.g, a
    // data component extends Base_Type::Integer_32 but also adds the property
    // Data_Size => 16 bits. So would need to 'findLast' when processing these
    // ... so instead remove duplicates? Unless there is a reason why we'd want to
    // know the parent values of properties the child shadows
    List<PropertyAssociation> uniqueProperties = VisitorUtil.removeShadowedProperties(allProperties);
    List<org.sireum.hamr.ir.Property> properties = uniqueProperties.stream().map(op -> buildProperty(op, VisitorUtil.iList())).collect(Collectors.toList());
    List<Annex> annexes = new ArrayList<>();
    for (AnnexVisitor av : annexVisitors) {
        annexes.addAll(av.visit(f, new ArrayList<>()));
    }
    // this is a hack as we're sticking something from the declarative
    // model into a node meant for things from the instance model. Todo
    // would be to add a declarative model AIR AST and ...
    final org.sireum.hamr.ir.Component c = // 
    factory.component(// identifier
    factory.name(VisitorUtil.iList(), null), // category
    AadlASTJavaFactory.ComponentCategory.Data, // features
    factory.classifier(name), // features
    VisitorUtil.iList(), // connections
    subComponents, // connections
    VisitorUtil.iList(), // connectionInstances
    VisitorUtil.iList(), // properties
    properties, // flows
    VisitorUtil.iList(), // modes
    VisitorUtil.iList(), // annexes
    annexes, "");
    datamap.put(name, c);
    return c;
}
Also used : Arrays(java.util.Arrays) DataImplementation(org.osate.aadl2.DataImplementation) ListValue(org.osate.aadl2.ListValue) Element(org.osate.aadl2.Element) NamedValue(org.osate.aadl2.NamedValue) RangeValue(org.osate.aadl2.RangeValue) PropertyUtils(org.osate.xtext.aadl2.properties.util.PropertyUtils) PropertyExpression(org.osate.aadl2.PropertyExpression) AnnexLib(org.sireum.hamr.ir.AnnexLib) Classifier(org.osate.aadl2.Classifier) RecordValue(org.osate.aadl2.RecordValue) FeatureConnection(org.osate.aadl2.FeatureConnection) AccessImpl(org.osate.aadl2.impl.AccessImpl) Map(java.util.Map) ParameterConnection(org.osate.aadl2.ParameterConnection) FeatureInstance(org.osate.aadl2.instance.FeatureInstance) Bundle(org.osgi.framework.Bundle) EnumerationLiteral(org.osate.aadl2.EnumerationLiteral) Annex(org.sireum.hamr.ir.Annex) AccessConnection(org.osate.aadl2.AccessConnection) ConnectionEnd(org.osate.aadl2.ConnectionEnd) DirectedFeatureImpl(org.osate.aadl2.impl.DirectedFeatureImpl) FeatureCategory(org.osate.aadl2.instance.FeatureCategory) InstancePackage(org.osate.aadl2.instance.InstancePackage) FeatureGroupConnection(org.osate.aadl2.FeatureGroupConnection) BusAccessImpl(org.osate.aadl2.impl.BusAccessImpl) Set(java.util.Set) EObject(org.eclipse.emf.ecore.EObject) Connection(org.osate.aadl2.Connection) AadlASTJavaFactory(org.sireum.hamr.ir.AadlASTJavaFactory) Collectors(java.util.stream.Collectors) UnitLiteral(org.osate.aadl2.UnitLiteral) List(java.util.List) Property(org.osate.aadl2.Property) AccessType(org.osate.aadl2.AccessType) ReferenceValue(org.osate.aadl2.ReferenceValue) BusSubcomponentImpl(org.osate.aadl2.impl.BusSubcomponentImpl) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) StringLiteral(org.osate.aadl2.StringLiteral) Option(org.sireum.Option) Feature(org.osate.aadl2.Feature) HashMap(java.util.HashMap) Constructor(java.lang.reflect.Constructor) ConnectionInstanceEnd(org.osate.aadl2.instance.ConnectionInstanceEnd) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) DataSubcomponent(org.osate.aadl2.DataSubcomponent) PropertyAssociation(org.osate.aadl2.PropertyAssociation) PreferenceValues(org.sireum.aadl.osate.PreferenceValues) DirectionType(org.osate.aadl2.DirectionType) Subcomponent(org.osate.aadl2.Subcomponent) Position(org.sireum.message.Position) FeatureGroup(org.osate.aadl2.FeatureGroup) NumberValue(org.osate.aadl2.NumberValue) FeatureGroupImpl(org.osate.aadl2.impl.FeatureGroupImpl) ClassifierValue(org.osate.aadl2.ClassifierValue) AadlUtil(org.osate.aadl2.modelsupport.util.AadlUtil) InstanceReferenceValue(org.osate.aadl2.instance.InstanceReferenceValue) Some(org.sireum.Some) PropertyConstant(org.osate.aadl2.PropertyConstant) ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) ModeTransitionInstance(org.osate.aadl2.instance.ModeTransitionInstance) AbstractNamedValue(org.osate.aadl2.AbstractNamedValue) FeatureGroupType(org.osate.aadl2.FeatureGroupType) PortConnection(org.osate.aadl2.PortConnection) ConnectionReference(org.osate.aadl2.instance.ConnectionReference) DataTypeImpl(org.osate.aadl2.impl.DataTypeImpl) DataClassifier(org.osate.aadl2.DataClassifier) BooleanLiteral(org.osate.aadl2.BooleanLiteral) Platform(org.eclipse.core.runtime.Platform) NamedElement(org.osate.aadl2.NamedElement) FlowSpecificationInstance(org.osate.aadl2.instance.FlowSpecificationInstance) ConnectedElement(org.osate.aadl2.ConnectedElement) PropertyAssociation(org.osate.aadl2.PropertyAssociation) ArrayList(java.util.ArrayList) Classifier(org.osate.aadl2.Classifier) DataClassifier(org.osate.aadl2.DataClassifier) DataClassifier(org.osate.aadl2.DataClassifier) DataSubcomponent(org.osate.aadl2.DataSubcomponent) Subcomponent(org.osate.aadl2.Subcomponent) List(java.util.List) ArrayList(java.util.ArrayList) Property(org.osate.aadl2.Property) DataImplementation(org.osate.aadl2.DataImplementation) Annex(org.sireum.hamr.ir.Annex) DataTypeImpl(org.osate.aadl2.impl.DataTypeImpl) DataSubcomponent(org.osate.aadl2.DataSubcomponent)

Aggregations

Constructor (java.lang.reflect.Constructor)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Platform (org.eclipse.core.runtime.Platform)1 EObject (org.eclipse.emf.ecore.EObject)1 AbstractNamedValue (org.osate.aadl2.AbstractNamedValue)1 AccessConnection (org.osate.aadl2.AccessConnection)1 AccessType (org.osate.aadl2.AccessType)1 BooleanLiteral (org.osate.aadl2.BooleanLiteral)1 Classifier (org.osate.aadl2.Classifier)1 ClassifierValue (org.osate.aadl2.ClassifierValue)1 ConnectedElement (org.osate.aadl2.ConnectedElement)1 Connection (org.osate.aadl2.Connection)1 ConnectionEnd (org.osate.aadl2.ConnectionEnd)1