Search in sources :

Example 11 with ContractItem

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

the class VerdictLustreListener method exitContractMode.

/**
 * Extract a contract mode.
 */
@Override
public void exitContractMode(LustreParser.ContractModeContext ctx) {
    ctx.mode = new ContractMode();
    ctx.mode.setName(ctx.ID().getText());
    ctx.require.forEach(require -> {
        ContractItem contractItem = new ContractItem();
        contractItem.setExpression(require.expression);
        ctx.mode.getRequire().add(contractItem);
    });
    ctx.ensure.forEach(ensure -> {
        ContractItem contractItem = new ContractItem();
        contractItem.setExpression(ensure.expression);
        ctx.mode.getEnsure().add(contractItem);
    });
}
Also used : ContractItem(verdict.vdm.vdm_lustre.ContractItem) ContractMode(verdict.vdm.vdm_lustre.ContractMode)

Example 12 with ContractItem

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

the class PrettyPrinter method visit.

public void visit(ContractMode contractMode) {
    contractMode.getName();
    sb.append(NL);
    // Ensure
    for (ContractItem contractItem : contractMode.getEnsure()) {
        sb.append(TAB);
        sb.append("require ");
        visit(contractItem);
        sb.append(";");
        sb.append(NL);
    }
    // Require
    for (ContractItem contractItem : contractMode.getRequire()) {
        sb.append(TAB);
        sb.append("ensure ");
        visit(contractItem);
        sb.append(";");
        sb.append(NL);
    }
}
Also used : ContractItem(verdict.vdm.vdm_lustre.ContractItem)

Example 13 with ContractItem

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

the class PrettyPrinter method visit.

public void visit(ContractSpec contractSpec) {
    // Symbols
    for (SymbolDefinition symbolDef : contractSpec.getSymbol()) {
        sb.append(TAB);
        sb.append("var ");
        visit(symbolDef);
        sb.append(";");
        sb.append(NL);
    }
    // Assumuptions
    for (ContractItem contractItem : contractSpec.getAssume()) {
        sb.append(TAB).append("assume ");
        visit(contractItem);
        sb.append(";");
        sb.append(NL);
    }
    sb.append(NL);
    // Guarantees
    for (ContractItem contractItem : contractSpec.getGuarantee()) {
        sb.append(TAB).append("guarantee ");
        visit(contractItem);
        sb.append(";");
        sb.append(NL);
    }
    sb.append(NL);
    // Modes
    for (ContractMode contractMode : contractSpec.getMode()) {
        sb.append(TAB).append("mode ");
        sb.append(TAB).append(" (");
        sb.append(TAB).append(NL);
        visit(contractMode);
        sb.append(";");
        sb.append(NL);
    }
    // Imports
    for (ContractImport contractImport : contractSpec.getImport()) {
        sb.append(TAB);
        sb.append("import ");
        visit(contractImport);
        sb.append(";");
        sb.append(NL);
    }
}
Also used : ContractItem(verdict.vdm.vdm_lustre.ContractItem) ContractImport(verdict.vdm.vdm_lustre.ContractImport) ContractMode(verdict.vdm.vdm_lustre.ContractMode) SymbolDefinition(verdict.vdm.vdm_lustre.SymbolDefinition)

Example 14 with ContractItem

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

the class Agree2Vdm method translateAssumeStatement.

