Search in sources :

Example 1 with Classifier

use of org.geotoolkit.sml.xml.v101.Classifier in project alisa-examples by osate.

the class ModelVerifications method sameVoltage.

public static boolean sameVoltage(ComponentInstance ci) {
    EList<FeatureInstance> inlets = new BasicEList<FeatureInstance>();
    for (FeatureInstance fi : ci.getAllFeatureInstances(FeatureCategory.ABSTRACT_FEATURE)) {
        Classifier cl = fi.getFeature().getAllClassifier();
        if (cl.getName().equalsIgnoreCase("power")) {
            inlets.add(fi);
        }
    }
    if (inlets.size() == 2) {
        double v1 = getVoltage(inlets.get(0));
        double v2 = getVoltage(inlets.get(1));
        return v1 == v2;
    }
    return false;
}
Also used : FeatureInstance(org.osate.aadl2.instance.FeatureInstance) BasicEList(org.eclipse.emf.common.util.BasicEList) Classifier(org.osate.aadl2.Classifier)

Example 2 with Classifier

use of org.geotoolkit.sml.xml.v101.Classifier 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 3 with Classifier

use of org.geotoolkit.sml.xml.v101.Classifier 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)

Example 4 with Classifier

use of org.geotoolkit.sml.xml.v101.Classifier in project AGREE by loonwerks.

the class AgreeValidator method checkAssume.

@Check(CheckType.FAST)
public void checkAssume(AssumeStatement assume) {
    Classifier comp = assume.getContainingClassifier();
    if (!(comp instanceof ComponentType)) {
        error(assume, "Assume statements are allowed only in component types");
    }
    // the expression could be null if a pattern is used
    Expr expr = assume.getExpr();
    if (expr != null) {
        TypeDef exprType = AgreeTypeSystem.infer(expr);
        if (!AgreeTypeSystem.typesEqual(AgreeTypeSystem.Prim.BoolTypeDef, exprType)) {
            error(assume, "Expression for assume statement is of type '" + nameOfTypeDef(exprType) + "' but must be of type 'bool'");
        }
    }
    if (assume.getName() == null) {
        info(assume, "It is recommended that assume statements be named." + " (Hint: an identifier may be placed between the \"assume\" keyword and the quoted description.)");
    }
}
Also used : ComponentType(org.osate.aadl2.ComponentType) EnumLitExpr(com.rockwellcollins.atc.agree.agree.EnumLitExpr) IndicesExpr(com.rockwellcollins.atc.agree.agree.IndicesExpr) TimeRiseExpr(com.rockwellcollins.atc.agree.agree.TimeRiseExpr) FlatmapExpr(com.rockwellcollins.atc.agree.agree.FlatmapExpr) TimeFallExpr(com.rockwellcollins.atc.agree.agree.TimeFallExpr) RealLitExpr(com.rockwellcollins.atc.agree.agree.RealLitExpr) GetPropertyExpr(com.rockwellcollins.atc.agree.agree.GetPropertyExpr) TimeOfExpr(com.rockwellcollins.atc.agree.agree.TimeOfExpr) PrevExpr(com.rockwellcollins.atc.agree.agree.PrevExpr) FoldRightExpr(com.rockwellcollins.atc.agree.agree.FoldRightExpr) TagExpr(com.rockwellcollins.atc.agree.agree.TagExpr) EventExpr(com.rockwellcollins.atc.agree.agree.EventExpr) LatchedExpr(com.rockwellcollins.atc.agree.agree.LatchedExpr) NamedElmExpr(com.rockwellcollins.atc.agree.agree.NamedElmExpr) SelectionExpr(com.rockwellcollins.atc.agree.agree.SelectionExpr) IfThenElseExpr(com.rockwellcollins.atc.agree.agree.IfThenElseExpr) ArraySubExpr(com.rockwellcollins.atc.agree.agree.ArraySubExpr) PreExpr(com.rockwellcollins.atc.agree.agree.PreExpr) RecordLitExpr(com.rockwellcollins.atc.agree.agree.RecordLitExpr) BinaryExpr(com.rockwellcollins.atc.agree.agree.BinaryExpr) UnaryExpr(com.rockwellcollins.atc.agree.agree.UnaryExpr) ExistsExpr(com.rockwellcollins.atc.agree.agree.ExistsExpr) FoldLeftExpr(com.rockwellcollins.atc.agree.agree.FoldLeftExpr) RecordUpdateExpr(com.rockwellcollins.atc.agree.agree.RecordUpdateExpr) ForallExpr(com.rockwellcollins.atc.agree.agree.ForallExpr) Expr(com.rockwellcollins.atc.agree.agree.Expr) ArrayUpdateExpr(com.rockwellcollins.atc.agree.agree.ArrayUpdateExpr) BoolLitExpr(com.rockwellcollins.atc.agree.agree.BoolLitExpr) NodeBodyExpr(com.rockwellcollins.atc.agree.agree.NodeBodyExpr) IntLitExpr(com.rockwellcollins.atc.agree.agree.IntLitExpr) CallExpr(com.rockwellcollins.atc.agree.agree.CallExpr) ArrayLiteralExpr(com.rockwellcollins.atc.agree.agree.ArrayLiteralExpr) AgreeTypeSystem.nameOfTypeDef(com.rockwellcollins.atc.agree.AgreeTypeSystem.nameOfTypeDef) ArrayTypeDef(com.rockwellcollins.atc.agree.AgreeTypeSystem.ArrayTypeDef) RecordTypeDef(com.rockwellcollins.atc.agree.AgreeTypeSystem.RecordTypeDef) TypeDef(com.rockwellcollins.atc.agree.AgreeTypeSystem.TypeDef) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier) Check(org.eclipse.xtext.validation.Check)

