Search in sources :

Example 1 with TypeDef

use of jkind.lustre.TypeDef in project AGREE by loonwerks.

the class AgreeASTPrettyprinter method visit.

@Override
public Void visit(AgreeProgram program) {
    if (program.containsRealTimePatterns) {
        write("-- Program contains real-time patterns");
        newline();
        newline();
    }
    write("-- Program top-level node is: " + program.topNode.id);
    newline();
    newline();
    if (!program.globalTypes.isEmpty()) {
        for (Type type : program.globalTypes) {
            String name = "dummy";
            if (type instanceof RecordType) {
                name = ((RecordType) type).id;
            } else if (type instanceof EnumType) {
                name = ((EnumType) type).id;
            }
            TypeDef typeDef = new TypeDef(Location.NULL, name, type);
            typeDef.accept(this);
            newline();
        }
        newline();
    }
    if (!program.globalLustreNodes.isEmpty()) {
        Iterator<Node> iterator = program.globalLustreNodes.iterator();
        while (iterator.hasNext()) {
            iterator.next().accept(this);
            newline();
            if (iterator.hasNext()) {
                newline();
            }
        }
        newline();
    }
    if (!program.uninterpretedFunctions.isEmpty()) {
        Iterator<Function> iterator = program.uninterpretedFunctions.iterator();
        while (iterator.hasNext()) {
            iterator.next().accept(this);
            newline();
            if (iterator.hasNext()) {
                newline();
            }
        }
        newline();
    }
    Iterator<AgreeNode> iterator = program.agreeNodes.iterator();
    while (iterator.hasNext()) {
        iterator.next().accept(this);
        newline();
        if (iterator.hasNext()) {
            newline();
        }
    }
    newline();
    return null;
}
Also used : Function(jkind.lustre.Function) RecordType(jkind.lustre.RecordType) Type(jkind.lustre.Type) EnumType(jkind.lustre.EnumType) AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) RecordType(jkind.lustre.RecordType) TypeDef(jkind.lustre.TypeDef) EnumType(jkind.lustre.EnumType) Node(jkind.lustre.Node) AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode)

Example 2 with TypeDef

use of jkind.lustre.TypeDef in project AGREE by loonwerks.

the class AgreeNodeToLustreContract method translate.

public static Node translate(AgreeNode agreeNode, AgreeProgram agreeProgram) {
    List<Node> nodes = new ArrayList<>();
    nodes.addAll(agreeProgram.globalLustreNodes);
    // this node needs to be the last in the list
    // so that it is set as the main node in the program
    nodes.add(translateNode(agreeNode));
    List<TypeDef> types = new ArrayList<>();
    for (Type type : agreeProgram.globalTypes) {
        RecordType recType = (RecordType) type;
        types.add(new TypeDef(recType.id, type));
    }
    Program program = new ProgramBuilder().addTypes(types).addNodes(nodes).build();
    program = InlineNodeCalls.program(program);
    program = FlattenPres.program(program);
    Node main = DistributePres.node(program.getMainNode());
    main = OrderEquations.node(main);
    return main;
}
Also used : RecordType(jkind.lustre.RecordType) Type(jkind.lustre.Type) NamedType(jkind.lustre.NamedType) Program(jkind.lustre.Program) AgreeProgram(com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram) TypeDef(jkind.lustre.TypeDef) RecordType(jkind.lustre.RecordType) ProgramBuilder(jkind.lustre.builders.ProgramBuilder) AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) Node(jkind.lustre.Node) ArrayList(java.util.ArrayList)

Example 3 with TypeDef

use of jkind.lustre.TypeDef in project AGREE by loonwerks.

the class LustreAstBuilder method getRealizabilityLustreProgram.

