Search in sources :

Example 26 with AgreeNode

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

the class LustreAstBuilder method addSubNodeLustre.

protected static Node addSubNodeLustre(AgreeProgram agreeProgram, AgreeNode agreeNode, String nodePrefix, AgreeNode flatNode) {
    Node lustreNode = getLustreNode(flatNode, nodePrefix);
    if (agreeNode.timing == TimingModel.ASYNC || agreeNode.timing == TimingModel.LATCHED) {
        lustreNode = LustreCondactNodeVisitor.translate(agreeProgram, flatNode, lustreNode);
    }
    addToNodes(lustreNode);
    return lustreNode;
}
Also used : Node(jkind.lustre.Node) AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode)

Example 27 with AgreeNode

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

the class LustreAstBuilder method getConsistencyChecks.

public static List<Pair<String, Program>> getConsistencyChecks(AgreeProgram agreeProgram) {
    List<Pair<String, Program>> programs = new ArrayList<>();
    List<TypeDef> types = AgreeUtils.getLustreTypes(agreeProgram);
    nodes = new ArrayList<>();
    uninterpretedFcns = new ArrayList<>();
    Node topConsist = getConsistencyLustreNode(agreeProgram.topNode, false);
    // we don't want node lemmas to show up in the consistency check
    for (Node node : agreeProgram.globalLustreNodes) {
        nodes.add(removeProperties(node));
    }
    nodes.add(topConsist);
    nodes.add(getHistNode());
    nodes.addAll(AgreeRealtimeCalendarBuilder.getRealTimeNodes());
    uninterpretedFcns.addAll(agreeProgram.uninterpretedFunctions);
    Program topConsistProg = new ProgramBuilder().addTypes(types).addFunctions(uninterpretedFcns).addNodes(nodes).setMain(topConsist.id).build();
    // String topComponentName = agreeProgram.topNode.id.replace("_Instance", "");
    // programs.add(Tuples.create(topComponentName + " consistent", topConsistProg));
    programs.add(Tuples.create("This component consistent", topConsistProg));
    for (AgreeNode subNode : agreeProgram.topNode.subNodes) {
        nodes = new ArrayList<>();
        subNode = flattenAgreeNode(agreeProgram, subNode, "_TOP__");
        Node subConsistNode = getConsistencyLustreNode(subNode, true);
        for (Node node : agreeProgram.globalLustreNodes) {
            nodes.add(removeProperties(node));
        }
        nodes.add(subConsistNode);
        nodes.add(getHistNode());
        nodes.addAll(AgreeRealtimeCalendarBuilder.getRealTimeNodes());
        Program subConsistProg = new ProgramBuilder().addTypes(types).addFunctions(uninterpretedFcns).addNodes(nodes).setMain(subConsistNode.id).build();
        programs.add(Tuples.create(subNode.id + " consistent", subConsistProg));
    }
    nodes = new ArrayList<>();
    // agreeProgram = translate(agreeProgram);
    AgreeNode compositionNode = flattenAgreeNode(agreeProgram, agreeProgram.topNode, "_TOP__");
    Node topCompositionConsist = getConsistencyLustreNode(compositionNode, true);
    for (Node node : agreeProgram.globalLustreNodes) {
        nodes.add(removeProperties(node));
    }
    // nodes.addAll(agreeProgram.globalLustreNodes);
    nodes.add(topCompositionConsist);
    nodes.add(getHistNode());
    nodes.addAll(AgreeRealtimeCalendarBuilder.getRealTimeNodes());
    Program topCompositConsistProg = new ProgramBuilder().addTypes(types).addFunctions(uninterpretedFcns).addNodes(nodes).setMain(topCompositionConsist.id).build();
    programs.add(Tuples.create("Component composition consistent", topCompositConsistProg));
    return programs;
}
Also used : Program(jkind.lustre.Program) AgreeProgram(com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram) AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) TypeDef(jkind.lustre.TypeDef) ProgramBuilder(jkind.lustre.builders.ProgramBuilder) Node(jkind.lustre.Node) AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) ArrayList(java.util.ArrayList) Pair(org.eclipse.xtext.util.Pair)

Example 28 with AgreeNode

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

the class LustreAstBuilder method getConsistencyLustreNode.

