Search in sources :

Example 1 with ComponentType

use of org.geotoolkit.sml.xml.v101.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());
        }
    }
}
Also used : ProcessImplementation(org.osate.aadl2.ProcessImplementation) ArrayList(java.util.ArrayList) SystemType(org.osate.aadl2.SystemType) VirtualProcessorImplementation(org.osate.aadl2.VirtualProcessorImplementation) BusImplementation(org.osate.aadl2.BusImplementation) EObject(org.eclipse.emf.ecore.EObject) ThreadImplementation(org.osate.aadl2.ThreadImplementation) HashSet(java.util.HashSet) Verdict(com.ge.research.osate.verdict.dsl.verdict.Verdict) ThreadGroupType(org.osate.aadl2.ThreadGroupType) ThreadGroupImplementation(org.osate.aadl2.ThreadGroupImplementation) PropertySetImpl(org.osate.aadl2.impl.PropertySetImpl) DeviceType(org.osate.aadl2.DeviceType) ThreadType(org.osate.aadl2.ThreadType) AbstractType(org.osate.aadl2.AbstractType) SubprogramType(org.osate.aadl2.SubprogramType) AbstractImplementation(org.osate.aadl2.AbstractImplementation) AnnexSubclause(org.osate.aadl2.AnnexSubclause) ComponentImplementation(org.osate.aadl2.ComponentImplementation) MemoryImplementation(org.osate.aadl2.MemoryImplementation) PropertyOwner(org.osate.aadl2.PropertyOwner) BusType(org.osate.aadl2.BusType) VirtualProcessorType(org.osate.aadl2.VirtualProcessorType) ProcessorType(org.osate.aadl2.ProcessorType) MetaclassReferenceImpl(org.osate.aadl2.impl.MetaclassReferenceImpl) ProcessType(org.osate.aadl2.ProcessType) ProcessorImplementation(org.osate.aadl2.ProcessorImplementation) VirtualProcessorImplementation(org.osate.aadl2.VirtualProcessorImplementation) VirtualProcessorType(org.osate.aadl2.VirtualProcessorType) Property(org.osate.aadl2.Property) MemoryType(org.osate.aadl2.MemoryType) CyberRel(com.ge.research.osate.verdict.dsl.verdict.CyberRel) ComponentType(org.osate.aadl2.ComponentType) CyberMission(com.ge.research.osate.verdict.dsl.verdict.CyberMission) CyberReq(com.ge.research.osate.verdict.dsl.verdict.CyberReq) Statement(com.ge.research.osate.verdict.dsl.verdict.Statement) SubprogramImplementation(org.osate.aadl2.SubprogramImplementation) SystemImplementation(org.osate.aadl2.SystemImplementation) SafetyRel(com.ge.research.osate.verdict.dsl.verdict.SafetyRel) Event(com.ge.research.osate.verdict.dsl.verdict.Event) DeviceImplementation(org.osate.aadl2.DeviceImplementation) SafetyReq(com.ge.research.osate.verdict.dsl.verdict.SafetyReq)

Example 2 with ComponentType

use of org.geotoolkit.sml.xml.v101.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");
        }
    }
}
Also used : ComponentType(org.osate.aadl2.ComponentType) Check(org.eclipse.xtext.validation.Check)

Example 3 with ComponentType

use of org.geotoolkit.sml.xml.v101.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;
}
Also used : ComponentType(org.osate.aadl2.ComponentType) EObject(org.eclipse.emf.ecore.EObject)

Example 4 with ComponentType

use of org.geotoolkit.sml.xml.v101.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");
        }
    }
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) ComponentType(org.osate.aadl2.ComponentType) Shell(org.eclipse.swt.widgets.Shell) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) Classifier(org.osate.aadl2.Classifier) ComponentClassifier(org.osate.aadl2.ComponentClassifier) PartInitException(org.eclipse.ui.PartInitException) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) JKindException(jkind.JKindException)

Example 5 with ComponentType

use of org.geotoolkit.sml.xml.v101.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();
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) ComponentImplementation(org.osate.aadl2.ComponentImplementation) Path(java.nio.file.Path) ComponentType(org.osate.aadl2.ComponentType) Node(jkind.lustre.Node) AgreeProgram(com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram) Classifier(org.osate.aadl2.Classifier) MATLABPrimaryFunction(com.rockwellcollins.atc.agree.codegen.ast.MATLABPrimaryFunction) EphemeralImplementationUtil(com.rockwellcollins.atc.agree.analysis.EphemeralImplementationUtil) AgreeASTBuilder(com.rockwellcollins.atc.agree.analysis.ast.AgreeASTBuilder) SystemInstance(org.osate.aadl2.instance.SystemInstance) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) File(java.io.File) AnnexSubclause(org.osate.aadl2.AnnexSubclause)

Aggregations

ComponentType (org.osate.aadl2.ComponentType)73 ComponentImplementation (org.osate.aadl2.ComponentImplementation)42 Classifier (org.osate.aadl2.Classifier)33 ComponentClassifier (org.osate.aadl2.ComponentClassifier)21 ArrayList (java.util.ArrayList)18 EObject (org.eclipse.emf.ecore.EObject)16 NamedElement (org.osate.aadl2.NamedElement)15 AnnexSubclause (org.osate.aadl2.AnnexSubclause)13 Feature (org.osate.aadl2.Feature)13 BasicEList (org.eclipse.emf.common.util.BasicEList)11 AadlPackage (org.osate.aadl2.AadlPackage)11 HashSet (java.util.HashSet)10 FeatureGroupType (org.osate.aadl2.FeatureGroupType)10 List (java.util.List)9 Subcomponent (org.osate.aadl2.Subcomponent)8 FeatureGroup (org.osate.aadl2.FeatureGroup)7 EList (org.eclipse.emf.common.util.EList)6 Property (org.osate.aadl2.Property)6 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)6 GetPropertyExpr (com.rockwellcollins.atc.agree.agree.GetPropertyExpr)5