Search in sources :

Example 16 with AgreeException

use of com.rockwellcollins.atc.agree.analysis.AgreeException in project AGREE by loonwerks.

the class LustreContractAstBuilder method addCondactCall.

protected static void addCondactCall(AgreeNode agreeNode, String nodePrefix, List<AgreeVar> inputs, List<AgreeStatement> assertions, AgreeNode subAgreeNode, String prefix, Expr clockExpr, Node lustreNode) {
    List<Expr> inputIds = new ArrayList<>();
    List<Expr> initOutputsVals = new ArrayList<>();
    List<IdExpr> nodeOutputIds = new ArrayList<>();
    for (VarDecl var : lustreNode.inputs) {
        inputIds.add(new IdExpr(prefix + var.id));
    }
    for (VarDecl var : lustreNode.outputs) {
        AgreeVar outputVar = (AgreeVar) var;
        String dummyName = prefix + var.id + "__DUMMY";
        AgreeVar dummyVar = new AgreeVar(dummyName, outputVar.type, outputVar.reference, outputVar.compInst, outputVar.featInst);
        if (!inputs.contains(dummyVar)) {
            inputs.add(dummyVar);
        }
        initOutputsVals.add(new IdExpr(dummyName));
        nodeOutputIds.add(new IdExpr(prefix + var.id));
    }
    if (agreeNode.timing == TimingModel.LATCHED) {
        throw new AgreeException("check how we do this in the generic lustre translation now" + " to make sure that it is correct");
    }
    Expr condactExpr = new CondactExpr(clockExpr, new NodeCallExpr(lustreNode.id, inputIds), initOutputsVals);
    Expr condactOutput;
    if (nodeOutputIds.size() > 1) {
        condactOutput = new TupleExpr(nodeOutputIds);
    } else {
        condactOutput = nodeOutputIds.get(0);
    }
    Expr condactCall = new BinaryExpr(condactOutput, BinaryOp.EQUAL, condactExpr);
    assertions.add(new AgreeStatement("", condactCall, null));
}
Also used : AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) IdExpr(jkind.lustre.IdExpr) CondactExpr(jkind.lustre.CondactExpr) BinaryExpr(jkind.lustre.BinaryExpr) ArrayList(java.util.ArrayList) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar) TupleExpr(jkind.lustre.TupleExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) TupleExpr(jkind.lustre.TupleExpr) UnaryExpr(jkind.lustre.UnaryExpr) CondactExpr(jkind.lustre.CondactExpr) Expr(jkind.lustre.Expr) IdExpr(jkind.lustre.IdExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) VarDecl(jkind.lustre.VarDecl) NodeCallExpr(jkind.lustre.NodeCallExpr) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException)

Example 17 with AgreeException

use of com.rockwellcollins.atc.agree.analysis.AgreeException in project AGREE by loonwerks.

the class LustreContractAstBuilder method getContractLustreProgram.

