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;
}
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.");
}
}
}
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;
}
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;
}
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.");
}
}
Aggregations