Search in sources :

Example 1 with Function

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

the class AgreeASTBuilder method caseUninterpretedFnDef.

@Override
public Expr caseUninterpretedFnDef(UninterpretedFnDef uFnDef) {
    String functionName = AgreeUtils.getNodeName(uFnDef).replace("::", "__");
    for (Function function : uninterpretedFunc) {
        if (function.id.equals(functionName)) {
            return null;
        }
    }
    List<VarDecl> inputs = agreeVarsFromArgs(uFnDef.getArgs(), null);
    Type outType = symbolTable.updateLustreTypeMap(AgreeTypeSystem.typeDefFromType(uFnDef.getType()));
    if (outType != null) {
        VarDecl outVar = new VarDecl("_outvar", outType);
        List<VarDecl> outputs = Collections.singletonList(outVar);
        Function function = new Function(functionName, inputs, outputs);
        addToFunctionList(function);
    }
    return null;
}
Also used : Function(jkind.lustre.Function) ConnectionType(com.rockwellcollins.atc.agree.analysis.ast.AgreeAADLConnection.ConnectionType) Type(jkind.lustre.Type) NamedType(jkind.lustre.NamedType) FeatureGroupType(org.osate.aadl2.FeatureGroupType) DataSubcomponentType(org.osate.aadl2.DataSubcomponentType) ComponentType(org.osate.aadl2.ComponentType) VarDecl(jkind.lustre.VarDecl)

Example 2 with Function

use of jkind.lustre.Function 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 3 with Function

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

the class AgreeASTMapVisitor method visit.

@Override
public AgreeProgram visit(AgreeProgram e) {
    List<AgreeNode> agreeNodes = new ArrayList<>();
    for (AgreeNode node : e.agreeNodes) {
        AgreeNode visitedNode = visitedNodes.get(node.compInst);
        if (visitedNode == null) {
            visitedNode = this.visit(node);
        }
        agreeNodes.add(visitedNode);
    }
    List<Node> globalLustreNodes = new ArrayList<>();
    for (Node node : e.globalLustreNodes) {
        globalLustreNodes.add(this.visit(node));
    }
    List<Function> uninterpretedFunctions = new ArrayList<>();
    for (Function function : e.uninterpretedFunctions) {
        uninterpretedFunctions.add(this.visit(function));
    }
    List<jkind.lustre.Type> globalTypes = new ArrayList<>();
    for (Type ty : e.globalTypes) {
        globalTypes.add(ty.accept(lustreTypeMapVisitor));
    }
    AgreeNode topNode = this.visit(e.topNode);
    return new AgreeProgram(agreeNodes, globalLustreNodes, uninterpretedFunctions, globalTypes, topNode);
}
Also used : Function(jkind.lustre.Function) Type(jkind.lustre.Type) ConnectionType(com.rockwellcollins.atc.agree.analysis.ast.AgreeAADLConnection.ConnectionType) AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) Node(jkind.lustre.Node) ArrayList(java.util.ArrayList) AgreeProgram(com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram)

Example 4 with Function

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

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

the class AgreeASTBuilder method caseCallExpr.

/*
	 * CallExpr could be a node call, a regular function call, or an uninterpreted function call.
	 * The former two cases will return a NodeCallExpr, the third case will return a FunctionCallExpr.
	 */