// private static AgreeProgram translate(AgreeProgram program){
// return AgreeInlineLatchedConnections.translate(program);
// }
public static Program getRealizabilityLustreProgram(AgreeProgram agreeProgram) {
    List<TypeDef> types = AgreeUtils.getLustreTypes(agreeProgram);
    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<>();
    AgreeNode topNode = agreeProgram.topNode;
    for (AgreeStatement assumption : topNode.assumptions) {
        assertions.add(assumption.expr);
    }
    int i = 0;
    for (AgreeStatement guarantee : topNode.guarantees) {
        String guarName = guarSuffix + i++;
        locals.add(new AgreeVar(guarName, NamedType.BOOL, guarantee.reference, topNode.compInst, null));
        equations.add(new Equation(new IdExpr(guarName), guarantee.expr));
        properties.add(guarName);
    }
    List<String> inputStrs = new ArrayList<>();
    for (AgreeVar var : topNode.inputs) {
        inputs.add(var);
        inputStrs.add(var.id);
    }
    for (AgreeVar var : topNode.outputs) {
        inputs.add(var);
    }
    // and type equations. This would clear this up
    for (AgreeStatement statement : topNode.assertions) {
        if (AgreeUtils.referenceIsInContract(statement, topNode.compInst)) {
            // this is a strange hack we have to do. we have to make
            // equation and property
            // statements not assertions. They should all be binary
            // expressions with an
            // equals operator. We will need to removing their corresponding
            // variable
            // from the inputs and add them to the local variables
            BinaryExpr binExpr;
            IdExpr varId;
            try {
                binExpr = (BinaryExpr) statement.expr;
                varId = (IdExpr) binExpr.left;
            } catch (ClassCastException e) {
                // some equation variables are assertions for
                // subrange types. do not translate these to
                // local equations. Just add them to assertions
                assertions.add(statement.expr);
                continue;
            }
            boolean found = false;
            int index;
            for (index = 0; index < inputs.size(); index++) {
                VarDecl var = inputs.get(index);
                if (var.id.equals(varId.id)) {
                    found = true;
                    break;
                }
            }
            if (!found || binExpr.op != BinaryOp.EQUAL) {
                throw new AgreeException("Something went very wrong with the lustre generation in the realizability analysis");
            }
            locals.add(inputs.remove(index));
            equations.add(new Equation(varId, binExpr.right));
        }
    }
    NodeBuilder builder = new NodeBuilder("main");
    builder.addInputs(inputs);
    builder.addLocals(locals);
    builder.addEquations(equations);
    builder.addProperties(properties);
    builder.addAssertions(assertions);
    builder.setRealizabilityInputs(inputStrs);
    Node main = builder.build();
    List<Node> nodes = new ArrayList<>();
    nodes.add(main);
    nodes.addAll(agreeProgram.globalLustreNodes);
    List<Function> uFunctions = new ArrayList<>();
    uFunctions.addAll(agreeProgram.uninterpretedFunctions);
    Program program = new ProgramBuilder().addTypes(types).addFunctions(uFunctions).addNodes(nodes).setMain(main.id).build();
    return program;
}
Also used : AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) Node(jkind.lustre.Node) AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) ArrayList(java.util.ArrayList) NodeBuilder(jkind.lustre.builders.NodeBuilder) AgreeNodeBuilder(com.rockwellcollins.atc.agree.analysis.ast.AgreeNodeBuilder) Function(jkind.lustre.Function) TypeDef(jkind.lustre.TypeDef) VarDecl(jkind.lustre.VarDecl) AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) Program(jkind.lustre.Program) AgreeProgram(com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram) IdExpr(jkind.lustre.IdExpr) ProgramBuilder(jkind.lustre.builders.ProgramBuilder) BinaryExpr(jkind.lustre.BinaryExpr) Equation(jkind.lustre.Equation) 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)

Example 4 with TypeDef

use of jkind.lustre.TypeDef 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 5 with TypeDef

use of jkind.lustre.TypeDef in project AGREE by loonwerks.

the class LustreAstBuilder method getAssumeGuaranteeLustreProgram.

