Search in sources :

Example 26 with Expression

use of verdict.vdm.vdm_lustre.Expression in project VERDICT by ge-high-assurance.

the class VDM2Lustre method recordLiteral.

public void recordLiteral(Expression expr) {
    if (expr != null) {
        RecordLiteral recordLiteral = expr.getRecordLiteral();
        if (recordLiteral != null) {
            String identifier = recordLiteral.getRecordType();
            identifier = identifier.replace(".", "_dot_");
            identifier = identifier.replace("::", "_double_colon_");
            recordLiteral.setRecordType(identifier);
            for (FieldDefinition fieldDef : recordLiteral.getFieldDefinition()) {
                expr = fieldDef.getFieldValue();
                recordLiteral(expr);
            }
        } else {
            BinaryOperation op = expr.getEqual();
            if (op == null) {
                op = expr.getNotEqual();
                if (op == null) {
                    op = expr.getAnd();
                    if (op == null) {
                        op = expr.getImplies();
                    }
                }
            }
            if (op != null) {
                Expression lhs_expr = op.getLhsOperand();
                recordLiteral(lhs_expr);
                Expression rhs_expr = op.getRhsOperand();
                recordLiteral(rhs_expr);
            }
            Expression not_expr = expr.getNot();
            if (not_expr != null) {
                recordLiteral(not_expr);
            } else {
                Expression pre_expr = expr.getPre();
                recordLiteral(pre_expr);
            }
            NodeCall nodeCall = expr.getCall();
            if (nodeCall != null) {
                for (Expression arg : nodeCall.getArgument()) {
                    recordLiteral(arg);
                }
            }
        }
    }
}
Also used : RecordLiteral(verdict.vdm.vdm_lustre.RecordLiteral) NodeCall(verdict.vdm.vdm_lustre.NodeCall) Expression(verdict.vdm.vdm_lustre.Expression) BinaryOperation(verdict.vdm.vdm_lustre.BinaryOperation) FieldDefinition(verdict.vdm.vdm_lustre.FieldDefinition)

Example 27 with Expression

use of verdict.vdm.vdm_lustre.Expression in project VERDICT by ge-high-assurance.

the class VDM2Lustre method visit.

// 1) Node signature +/- contract
// a) Imported Node (Contract, no Implementation)
// b) Node Impl
// c) Node Impl + contract
// d) @TODO: no Contract, no Implementation -- (*@contract gurantee true*)
public Node visit(ComponentType componentType, boolean is_implemented) {
    Node node = new Node();
    String identifier = componentType.getName();
    // Replace dot identifier to support lustre naming compliance
    identifier = identifier.replace(".", "_dot_");
    identifier = identifier.replace("::", "_double_colon_");
    if (is_implemented) {
        identifier += "_dot_Impl";
    } else {
        // Imported Node
        node.setIsImported(true);
    // System.out.println("Imported Nodes:" +identifier );
    }
    node.setName(identifier);
    for (Port port : componentType.getPort()) {
        if (port.isEvent() != null && port.isEvent()) {
            this.eventDeclarations.put(port.getName(), port.getType());
        }
        visit(port, node);
    }
    // + Contract (Optional)
    ContractSpec contractSpec = componentType.getContract();
    if (is_implemented == false && contractSpec == null) {
        // Rename output renaming to avoid Duplicate.
        // List<NodeParameter> node_parameters = node.getOutputParameter();
        // for (NodeParameter instrumented_param : node_parameters) {
        // String param_identifier = instrumented_param.getName();
        // instrumented_param.setName(param_identifier + "_intrumented");
        // }
        ContractItem true_guarantee_item = new ContractItem();
        Expression true_expr = new Expression();
        Boolean true_lit = Boolean.TRUE;
        true_expr.setBoolLiteral(true_lit);
        true_guarantee_item.setExpression(true_expr);
        contractSpec = new ContractSpec();
        contractSpec.getGuarantee().add(true_guarantee_item);
        componentType.setContract(contractSpec);
    }
    if (contractSpec != null) {
        visit(contractSpec);
        if (contractSpec.getGuarantee().size() != 0) {
            node.setContract(contractSpec);
            this.eventDeclarations.clear();
        }
    }
    return node;
}
Also used : ContractItem(verdict.vdm.vdm_lustre.ContractItem) Expression(verdict.vdm.vdm_lustre.Expression) Node(verdict.vdm.vdm_lustre.Node) CompInstancePort(verdict.vdm.vdm_model.CompInstancePort) Port(verdict.vdm.vdm_model.Port) ContractSpec(verdict.vdm.vdm_lustre.ContractSpec)