@Override
public Expr caseCallExpr(CallExpr expr) {
    NamedElement namedEl = expr.getRef().getElm();
    String fnName = AgreeUtils.getNodeName(namedEl);
    boolean found = false;
    for (Node node : globalNodes) {
        if (node.id.equals(fnName)) {
            found = true;
            break;
        }
    }
    if (!found) {
        for (Function function : uninterpretedFunc) {
            if (function.id.equals(fnName)) {
                found = true;
                break;
            }
        }
    }
    if (!found) {
        DoubleDotRef fn = expr.getRef();
        doSwitch(fn.getElm());
        // for dReal integration
        if (fnName.substring(0, 7).equalsIgnoreCase("dreal__")) {
            fnName = namedEl.getName();
        }
    }
    List<Expr> argResults = new ArrayList<>();
    for (com.rockwellcollins.atc.agree.agree.Expr argExpr : expr.getArgs()) {
        argResults.add(doSwitch(argExpr));
    }
    if (functionNameExists(fnName)) {
        FunctionCallExpr functionCall = new FunctionCallExpr(fnName.replace("::", "__"), argResults);
        return functionCall;
    }
    NodeCallExpr nodeCall = new NodeCallExpr(fnName.replace("::", "__"), argResults);
    return nodeCall;
}
Also used : Node(jkind.lustre.Node) ArrayList(java.util.ArrayList) Function(jkind.lustre.Function) FunctionCallExpr(jkind.lustre.FunctionCallExpr) EnumLitExpr(com.rockwellcollins.atc.agree.agree.EnumLitExpr) IndicesExpr(com.rockwellcollins.atc.agree.agree.IndicesExpr) TimeRiseExpr(com.rockwellcollins.atc.agree.agree.TimeRiseExpr) RecordAccessExpr(jkind.lustre.RecordAccessExpr) FlatmapExpr(com.rockwellcollins.atc.agree.agree.FlatmapExpr) TimeFallExpr(com.rockwellcollins.atc.agree.agree.TimeFallExpr) RealLitExpr(com.rockwellcollins.atc.agree.agree.RealLitExpr) GetPropertyExpr(com.rockwellcollins.atc.agree.agree.GetPropertyExpr) Expr(jkind.lustre.Expr) CastExpr(jkind.lustre.CastExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) TimeOfExpr(com.rockwellcollins.atc.agree.agree.TimeOfExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) RealExpr(jkind.lustre.RealExpr) ArrayExpr(jkind.lustre.ArrayExpr) PrevExpr(com.rockwellcollins.atc.agree.agree.PrevExpr) IdExpr(jkind.lustre.IdExpr) TimeExpr(com.rockwellcollins.atc.agree.agree.TimeExpr) FoldRightExpr(com.rockwellcollins.atc.agree.agree.FoldRightExpr) TagExpr(com.rockwellcollins.atc.agree.agree.TagExpr) EventExpr(com.rockwellcollins.atc.agree.agree.EventExpr) LatchedExpr(com.rockwellcollins.atc.agree.agree.LatchedExpr) NamedElmExpr(com.rockwellcollins.atc.agree.agree.NamedElmExpr) FunctionCallExpr(jkind.lustre.FunctionCallExpr) SelectionExpr(com.rockwellcollins.atc.agree.agree.SelectionExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) TupleExpr(jkind.lustre.TupleExpr) UnaryExpr(jkind.lustre.UnaryExpr) ArraySubExpr(com.rockwellcollins.atc.agree.agree.ArraySubExpr) IntExpr(jkind.lustre.IntExpr) PreExpr(com.rockwellcollins.atc.agree.agree.PreExpr) RecordLitExpr(com.rockwellcollins.atc.agree.agree.RecordLitExpr) ExistsExpr(com.rockwellcollins.atc.agree.agree.ExistsExpr) FoldLeftExpr(com.rockwellcollins.atc.agree.agree.FoldLeftExpr) RecordUpdateExpr(com.rockwellcollins.atc.agree.agree.RecordUpdateExpr) ForallExpr(com.rockwellcollins.atc.agree.agree.ForallExpr) ArrayAccessExpr(jkind.lustre.ArrayAccessExpr) ArrayUpdateExpr(com.rockwellcollins.atc.agree.agree.ArrayUpdateExpr) 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) ArrayLiteralExpr(com.rockwellcollins.atc.agree.agree.ArrayLiteralExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) DoubleDotRef(com.rockwellcollins.atc.agree.agree.DoubleDotRef) NamedElement(org.osate.aadl2.NamedElement)

Aggregations

Function (jkind.lustre.Function)5 AgreeNode (com.rockwellcollins.atc.agree.analysis.ast.AgreeNode)3 ArrayList (java.util.ArrayList)3 Node (jkind.lustre.Node)3 Type (jkind.lustre.Type)3 ConnectionType (com.rockwellcollins.atc.agree.analysis.ast.AgreeAADLConnection.ConnectionType)2 AgreeProgram (com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram)2 BinaryExpr (jkind.lustre.BinaryExpr)2 BoolExpr (jkind.lustre.BoolExpr)2 Expr (jkind.lustre.Expr)2 IdExpr (jkind.lustre.IdExpr)2 TypeDef (jkind.lustre.TypeDef)2 VarDecl (jkind.lustre.VarDecl)2 ArrayLiteralExpr (com.rockwellcollins.atc.agree.agree.ArrayLiteralExpr)1 ArraySubExpr (com.rockwellcollins.atc.agree.agree.ArraySubExpr)1 ArrayUpdateExpr (com.rockwellcollins.atc.agree.agree.ArrayUpdateExpr)1 BoolLitExpr (com.rockwellcollins.atc.agree.agree.BoolLitExpr)1 CallExpr (com.rockwellcollins.atc.agree.agree.CallExpr)1 DoubleDotRef (com.rockwellcollins.atc.agree.agree.DoubleDotRef)1 EnumLitExpr (com.rockwellcollins.atc.agree.agree.EnumLitExpr)1