Search in sources :

Example 16 with Expression

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

the class VerdictLustreListener method exitIntExpr.

/**
 * Extract an int literal.
 */
@Override
public void exitIntExpr(LustreParser.IntExprContext ctx) {
    ctx.expression = new Expression();
    ctx.expression.setIntLiteral(new BigInteger(ctx.INT().getText()));
}
Also used : Expression(verdict.vdm.vdm_lustre.Expression) BigInteger(java.math.BigInteger)

Example 17 with Expression

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

the class VerdictLustreListener method exitBoolExpr.

/**
 * Extract a bool literal.
 */
@Override
public void exitBoolExpr(LustreParser.BoolExprContext ctx) {
    ctx.expression = new Expression();
    ctx.expression.setBoolLiteral(Boolean.valueOf(ctx.BOOL().getText()));
}
Also used : Expression(verdict.vdm.vdm_lustre.Expression)

Example 18 with Expression

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

the class VerdictLustreListener method exitNaryExpr.

/**
 * Extract a nary expression.
 */
@Override
public void exitNaryExpr(LustreParser.NaryExprContext ctx) {
    ExpressionList expressionList = new ExpressionList();
    ctx.expr().forEach(e -> expressionList.getExpression().add(e.expression));
    ctx.expression = new Expression();
    switch(ctx.op.getText()) {
        case "#":
            ctx.expression.setDiese(expressionList);
            break;
        case "nor":
            ctx.expression.setNor(expressionList);
            break;
    }
}
Also used : Expression(verdict.vdm.vdm_lustre.Expression) ExpressionList(verdict.vdm.vdm_lustre.ExpressionList)

Example 19 with Expression

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

the class VerdictLustreListener method exitRecordExpr.

/**
 * Extract a record literal.
 */
@Override
public void exitRecordExpr(LustreParser.RecordExprContext ctx) {
    RecordLiteral recordLiteral = new RecordLiteral();
    recordLiteral.setRecordType(ctx.ID().getText());
    ctx.fieldExpr().forEach(f -> recordLiteral.getFieldDefinition().add(f.fieldDefinition));
    ctx.expression = new Expression();
    ctx.expression.setRecordLiteral(recordLiteral);
}
Also used : RecordLiteral(verdict.vdm.vdm_lustre.RecordLiteral) Expression(verdict.vdm.vdm_lustre.Expression)

Example 20 with Expression

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

the class VDM2Lustre method visit.

public void visit(ComponentType componentType, NodeBody nodeBody, String componentInstanceID, boolean impl_type) {
    // Rename componentType
    String cmpName = componentType.getName();
    cmpName = cmpName.replace(".", "_dot_");
    cmpName = cmpName.replace("::", "_double_colon_");
    componentType.setName(cmpName);
    // Node Equation
    NodeEquation node_eq = new NodeEquation();
    // Return variables
    NodeEquationLHS eq_lhs = new NodeEquationLHS();
    // Node Call
    Expression node = new Expression();
    NodeCall nodeCall = new NodeCall();
    if (impl_type) {
        nodeCall.setNodeId(componentType.getName() + "_dot_Impl");
    } else {
        nodeCall.setNodeId(componentType.getName());
    }
    // Port
    for (Port port : componentType.getPort()) {
        // //Event Port Definition
        // for (Port port : componentType.getPort()) {
        // visit(port);
        // }
        // MODE
        PortMode port_mode = port.getMode();
        if (port_mode == PortMode.IN) {
            Expression arg = new Expression();
            arg.setIdentifier(port.getName());
            nodeCall.getArgument().add(arg);
        }
        if (port_mode == PortMode.OUT) {
            VariableDeclaration var = new VariableDeclaration();
            // Node Name
            String output_name = port.getName();
            String var_name = componentInstanceID + "_port_" + output_name;
            var.setName(var_name);
            // Node DataType
            DataType dataType = port.getType();
            var.setDataType(dataType);
            nodeBody.getVariableDeclaration().add(var);
            eq_lhs.getIdentifier().add(var_name);
        }
    }
    // Ignore node call that do not have output
    if (eq_lhs.getIdentifier() != null) {
        node.setCall(nodeCall);
        node_eq.setRhs(node);
        node_eq.setLhs(eq_lhs);
        nodeBody.getEquation().add(node_eq);
    }
}
Also used : NodeEquation(verdict.vdm.vdm_lustre.NodeEquation) NodeCall(verdict.vdm.vdm_lustre.NodeCall) Expression(verdict.vdm.vdm_lustre.Expression) PortMode(verdict.vdm.vdm_model.PortMode) CompInstancePort(verdict.vdm.vdm_model.CompInstancePort) Port(verdict.vdm.vdm_model.Port) NodeEquationLHS(verdict.vdm.vdm_lustre.NodeEquationLHS) DataType(verdict.vdm.vdm_data.DataType) VariableDeclaration(verdict.vdm.vdm_lustre.VariableDeclaration)

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