protected static Node getConsistencyLustreNode(AgreeNode agreeNode, boolean withAssertions) {
    final String stuffPrefix = "__STUFF";
    List<Expr> assertions = new ArrayList<>();
    List<VarDecl> locals = new ArrayList<>();
    List<VarDecl> inputs = new ArrayList<>();
    List<Equation> equations = new ArrayList<>();
    List<String> properties = new ArrayList<>();
    List<String> ivcs = new ArrayList<>();
    Expr stuffConj = new BoolExpr(true);
    int stuffAssumptionIndex = 0;
    for (AgreeStatement assumption : agreeNode.assumptions) {
        AgreeVar stuffAssumptionVar = new AgreeVar(stuffPrefix + assumeSuffix + stuffAssumptionIndex++, NamedType.BOOL, assumption.reference, agreeNode.compInst, null);
        locals.add(stuffAssumptionVar);
        ivcs.add(stuffAssumptionVar.id);
        IdExpr stuffAssumptionId = new IdExpr(stuffAssumptionVar.id);
        equations.add(new Equation(stuffAssumptionId, assumption.expr));
        stuffConj = LustreExprFactory.makeANDExpr(stuffConj, stuffAssumptionId);
    }
    int stuffGuaranteeIndex = 0;
    for (AgreeStatement guarantee : agreeNode.guarantees) {
        AgreeVar stuffGuaranteeVar = new AgreeVar(stuffPrefix + guarSuffix + stuffGuaranteeIndex++, NamedType.BOOL, guarantee.reference, agreeNode.compInst, null);
        locals.add(stuffGuaranteeVar);
        ivcs.add(stuffGuaranteeVar.id);
        IdExpr stuffGuaranteeId = new IdExpr(stuffGuaranteeVar.id);
        equations.add(new Equation(stuffGuaranteeId, guarantee.expr));
        stuffConj = LustreExprFactory.makeANDExpr(stuffConj, stuffGuaranteeId);
    }
    if (withAssertions) {
        equations.addAll(agreeNode.localEquations);
    } else {
        for (AgreeEquation eq : agreeNode.localEquations) {
            if (AgreeUtils.referenceIsInContract(eq.reference, agreeNode.compInst)) {
                equations.add(eq);
            }
        }
    }
    // TODO should we include lemmas in the consistency check?
    // for(AgreeStatement guarantee : agreeNode.lemmas){
    // histConj = new BinaryExpr(histConj, BinaryOp.AND, guarantee.expr);
    // }
    int stuffAssertionIndex = 0;
    if (withAssertions) {
        for (AgreeStatement assertion : agreeNode.assertions) {
            AgreeVar stuffAssertionVar = new AgreeVar(stuffPrefix + assertSuffix + stuffAssertionIndex++, NamedType.BOOL, assertion.reference, null, null);
            locals.add(stuffAssertionVar);
            IdExpr stuffAssertionId = new IdExpr(stuffAssertionVar.id);
            equations.add(new Equation(stuffAssertionId, assertion.expr));
            stuffConj = LustreExprFactory.makeANDExpr(stuffConj, stuffAssertionId);
        }
    } else {
        // equations  and type equations. That would clear this up.
        for (AgreeStatement assertion : agreeNode.assertions) {
            if (AgreeUtils.referenceIsInContract(assertion.reference, agreeNode.compInst)) {
                AgreeVar stuffAssertionVar = new AgreeVar(stuffPrefix + assertSuffix + stuffAssertionIndex++, NamedType.BOOL, assertion.reference, null, null);
                locals.add(stuffAssertionVar);
                IdExpr stuffAssertionId = new IdExpr(stuffAssertionVar.id);
                equations.add(new Equation(stuffAssertionId, assertion.expr));
                stuffConj = LustreExprFactory.makeANDExpr(stuffConj, stuffAssertionId);
            }
        }
    }
    // add realtime constraints
    Set<AgreeVar> eventTimes = new HashSet<>();
    if (withAssertions) {
        eventTimes.addAll(agreeNode.eventTimes);
    } else {
        for (AgreeVar eventVar : agreeNode.eventTimes) {
            if (AgreeUtils.referenceIsInContract(eventVar.reference, agreeNode.compInst)) {
                eventTimes.add(eventVar);
            }
        }
    }
    assertions.add(AgreeRealtimeCalendarBuilder.getTimeConstraint(eventTimes));
    for (AgreeVar var : agreeNode.inputs) {
        inputs.add(var);
    }
    for (AgreeVar var : agreeNode.outputs) {
        inputs.add(var);
    }
    for (AgreeVar var : agreeNode.locals) {
        if (withAssertions) {
            locals.add(var);
        } else {
            if (AgreeUtils.referenceIsInContract(var.reference, agreeNode.compInst)) {
                locals.add(var);
            }
        }
    }
    EObject classifier = agreeNode.compInst.getComponentClassifier();
    AgreeVar countVar = new AgreeVar("__COUNT", NamedType.INT, null, null, null);
    AgreeVar stuffVar = new AgreeVar(stuffPrefix, NamedType.BOOL, null, null, null);
    AgreeVar histVar = new AgreeVar("__HIST", NamedType.BOOL, null, null, null);
    AgreeVar propVar = new AgreeVar("__PROP", NamedType.BOOL, classifier, agreeNode.compInst, null);
    locals.add(countVar);
    locals.add(stuffVar);
    locals.add(histVar);
    locals.add(propVar);
    IdExpr countId = new IdExpr(countVar.id);
    IdExpr stuffId = new IdExpr(stuffVar.id);
    IdExpr histId = new IdExpr(histVar.id);
    IdExpr propId = new IdExpr(propVar.id);
    equations.add(new Equation(stuffId, stuffConj));
    Expr histExpr = new UnaryExpr(UnaryOp.PRE, histId);
    histExpr = LustreExprFactory.makeANDExpr(histExpr, stuffId);
    histExpr = new BinaryExpr(stuffId, BinaryOp.ARROW, histExpr);
    equations.add(new Equation(histId, histExpr));
    Expr countExpr = new UnaryExpr(UnaryOp.PRE, countId);
    countExpr = new BinaryExpr(countExpr, BinaryOp.PLUS, new IntExpr(BigInteger.ONE));
    countExpr = new BinaryExpr(new IntExpr(BigInteger.ZERO), BinaryOp.ARROW, countExpr);
    equations.add(new Equation(countId, countExpr));
    IPreferenceStore prefs = Activator.getDefault().getPreferenceStore();
    int consistDetph = prefs.getInt(PreferenceConstants.PREF_CONSIST_DEPTH);
    Expr propExpr = new BinaryExpr(countId, BinaryOp.EQUAL, new IntExpr(BigInteger.valueOf(consistDetph)));
    propExpr = new BinaryExpr(propExpr, BinaryOp.AND, histId);
    equations.add(new Equation(propId, new UnaryExpr(UnaryOp.NOT, propExpr)));
    properties.add(propId.id);
    NodeBuilder builder = new NodeBuilder("consistency");
    builder.addInputs(inputs);
    builder.addLocals(locals);
    builder.addEquations(equations);
    builder.addProperties(properties);
    builder.addAssertions(assertions);
    builder.addIvcs(ivcs);
    Node node = builder.build();
    return node;
}
Also used : BoolExpr(jkind.lustre.BoolExpr) AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) IdExpr(jkind.lustre.IdExpr) BinaryExpr(jkind.lustre.BinaryExpr) Node(jkind.lustre.Node) AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) ArrayList(java.util.ArrayList) Equation(jkind.lustre.Equation) AgreeEquation(com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation) AgreeEquation(com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation) NodeBuilder(jkind.lustre.builders.NodeBuilder) AgreeNodeBuilder(com.rockwellcollins.atc.agree.analysis.ast.AgreeNodeBuilder) UnaryExpr(jkind.lustre.UnaryExpr) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar) UnaryExpr(jkind.lustre.UnaryExpr) Expr(jkind.lustre.Expr) IntExpr(jkind.lustre.IntExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) IdExpr(jkind.lustre.IdExpr) VarDecl(jkind.lustre.VarDecl) EObject(org.eclipse.emf.ecore.EObject) IntExpr(jkind.lustre.IntExpr) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) HashSet(java.util.HashSet)