Example 28 with Expression

use of verdict.vdm.vdm_lustre.Expression in project VERDICT by ge-high-assurance.

the class VDM2Lustre method visit.

public void visit(ContractItem contractItem) {
    Expression expr = contractItem.getExpression();
    expr = visitExpression(expr);
    contractItem.setExpression(expr);
    recordLiteral(expr);
}
Also used : Expression(verdict.vdm.vdm_lustre.Expression)

Example 29 with Expression

use of verdict.vdm.vdm_lustre.Expression in project VERDICT by ge-high-assurance.

the class VDMInstrumentor method xor_expr.

protected Expression xor_expr(String i_id, String j_id) {
    Expression amo_expr = new Expression();
    Expression expr_i = new Expression();
    expr_i.setIdentifier(i_id);
    Expression expr_j = new Expression();
    expr_j.setIdentifier(j_id);
    Expression notexpr_i = new Expression();
    notexpr_i.setNot(expr_i);
    Expression notexpr_j = new Expression();
    notexpr_j.setNot(expr_j);
    BinaryOperation or_op = new BinaryOperation();
    or_op.setLhsOperand(notexpr_i);
    or_op.setRhsOperand(notexpr_j);
    amo_expr.setOr(or_op);
    return amo_expr;
}
Also used : Expression(verdict.vdm.vdm_lustre.Expression) BinaryOperation(verdict.vdm.vdm_lustre.BinaryOperation)

Example 30 with Expression

use of verdict.vdm.vdm_lustre.Expression in project VERDICT by ge-high-assurance.

the class VDMInstrumentor method and_expr.

protected Expression and_expr(Stack<Expression> expr_stack) {
    while (expr_stack.size() > 1) {
        Expression left_expr = expr_stack.pop();
        Expression right_expr = expr_stack.pop();
        BinaryOperation and_op = new BinaryOperation();
        and_op.setLhsOperand(left_expr);
        and_op.setRhsOperand(right_expr);
        Expression and_expr = new Expression();
        and_expr.setAnd(and_op);
        expr_stack.push(and_expr);
    }
    return expr_stack.pop();
}
Also used : Expression(verdict.vdm.vdm_lustre.Expression) BinaryOperation(verdict.vdm.vdm_lustre.BinaryOperation)

Aggregations

Expression (verdict.vdm.vdm_lustre.Expression)45 ContractItem (verdict.vdm.vdm_lustre.ContractItem)9 BinaryOperation (verdict.vdm.vdm_lustre.BinaryOperation)8 NodeCall (verdict.vdm.vdm_lustre.NodeCall)7 DataType (verdict.vdm.vdm_data.DataType)6 ComponentType (verdict.vdm.vdm_model.ComponentType)6 PropertyExpression (org.osate.aadl2.PropertyExpression)5 ConstantDeclaration (verdict.vdm.vdm_lustre.ConstantDeclaration)5 IfThenElse (verdict.vdm.vdm_lustre.IfThenElse)5 NodeEquation (verdict.vdm.vdm_lustre.NodeEquation)5 RecordLiteral (verdict.vdm.vdm_lustre.RecordLiteral)5 SymbolDefinition (verdict.vdm.vdm_lustre.SymbolDefinition)5 CompInstancePort (verdict.vdm.vdm_model.CompInstancePort)5 ComponentImpl (verdict.vdm.vdm_model.ComponentImpl)5 Port (verdict.vdm.vdm_model.Port)5 BinaryExpr (com.rockwellcollins.atc.agree.agree.BinaryExpr)4 BoolLitExpr (com.rockwellcollins.atc.agree.agree.BoolLitExpr)4 CallExpr (com.rockwellcollins.atc.agree.agree.CallExpr)4 EnumLitExpr (com.rockwellcollins.atc.agree.agree.EnumLitExpr)4 EventExpr (com.rockwellcollins.atc.agree.agree.EventExpr)4