Search in sources :

Example 1 with FeatureGroupType

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

the class AgreeASTBuilder method getAgreePortNames.

private List<AgreeVar> getAgreePortNames(ConnectionEnd port, String prefix, ComponentInstance compInst) {
    String portName = port.getName();
    List<AgreeVar> subVars = new ArrayList<>();
    // of a record type. Otherwise it is the first member of a feature group
    if (prefix == null) {
        prefix = "";
    } else if (port instanceof DataSubcomponent) {
        prefix = prefix + ".";
    } else {
        prefix = prefix + dotChar;
    }
    if (port instanceof FeatureGroup) {
        FeatureGroup featGroup = (FeatureGroup) port;
        FeatureGroupType featType = featGroup.getFeatureGroupType();
        for (FeatureGroup subFeatGroup : featType.getOwnedFeatureGroups()) {
            subVars.addAll(getAgreePortNames(subFeatGroup, null, compInst));
        }
        for (DataPort subPort : featType.getOwnedDataPorts()) {
            subVars.addAll(getAgreePortNames(subPort, null, compInst));
        }
        for (EventDataPort subPort : featType.getOwnedEventDataPorts()) {
            subVars.addAll(getAgreePortNames(subPort, null, compInst));
        }
        for (EventPort subPort : featType.getOwnedEventPorts()) {
            subVars.addAll(getAgreePortNames(subPort, null, compInst));
        }
        List<AgreeVar> prefixedStrs = new ArrayList<>();
        for (AgreeVar subVar : subVars) {
            prefixedStrs.add(new AgreeVar(prefix + portName + dotChar + subVar.id, subVar.type, subVar.reference, compInst));
        }
        subVars = prefixedStrs;
    }
    if (port instanceof DataPort || port instanceof EventDataPort || port instanceof DataSubcomponent) {
        Type type = getConnectionEndType(port);
        if (type != null) {
            subVars.add(new AgreeVar(prefix + portName, type, port, compInst));
        }
    }
    if (port instanceof EventDataPort || port instanceof EventPort) {
        subVars.add(new AgreeVar(prefix + portName + eventSuffix, NamedType.BOOL, port, compInst));
    }
    return subVars;
}
Also used : DataPort(org.osate.aadl2.DataPort) EventDataPort(org.osate.aadl2.EventDataPort) FeatureGroup(org.osate.aadl2.FeatureGroup) ConnectionType(com.rockwellcollins.atc.agree.analysis.ast.AgreeAADLConnection.ConnectionType) Type(jkind.lustre.Type) NamedType(jkind.lustre.NamedType) FeatureGroupType(org.osate.aadl2.FeatureGroupType) DataSubcomponentType(org.osate.aadl2.DataSubcomponentType) ComponentType(org.osate.aadl2.ComponentType) EventPort(org.osate.aadl2.EventPort) DataSubcomponent(org.osate.aadl2.DataSubcomponent) ArrayList(java.util.ArrayList) FeatureGroupType(org.osate.aadl2.FeatureGroupType) EventDataPort(org.osate.aadl2.EventDataPort)

Example 2 with FeatureGroupType

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

the class AgreeValidator method checkRecordDefExpr.