Example 29 with AgreeNode

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

the class LustreAstBuilder method flattenAgreeNode.

protected static AgreeNode flattenAgreeNode(AgreeProgram agreeProgram, AgreeNode agreeNode, String nodePrefix) {
    List<AgreeVar> inputs = new ArrayList<>();
    List<AgreeVar> outputs = new ArrayList<>();
    List<AgreeVar> locals = new ArrayList<>();
    List<AgreeStatement> patternProps = new ArrayList<>();
    List<AgreeEquation> equations = new ArrayList<>();
    List<AgreeStatement> assertions = new ArrayList<>();
    Set<AgreeVar> timeEvents = new HashSet<>(agreeNode.eventTimes);
    Expr someoneTicks = null;
    for (AgreeNode subAgreeNode : agreeNode.subNodes) {
        String prefix = subAgreeNode.id + AgreeASTBuilder.dotChar;
        Expr clockExpr = getClockExpr(agreeNode, subAgreeNode);
        if (someoneTicks == null) {
            someoneTicks = clockExpr;
        } else {
            someoneTicks = new BinaryExpr(someoneTicks, BinaryOp.OR, clockExpr);
        }
        AgreeNode flatNode = flattenAgreeNode(agreeProgram, subAgreeNode, nodePrefix + subAgreeNode.id + AgreeASTBuilder.dotChar);
        Node lustreNode = addSubNodeLustre(agreeProgram, agreeNode, nodePrefix, flatNode);
        addInputsAndOutputs(agreeNode, inputs, outputs, patternProps, flatNode, lustreNode, prefix);
        addTimeEvents(timeEvents, flatNode, prefix, assertions);
        addNodeCall(agreeNode, assertions, prefix, clockExpr, lustreNode);
        addHistoricalAssumptionConstraint(agreeNode, prefix, clockExpr, assertions, lustreNode);
    }
    if (agreeNode.timing == TimingModel.ASYNC) {
        if (someoneTicks == null) {
            throw new AgreeException("Somehow we generated a clock constraint without any clocks." + " Perhaps none of your subcomponents have an agree annex?");
        }
        assertions.add(new AgreeStatement("someone ticks", someoneTicks, null));
    }
    addConnectionConstraints(agreeNode, assertions);
    // add any clock constraints
    assertions.addAll(agreeNode.assertions);
    assertions.add(new AgreeStatement("", agreeNode.clockConstraint, null));
    inputs.addAll(agreeNode.inputs);
    outputs.addAll(agreeNode.outputs);
    locals.addAll(agreeNode.locals);
    equations.addAll(agreeNode.localEquations);
    patternProps.addAll(agreeNode.patternProps);
    AgreeNodeBuilder builder = new AgreeNodeBuilder(agreeNode.id);
    builder.addInput(inputs);
    builder.addOutput(outputs);
    builder.addLocal(locals);
    builder.addLocalEquation(equations);
    builder.addIvcElements(agreeNode.getivcElements());
    builder.addSubNode(agreeNode.subNodes);
    builder.addAssertion(assertions);
    builder.addAssumption(agreeNode.assumptions);
    builder.addGuarantee(agreeNode.guarantees);
    builder.addLemma(agreeNode.lemmas);
    builder.addPatternProp(patternProps);
    builder.setClockConstraint(new BoolExpr(true));
    builder.setInitialConstraint(agreeNode.initialConstraint);
    builder.setClockVar(agreeNode.clockVar);
    builder.setReference(agreeNode.reference);
    builder.setTiming(null);
    builder.addEventTime(timeEvents);
    builder.setCompInst(agreeNode.compInst);
    builder.setFaultTreeFlag(agreeNode.faultTreeFlag);
    return builder.build();
}
Also used : BoolExpr(jkind.lustre.BoolExpr) AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) BinaryExpr(jkind.lustre.BinaryExpr) Node(jkind.lustre.Node) AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) ArrayList(java.util.ArrayList) AgreeEquation(com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar) UnaryExpr(jkind.lustre.UnaryExpr) Expr(jkind.lustre.Expr) IntExpr(jkind.lustre.IntExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) IdExpr(jkind.lustre.IdExpr) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) AgreeNodeBuilder(com.rockwellcollins.atc.agree.analysis.ast.AgreeNodeBuilder) HashSet(java.util.HashSet)