public static Program getAssumeGuaranteeLustreProgram(AgreeProgram agreeProgram) {
    nodes = new ArrayList<>();
    uninterpretedFcns = new ArrayList<>();
    AgreeNode flatNode = flattenAgreeNode(agreeProgram, agreeProgram.topNode, "_TOP__");
    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<>();
    int j = 0;
    for (AgreeStatement assumption : flatNode.assumptions) {
        String assumName = assumeSuffix + j++;
        locals.add(new AgreeVar(assumName, NamedType.BOOL, assumption.reference, flatNode.compInst, null));
        IdExpr assumId = new IdExpr(assumName);
        equations.add(new Equation(assumId, assumption.expr));
        assertions.add(assumId);
        // Else add the defined ivc list.
        if (flatNode.getFaultTreeFlag() == false) {
            ivcs.add(assumId.id);
        }
    }
    for (AgreeStatement assertion : flatNode.assertions) {
        assertions.add(assertion.expr);
    }
    // add assumption and monolithic lemmas first (helps with proving)
    for (AgreeVar var : flatNode.outputs) {
        if (var.reference instanceof AssumeStatement || var.reference instanceof LemmaStatement) {
            properties.add(var.id);
        }
        inputs.add(var);
    }
    // add property that all assumption history is true
    Expr assumeConj = new BoolExpr(true);
    for (AgreeNode subNode : agreeProgram.topNode.subNodes) {
        assumeConj = new BinaryExpr(new IdExpr(subNode.id + "__" + assumeHistSufix), BinaryOp.AND, assumeConj);
    }
    AgreeVar assumeHistVar = new AgreeVar(assumeHistSufix, NamedType.BOOL, agreeProgram.topNode.compInst.getComponentClassifier(), agreeProgram.topNode.compInst, null);
    locals.add(assumeHistVar);
    equations.add(new Equation(new IdExpr(assumeHistVar.id), assumeConj));
    properties.add(assumeHistVar.id);
    int k = 0;
    for (AgreeStatement patternPropState : flatNode.patternProps) {
        String patternVarName = patternPropSuffix + k++;
        locals.add(new AgreeVar(patternVarName, NamedType.BOOL, patternPropState, flatNode.compInst, null));
        equations.add(new Equation(new IdExpr(patternVarName), patternPropState.expr));
        properties.add(patternVarName);
    }
    int lemmaCount = 0;
    for (AgreeStatement lemma : flatNode.lemmas) {
        String lemmaName = lemmaSuffix + lemmaCount++;
        locals.add(new AgreeVar(lemmaName, NamedType.BOOL, lemma.reference, flatNode.compInst, null));
        equations.add(new Equation(new IdExpr(lemmaName), lemma.expr));
        properties.add(lemmaName);
    }
    int i = 0;
    for (AgreeStatement guarantee : flatNode.guarantees) {
        String guarName = guarSuffix + i++;
        locals.add(new AgreeVar(guarName, NamedType.BOOL, guarantee.reference, flatNode.compInst, null));
        equations.add(new Equation(new IdExpr(guarName), guarantee.expr));
        properties.add(guarName);
    }
    if (flatNode.getFaultTreeFlag()) {
        ivcs.addAll(agreeProgram.topNode.getivcElements());
    }
    for (AgreeVar var : flatNode.inputs) {
        inputs.add(var);
    }
    for (AgreeVar var : flatNode.locals) {
        locals.add(var);
    }
    equations.addAll(flatNode.localEquations);
    assertions.add(AgreeRealtimeCalendarBuilder.getTimeConstraint(flatNode.eventTimes));
    NodeBuilder builder = new NodeBuilder("main");
    builder.addInputs(inputs);
    builder.addLocals(locals);
    builder.addEquations(equations);
    builder.addProperties(properties);
    builder.addAssertions(assertions);
    builder.addIvcs(ivcs);
    Node main = builder.build();
    nodes.add(main);
    nodes.addAll(agreeProgram.globalLustreNodes);
    nodes.add(getHistNode());
    // add realtime constraint nodes
    nodes.addAll(AgreeRealtimeCalendarBuilder.getRealTimeNodes());
    List<TypeDef> types = AgreeUtils.getLustreTypes(agreeProgram);
    uninterpretedFcns.addAll(agreeProgram.uninterpretedFunctions);
    Program program = new ProgramBuilder().addTypes(types).addFunctions(uninterpretedFcns).addNodes(nodes).setMain(main.id).build();
    return program;
}
Also used : BoolExpr(jkind.lustre.BoolExpr) AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) Node(jkind.lustre.Node) AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) ArrayList(java.util.ArrayList) NodeBuilder(jkind.lustre.builders.NodeBuilder) AgreeNodeBuilder(com.rockwellcollins.atc.agree.analysis.ast.AgreeNodeBuilder) LemmaStatement(com.rockwellcollins.atc.agree.agree.LemmaStatement) TypeDef(jkind.lustre.TypeDef) VarDecl(jkind.lustre.VarDecl) AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) Program(jkind.lustre.Program) AgreeProgram(com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram) IdExpr(jkind.lustre.IdExpr) AssumeStatement(com.rockwellcollins.atc.agree.agree.AssumeStatement) ProgramBuilder(jkind.lustre.builders.ProgramBuilder) BinaryExpr(jkind.lustre.BinaryExpr) Equation(jkind.lustre.Equation) 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)

Aggregations

TypeDef (jkind.lustre.TypeDef)10 ArrayList (java.util.ArrayList)7 Node (jkind.lustre.Node)7 AgreeNode (com.rockwellcollins.atc.agree.analysis.ast.AgreeNode)6 AgreeProgram (com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram)5 Program (jkind.lustre.Program)5 ProgramBuilder (jkind.lustre.builders.ProgramBuilder)5 RecordType (jkind.lustre.RecordType)4 Type (jkind.lustre.Type)4 AgreeNodeBuilder (com.rockwellcollins.atc.agree.analysis.ast.AgreeNodeBuilder)3 AgreeStatement (com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement)3 AgreeVar (com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)3 BinaryExpr (jkind.lustre.BinaryExpr)3 BoolExpr (jkind.lustre.BoolExpr)3 Equation (jkind.lustre.Equation)3 Expr (jkind.lustre.Expr)3 IdExpr (jkind.lustre.IdExpr)3 NamedType (jkind.lustre.NamedType)3 NodeCallExpr (jkind.lustre.NodeCallExpr)3 UnaryExpr (jkind.lustre.UnaryExpr)3