// =======
// //    private List<AgreeType> getArgTypes(NestedDotID recId){
// //
// //    	NamedElement rec = getFinalNestId(recId);
// //    	List<AgreeType> types = new ArrayList<AgreeType>();
// //
// //    	if(rec instanceof RecordDefExpr){
// //    		RecordDefExpr recDef = (RecordDefExpr)rec;
// //    		for(Arg arg : recDef.getArgs()){
// //    			types.add(getAgreeType(arg.getType()));
// //    		}
// //    	}else if(rec instanceof FeatureGroupType){
// //    		FeatureGroupType featGroup = (FeatureGroupType)rec;
// //    		for(Feature feat : featGroup.getAllFeatures()){
// //    			types.add(getAgreeType(feat));
// //    		}
// //    	}
// //
// //    	return types;
// //    }
// 
// private void dataImplCycleCheck(NestedDotID dataID) {
// NamedElement finalId = dataID.getBase();
// DataImplementation dataImpl = (DataImplementation) finalId;
// dataImplCycleCheck(dataImpl, dataID);
// }
// 
// private void dataImplCycleCheck(DoubleDotRef dataID) {
// NamedElement finalId = dataID.getElm();
// DataImplementation dataImpl = (DataImplementation) finalId;
// dataImplCycleCheck(dataImpl, dataID);
// }
// 
// 
// private void dataImplCycleCheck(DataImplementation dataImpl, EObject errorSource) {
// Set<DataImplementation> dataClosure = new HashSet<>();
// Set<DataImplementation> prevClosure = null;
// 
// for (Subcomponent sub : dataImpl.getAllSubcomponents()) {
// ComponentImplementation subImpl = sub.getComponentImplementation();
// if (subImpl != null) {
// dataClosure.add((DataImplementation) subImpl);
// }
// }
// 
// do {
// prevClosure = new HashSet<>(dataClosure);
// for (DataImplementation subImpl : prevClosure) {
// if (subImpl == dataImpl) {
// error(errorSource, "The component implementation '" + dataImpl.getName()
// + "' has a cyclic definition.  This cannot be reasoned about by AGREE.");
// break;
// }
// for (Subcomponent subSub : subImpl.getAllSubcomponents()) {
// ComponentImplementation subSubImpl = subSub.getComponentImplementation();
// if (subSubImpl != null) {
// dataClosure.add((DataImplementation) subSubImpl);
// }
// }
// 
// }
// 
// } while (!prevClosure.equals(dataClosure));
// 
// }
// >>>>>>> origin/develop
@Check(CheckType.FAST)
public void checkRecordDefExpr(RecordDef recordDef) {
    Set<RecordDef> recordClosure = new HashSet<>();
    Set<RecordDef> prevClosure = null;
    for (Arg arg : recordDef.getArgs()) {
        Type type = arg.getType();
        if (type instanceof DoubleDotRef) {
            NamedElement finalId = ((DoubleDotRef) type).getElm();
            if (finalId instanceof RecordDef) {
                recordClosure.add((RecordDef) finalId);
            }
        }
    }
    do {
        prevClosure = new HashSet<>(recordClosure);
        for (RecordDef subRecDef : prevClosure) {
            if (subRecDef == recordDef) {
                error(recordDef, "The definition of type '" + recordDef.getName() + "' is involved in a cyclic definition");
                break;
            }
            for (Arg arg : subRecDef.getArgs()) {
                Type type = arg.getType();
                if (type instanceof DoubleDotRef) {
                    NamedElement subFinalEl = ((DoubleDotRef) type).getElm();
                    if (subFinalEl instanceof RecordDef) {
                        recordClosure.add((RecordDef) subFinalEl);
                    // =======
                    // if (type instanceof RecordType) {
                    // DoubleDotRef subRecId = ((RecordType) type).getRecord();
                    // NamedElement subFinalEl = subRecId.getElm();
                    // if (subFinalEl instanceof RecordDefExpr) {
                    // recordClosure.add((RecordDefExpr) subFinalEl);
                    // >>>>>>> origin/develop
                    }
                }
            }
        }
    } while (!prevClosure.equals(recordClosure));
}
Also used : PrimType(com.rockwellcollins.atc.agree.agree.PrimType) DataType(org.osate.aadl2.DataType) CheckType(org.eclipse.xtext.validation.CheckType) FeatureGroupType(org.osate.aadl2.FeatureGroupType) ComponentType(org.osate.aadl2.ComponentType) Type(com.rockwellcollins.atc.agree.agree.Type) DirectionType(org.osate.aadl2.DirectionType) Arg(com.rockwellcollins.atc.agree.agree.Arg) DoubleDotRef(com.rockwellcollins.atc.agree.agree.DoubleDotRef) NamedElement(org.osate.aadl2.NamedElement) RecordDef(com.rockwellcollins.atc.agree.agree.RecordDef) HashSet(java.util.HashSet) Check(org.eclipse.xtext.validation.Check)

Example 3 with FeatureGroupType

use of org.osate.aadl2.FeatureGroupType 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 4 with FeatureGroupType

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

the class AadlBaUtils method prototypeBindingResolver.

