use of com.ge.research.osate.verdict.dsl.verdict.LOr in project VERDICT by ge-high-assurance.
the class Aadl2Vdm method createVdmCyberExpr.
/**
* creates a Vdm CyberExpr object and returns
* @param expr
* @return
*/
verdict.vdm.vdm_model.CyberExpr createVdmCyberExpr(LExpr expr) {
// to pack the CyberExpr and return
verdict.vdm.vdm_model.CyberExpr packCyberExpr = new verdict.vdm.vdm_model.CyberExpr();
// --------- variables for debugging
List<String> allPortNames = new ArrayList<>();
List<String> allPortCIAs = new ArrayList<>();
if (expr instanceof LOr) {
// HAS to be an LOr since LExpr can only be an LOr
if (((LOr) expr).getExprs().size() == 1) {
// Is a solo disjunct
/**
* If it is a single disjunct, just send it to handleAndCyberExpr
* and return the same package returned by handleAndCyberExpr
*/
LAnd soloAndExpr = ((LOr) expr).getExprs().get(0);
packCyberExpr = handleAndCyberExpr(soloAndExpr, allPortNames, allPortCIAs);
} else if (((LOr) expr).getExprs().size() > 1) {
verdict.vdm.vdm_model.CyberExprKind kind = verdict.vdm.vdm_model.CyberExprKind.fromValue("Or");
// setting "kind" of expression
packCyberExpr.setKind(kind);
// to pack all disjunct subexpressions in a single list
verdict.vdm.vdm_model.CyberExprList packAndList = new verdict.vdm.vdm_model.CyberExprList();
for (LAnd andExpr : ((LOr) expr).getExprs()) {
// for each disjunct (each disjunct is a LAnd)
// to pack the CyberExpr for this disjunct
verdict.vdm.vdm_model.CyberExpr packDisjunctCyberExpr = handleAndCyberExpr(andExpr, allPortNames, allPortCIAs);
// adding to the list of disjuncts
packAndList.getExpr().add(packDisjunctCyberExpr);
}
// setting the "or" field of packCyberExpr
packCyberExpr.setOr(packAndList);
}
} else {
// Should never occur, but keeping for sanity
throw new RuntimeException("Warning -- LExpr should be an LOr");
}
// return the CyberExpr
return packCyberExpr;
}
use of com.ge.research.osate.verdict.dsl.verdict.LOr 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.LOr in project VERDICT by ge-high-assurance.
the class Aadl2Vdm method handleOrCyberExpr.
/**
* to handle LOr expressions while creating a CyberExpr object
* @param orExpr
* @param allPortNames
* @param allPortCIAs
* @return
*/
verdict.vdm.vdm_model.CyberExpr handleOrCyberExpr(LExpr orExpr, List<String> allPortNames, List<String> allPortCIAs) {
// to pack this CyberExpr
verdict.vdm.vdm_model.CyberExpr packCyberExpr = new verdict.vdm.vdm_model.CyberExpr();
if (orExpr instanceof LPort) {
verdict.vdm.vdm_model.CIAPort port = handleCIAPort(orExpr, allPortNames, allPortCIAs);
// setting "port" field of packCyberExp
packCyberExpr.setPort(port);
} else if (orExpr 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 expression
verdict.vdm.vdm_model.CyberExpr packNotCyberExpr = handleNotCyberExpr((LNot) orExpr, allPortNames, allPortCIAs);
// set the "not" of packCyberExpr
packCyberExpr.setNot(packNotCyberExpr);
} else if (((LOr) orExpr).getExprs().size() == 1) {
// Is a solo disjunct
/**
* If it is a single disjunct, just send it to handleAndCyberExpr
* and return the same package returned by handleAndCyberExpr
*/
LAnd soloAndExpr = ((LOr) orExpr).getExprs().get(0);
packCyberExpr = handleAndCyberExpr(soloAndExpr, allPortNames, allPortCIAs);
} else if (((LOr) orExpr).getExprs().size() > 1) {
verdict.vdm.vdm_model.CyberExprKind kind = verdict.vdm.vdm_model.CyberExprKind.fromValue("Or");
// setting "kind" of expression
packCyberExpr.setKind(kind);
// to pack all disjunct subexpressions in a single list
verdict.vdm.vdm_model.CyberExprList packAndList = new verdict.vdm.vdm_model.CyberExprList();
for (LAnd andExpr : ((LOr) orExpr).getExprs()) {
// for each disjunct (each disjunct is a LAnd)
// to pack the CyberExpr for this disjunct
verdict.vdm.vdm_model.CyberExpr packDisjunctCyberExpr = handleAndCyberExpr(andExpr, allPortNames, allPortCIAs);
// adding to the list of disjuncts
packAndList.getExpr().add(packDisjunctCyberExpr);
}
// setting the "and" field of packCyberExpr
packCyberExpr.setOr(packAndList);
}
return packCyberExpr;
}
Aggregations