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