/**
 * Resolves the given prototype binding by returning the binded classifier
 * It returns {@code null} if the given prototype binding is not defined.
 *
 * @param pb the given prototype binding
 * @return the binded classifier or {@code null}
 */
public static Classifier prototypeBindingResolver(PrototypeBinding pb) {
    Classifier result = null;
    if (pb instanceof ComponentPrototypeBinding) {
        ComponentPrototypeBinding cpb;
        cpb = (ComponentPrototypeBinding) pb;
        // Takes the last binding.
        ComponentPrototypeActual cpa = cpb.getActuals().get(cpb.getActuals().size() - 1);
        result = (Classifier) cpa.getSubcomponentType();
    } else if (pb instanceof FeaturePrototypeBinding) {
        FeaturePrototypeBinding fpb;
        fpb = (FeaturePrototypeBinding) pb;
        FeaturePrototypeActual fpa = fpb.getActual();
        if (fpa instanceof AccessSpecification) {
            result = ((AccessSpecification) fpa).getClassifier();
        } else if (fpa instanceof PortSpecification) {
            result = ((PortSpecification) fpa).getClassifier();
        } else {
            // Reports error.
            String errorMsg = "prototypeBindingResolver : " + fpa.getClass().getSimpleName() + " is not supported yet.";
            System.err.println(errorMsg);
            throw new UnsupportedOperationException(errorMsg);
        }
    } else if (pb instanceof FeatureGroupPrototypeBinding) {
        FeatureGroupPrototypeBinding fgpb = (FeatureGroupPrototypeBinding) pb;
        result = (FeatureGroupType) fgpb.getActual().getFeatureType();
    } else {
        // Reports error.
        String errorMsg = "prototypeBindingResolver : " + pb.getClass().getSimpleName() + " is not supported yet.";
        System.err.println(errorMsg);
        throw new UnsupportedOperationException(errorMsg);
    }
    return result;
}
Also used : PortSpecification(org.osate.aadl2.PortSpecification) FeaturePrototypeActual(org.osate.aadl2.FeaturePrototypeActual) FeatureGroupPrototypeBinding(org.osate.aadl2.FeatureGroupPrototypeBinding) ComponentPrototypeActual(org.osate.aadl2.ComponentPrototypeActual) AccessSpecification(org.osate.aadl2.AccessSpecification) 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) ComponentPrototypeBinding(org.osate.aadl2.ComponentPrototypeBinding) FeaturePrototypeBinding(org.osate.aadl2.FeaturePrototypeBinding)

Example 5 with FeatureGroupType

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

the class CreateConnectionsSwitch method finalizeConnectionInstance.

