use of org.geotoolkit.sml.xml.v100.ComponentType in project AGREE by loonwerks.
the class RenamingVisitor method getReferenceStr.
private String getReferenceStr(AgreeVar var) {
String prefix = getCategory(rootInstance, var);
if (prefix == null) {
return null;
}
if (var.id.endsWith(AgreeASTBuilder.clockIDSuffix)) {
return null;
}
String seperator = (prefix == "" ? "" : ".");
EObject reference = var.reference;
String suffix = "";
if (var.id.endsWith(AgreeASTBuilder.eventSuffix + AgreeInlineLatchedConnections.LATCHED_SUFFIX)) {
suffix = "._EVENT_._LATCHED_";
} else if (var.id.endsWith(AgreeASTBuilder.eventSuffix)) {
suffix = "._EVENT_";
} else if (var.id.endsWith(AgreeInlineLatchedConnections.LATCHED_SUFFIX)) {
suffix = "._LATCHED_";
}
if (reference instanceof GuaranteeStatement) {
String id = ((GuaranteeStatement) reference).getName();
if (id == null || id.isEmpty()) {
id = "";
} else {
id = "[" + id + "] ";
}
return id + ((GuaranteeStatement) reference).getStr();
} else if (reference instanceof AssumeStatement) {
String id = ((AssumeStatement) reference).getName();
if (id == null || id.isEmpty()) {
id = "";
} else {
id = "[" + id + "] ";
}
return prefix + " assume: " + id + ((AssumeStatement) reference).getStr();
} else if (reference instanceof LemmaStatement) {
String id = ((LemmaStatement) reference).getName();
if (id == null || id.isEmpty()) {
id = "";
} else {
id = "[" + id + "] ";
}
return prefix + " lemma: " + id + ((LemmaStatement) reference).getStr();
} else if (reference instanceof ReachableStatement) {
renaming.addInvertedProperty(var.id);
String id = ((ReachableStatement) reference).getName();
if (id == null || id.isEmpty()) {
id = "";
} else {
id = "[" + id + "] ";
}
return prefix + " reachable: " + id + ((ReachableStatement) reference).getStr();
} else if (reference instanceof AssertStatement) {
throw new AgreeException("We really didn't expect to see an assert statement here");
} else if (reference instanceof Arg) {
return prefix + seperator + ((Arg) reference).getName() + suffix;
} else if (reference instanceof EqStatement) {
return prefix + "eq " + String.join(", ", ((EqStatement) reference).getLhs().stream().map(lhs -> argToString(lhs)).collect(Collectors.toList()));
} else if (reference instanceof InputStatement) {
return prefix + "agree_input " + String.join(", ", ((InputStatement) reference).getLhs().stream().map(lhs -> argToString(lhs)).collect(Collectors.toList()));
} else if (reference instanceof DataPort) {
return prefix + seperator + ((DataPort) reference).getName() + suffix;
} else if (reference instanceof EventPort) {
return prefix + seperator + ((EventPort) reference).getName() + suffix;
} else if (reference instanceof EventDataPort) {
return prefix + seperator + ((EventDataPort) reference).getName() + suffix;
} else if (reference instanceof FeatureGroup) {
String featName = ((FeatureGroup) reference).getName();
String varName = var.toString();
featName = varName.substring(varName.indexOf(featName)).replace("__", ".");
return prefix + seperator + featName;
} else if (reference instanceof PropertyStatement) {
return prefix + seperator + ((PropertyStatement) reference).getName();
} else if (reference instanceof Property) {
return "AADL property " + ((Property) reference).getName();
} else if (reference instanceof GetPropertyExpr) {
return "Get_Property(" + ((GetPropertyExpr) reference).getContainingClassifier().getName() + ", " + ((Property) ((GetPropertyExpr) reference).getProp()).getName() + ")";
} else if (reference instanceof ComponentType || reference instanceof ComponentImplementation || reference instanceof SystemImplementation) {
if (var.id.equals(LustreAstBuilder.assumeHistSufix)) {
return "Subcomponent Assumptions";
}
return "Result";
} else if (reference instanceof AgreeStatement) {
return prefix + reference.toString();
}
throw new AgreeException("Unhandled reference type: '" + reference.getClass().getName() + "'");
}
use of org.geotoolkit.sml.xml.v100.ComponentType in project AGREE by loonwerks.
the class AgreeBusinessObjectProvider method getAllSpecStatements.
public static Stream<SpecStatement> getAllSpecStatements(final Classifier classifier) {
// Work around for exception when an implementation does not have a type.
if (classifier instanceof ComponentImplementation && ((ComponentImplementation) classifier).getType() == null) {
return Stream.empty();
}
Stream<SpecStatement> results = getSpecStatements(classifier);
if (classifier instanceof ComponentImplementation) {
final ComponentType ct = ((ComponentImplementation) classifier).getType();
results = Stream.concat(getSpecStatements(ct), results);
}
return results;
}
use of org.geotoolkit.sml.xml.v100.ComponentType in project AGREE by loonwerks.
the class AgreeTypeSystem method typeDefFromClassifier.
public static TypeDef typeDefFromClassifier(Classifier c) {
if (c instanceof DataType || (c instanceof DataImplementation && ((DataImplementation) c).getAllSubcomponents().isEmpty() && ((DataImplementation) c).getType() != null)) {
// Includes special case for data implementations implementing extensions of primitive types
Classifier classifierType = c instanceof DataImplementation ? ((DataImplementation) c).getType() : c;
List<PropertyAssociation> pas = classifierType.getAllPropertyAssociations();
for (Classifier classType : classifierType.getSelfPlusAllExtended()) {
if (classType != null && hasIntegerDataRepresentation(classType)) {
for (PropertyAssociation choice : pas) {
Property p = choice.getProperty();
PropertyExpression v = choice.getOwnedValues().get(0).getOwnedValue();
String key = p.getQualifiedName();
if (key.equals("Data_Model::Integer_Range")) {
if (v instanceof RangeValue) {
try {
RangeValue rangeValue = (RangeValue) v;
long min = intFromPropExp(rangeValue.getMinimum()).get();
long max = intFromPropExp(rangeValue.getMaximum()).get();
return new RangeIntTypeDef(min, max);
} catch (Exception e) {
return Prim.ErrorTypeDef;
}
}
}
}
return Prim.IntTypeDef;
} else if (classType != null && hasFloatDataRepresentation(classType)) {
for (PropertyAssociation choice : pas) {
Property p = choice.getProperty();
PropertyExpression v = choice.getOwnedValues().get(0).getOwnedValue();
String key = p.getQualifiedName();
if (key.equals("Data_Model::Real_Range")) {
if (v instanceof RangeValue) {
try {
RangeValue rangeValue = (RangeValue) v;
double min = realFromPropExp(rangeValue.getMinimum()).get();
double max = realFromPropExp(rangeValue.getMaximum()).get();
return new RangeRealTypeDef(min, max);
} catch (Exception e) {
return Prim.ErrorTypeDef;
}
}
}
}
return Prim.RealTypeDef;
} else if (classType != null && hasBooleanDataRepresentation(classType)) {
return Prim.BoolTypeDef;
}
}
boolean prop_isArray = false;
int prop_arraySize = 0;
TypeDef prop_arrayBaseType = null;
boolean prop_isEnum = false;
List<String> prop_enumValues = null;
for (PropertyAssociation choice : pas) {
Property p = choice.getProperty();
PropertyExpression v = choice.getOwnedValues().get(0).getOwnedValue();
String key = p.getQualifiedName();
key = key == null ? p.getName() : key;
if (key == null) {
return Prim.ErrorTypeDef;
}
if (key.equalsIgnoreCase("Data_Model::Data_Representation")) {
if (v instanceof NamedValue) {
AbstractNamedValue anv = ((NamedValue) v).getNamedValue();
if (anv instanceof EnumerationLiteral) {
EnumerationLiteral el = (EnumerationLiteral) anv;
prop_isArray = el.getName().equals("Array");
prop_isEnum = el.getName().equals("Enum");
}
}
} else if (key.equalsIgnoreCase("Data_Model::Enumerators")) {
if (v instanceof ListValue) {
EList<PropertyExpression> peList = ((ListValue) v).getOwnedListElements();
String prefix = c.getQualifiedName() + "_";
prop_enumValues = new ArrayList<>();
for (PropertyExpression pe : peList) {
if (pe instanceof StringLiteral) {
String enumString = prefix + ((StringLiteral) pe).getValue();
prop_enumValues.add(enumString);
}
}
}
} else if (key.equalsIgnoreCase("Data_Model::Base_Type")) {
if (v instanceof ListValue) {
ListValue l = (ListValue) v;
PropertyExpression pe = l.getOwnedListElements().get(0);
if (pe instanceof ClassifierValue) {
prop_arrayBaseType = typeDefFromClassifier(((ClassifierValue) pe).getClassifier());
}
}
} else if (key.equalsIgnoreCase("Data_Model::Dimension")) {
if (v instanceof ListValue) {
ListValue l = (ListValue) v;
PropertyExpression pe = l.getOwnedListElements().get(0);
prop_arraySize = Math.toIntExact(intFromPropExp(pe).orElse((long) -1).longValue());
}
}
}
if (prop_isArray && prop_arraySize > 0 && prop_arrayBaseType != null) {
return new ArrayTypeDef(prop_arrayBaseType, prop_arraySize, Optional.of(c));
} else if (prop_isEnum && prop_enumValues != null) {
String name = c.getQualifiedName();
return new EnumTypeDef(name, prop_enumValues, c);
}
} else if (c instanceof ComponentClassifier) {
Map<String, TypeDef> fields = new HashMap<>();
Classifier currClsfr = c;
while (currClsfr != null) {
ComponentType ct = null;
if (currClsfr instanceof ComponentImplementation) {
EList<Subcomponent> subcomps = ((ComponentImplementation) currClsfr).getAllSubcomponents();
for (Subcomponent sub : subcomps) {
String fieldName = sub.getName();
if (sub.getClassifier() != null) {
boolean prop_isArray = false;
int prop_arraySize = 0;
boolean prop_isEnum = false;
List<String> prop_enumValues = null;
for (PropertyAssociation pa : sub.getOwnedPropertyAssociations()) {
Property p = pa.getProperty();
String key = p.getQualifiedName();
key = key == null ? p.getName() : key;
PropertyExpression v = null;
if (!pa.getOwnedValues().isEmpty()) {
v = pa.getOwnedValues().get(0).getOwnedValue();
} else {
continue;
}
if (key.equals("Data_Model::Data_Representation")) {
if (v instanceof NamedValue) {
AbstractNamedValue anv = ((NamedValue) v).getNamedValue();
if (anv instanceof EnumerationLiteral) {
EnumerationLiteral el = (EnumerationLiteral) anv;
prop_isArray = el.getName().equals("Array");
prop_isEnum = el.getName().equals("Enum");
}
}
} else if (key.equals("Data_Model::Dimension")) {
if (v instanceof ListValue) {
ListValue l = (ListValue) v;
PropertyExpression pe = l.getOwnedListElements().get(0);
prop_arraySize = Math.toIntExact(intFromPropExp(pe).orElse((long) -1).longValue());
}
} else if (key.equals("Data_Model::Enumerators")) {
if (v instanceof ListValue) {
EList<PropertyExpression> peList = ((ListValue) v).getOwnedListElements();
String prefix = c.getQualifiedName() + "_";
prop_enumValues = new ArrayList<>();
for (PropertyExpression pe : peList) {
if (pe instanceof StringLiteral) {
String enumString = prefix + ((StringLiteral) pe).getValue();
prop_enumValues.add(enumString);
}
}
}
}
}
if (prop_isArray && prop_arraySize > 0) {
TypeDef typeDef = new ArrayTypeDef(typeDefFromClassifier(sub.getClassifier()), prop_arraySize, Optional.empty());
fields.putIfAbsent(fieldName, typeDef);
} else if (prop_isEnum && prop_enumValues != null) {
String name = c.getQualifiedName();
TypeDef typeDef = new EnumTypeDef(name, prop_enumValues, c);
fields.putIfAbsent(fieldName, typeDef);
} else if (sub.getArrayDimensions().size() == 0) {
TypeDef typeDef = typeDefFromClassifier(sub.getClassifier());
fields.putIfAbsent(fieldName, typeDef);
} else if (sub.getArrayDimensions().size() == 1) {
ArrayDimension ad = sub.getArrayDimensions().get(0);
int size = Math.toIntExact(getArraySize(ad));
TypeDef stem = typeDefFromClassifier(sub.getClassifier());
TypeDef typeDef = new ArrayTypeDef(stem, size, Optional.empty());
fields.putIfAbsent(fieldName, typeDef);
}
}
}
ct = ((ComponentImplementation) currClsfr).getType();
} else if (c instanceof ComponentType) {
ct = (ComponentType) currClsfr;
}
if (ct != null) {
EList<Feature> features = ct.getAllFeatures();
for (Feature feature : features) {
String fieldName = feature.getName();
if (feature.getClassifier() != null) {
if (feature.getArrayDimensions().size() == 0) {
TypeDef typeDef = typeDefFromClassifier(feature.getClassifier());
fields.putIfAbsent(fieldName, typeDef);
} else if (feature.getArrayDimensions().size() == 1) {
ArrayDimension ad = feature.getArrayDimensions().get(0);
int size = Math.toIntExact(getArraySize(ad));
TypeDef stem = typeDefFromClassifier(feature.getClassifier());
TypeDef typeDef = new ArrayTypeDef(stem, size, Optional.empty());
fields.putIfAbsent(fieldName, typeDef);
}
}
}
for (AnnexSubclause annex : AnnexUtil.getAllAnnexSubclauses(currClsfr, AgreePackage.eINSTANCE.getAgreeContractSubclause())) {
AgreeContract contract = (AgreeContract) ((AgreeContractSubclause) annex).getContract();
for (SpecStatement spec : contract.getSpecs()) {
List<Arg> args = new ArrayList<>();
if (spec instanceof EqStatement) {
args = ((EqStatement) spec).getLhs();
} else if (spec instanceof InputStatement) {
args = ((InputStatement) spec).getLhs();
}
for (Arg arg : args) {
String fieldName = arg.getName();
TypeDef typeDef = typeDefFromNE(arg);
fields.putIfAbsent(fieldName, typeDef);
}
if (spec instanceof ConstStatement) {
String fieldName = ((ConstStatement) spec).getName();
TypeDef typeDef = AgreeTypeSystem.typeDefFromType(((ConstStatement) spec).getType());
fields.putIfAbsent(fieldName, typeDef);
}
}
}
}
currClsfr = currClsfr.getExtended();
}
String name = c.getQualifiedName();
return new RecordTypeDef(name, fields, c);
}
return Prim.ErrorTypeDef;
}
use of org.geotoolkit.sml.xml.v100.ComponentType in project AGREE by loonwerks.
the class AGREESimulationEngineFactoryHelper method createSimulationEngine.
public static SimulationEngine createSimulationEngine(final SystemInstance systemInstance, final ExceptionHandler exceptionHandler, final SimulationProgramType type) {
Objects.requireNonNull(systemInstance, "systemInstance must not be null");
Objects.requireNonNull(exceptionHandler, "exceptionHandler must not be null");
// Check that the component type is compatible
if (!isCompatible(systemInstance.getComponentImplementation())) {
final ComponentType componentType = systemInstance.getComponentClassifier().getType();
throw new RuntimeException(componentType.getName() + " does not contain an AGREE annex subclause.");
}
final AgreeProgram agreeProgram = new AgreeASTBuilder().getAgreeProgram(systemInstance, type.isMonolithic());
final SimulationProgram simulationProgram = AgreeProgramToSimulationProgram.transform(agreeProgram, type);
final Simulation simulation = new Simulation(simulationProgram);
return new AGREESimulationEngine(simulation, systemInstance, exceptionHandler);
}
use of org.geotoolkit.sml.xml.v100.ComponentType in project AGREE by loonwerks.
the class AgreeUtils method getInstanceType.
public static ComponentType getInstanceType(ComponentInstance compInst) {
if (compInst instanceof SystemInstance) {
ComponentType ct;
ct = ((SystemInstance) compInst).getComponentImplementation().getType();
return ct;
}
try {
return ((ComponentImplementation) compInst.getComponentClassifier()).getType();
} catch (ClassCastException e) {
return (ComponentType) compInst.getComponentClassifier();
}
}
Aggregations