use of org.osate.aadl2.EnumerationLiteral in project VERDICT by ge-high-assurance.
the class Agree2Vdm method updateVDMDatatypeUsingProperties.
/**
* @param vdm dataType,
* @param list of property associations
* this method checks if the property indicates if it is an enum definition
* and gets information from the properties to define the enum in the VDM
* *
*/
public boolean updateVDMDatatypeUsingProperties(verdict.vdm.vdm_data.DataType dtype, EList<PropertyAssociation> properties) {
if (properties.size() == 2) {
// check if the property specifies it is enum type
PropertyAssociation firstProperty = properties.get(0);
EList<ModalPropertyValue> firstPropertyValues = firstProperty.getOwnedValues();
if (firstPropertyValues.size() == 1) {
PropertyExpression ownedval = firstPropertyValues.get(0).getOwnedValue();
if (ownedval instanceof NamedValueImpl) {
NamedValue namedVal = (NamedValue) ownedval;
if (namedVal.getNamedValue() instanceof EnumerationLiteralImpl) {
EnumerationLiteral namedValEnumLit = (EnumerationLiteral) namedVal.getNamedValue();
if (namedValEnumLit.getName().equalsIgnoreCase("Enum")) {
EnumType vdmEnumType = new EnumType();
// Fetch the enum values which are defined as the next property
PropertyAssociation secondProperty = properties.get(1);
EList<ModalPropertyValue> secondPropertyValues = secondProperty.getOwnedValues();
if (firstPropertyValues.size() == 1) {
PropertyExpression secPropValue = secondPropertyValues.get(0).getOwnedValue();
// enum should have multiple values so check if a list of values are defined
if (secPropValue instanceof ListValueImpl) {
ListValueImpl listValueImpl = (ListValueImpl) secPropValue;
EList<PropertyExpression> listOfValues = listValueImpl.getOwnedListElements();
for (PropertyExpression enumvalue : listOfValues) {
if (enumvalue instanceof StringLiteralImpl) {
StringLiteralImpl stringEnumVal = (StringLiteralImpl) enumvalue;
vdmEnumType.getEnumValue().add(stringEnumVal.getValue());
} else {
System.out.println("Unexpected non-string value for data type of type enum.");
}
}
dtype.setEnumType(vdmEnumType);
return true;
} else {
System.out.println("The second property of the data definition is not of ListValueImp type");
}
} else {
System.out.println("Unresolved data property. The first property of the data definition has no values or multiple values.");
}
} else {
System.out.println("Unresolved data property value. Property's owned value's named value does not contain Enum");
}
} else {
System.out.println("Unresolved data property value. Property's owned value's named value is not EnumerationLiteralImpl type.");
}
} else {
System.out.println("Unresolved data property value. Property's owned value is not NamedValueImpl type.");
}
} else {
System.out.println("Unresolved data property with no values or multiple values.");
}
} else {
System.out.println("Unresolved data property. Data definition has 0 or more than 2 properties associated with it");
}
return false;
}
use of org.osate.aadl2.EnumerationLiteral in project AGREE by loonwerks.
the class AgreeASTBuilder method caseGetPropertyExpr.
@Override
public Expr caseGetPropertyExpr(GetPropertyExpr expr) {
NamedElement propName = expr.getProp();
PropertyExpression propVal;
if (propName instanceof Property) {
ComponentRef cr = expr.getComponentRef();
NamedElement compName = null;
if (cr instanceof DoubleDotRef) {
compName = ((DoubleDotRef) cr).getElm();
} else if (cr instanceof ThisRef) {
compName = curInst;
}
Property prop = (Property) propName;
propVal = AgreeUtils.getPropExpression(compName, prop);
if (propVal == null) {
if (Activator.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.PREF_UNSPECIFIED_AADL_PROPERTIES)) {
String propInputName = unspecifiedAadlPropertyPrefix + compName.getName() + dotChar + prop.getName();
unspecifiedAadlProperties.put(propInputName, expr);
return new IdExpr(propInputName);
} else {
throw new AgreeException("Could not locate property value '" + prop.getQualifiedName() + "' in component '" + compName.getName() + "'. Is it possible " + "that a 'this' statement is used in a context in which it wasn't supposed to?" + " Analysis of unspecified AADL properties as inputs may be enabled in the AGREE preferences.");
}
}
} else {
propVal = AgreeUtils.getPropExpression((PropertyConstant) propName);
if (propVal == null) {
throw new AgreeException("Could not locate property value '" + propName.getQualifiedName());
}
}
Expr res = null;
if (propVal != null) {
if (propVal instanceof StringLiteral) {
// nodeStr += value.getValue() + ")";
throw new AgreeException("Property value for '" + propName.getQualifiedName() + "' cannot be of string type");
} else if (propVal instanceof NamedValue) {
// EnumerationLiteral enVal = (EnumerationLiteral) absVal;
throw new AgreeException("Property value for '" + propName.getQualifiedName() + "' cannot be of enumeration type");
} else if (propVal instanceof BooleanLiteral) {
BooleanLiteral value = (BooleanLiteral) propVal;
res = new BoolExpr(value.getValue());
} else if (propVal instanceof IntegerLiteral) {
IntegerLiteral value = (IntegerLiteral) propVal;
res = new IntExpr(BigInteger.valueOf((long) value.getScaledValue()));
} else {
assert (propVal instanceof RealLiteral);
RealLiteral value = (RealLiteral) propVal;
res = new RealExpr(BigDecimal.valueOf(value.getValue()));
}
}
assert (res != null);
return res;
}
use of org.osate.aadl2.EnumerationLiteral in project AGREE by loonwerks.
the class AgreeAADLPropertyUtils method getPropertyEnumString.
public static String getPropertyEnumString(NamedElement namedEl, String property) {
Property prop = Aadl2GlobalScopeUtil.get(namedEl, Aadl2Package.eINSTANCE.getProperty(), property);
EnumerationLiteral lit = PropertyUtils.getEnumLiteral(namedEl, prop);
return lit.getName();
}
use of org.osate.aadl2.EnumerationLiteral in project AGREE by loonwerks.
the class AgreeTypeSystem method hasBooleanDataRepresentation.
public static boolean hasBooleanDataRepresentation(Classifier classifier) {
boolean result = false;
EList<PropertyAssociation> propertyAssociations = classifier.getAllPropertyAssociations();
for (PropertyAssociation propertyAssociation : propertyAssociations) {
Property property = propertyAssociation.getProperty();
try {
PropertyExpression propertyExpr = classifier.getSimplePropertyValue(property);
if ("Data_Model::Data_Representation".equals(property.getQualifiedName()) && propertyExpr instanceof NamedValue) {
AbstractNamedValue abstractNamedValue = ((NamedValue) propertyExpr).getNamedValue();
if (abstractNamedValue instanceof EnumerationLiteral && "Boolean".equals(((EnumerationLiteral) abstractNamedValue).getName())) {
result = true;
}
}
} catch (Exception e) {
continue;
}
}
return result;
}
use of org.osate.aadl2.EnumerationLiteral in project osate2 by osate.
the class ThreadCheck method perform.
@Override
public void perform(SystemInstance si) {
final List<ComponentInstance> allThreads = si.getAllComponentInstances().stream().filter(comp -> (comp.getCategory() == ComponentCategory.THREAD)).collect(Collectors.toList());
/**
* Each thread needs to specify the dispatch protocol "periodic" or
* "sporadic"
*/
allThreads.stream().filter(comp -> {
EnumerationLiteral protocol = GetProperties.getDispatchProtocol(comp);
return protocol == null || !(protocol.toString().equalsIgnoreCase(AadlProject.PERIODIC_LITERAL) || protocol.toString().equalsIgnoreCase(AadlProject.SPORADIC_LITERAL));
}).forEach(thr -> addError(new ErrorReport(thr, "Thread needs a Thread_Properties::Dispatch_Protocol property of 'Periodic' or 'Sporadic'")));
/**
* Each thread needs to specify period
*/
final List<ComponentInstance> threadMissingPeriod = allThreads.stream().filter(comp -> (PropertyUtils.getScaled(TimingProperties::getPeriod, comp, TimeUnits.MS).orElse(0.0) == 0.0)).collect(Collectors.toList());
for (ComponentInstance thr : threadMissingPeriod) {
addError(new ErrorReport(thr, "Thread must define the property Timing_Properties::Period"));
}
final List<ComponentInstance> threadMissingDeadline = allThreads.stream().filter(comp -> (PropertyUtils.getScaled(TimingProperties::getDeadline, comp, TimeUnits.MS).orElse(0.0) == 0.0)).collect(Collectors.toList());
for (ComponentInstance thr : threadMissingDeadline) {
addError(new ErrorReport(thr, "Thread must define the property Timing_Properties::Deadline"));
}
for (ComponentInstance ci : allThreads) {
ComponentClassifier cc = ci.getComponentClassifier();
if (cc instanceof ThreadImplementation) {
ThreadImplementation ti = (ThreadImplementation) cc;
for (SubprogramCall sc : ti.getSubprogramCalls()) {
NamedElement cs = (NamedElement) sc.getCalledSubprogram();
if (GetProperties.getSourceName(cs) == null) {
addError(new ErrorReport(cs, "Subprogram must define the property Programming_Properties::Source_Name"));
}
if (GetProperties.getSourceText(cs).size() == 0) {
addError(new ErrorReport(cs, "Subprogram must define the property Programming_Properties::Source_Text"));
}
if (GetProperties.getSourceLanguage(cs).size() == 0) {
addError(new ErrorReport(cs, "Subprogram must define the property Programming_Properties::Source_Language"));
}
}
}
}
/**
* FIXME JD Each thread needs to specify execution time
*/
// List<ComponentInstance> threadMissingExecutionTime =
// (List<ComponentInstance>) si.getAllComponentInstances().stream().
// filter( comp -> (comp.getCategory() == ComponentCategory.THREAD) &&
// (GetProperties.get > 0.0));
// for (ComponentInstance thr : threadMissingPeriod)
// {
// addError (new ErrorReport (thr, "Thread needs to define a period"));
// }
}
Aggregations