use of org.geotoolkit.sml.xml.v100.ComponentType in project VERDICT by ge-high-assurance.
the class Aadl2CsvTranslator method populateDataFromAadlObjects.
/**
* Assume the input model is correct without any syntax errors
* Populate mission req, cyber and safety reqs and rels from AADL objects
*/
public void populateDataFromAadlObjects(List<EObject> objects) {
List<ComponentType> componentTypes = new ArrayList<>();
for (EObject obj : objects) {
if (obj instanceof SystemType) {
componentTypes.add((SystemType) obj);
} else if (obj instanceof BusType) {
componentTypes.add((BusType) obj);
} else if (obj instanceof SubprogramType) {
componentTypes.add((SubprogramType) obj);
} else if (obj instanceof ThreadType) {
componentTypes.add((ThreadType) obj);
} else if (obj instanceof MemoryType) {
componentTypes.add((MemoryType) obj);
} else if (obj instanceof DeviceType) {
componentTypes.add((DeviceType) obj);
} else if (obj instanceof AbstractType) {
componentTypes.add((AbstractType) obj);
} else if (obj instanceof ProcessType) {
componentTypes.add((ProcessType) obj);
} else if (obj instanceof ThreadGroupType) {
componentTypes.add((ThreadGroupType) obj);
} else if (obj instanceof VirtualProcessorType) {
componentTypes.add((VirtualProcessorType) obj);
} else if (obj instanceof ProcessorType) {
componentTypes.add((ProcessorType) obj);
} else if (obj instanceof SystemImplementation) {
compImpls.add((SystemImplementation) obj);
} else if (obj instanceof SubprogramImplementation) {
compImpls.add((SubprogramImplementation) obj);
} else if (obj instanceof ThreadImplementation) {
compImpls.add((ThreadImplementation) obj);
} else if (obj instanceof MemoryImplementation) {
compImpls.add((MemoryImplementation) obj);
} else if (obj instanceof BusImplementation) {
compImpls.add((BusImplementation) obj);
} else if (obj instanceof AbstractImplementation) {
compImpls.add((AbstractImplementation) obj);
} else if (obj instanceof DeviceImplementation) {
compImpls.add((DeviceImplementation) obj);
} else if (obj instanceof ProcessImplementation) {
compImpls.add((ProcessImplementation) obj);
} else if (obj instanceof ThreadGroupImplementation) {
compImpls.add((ThreadGroupImplementation) obj);
} else if (obj instanceof VirtualProcessorImplementation) {
compImpls.add((VirtualProcessorImplementation) obj);
} else if (obj instanceof ProcessorImplementation) {
compImpls.add((ProcessorImplementation) obj);
} else if (obj instanceof PropertySetImpl) {
// String propertySetName = ((PropertySetImpl)obj).getName();
// List<Property> compProps = new ArrayList<Property>();
Set<Property> compPropSet = new HashSet<Property>();
// List<Property> connProps = new ArrayList<Property>();
Set<Property> connPropSet = new HashSet<Property>();
for (Property prop : ((PropertySetImpl) obj).getOwnedProperties()) {
// Save property owner to be used later
for (PropertyOwner po : prop.getAppliesTos()) {
String propCat = ((MetaclassReferenceImpl) po).getMetaclass().getName().toLowerCase();
String propName = prop.getName();
switch(propCat) {
case "system":
{
componentPropertyToName.put(prop, propName);
compPropSet.add(prop);
break;
}
case "thread":
{
componentPropertyToName.put(prop, propName);
compPropSet.add(prop);
break;
}
case "processor":
{
componentPropertyToName.put(prop, propName);
compPropSet.add(prop);
break;
}
case "memory":
{
componentPropertyToName.put(prop, propName);
compPropSet.add(prop);
break;
}
case "connection":
{
connPropertyToName.put(prop, propName);
connPropSet.add(prop);
break;
}
case "process":
{
componentPropertyToName.put(prop, propName);
compPropSet.add(prop);
break;
}
case "abstract":
{
componentPropertyToName.put(prop, propName);
compPropSet.add(prop);
break;
}
case "device":
{
componentPropertyToName.put(prop, propName);
compPropSet.add(prop);
break;
}
case "threadgroup":
{
componentPropertyToName.put(prop, propName);
compPropSet.add(prop);
break;
}
case "virtualprocessor":
{
componentPropertyToName.put(prop, propName);
compPropSet.add(prop);
break;
}
case "bus":
{
componentPropertyToName.put(prop, propName);
compPropSet.add(prop);
break;
}
default:
{
System.out.println("Warning: unsupported property applies to: " + propCat);
break;
}
}
}
}
// compProps.addAll(compPropSet);
// connProps.addAll(connPropSet);
// propSetNameToCompProps.put(propertySetName, compProps);
// propSetNameToConnProps.put(propertySetName, connProps);
}
}
for (ComponentType compType : componentTypes) {
String compTypeName = compType.getName();
List<Event> events = new ArrayList<>();
List<CyberMission> missionReqs = new ArrayList<>();
List<CyberRel> cyberRels = new ArrayList<>();
List<SafetyRel> safetyRels = new ArrayList<>();
List<CyberReq> cyberReqs = new ArrayList<>();
List<SafetyReq> safetyReqs = new ArrayList<>();
for (AnnexSubclause annex : compType.getOwnedAnnexSubclauses()) {
if (annex.getName().equalsIgnoreCase("verdict")) {
Verdict verdictAnnex = VerdictUtil.getVerdict(annex);
for (Statement statement : verdictAnnex.getElements()) {
if (statement instanceof Event) {
events.add((Event) statement);
} else if (statement instanceof CyberMission) {
missionReqs.add((CyberMission) statement);
} else if (statement instanceof CyberReq) {
cyberReqs.add((CyberReq) statement);
} else if (statement instanceof CyberRel) {
cyberRels.add((CyberRel) statement);
} else if (statement instanceof SafetyReq) {
safetyReqs.add((SafetyReq) statement);
} else if (statement instanceof SafetyRel) {
safetyRels.add((SafetyRel) statement);
}
}
}
}
if (!events.isEmpty()) {
compTypeNameToEvents.put(compTypeName, events);
}
if (!missionReqs.isEmpty()) {
compTypeNameToMissions.put(compTypeName, missionReqs);
}
if (!cyberRels.isEmpty()) {
compTypeNameToCyberRels.put(compTypeName, cyberRels);
}
if (!safetyRels.isEmpty()) {
compTypeNameToSafetyRels.put(compTypeName, safetyRels);
}
if (!cyberReqs.isEmpty()) {
compTypeNameToCyberReqs.put(compTypeName, cyberReqs);
}
if (!safetyReqs.isEmpty()) {
compTypeNameToSafetyReqs.put(compTypeName, safetyReqs);
}
}
for (ComponentImplementation impl : compImpls) {
compTypeNameToImpl.put(impl.getType().getName(), impl);
if (!impl.getAllConnections().isEmpty()) {
sysImplToConns.put(impl, impl.getAllConnections());
}
}
}
use of org.geotoolkit.sml.xml.v100.ComponentType in project VERDICT by ge-high-assurance.
the class VerdictJavaValidator method checkFExpr.
/**
* Check that ports are valid input or output ports for the enclosing
* system, depending on what is required for the context.
*
* @param port
*/
@Check(CheckType.FAST)
public void checkFExpr(FExpr fExpr) {
String eventName = fExpr.getEventName();
ComponentType hostingSysType = VerdictUtil.getHostingSystemType(fExpr);
if (eventName == null) {
error("Event must have a name");
}
if (eventName != null && eventName.equals("")) {
error("Event name cannot be empty");
}
if (hostingSysType == null) {
error("No hosting system type found for the event expression");
} else {
Set<String> eventIds = VerdictUtil.getAvailableEventIds(hostingSysType);
if (eventIds != null && !eventIds.contains(fExpr.getEventName())) {
error("No such event has been declared in VERDICT");
}
}
}
use of org.geotoolkit.sml.xml.v100.ComponentType in project VERDICT by ge-high-assurance.
the class VerdictUtil method getHostingSystemType.
public static ComponentType getHostingSystemType(EObject element) {
ComponentType hostingSysType = null;
EObject container = element;
while (!(container instanceof ComponentType)) {
if (container == null) {
break;
}
container = container.eContainer();
}
if (container instanceof ComponentType) {
hostingSysType = (ComponentType) container;
}
return hostingSysType;
}
use of org.geotoolkit.sml.xml.v100.ComponentType in project AGREE by loonwerks.
the class VerifyHandler method getComponentImplementation.
protected ComponentImplementation getComponentImplementation(Element root, EphemeralImplementationUtil implUtil) {
Classifier classifier = getOutermostClassifier(root);
if (isRealizability()) {
if (!(classifier instanceof ComponentType)) {
throw new AgreeException("Must select an AADL Component Type");
}
ComponentImplementation result;
try {
result = implUtil.generateEphemeralCompImplFromType((ComponentType) classifier);
} catch (Exception e) {
e.printStackTrace();
throw new AgreeException("Error creating component implementation.");
}
return result;
} else {
if (classifier instanceof ComponentImplementation) {
return (ComponentImplementation) classifier;
}
if (!(classifier instanceof ComponentType)) {
throw new AgreeException("Must select an AADL Component Type or Implementation");
}
ComponentType ct = (ComponentType) classifier;
List<ComponentImplementation> cis = getComponentImplementations(ct);
if (cis.size() == 0) {
throw new AgreeException("AADL Component Type has no implementation to verify");
} else if (cis.size() == 1) {
ComponentImplementation ci = cis.get(0);
Shell shell = getWindow().getShell();
String message = "User selected " + ct.getFullName() + ".\nRunning analysis on " + ci.getFullName() + " instead.";
shell.getDisplay().asyncExec(() -> MessageDialog.openInformation(shell, "Analysis information", message));
return ci;
} else {
throw new AgreeException("AADL Component Type has multiple implementations to verify: please select just one");
}
}
}
use of org.geotoolkit.sml.xml.v100.ComponentType in project AGREE by loonwerks.
the class MATLABFunctionHandler method runJob.
@Override
protected IStatus runJob(Element root, IProgressMonitor monitor) {
Classifier classifier = getOutermostClassifier(root);
if (!(classifier instanceof ComponentType)) {
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Must select an AADL Component Type");
}
ComponentType ct = (ComponentType) classifier;
ComponentImplementation ci = null;
EphemeralImplementationUtil implUtil = new EphemeralImplementationUtil(monitor);
try {
SystemInstance si = implUtil.generateEphemeralCompInstanceFromType(ct);
ComponentType sysType = AgreeUtils.getInstanceType(si);
EList<AnnexSubclause> annexSubClauses = AnnexUtil.getAllAnnexSubclauses(sysType, AgreePackage.eINSTANCE.getAgreeContractSubclause());
if (annexSubClauses.size() == 0) {
throw new AgreeException("There is not an AGREE annex in the '" + sysType.getName() + "' system type.");
}
// Get Agree program
AgreeProgram agreeProgram = new AgreeASTBuilder().getAgreeProgram(si, false);
if (agreeProgram.containsRealTimePatterns) {
throw new AgreeException("'" + sysType.getName() + "' system type contains AGREE Real Time Patterns." + " Export of AGREE Real Time Patterns NOT Supported - they are considered scheduling properties" + " of components and can be decomposed further.");
}
// Translate Agree Node to Lustre Node with pre-statement flatten, helper nodes inlined,
// and variable declarations sorted so they are declared before use
Node lustreNode = AgreeNodeToLustreContract.translate(agreeProgram.topNode, agreeProgram);
// Translate Lustre Node to MATLAB Function AST
MATLABPrimaryFunction matlabFunction = LustreToMATLABTranslator.translate(lustreNode, agreeProgram);
ModelInfo info = getModelInfo(ct);
if (info == null) {
// return;
return Status.CANCEL_STATUS;
}
String dirStr = info.outputDirPath;
if (dirStr == null || dirStr.isEmpty()) {
// return;
return Status.CANCEL_STATUS;
}
boolean exportContractsPressed = info.exportPressed;
boolean genImplPressed = info.generatePressed;
boolean genVerificationPressed = info.updatePressed;
boolean verifySubsysPressed = info.verifyPressed;
String matlabFuncScriptName = matlabFunction.name + ".m";
if (genImplPressed) {
// Write MATLAB script to generate subsystem in the selected
// output folder
String subsysName = "";
if (info.subsystemName.equals("")) {
subsysName = sysType.getName();
} else {
subsysName = info.subsystemName;
}
MdlScriptCreator implMdlScript = new MdlScriptCreator(dirStr, info.implMdlPath, info.verifyMdlName, subsysName, matlabFunction.ports, matlabFuncScriptName, true, info.verifyPressed);
String implMdlScriptName = "generate_" + subsysName + ".m";
// generate the script to create the impl model file into the path specified for the model
File implMdlFile = new File(info.implMdlPath);
String implMdlDir = implMdlFile.getParent();
if (implMdlDir != null) {
Path implMdlScriptPath = Paths.get(implMdlDir, implMdlScriptName);
writeToFile(implMdlScriptPath, implMdlScript.toString());
}
}
if (exportContractsPressed || genVerificationPressed || verifySubsysPressed) {
Path matlabFuncScriptPath = Paths.get(dirStr, matlabFuncScriptName);
// Write MATLAB function code into the specified file in the
// selected output folder
writeToFile(matlabFuncScriptPath, matlabFunction.toString());
if (genVerificationPressed || verifySubsysPressed) {
// Create Simulink Model Update script into the output
// folder
MdlScriptCreator verifMdlScript = new MdlScriptCreator(dirStr, info.implMdlPath, info.verifyMdlName, info.subsystemName, matlabFunction.ports, matlabFuncScriptName, false, info.verifyPressed);
String verifMdlScriptName = matlabFunction.name + "_Observer.m";
Path verifMdlScriptPath = Paths.get(dirStr, verifMdlScriptName);
writeToFile(verifMdlScriptPath, verifMdlScript.toString());
}
}
// return;
return Status.OK_STATUS;
} catch (Throwable e) {
String messages = getNestedMessages(e);
e.printStackTrace();
Dialog.showError("AGREE Error", e.toString());
// return;
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, messages, e);
} finally {
if (ci != null) {
ci.eResource().getContents().remove(ci);
}
implUtil.cleanup();
}
}
Aggregations