// ------------------------------------------------------------------------
// Post-process completed connection instance
// ------------------------------------------------------------------------
protected void finalizeConnectionInstance(ComponentInstance parentci, final ConnectionInfo connInfo, ConnectionInstanceEnd dstEnd) {
    FeatureInstance upFi = null;
    if (dstEnd instanceof FeatureInstance) {
        FeatureInstance dstFi = (FeatureInstance) dstEnd;
        EList<FeatureInstance> flist = dstFi.getFeatureInstances();
        if (dstFi.getCategory() == FeatureCategory.FEATURE_GROUP && !upFeature.isEmpty()) {
            upFi = upFeature.pop();
            if (upFi.eContainer() == dstFi) {
                dstFi = upFi;
            } else {
                FeatureGroup upfg = ((FeatureGroup) ((FeatureInstance) upFi.getOwner()).getFeature());
                FeatureGroup downfg = ((FeatureGroup) dstFi.getFeature());
                FeatureGroupType upfgt = upfg.getAllFeatureGroupType();
                FeatureGroupType downfgt = downfg.getAllFeatureGroupType();
                if (downfgt == null) {
                    warning(dstFi.getContainingComponentInstance(), "In " + dstFi.getContainingComponentInstance().getName() + " (classifier " + dstFi.getContainingComponentInstance().getComponentClassifier().getName() + ") feature group " + dstFi.getName() + " has no type");
                }
                if (upfgt != null && downfgt != null && upfg.isInverseOf(downfg) && !upfgt.getAllFeatures().isEmpty() && !downfgt.getAllFeatures().isEmpty()) {
                    dstFi = flist.get(Aadl2InstanceUtil.getFeatureIndex(upFi));
                }
            }
        }
        if (connInfo.src instanceof FeatureInstance) {
            FeatureInstance srcFi = (FeatureInstance) connInfo.src;
            if (srcFi.getFeatureInstances().isEmpty() && dstFi.getFeatureInstances().isEmpty()) {
                addConnectionInstance(parentci.getSystemInstance(), connInfo, dstFi);
            } else {
                // src and/or dst is a feature group
                balanceFeatureGroupEnds(parentci, connInfo, srcFi, dstFi);
            }
        } else if (connInfo.src instanceof ComponentInstance) {
            ComponentInstance srcCi = (ComponentInstance) connInfo.src;
            if (dstFi.getFeatureInstances().isEmpty()) {
                addConnectionInstance(parentci.getSystemInstance(), connInfo, dstFi);
            } else {
                // dst is a feature group
                balanceFeatureGroupEnds(parentci, connInfo, srcCi, dstFi);
            }
        } else {
            error(parentci.getSystemInstance(), "Connection source is neither a feature nor a component: " + connInfo.src.getInstanceObjectPath() + " => " + connInfo.src.getInstanceObjectPath());
        }
        if (upFi != null) {
            upFeature.push(upFi);
        }
    } else {
        // Component Instance
        ComponentInstance dstCi = (ComponentInstance) dstEnd;
        if (connInfo.src instanceof FeatureInstance) {
            FeatureInstance srcFi = (FeatureInstance) connInfo.src;
            if (srcFi.getFeatureInstances().isEmpty()) {
                addConnectionInstance(parentci.getSystemInstance(), connInfo, dstCi);
            } else {
                // src is a feature group
                balanceFeatureGroupEnds(parentci, connInfo, srcFi, dstCi);
            }
        } else if (connInfo.src instanceof ComponentInstance) {
            error(parentci.getSystemInstance(), "Connection source and destination are components: " + connInfo.src.getInstanceObjectPath() + " => " + dstCi.getInstanceObjectPath());
        } else {
            error(parentci.getSystemInstance(), "Connection source is neither a feature nor a component: " + connInfo.src.getInstanceObjectPath() + " => " + dstCi.getInstanceObjectPath());
        }
    }
}
Also used : FeatureGroup(org.osate.aadl2.FeatureGroup) FeatureInstance(org.osate.aadl2.instance.FeatureInstance) FeatureGroupType(org.osate.aadl2.FeatureGroupType) ComponentInstance(org.osate.aadl2.instance.ComponentInstance)

Aggregations

FeatureGroupType (org.osate.aadl2.FeatureGroupType)48 Classifier (org.osate.aadl2.Classifier)23 FeatureGroup (org.osate.aadl2.FeatureGroup)22 ComponentClassifier (org.osate.aadl2.ComponentClassifier)20 Feature (org.osate.aadl2.Feature)15 Subcomponent (org.osate.aadl2.Subcomponent)13 ComponentPrototype (org.osate.aadl2.ComponentPrototype)10 ComponentType (org.osate.aadl2.ComponentType)10 FeatureGroupPrototype (org.osate.aadl2.FeatureGroupPrototype)10 NamedElement (org.osate.aadl2.NamedElement)10 FeatureInstance (org.osate.aadl2.instance.FeatureInstance)9 AadlPackage (org.osate.aadl2.AadlPackage)8 FeatureGroupPrototypeBinding (org.osate.aadl2.FeatureGroupPrototypeBinding)8 EObject (org.eclipse.emf.ecore.EObject)7 ComponentImplementation (org.osate.aadl2.ComponentImplementation)7 ComponentPrototypeBinding (org.osate.aadl2.ComponentPrototypeBinding)7 FeatureGroupPrototypeActual (org.osate.aadl2.FeatureGroupPrototypeActual)7 ArrayList (java.util.ArrayList)6 ContainmentPathElement (org.osate.aadl2.ContainmentPathElement)6 EClass (org.eclipse.emf.ecore.EClass)5