use of org.osate.aadl2.DataClassifier in project osate2 by osate.
the class AadlBaUtils method getDataRepresentation.
/**
* Returns the last data representation from the property stack of the given data
* classifier or DataRepresentation.UNKNOWN if Data_Model::Data_Representation
* property is not set or if the data classifier represents a data structure.
*
* @param c the given data classifier
* @return the data representation or DataRepresentation.UNKNOWN
*/
public static DataRepresentation getDataRepresentation(DataClassifier c) {
DataRepresentation result = null;
if (c == null) {
result = DataRepresentation.UNKNOWN;
} else {
EList<PropertyExpression> l = PropertyUtils.findPropertyExpression(c, DataModelProperties.DATA_REPRESENTATION);
if (l.size() > 0) {
// Fetches the last enumeration value from the inheritance stack of
// properties.
NamedValue nv = (NamedValue) l.get(l.size() - 1);
String tmp = ((EnumerationLiteral) nv.getNamedValue()).getName();
result = DataRepresentation.getByName(tmp);
if (result == null) {
result = DataRepresentation.UNKNOWN;
}
} else {
result = DataRepresentation.UNKNOWN;
}
}
return result;
}
use of org.osate.aadl2.DataClassifier in project osate2 by osate.
the class AadlBaUtils method getTypeHolder.
/**
* Returns the TypeHolder (data representation and component's DataClassifier
* if any) of the given Element object.
* <BR><BR>
* For now, only the following objects are supported:<BR>
* <BR>_ IterativeVariable
* <BR>_ DataClassifier
* <BR>_ Target
* <BR>_ Value
* <BR><BR>
*
* @param el the given Element object.
* @param parentContainer only for AADLBA declarative objects which have no
* parent set, yet
* @return the type holder of the given Element object. If the given element
* is null, it returns the default type holder object.
* @exception UnsupportedOperationException for the unsupported types
* or Element instances.
* @exception DimensionException in any case of array dimension overflow.
*/
public static TypeHolder getTypeHolder(Element el, ComponentClassifier parentContainer) throws DimensionException {
TypeHolder result = null;
if (el instanceof IterativeVariable) {
IterativeVariable iv = (IterativeVariable) el;
result = getTypeHolder(iv);
processArrayDataRepresentation(el, result, 0);
return result;
} else if (el instanceof DataClassifier) {
DataClassifier dc = (DataClassifier) el;
result = getTypeHolder(dc);
return result;
} else if (el instanceof ValueConstant) {
return result = getTypeHolder((ValueConstant) el, parentContainer);
} else if (el instanceof Target || el instanceof ValueVariable) {
result = getTypeHolder((Value) el, parentContainer);
// The declared variable dimension: the number of [] in the element
// declaration.
int declaredDim = 0;
// The expression dimension: the number of [] in the expression.
// Only targets and values can express dimension.
int exprDim = 0;
boolean hasToProcessDataRepresentation = false;
// for/forall statement.
if (el.eContainer() instanceof ForOrForAllStatement) {
hasToProcessDataRepresentation = true;
}
// Either ElementHolder or DataComponentReference object.
Element bindedEl = null;
ElementHolder elHolder = null;
if (el instanceof ElementHolder) {
elHolder = (ElementHolder) el;
bindedEl = elHolder.getElement();
} else // DataComponentReference case.
{
DataComponentReference dcr = (DataComponentReference) el;
elHolder = dcr.getData().get(dcr.getData().size() - 1);
}
bindedEl = elHolder.getElement();
if (elHolder instanceof IndexableElement) {
IndexableElement ie = (IndexableElement) elHolder;
if (ie.isSetArrayIndexes()) {
exprDim = ie.getArrayIndexes().size();
}
}
// Set up the declared, expression dimension and dimension sizes.
if (bindedEl instanceof ArrayableElement) {
ArrayableElement ae = (ArrayableElement) bindedEl;
if (false == ae.getArrayDimensions().isEmpty()) {
EList<ArrayDimension> adl = ae.getArrayDimensions();
declaredDim = adl.size();
if (exprDim <= declaredDim) {
long[] ds = new long[declaredDim - exprDim];
for (int i = exprDim; i < declaredDim; i++) {
ds[i - exprDim] = adl.get(i).getSize().getSize();
}
result.setDimensionSizes(ds);
}
}
}
// or if the element is an element values of a for/forall statement.
if (declaredDim == 0 && (exprDim > 0 || hasToProcessDataRepresentation)) {
processArrayDataRepresentation(el, result, exprDim);
} else {
if (exprDim <= declaredDim) {
result.setDimension(declaredDim - exprDim);
} else {
// The given type is expressed as an array in AADL standard
// core way. We don't evaluate array behavior expressed in
// the Data Model Annex standard as we don't want to mix up
// the two standards.
String msg = "mixs up AADL standard array and data model array";
throw new DimensionException(el, msg, true);
}
}
return result;
} else if (el == null || el instanceof Abstract) {
// returns the default type holder for untyped prototypes.
return new TypeHolder();
} else {
String errorMsg = "getTypeHolder : " + el.getClass().getSimpleName() + " is not supported yet at line " + Aadl2Utils.getLocationReference(el).getLine() + ".";
System.err.println(errorMsg);
throw new UnsupportedOperationException(errorMsg);
}
}
use of org.osate.aadl2.DataClassifier in project osate2 by osate.
the class AadlBaUtils method getDataClassifier.
/**
* Returns the DataClassifier object associated to the given List of PrototypeBinging objects.
*
* @param prototypeBindings the list of PrototypeBinging object
* @param dp the DataPrototype searched for in prototypeBindings
* @return the DataClassifier object (null if not found)
*/
private static DataClassifier getDataClassifier(List<PrototypeBinding> prototypeBindings, DataPrototype dp) {
for (PrototypeBinding pb : prototypeBindings) {
if (pb instanceof ComponentPrototypeBinding && pb.getFormal().equals(dp)) {
ComponentPrototypeBinding cpb = (ComponentPrototypeBinding) pb;
ComponentPrototypeActual cpa = cpb.getActuals().get(cpb.getActuals().size() - 1);
if (cpa.getSubcomponentType() instanceof DataClassifier) {
return (DataClassifier) cpa.getSubcomponentType();
}
}
}
return null;
}
use of org.osate.aadl2.DataClassifier in project osate2 by osate.
the class AadlBaUtils method prototypeBindingResolverForDataComponentReference.
/**
* Returns the DataClassifier object associated to prototype binding in a DataComponentReference
*
* @param r the DataComponentRefenrence object from which the binding will be resolved
* @param dp the DataPrototpye object that enables to identify the targeted prototype binding
* @param parentContainer the object that contains the element binded to the
* given DataComponentRefenrence
* @return the DataClassifier object
*/
private static DataClassifier prototypeBindingResolverForDataComponentReference(DataComponentReference r, DataPrototype dp, NamedElement parentContainer) {
if (r.getData().size() > 1) {
DataHolder h = r.getData().get(r.getData().size() - 2);
NamedElement parent = h.getElement();
if (parent instanceof Classifier) {
Classifier c = (Classifier) parent;
return getDataClassifier(c.getOwnedPrototypeBindings(), dp);
}
if (parent instanceof Subcomponent) {
Subcomponent s = (Subcomponent) parent;
return getDataClassifier(s.getOwnedPrototypeBindings(), dp);
} else if (parent instanceof DataAccess) {
DataAccess da = (DataAccess) parent;
DataSubcomponentType parentDst = da.getDataFeatureClassifier();
Classifier c = (Classifier) parentDst;
DataClassifier matchedPrototype = getDataClassifier(c.getOwnedPrototypeBindings(), dp);
if (matchedPrototype == null) {
if (parentContainer instanceof ComponentType) {
ComponentType ct = (ComponentType) parentContainer;
for (Feature f : ct.getOwnedFeatures()) {
if (f instanceof DataAccess && f.getName().equals(parent.getName())) {
DataAccess containerDa = (DataAccess) f;
DataSubcomponentType containerDst = containerDa.getDataFeatureClassifier();
Classifier c2 = (Classifier) containerDst;
return getDataClassifier(c2.getOwnedPrototypeBindings(), dp);
}
}
}
}
} else if (parent instanceof DataPort) {
DataPort dataport = (DataPort) parent;
DataSubcomponentType parentDst = dataport.getDataFeatureClassifier();
Classifier c = (Classifier) parentDst;
DataClassifier matchedPrototype = getDataClassifier(c.getOwnedPrototypeBindings(), dp);
if (matchedPrototype == null) {
if (parentContainer instanceof ComponentType) {
ComponentType ct = (ComponentType) parentContainer;
for (Feature f : ct.getOwnedFeatures()) {
if (f instanceof DataPort && f.getName().equals(parent.getName())) {
DataPort containerDp = (DataPort) f;
DataSubcomponentType containerDst = containerDp.getDataFeatureClassifier();
Classifier c2 = (Classifier) containerDst;
return getDataClassifier(c2.getOwnedPrototypeBindings(), dp);
}
}
}
}
}
}
return null;
}
use of org.osate.aadl2.DataClassifier 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;
}
}
Aggregations