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;
}
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));
}
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;
}
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;
}
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());
}
}
}
Aggregations