Example 5 with Classifier

use of org.geotoolkit.sml.xml.v101.Classifier in project AGREE by loonwerks.

the class AgreeValidator method checkOrderStatement.

@Check(CheckType.FAST)
public void checkOrderStatement(OrderStatement order) {
    Classifier container = order.getContainingClassifier();
    if (container instanceof ComponentImplementation) {
        ComponentImplementation compImpl = (ComponentImplementation) container;
        for (int index = 0; index < order.getComps().size(); ++index) {
            NamedElement comp = order.getComps().get(index);
            if (!(comp instanceof Subcomponent) || !((Subcomponent) comp).getContainingComponentImpl().equals(container)) {
                error("Element '" + comp.getName() + "' is not a subcomponent of '" + container.getName() + "'", order, AgreePackage.Literals.ORDER_STATEMENT__COMPS, index);
            }
        }
        List<NamedElement> notPresent = new ArrayList<>();
        for (Subcomponent subcomp : compImpl.getAllSubcomponents()) {
            boolean found = false;
            for (NamedElement el : order.getComps()) {
                if (el.equals(subcomp)) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                notPresent.add(subcomp);
            }
        }
        if (notPresent.size() != 0) {
            String delim = "";
            StringBuilder errorStr = new StringBuilder("The following subcomponents are not present in the ordering: ");
            for (NamedElement subcomp : notPresent) {
                errorStr.append(delim);
                errorStr.append(subcomp.getName());
                delim = ", ";
            }
            error(order, errorStr.toString());
        }
    } else {
        error(order, "Ordering statements can appear only in component implementations");
    }
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) Subcomponent(org.osate.aadl2.Subcomponent) DataSubcomponent(org.osate.aadl2.DataSubcomponent) ArrayList(java.util.ArrayList) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier) NamedElement(org.osate.aadl2.NamedElement) Check(org.eclipse.xtext.validation.Check)

Aggregations

Classifier (org.osate.aadl2.Classifier)203 ComponentClassifier (org.osate.aadl2.ComponentClassifier)90 ComponentImplementation (org.osate.aadl2.ComponentImplementation)49 NamedElement (org.osate.aadl2.NamedElement)40 AadlPackage (org.osate.aadl2.AadlPackage)38 Subcomponent (org.osate.aadl2.Subcomponent)37 ComponentType (org.osate.aadl2.ComponentType)34 EObject (org.eclipse.emf.ecore.EObject)31 ArrayList (java.util.ArrayList)29 BasicEList (org.eclipse.emf.common.util.BasicEList)28 Feature (org.osate.aadl2.Feature)26 DataClassifier (org.osate.aadl2.DataClassifier)22 FeatureGroupType (org.osate.aadl2.FeatureGroupType)21 ProcessorClassifier (org.osate.aadl2.ProcessorClassifier)21 AnnexSubclause (org.osate.aadl2.AnnexSubclause)17 Element (org.osate.aadl2.Element)17 EList (org.eclipse.emf.common.util.EList)15 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)15 FeatureGroup (org.osate.aadl2.FeatureGroup)14 PropertyExpression (org.osate.aadl2.PropertyExpression)14