Search in sources :

Example 1 with LOr

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;
}
Also used : ArrayList(java.util.ArrayList) LAnd(com.ge.research.osate.verdict.dsl.verdict.LAnd) SLAnd(com.ge.research.osate.verdict.dsl.verdict.SLAnd) LOr(com.ge.research.osate.verdict.dsl.verdict.LOr) SLOr(com.ge.research.osate.verdict.dsl.verdict.SLOr)

Example 2 with LOr

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;
}
Also used : LNot(com.ge.research.osate.verdict.dsl.verdict.LNot) SLNot(com.ge.research.osate.verdict.dsl.verdict.SLNot) LOr(com.ge.research.osate.verdict.dsl.verdict.LOr) SLOr(com.ge.research.osate.verdict.dsl.verdict.SLOr) SLExpr(com.ge.research.osate.verdict.dsl.verdict.SLExpr) LExpr(com.ge.research.osate.verdict.dsl.verdict.LExpr) SLPort(com.ge.research.osate.verdict.dsl.verdict.SLPort) LPort(com.ge.research.osate.verdict.dsl.verdict.LPort)

Example 3 with LOr

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;
}
Also used : LNot(com.ge.research.osate.verdict.dsl.verdict.LNot) SLNot(com.ge.research.osate.verdict.dsl.verdict.SLNot) LAnd(com.ge.research.osate.verdict.dsl.verdict.LAnd) SLAnd(com.ge.research.osate.verdict.dsl.verdict.SLAnd) LOr(com.ge.research.osate.verdict.dsl.verdict.LOr) SLOr(com.ge.research.osate.verdict.dsl.verdict.SLOr) SLPort(com.ge.research.osate.verdict.dsl.verdict.SLPort) LPort(com.ge.research.osate.verdict.dsl.verdict.LPort)

Aggregations

LOr (com.ge.research.osate.verdict.dsl.verdict.LOr)3 SLOr (com.ge.research.osate.verdict.dsl.verdict.SLOr)3 LAnd (com.ge.research.osate.verdict.dsl.verdict.LAnd)2 LNot (com.ge.research.osate.verdict.dsl.verdict.LNot)2 LPort (com.ge.research.osate.verdict.dsl.verdict.LPort)2 SLAnd (com.ge.research.osate.verdict.dsl.verdict.SLAnd)2 SLNot (com.ge.research.osate.verdict.dsl.verdict.SLNot)2 SLPort (com.ge.research.osate.verdict.dsl.verdict.SLPort)2 LExpr (com.ge.research.osate.verdict.dsl.verdict.LExpr)1 SLExpr (com.ge.research.osate.verdict.dsl.verdict.SLExpr)1 ArrayList (java.util.ArrayList)1