use of com.ge.research.osate.verdict.dsl.verdict.LExpr in project VERDICT by ge-high-assurance.
the class Aadl2Vdm method handleAndCyberExpr.
/**
* to handle LAnd expressions while creating a CyberExpr object
* @param andExpr
* @param allPortNames
* @param allPortCIAs
* @return
*/
verdict.vdm.vdm_model.CyberExpr handleAndCyberExpr(LAnd andExpr, List<String> allPortNames, List<String> allPortCIAs) {
// to pack this CyberExpr
verdict.vdm.vdm_model.CyberExpr packCyberExpr = new verdict.vdm.vdm_model.CyberExpr();
if (andExpr.getExprs().size() == 1) {
// Is a Port or a Not
LExpr subAndExpr = andExpr.getExprs().get(0);
if (subAndExpr instanceof LPort) {
verdict.vdm.vdm_model.CIAPort port = handleCIAPort(subAndExpr, allPortNames, allPortCIAs);
// setting "port" field of packCyberExp
packCyberExpr.setPort(port);
} else if (subAndExpr instanceof LNot) {
verdict.vdm.vdm_model.CyberExprKind kind = verdict.vdm.vdm_model.CyberExprKind.fromValue("Not");
// setting "kind" of expression
packCyberExpr.setKind(kind);
// send to handler for not expressions
verdict.vdm.vdm_model.CyberExpr packNotCyberExpr = handleNotCyberExpr((LNot) subAndExpr, allPortNames, allPortCIAs);
// set the "not" of packCyberExpr
packCyberExpr.setNot(packNotCyberExpr);
} else if (subAndExpr instanceof LOr) {
/**
* If it is a single conjunct, just send it to handleOrCyberExpr
* and return the same package returned by handleAndCyberExpr
*/
packCyberExpr = handleOrCyberExpr(subAndExpr, allPortNames, allPortCIAs);
}
} else if (andExpr.getExprs().size() > 1) {
// collection of conjuncts
verdict.vdm.vdm_model.CyberExprKind kind = verdict.vdm.vdm_model.CyberExprKind.fromValue("And");
// setting "kind" of expression
packCyberExpr.setKind(kind);
// to pack all conjunct subexpressions in a single list
verdict.vdm.vdm_model.CyberExprList packOrList = new verdict.vdm.vdm_model.CyberExprList();
for (LExpr expr : andExpr.getExprs()) {
// for each conjunct (each disjunct is a LExpr)
// to pack the CyberExpr for this conjunct
verdict.vdm.vdm_model.CyberExpr packConjunctCyberExpr = handleOrCyberExpr(expr, allPortNames, allPortCIAs);
// adding to the list of conjuncts
packOrList.getExpr().add(packConjunctCyberExpr);
}
// setting the "or" field of packCyberExpr
packCyberExpr.setAnd(packOrList);
}
return packCyberExpr;
}
use of com.ge.research.osate.verdict.dsl.verdict.LExpr in project VERDICT by ge-high-assurance.
the class Aadl2CsvTranslator method extractPortsFromAndExpr.
void extractPortsFromAndExpr(LAnd andExpr, List<String> allPortNames, List<String> allPortCIAs) {
StringBuilder portEventNames = new StringBuilder();
StringBuilder cias = new StringBuilder();
for (int i = 0; i < andExpr.getExprs().size(); ++i) {
LExpr subAndExpr = andExpr.getExprs().get(i);
if (subAndExpr instanceof LPort) {
portEventNames.append(((LPort) subAndExpr).getPort());
cias.append(convertAbbreviation(((LPort) subAndExpr).getCia().getLiteral()));
// We probably need to change this to support nested conjunction expressions
} else {
throw new RuntimeException("MBAA does not support parsing nested safety relation expression: " + subAndExpr);
}
if (i < andExpr.getExprs().size() - 1) {
portEventNames.append(";");
cias.append(";");
}
}
allPortNames.add(portEventNames.toString());
allPortCIAs.add(cias.toString());
}
Aggregations