public static Program getContractLustreProgram(AgreeProgram agreeProgram) {
    nodes = new ArrayList<>();
    List<TypeDef> types = AgreeUtils.getLustreTypes(agreeProgram);
    AgreeNode flatNode = flattenAgreeNodeKindContract(agreeProgram.topNode, "_TOP__");
    List<Expr> assertions = new ArrayList<>();
    List<VarDecl> locals = new ArrayList<>();
    List<VarDecl> inputs = new ArrayList<>();
    List<VarDecl> outputs = new ArrayList<>();
    List<Equation> equations = new ArrayList<>();
    List<String> properties = new ArrayList<>();
    List<Expr> requires = new ArrayList<>();
    List<Expr> ensures = new ArrayList<>();
    for (AgreeStatement assertion : flatNode.assertions) {
        assertions.add(assertion.expr);
    }
    for (AgreeStatement assumption : flatNode.assumptions) {
        requires.add(assumption.expr);
    }
    for (AgreeStatement guarantee : flatNode.lemmas) {
        ensures.add(guarantee.expr);
    }
    for (AgreeStatement guarantee : flatNode.guarantees) {
        ensures.add(guarantee.expr);
    }
    for (AgreeVar var : flatNode.inputs) {
        inputs.add(var);
    }
    for (AgreeVar var : flatNode.outputs) {
        outputs.add(var);
    }
    for (AgreeVar var : flatNode.outputs) {
        if (var.reference instanceof AssumeStatement || var.reference instanceof LemmaStatement) {
            throw new AgreeException("This shouldn't happen");
        }
    }
    Contract contract = new Contract(requires, ensures);
    NodeBuilder builder = new NodeBuilder("_TOP");
    builder.addInputs(inputs);
    builder.addOutputs(outputs);
    builder.addLocals(locals);
    builder.addEquations(equations);
    builder.addProperties(properties);
    builder.addAssertions(assertions);
    builder.setContract(contract);
    Node main = builder.build();
    nodes.addAll(agreeProgram.globalLustreNodes);
    nodes.add(main);
    Program program = new ProgramBuilder().addTypes(types).addNodes(nodes).setMain(main.id).build();
    return program;
}
Also used : AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) Program(jkind.lustre.Program) AgreeProgram(com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram) AssumeStatement(com.rockwellcollins.atc.agree.agree.AssumeStatement) ProgramBuilder(jkind.lustre.builders.ProgramBuilder) AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) Node(jkind.lustre.Node) ArrayList(java.util.ArrayList) Equation(jkind.lustre.Equation) NodeBuilder(jkind.lustre.builders.NodeBuilder) AgreeNodeBuilder(com.rockwellcollins.atc.agree.analysis.ast.AgreeNodeBuilder) LemmaStatement(com.rockwellcollins.atc.agree.agree.LemmaStatement) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar) TypeDef(jkind.lustre.TypeDef) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) TupleExpr(jkind.lustre.TupleExpr) UnaryExpr(jkind.lustre.UnaryExpr) CondactExpr(jkind.lustre.CondactExpr) Expr(jkind.lustre.Expr) IdExpr(jkind.lustre.IdExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) VarDecl(jkind.lustre.VarDecl) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) Contract(jkind.lustre.Contract)

Example 18 with AgreeException

use of com.rockwellcollins.atc.agree.analysis.AgreeException in project AGREE by loonwerks.

the class LustreContractAstBuilder method addInputsAndOutputs.

protected static void addInputsAndOutputs(List<AgreeVar> inputs, List<AgreeVar> outputs, AgreeNode subAgreeNode, Node lustreNode, String prefix) {
    for (AgreeVar var : subAgreeNode.inputs) {
        AgreeVar input = new AgreeVar(prefix + var.id, var.type, var.reference, var.compInst, var.featInst);
        inputs.add(input);
    }
    for (AgreeVar var : subAgreeNode.outputs) {
        AgreeVar output = new AgreeVar(prefix + var.id, var.type, var.reference, var.compInst, var.featInst);
        outputs.add(output);
    }
    // }
    if (!subAgreeNode.locals.isEmpty()) {
        throw new AgreeException("What is an example of this?");
    }
    inputs.add(subAgreeNode.clockVar);
}
Also used : AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)

Example 19 with AgreeException

use of com.rockwellcollins.atc.agree.analysis.AgreeException in project AGREE by loonwerks.

the class AgreePatternBuilder method getIntervalType.