private ContractItem translateAssumeStatement(AssumeStatement assumeStmt, HashSet<String> dataTypeDecl, HashSet<String> nodeDecl, Model model) {
    ContractItem contractItem = new ContractItem();
    contractItem.setName(assumeStmt.getStr());
    Expr agreeExpr = assumeStmt.getExpr();
    Expression vdmlustrExpr = getVdmExpressionFromAgreeExpression(agreeExpr, dataTypeDecl, nodeDecl, model);
    contractItem.setExpression(vdmlustrExpr);
    return contractItem;
}
Also used : EnumLitExpr(com.rockwellcollins.atc.agree.agree.EnumLitExpr) RealLitExpr(com.rockwellcollins.atc.agree.agree.RealLitExpr) EventExpr(com.rockwellcollins.atc.agree.agree.EventExpr) NamedElmExpr(com.rockwellcollins.atc.agree.agree.NamedElmExpr) SelectionExpr(com.rockwellcollins.atc.agree.agree.SelectionExpr) IfThenElseExpr(com.rockwellcollins.atc.agree.agree.IfThenElseExpr) PreExpr(com.rockwellcollins.atc.agree.agree.PreExpr) RecordLitExpr(com.rockwellcollins.atc.agree.agree.RecordLitExpr) BinaryExpr(com.rockwellcollins.atc.agree.agree.BinaryExpr) UnaryExpr(com.rockwellcollins.atc.agree.agree.UnaryExpr) Expr(com.rockwellcollins.atc.agree.agree.Expr) BoolLitExpr(com.rockwellcollins.atc.agree.agree.BoolLitExpr) NodeBodyExpr(com.rockwellcollins.atc.agree.agree.NodeBodyExpr) IntLitExpr(com.rockwellcollins.atc.agree.agree.IntLitExpr) CallExpr(com.rockwellcollins.atc.agree.agree.CallExpr) ContractItem(verdict.vdm.vdm_lustre.ContractItem) PropertyExpression(org.osate.aadl2.PropertyExpression) Expression(verdict.vdm.vdm_lustre.Expression)

Example 15 with ContractItem

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

the class VerdictTestInstrumentor method instrumentTests.

/**
 * Produce one affirmative and one negated guarantee for every cyber requirement in the
 * top-level system of the model.
 */
public void instrumentTests() {
    ComponentType topLevel = getTopLevelSystemType();
    List<ContractItem> guarantees = topLevel.getContract().getGuarantee();
    List<ContractItem> replaceWith = new ArrayList<>();
    for (ContractItem guarantee : guarantees) {
        String name = guarantee.getName();
        // Build negated expression
        Expression negExpr = new Expression();
        negExpr.setNot(guarantee.getExpression());
        ContractItem pos = new ContractItem();
        pos.setExpression(guarantee.getExpression());
        pos.setName("pos_" + name);
        ContractItem neg = new ContractItem();
        neg.setExpression(negExpr);
        neg.setName("neg_" + name);
        replaceWith.add(pos);
        replaceWith.add(neg);
    }
    // Remove old guarantees and use our own
    guarantees.clear();
    guarantees.addAll(replaceWith);
}
Also used : ComponentType(verdict.vdm.vdm_model.ComponentType) ContractItem(verdict.vdm.vdm_lustre.ContractItem) Expression(verdict.vdm.vdm_lustre.Expression) ArrayList(java.util.ArrayList)

Aggregations

ContractItem (verdict.vdm.vdm_lustre.ContractItem)15 Expression (verdict.vdm.vdm_lustre.Expression)9 SymbolDefinition (verdict.vdm.vdm_lustre.SymbolDefinition)5 ArrayList (java.util.ArrayList)4 ContractSpec (verdict.vdm.vdm_lustre.ContractSpec)4 ComponentImpl (verdict.vdm.vdm_model.ComponentImpl)4 ComponentType (verdict.vdm.vdm_model.ComponentType)4 PropertyExpression (org.osate.aadl2.PropertyExpression)3 ContractMode (verdict.vdm.vdm_lustre.ContractMode)3 CompInstancePort (verdict.vdm.vdm_model.CompInstancePort)3 Port (verdict.vdm.vdm_model.Port)3 BinaryExpr (com.rockwellcollins.atc.agree.agree.BinaryExpr)2 BoolLitExpr (com.rockwellcollins.atc.agree.agree.BoolLitExpr)2 CallExpr (com.rockwellcollins.atc.agree.agree.CallExpr)2 EnumLitExpr (com.rockwellcollins.atc.agree.agree.EnumLitExpr)2 EventExpr (com.rockwellcollins.atc.agree.agree.EventExpr)2 Expr (com.rockwellcollins.atc.agree.agree.Expr)2 IfThenElseExpr (com.rockwellcollins.atc.agree.agree.IfThenElseExpr)2 IntLitExpr (com.rockwellcollins.atc.agree.agree.IntLitExpr)2 NamedElmExpr (com.rockwellcollins.atc.agree.agree.NamedElmExpr)2