Search in sources :

Example 6 with NodeDef

use of com.rockwellcollins.atc.agree.agree.NodeDef in project AGREE by loonwerks.

the class AgreeLinkingService method getElm.

private Element getElm(EObject context, EReference reference, String name) {
    String[] segments = name.split("::");
    if (segments.length >= 2) {
        String pkgName = String.join("::", Arrays.copyOf(segments, segments.length - 1));
        String statementName = segments[segments.length - 1];
        Namespace namespace = AadlUtil.getContainingTopLevelNamespace(context);
        PropertySet propSet = AadlUtil.findImportedPropertySet(pkgName, namespace);
        if (propSet != null) {
            Element elm = propSet.findNamedElement(statementName);
            return elm;
        }
        AadlPackage aadlPackage = AadlUtil.findImportedPackage(pkgName, namespace);
        if (aadlPackage == null) {
            for (PackageRename rename : EcoreUtil2.getAllContentsOfType(namespace.getElementRoot(), PackageRename.class)) {
                if (rename.getName() != null && pkgName.equals(rename.getName())) {
                    aadlPackage = rename.getRenamedPackage();
                }
            }
        }
        if (aadlPackage != null) {
            for (AnnexLibrary annex : AnnexUtil.getAllActualAnnexLibraries(aadlPackage, AgreePackage.eINSTANCE.getAgreeContractLibrary())) {
                AgreeContract contract = (AgreeContract) ((AgreeContractLibrary) annex).getContract();
                for (SpecStatement spec : contract.getSpecs()) {
                    if (spec instanceof RecordDef) {
                        if (((RecordDef) spec).getName().equals(statementName)) {
                            return (spec);
                        }
                    } else if (spec instanceof FnDef) {
                        if (((FnDef) spec).getName().equals(statementName)) {
                            return (spec);
                        }
                    } else if (spec instanceof LibraryFnDef) {
                        if (((LibraryFnDef) spec).getName().equals(statementName)) {
                            return (spec);
                        }
                    } else if (spec instanceof UninterpretedFnDef) {
                        if (((UninterpretedFnDef) spec).getName().equals(statementName)) {
                            return (spec);
                        }
                    } else if (spec instanceof NodeDef) {
                        if (((NodeDef) spec).getName().equals(statementName)) {
                            return (spec);
                        }
                    } else if (spec instanceof LinearizationDef) {
                        if (((LinearizationDef) spec).getName().equals(statementName)) {
                            return (spec);
                        }
                    } else if (spec instanceof ConstStatement) {
                        if (((ConstStatement) spec).getName().equals(statementName)) {
                            return (spec);
                        }
                    } else if (spec instanceof EnumStatement) {
                        if (((EnumStatement) spec).getName().equals(statementName)) {
                            return (spec);
                        }
                        EList<NamedID> enums = ((EnumStatement) spec).getEnums();
                        for (NamedID nid : enums) {
                            if (nid.getName().contentEquals(statementName)) {
                                return nid;
                            }
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : AgreeContract(com.rockwellcollins.atc.agree.agree.AgreeContract) AadlPackage(org.osate.aadl2.AadlPackage) LibraryFnDef(com.rockwellcollins.atc.agree.agree.LibraryFnDef) NodeDef(com.rockwellcollins.atc.agree.agree.NodeDef) Element(org.osate.aadl2.Element) LinearizationDef(com.rockwellcollins.atc.agree.agree.LinearizationDef) SpecStatement(com.rockwellcollins.atc.agree.agree.SpecStatement) UninterpretedFnDef(com.rockwellcollins.atc.agree.agree.UninterpretedFnDef) Namespace(org.osate.aadl2.Namespace) NamedID(com.rockwellcollins.atc.agree.agree.NamedID) FnDef(com.rockwellcollins.atc.agree.agree.FnDef) LibraryFnDef(com.rockwellcollins.atc.agree.agree.LibraryFnDef) UninterpretedFnDef(com.rockwellcollins.atc.agree.agree.UninterpretedFnDef) ConstStatement(com.rockwellcollins.atc.agree.agree.ConstStatement) EList(org.eclipse.emf.common.util.EList) PackageRename(org.osate.aadl2.PackageRename) EnumStatement(com.rockwellcollins.atc.agree.agree.EnumStatement) PropertySet(org.osate.aadl2.PropertySet) AnnexLibrary(org.osate.aadl2.AnnexLibrary) RecordDef(com.rockwellcollins.atc.agree.agree.RecordDef)

Example 7 with NodeDef

use of com.rockwellcollins.atc.agree.agree.NodeDef in project AMASE by loonwerks.

the class FaultASTBuilder method setFaultNode.

/**
 * Add the fault node to Lustre program.
 *
 * @param faultStatement the fault statement from the annex
 * @param	fault the fault built using the fault stmt
 */
private void setFaultNode(FaultStatement faultStatement, Fault fault) {
    NodeDef defExpr = SafetyUtil.getFaultNode(faultStatement);
    // to keep consistent with AGREE, we will use the AGREE functions
    // to construct names
    String fnName = AgreeUtils.getNodeName(defExpr);
    fault.faultNode = SafetyUtil.findNode(fnName, globalLustreNodes);
    if (fault.faultNode == null) {
        // if we can get AgreeASTBuilder to
        // build us a node, we will add it to our list and return it.
        builder.caseNodeDef(defExpr);
        fault.faultNode = SafetyUtil.findNode(fnName, AgreeASTBuilder.globalNodes);
        if (fault.faultNode != null) {
            this.addGlobalLustreNode(fault.faultNode);
        } else {
            throw new SafetyException("Fault node: " + defExpr.getFullName() + " unable to find it in model.");
        }
    }
}
Also used : NodeDef(com.rockwellcollins.atc.agree.agree.NodeDef) SafetyException(edu.umn.cs.crisys.safety.analysis.SafetyException)

Example 8 with NodeDef

use of com.rockwellcollins.atc.agree.agree.NodeDef in project AMASE by loonwerks.

the class SafetyUtil method getFaultNode.

/**
 * Gets a fault node from a fault statement.
 * @param faultStatement fault definition statement created by user.
 * @return NodeDef object referenced in fault statement
 */
public static NodeDef getFaultNode(FaultStatement faultStatement) {
    // defName: faults.fail_to
    DoubleDotRef defName = faultStatement.getFaultDefName();
    // defNameSub: fail_to
    NamedElement defNameField = null;
    if (defName != null) {
        defNameField = defName.getElm();
    } else {
        new Exception("Fault definition name in " + faultStatement.getName() + " is not allowed.");
    }
    if (!(defNameField instanceof NodeDef)) {
        new Exception("Fault node definition is not working correctly. " + "A possible reason is that the project needs to be cleaned.");
    } else {
        return (NodeDef) defNameField;
    }
    return null;
}
Also used : NodeDef(com.rockwellcollins.atc.agree.agree.NodeDef) DoubleDotRef(com.rockwellcollins.atc.agree.agree.DoubleDotRef) NamedElement(org.osate.aadl2.NamedElement) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException)

Example 9 with NodeDef

use of com.rockwellcollins.atc.agree.agree.NodeDef in project AMASE by loonwerks.

the class SafetyValidator method getNodeReturnArgs.

/**
 * Method finds return values of fault node given a fault statement.
 * @param fStmt
 * @return List<Arg> of return arguments.
 */
private List<Arg> getNodeReturnArgs(FaultStatement fStmt) {
    List<Arg> returnArgs = new ArrayList<Arg>();
    NodeDef nodeDef = null;
    try {
        nodeDef = SafetyUtil.getFaultNode(fStmt);
    } catch (IllegalArgumentException e) {
        return null;
    }
    // Get the return values
    if (nodeDef != null) {
        returnArgs = nodeDef.getRets();
    } else {
        return null;
    }
    return returnArgs;
}
Also used : NodeDef(com.rockwellcollins.atc.agree.agree.NodeDef) Arg(com.rockwellcollins.atc.agree.agree.Arg) ArrayList(java.util.ArrayList)

Example 10 with NodeDef

use of com.rockwellcollins.atc.agree.agree.NodeDef 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.");
    }
}
Also used : NodeDef(com.rockwellcollins.atc.agree.agree.NodeDef) ArrayList(java.util.ArrayList) FaultStatement(edu.umn.cs.crisys.safety.safety.FaultStatement) HWFaultStatement(edu.umn.cs.crisys.safety.safety.HWFaultStatement) PropertyImpl(org.osate.aadl2.impl.PropertyImpl) RealLitExpr(com.rockwellcollins.atc.agree.agree.RealLitExpr) UnaryExpr(com.rockwellcollins.atc.agree.agree.UnaryExpr) Expr(com.rockwellcollins.atc.agree.agree.Expr) PrevExpr(com.rockwellcollins.atc.agree.agree.PrevExpr) BoolLitExpr(com.rockwellcollins.atc.agree.agree.BoolLitExpr) IntLitExpr(com.rockwellcollins.atc.agree.agree.IntLitExpr) NamedElmExpr(com.rockwellcollins.atc.agree.agree.NamedElmExpr) DataTypeImpl(org.osate.aadl2.impl.DataTypeImpl) EObject(org.eclipse.emf.ecore.EObject) DoubleDotRef(com.rockwellcollins.atc.agree.agree.DoubleDotRef) Arg(com.rockwellcollins.atc.agree.agree.Arg) DoubleDotRefImpl(com.rockwellcollins.atc.agree.agree.impl.DoubleDotRefImpl) NamedElement(org.osate.aadl2.NamedElement) Check(org.eclipse.xtext.validation.Check)

Aggregations

NodeDef (com.rockwellcollins.atc.agree.agree.NodeDef)19 NamedElement (org.osate.aadl2.NamedElement)10 Arg (com.rockwellcollins.atc.agree.agree.Arg)7 Check (org.eclipse.xtext.validation.Check)7 DoubleDotRef (com.rockwellcollins.atc.agree.agree.DoubleDotRef)6 LibraryFnDef (com.rockwellcollins.atc.agree.agree.LibraryFnDef)6 FnDef (com.rockwellcollins.atc.agree.agree.FnDef)5 NamedElmExpr (com.rockwellcollins.atc.agree.agree.NamedElmExpr)5 RecordDef (com.rockwellcollins.atc.agree.agree.RecordDef)5 BoolLitExpr (com.rockwellcollins.atc.agree.agree.BoolLitExpr)4 ConstStatement (com.rockwellcollins.atc.agree.agree.ConstStatement)4 Expr (com.rockwellcollins.atc.agree.agree.Expr)4 LinearizationDef (com.rockwellcollins.atc.agree.agree.LinearizationDef)4 RealLitExpr (com.rockwellcollins.atc.agree.agree.RealLitExpr)4 UninterpretedFnDef (com.rockwellcollins.atc.agree.agree.UninterpretedFnDef)4 ArrayList (java.util.ArrayList)4 BinaryExpr (com.rockwellcollins.atc.agree.agree.BinaryExpr)3 CallExpr (com.rockwellcollins.atc.agree.agree.CallExpr)3 NodeBodyExpr (com.rockwellcollins.atc.agree.agree.NodeBodyExpr)3 EObject (org.eclipse.emf.ecore.EObject)3