private AgreePatternInterval getIntervalType(TimeInterval interval) {
    if (interval == null) {
        return null;
    }
    Expr low = builder.doSwitch(interval.getLow());
    Expr high = builder.doSwitch(interval.getHigh());
    IntervalType type;
    if (interval instanceof OpenTimeInterval) {
        type = IntervalType.OPEN;
    } else if (interval instanceof OpenLeftTimeInterval) {
        type = IntervalType.OPEN_LEFT;
    } else if (interval instanceof OpenRightTimeInterval) {
        type = IntervalType.OPEN_RIGHT;
    } else if (interval instanceof ClosedTimeInterval) {
        type = IntervalType.CLOSED;
    } else {
        throw new AgreeException("Unhandled TimeInterval type: " + interval.getClass());
    }
    return new AgreePatternInterval(type, low, high);
}
Also used : ClosedTimeInterval(com.rockwellcollins.atc.agree.agree.ClosedTimeInterval) Expr(jkind.lustre.Expr) IntExpr(jkind.lustre.IntExpr) IdExpr(jkind.lustre.IdExpr) IntervalType(com.rockwellcollins.atc.agree.analysis.realtime.AgreePatternInterval.IntervalType) OpenLeftTimeInterval(com.rockwellcollins.atc.agree.agree.OpenLeftTimeInterval) OpenRightTimeInterval(com.rockwellcollins.atc.agree.agree.OpenRightTimeInterval) OpenTimeInterval(com.rockwellcollins.atc.agree.agree.OpenTimeInterval) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException)

Example 20 with AgreeException

use of com.rockwellcollins.atc.agree.analysis.AgreeException in project AGREE by loonwerks.

the class AgreePatternBuilder method caseWhenOccursStatment.

@Override
public AgreeStatement caseWhenOccursStatment(WhenOccursStatment object) {
    IdExpr condition = (IdExpr) builder.doSwitch(object.getCondition());
    IdExpr effect = (IdExpr) builder.doSwitch(object.getEvent());
    Expr timesExpr = builder.doSwitch(object.getTimes());
    boolean exclusive = object.getExcl() != null;
    if (!(timesExpr instanceof IntExpr)) {
        throw new AgreeException("Expected an integer literal in 'When Occurs' pattern");
    }
    BigInteger times = ((IntExpr) timesExpr).value;
    AgreePatternInterval interval = getIntervalType(object.getInterval());
    return new AgreeTimesPattern(str, ref, exclusive, condition, effect, interval, null, TriggerType.CONDITION, TriggerType.CONDITION, times, null);
}
Also used : IdExpr(jkind.lustre.IdExpr) Expr(jkind.lustre.Expr) IntExpr(jkind.lustre.IntExpr) IdExpr(jkind.lustre.IdExpr) BigInteger(java.math.BigInteger) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) IntExpr(jkind.lustre.IntExpr)

Aggregations

AgreeException (com.rockwellcollins.atc.agree.analysis.AgreeException)47 IdExpr (jkind.lustre.IdExpr)23 Expr (jkind.lustre.Expr)21 BinaryExpr (jkind.lustre.BinaryExpr)19 BoolExpr (jkind.lustre.BoolExpr)18 NodeCallExpr (jkind.lustre.NodeCallExpr)18 UnaryExpr (jkind.lustre.UnaryExpr)18 ArrayList (java.util.ArrayList)16 IntExpr (jkind.lustre.IntExpr)15 ComponentImplementation (org.osate.aadl2.ComponentImplementation)13 SelectionExpr (com.rockwellcollins.atc.agree.agree.SelectionExpr)12 IfThenElseExpr (jkind.lustre.IfThenElseExpr)12 GetPropertyExpr (com.rockwellcollins.atc.agree.agree.GetPropertyExpr)11 IntLitExpr (com.rockwellcollins.atc.agree.agree.IntLitExpr)11 NamedElmExpr (com.rockwellcollins.atc.agree.agree.NamedElmExpr)11 RealLitExpr (com.rockwellcollins.atc.agree.agree.RealLitExpr)11 ArrayLiteralExpr (com.rockwellcollins.atc.agree.agree.ArrayLiteralExpr)10 ArraySubExpr (com.rockwellcollins.atc.agree.agree.ArraySubExpr)10 ArrayUpdateExpr (com.rockwellcollins.atc.agree.agree.ArrayUpdateExpr)10 BoolLitExpr (com.rockwellcollins.atc.agree.agree.BoolLitExpr)10