Example 30 with AgreeNode

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

the class LustreContractAstBuilder method addSubNodeLustre.

protected static Node addSubNodeLustre(AgreeNode agreeNode, String nodePrefix, AgreeNode flatNode) {
    Node lustreNode = getLustreNode(flatNode, nodePrefix);
    addToNodes(lustreNode);
    return lustreNode;
}
Also used : AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) Node(jkind.lustre.Node)

Aggregations

AgreeNode (com.rockwellcollins.atc.agree.analysis.ast.AgreeNode)30 ArrayList (java.util.ArrayList)17 Node (jkind.lustre.Node)15 AgreeStatement (com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement)13 AgreeVar (com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)13 IdExpr (jkind.lustre.IdExpr)12 AgreeNodeBuilder (com.rockwellcollins.atc.agree.analysis.ast.AgreeNodeBuilder)11 Expr (jkind.lustre.Expr)11 NodeCallExpr (jkind.lustre.NodeCallExpr)10 AgreeProgram (com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram)9 BinaryExpr (jkind.lustre.BinaryExpr)9 BoolExpr (jkind.lustre.BoolExpr)9 UnaryExpr (jkind.lustre.UnaryExpr)9 Program (jkind.lustre.Program)7 TypeDef (jkind.lustre.TypeDef)7 ProgramBuilder (jkind.lustre.builders.ProgramBuilder)7 AgreeException (com.rockwellcollins.atc.agree.analysis.AgreeException)6 AgreeEquation (com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation)6 VarDecl (jkind.lustre.VarDecl)6 Equation (jkind.lustre.Equation)5