use of org.osate.aadl2.impl.DataTypeImpl in project AMASE by loonwerks.
the class SafetyValidator method checkInput.
/**
* Checks fault def name is valid,
* expressions passed into node match parameter types,
* and correct number of arguments passed in.
*
* @param inputs
*/
@Check(CheckType.FAST)
public void checkInput(InputStatement inputs) {
EObject container = inputs.eContainer();
NamedElement defNameSub;
List<Expr> exprList = inputs.getNom_conn();
List<String> inputList = inputs.getFault_in();
ArrayList<String> argNames = new ArrayList<String>();
if (container instanceof FaultStatement) {
FaultStatement faultStatement = (FaultStatement) container;
DoubleDotRef defName = faultStatement.getFaultDefName();
defNameSub = defName.getElm();
// Make sure we have a NodeDefExpr
if (defNameSub instanceof NodeDef) {
List<Arg> nodeArgs = ((NodeDef) defNameSub).getArgs();
for (Arg arg : nodeArgs) {
argNames.add(arg.getFullName());
if (arg.getType() instanceof DoubleDotRefImpl) {
if ((((DoubleDotRefImpl) arg.getType()).getElm() instanceof PropertyImpl) || (((DoubleDotRefImpl) arg.getType()).getElm() instanceof DataTypeImpl)) {
error(inputs, "Fault node parameters are not recognized: a possible issue is that the keyword 'float' is used instead of 'real.'");
}
}
}
// If the sizes are accurate, make sure names match
if (nodeArgs.size() - 1 == (inputList.size())) {
// Go through input list and make sure each name is in the arg list
for (String inputName : inputList) {
if (!argNames.contains(inputName)) {
error(inputs, "Input names must match fault node definition names. " + "The input name " + inputName + " is not an input in the node definition. " + "All possible input names are: " + argNames.toString());
}
}
} else {
argNames.remove("trigger");
error(inputs, "With this fault definition, you must have " + (argNames.size() - 1) + " inputs." + " These are called: " + argNames.toString());
}
if (inputListHasRepeats(inputList)) {
error(inputs, "There is a repeated name in the input list: " + inputList.toString());
}
if (!checkInputTypes(exprList, nodeArgs)) {
error(inputs, "Types of inputs do not match types of node parameters");
}
} else {
// Not a node def expr
error(defName, "Fault definition: " + defNameSub.getFullName() + " must be a valid agree node definition name.");
}
} else {
error(inputs, "Fault inputs must be defined within a fault statement.");
}
}
use of org.osate.aadl2.impl.DataTypeImpl 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;
}
use of org.osate.aadl2.impl.DataTypeImpl in project VERDICT by ge-high-assurance.
the class Aadl2Vdm method createVdmPort.
/**
* @author Vidhya Tekken Valapil
* Creates a new Vdm Port object and returns
* Populates "name", "mode" and "type"
* @param dataport
* @return vdm port
*/
private Port createVdmPort(DataPort dataPort, Model model, HashSet<String> dataTypeDecl) {
String modeString = "in";
if (dataPort.isIn()) {
modeString = "in";
} else if (dataPort.isOut()) {
modeString = "out";
}
// fetching data type information
DataSubcomponentType dSubCompType = dataPort.getDataFeatureClassifier();
verdict.vdm.vdm_data.DataType dtype = new verdict.vdm.vdm_data.DataType();
if (dSubCompType instanceof DataTypeImpl) {
org.osate.aadl2.DataType aadlDType = (org.osate.aadl2.DataType) dSubCompType;
dtype = resolveAADLDataType(aadlDType, model, dataTypeDecl);
} else if (dSubCompType instanceof DataImplementationImpl) {
org.osate.aadl2.DataImplementation aadlDImpl = (org.osate.aadl2.DataImplementation) dSubCompType;
dtype = resolveAADLDataImplementationType(aadlDImpl, model, dataTypeDecl);
} else {
System.out.println("Unresolved/unexpected Named Element.");
}
verdict.vdm.vdm_model.Port newPort = new verdict.vdm.vdm_model.Port();
newPort.setProbe(false);
if (dataPort.getOwnedPropertyAssociations().size() != 0) {
EList<PropertyAssociation> propertyAssocs = dataPort.getOwnedPropertyAssociations();
for (PropertyAssociation propertyAssoc : propertyAssocs) {
if (propertyAssoc.getProperty().getName().equalsIgnoreCase("probe")) {
EList<ModalPropertyValue> propVals = propertyAssoc.getOwnedValues();
if (propVals.size() == 0 || propVals.size() > 1) {
throw new RuntimeException("Unexpected number for values for probe property of port.");
}
if (propVals.get(0).getOwnedValue() instanceof BooleanLiteral) {
BooleanLiteral probeVal = (BooleanLiteral) propVals.get(0).getOwnedValue();
newPort.setProbe(probeVal.getValue());
} else {
throw new RuntimeException("Unexpected type of value for probe property of port.");
}
}
}
}
newPort.setId(dataPort.getQualifiedName());
newPort.setName(dataPort.getName());
newPort.setMode(convertToVdmPortMode(modeString));
newPort.setType(dtype);
return newPort;
}
use of org.osate.aadl2.impl.DataTypeImpl in project VERDICT by ge-high-assurance.
the class Aadl2Vdm method defineDataImplementationType.
/**
* @author Vidhya Tekken Valapil
* populate information related to data implementation types in the vdm
*/
private void defineDataImplementationType(DataImplementation dataImplementation, Model model, HashSet<String> dataTypeDecl) {
// DEFINE DATA TYPE IN DECLARATIONS IF NOT ALREADY DEFINED
String dataImplementationName = dataImplementation.getName();
if (!dataTypeDecl.contains(dataImplementationName)) {
dataTypeDecl.add(dataImplementationName);
// vdm data type declaration
TypeDeclaration dataTypeVdm = new TypeDeclaration();
dataTypeVdm.setName(dataImplementationName);
verdict.vdm.vdm_data.DataType dtype = new verdict.vdm.vdm_data.DataType();
// GET DETAILS OF THE DATA IMPLEMENTATION AND CREATE CORRESPONDING VDM DATATYPE
EList<DataSubcomponent> subcomponents = dataImplementation.getOwnedDataSubcomponents();
if (!(subcomponents.isEmpty())) {
// if the dataType definition has subcomponents
RecordType recType = new RecordType();
for (DataSubcomponent dataSubComp : subcomponents) {
RecordField recField = new RecordField();
recField.setName(dataSubComp.getName());
DataSubcomponentType dataSubCompType = dataSubComp.getDataSubcomponentType();
if (dataSubCompType instanceof org.osate.aadl2.DataType) {
org.osate.aadl2.DataType aadlDataType = (org.osate.aadl2.DataType) dataSubCompType;
Agree2Vdm agree2vdm = new Agree2Vdm();
verdict.vdm.vdm_data.DataType recFieldDtype = agree2vdm.getVdmTypeFromAADLType(aadlDataType);
recField.setType(recFieldDtype);
resolveAADLDataType(aadlDataType, model, dataTypeDecl);
recType.getRecordField().add(recField);
} else if (dataSubCompType instanceof DataImplementation) {
DataImplementation dataSubCompDataImplementation = (DataImplementation) dataSubCompType;
verdict.vdm.vdm_data.DataType recFieldDtype = new verdict.vdm.vdm_data.DataType();
recFieldDtype.setUserDefinedType(dataSubCompDataImplementation.getName());
recField.setType(recFieldDtype);
defineDataImplementationType(dataSubCompDataImplementation, model, dataTypeDecl);
recType.getRecordField().add(recField);
} else {
System.out.println("Unexpected Data Subcomponent that is not a DataTypeImpl or DataImplementatioImpl.");
}
}
if (recType.getRecordField().size() != 0) {
dtype.setRecordType(recType);
dataTypeVdm.setDefinition(dtype);
}
} else {
// if the dataType is base type boolean or integer or char or string
System.out.println("Data implementation type has no subcomponents");
}
// add the typeDeclaration to the model
model.getTypeDeclaration().add(dataTypeVdm);
}
}
Aggregations