Search in sources :

Example 1 with RecordType

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

the class ExpressionFlattener method flattenEqualsExpression.

private void flattenEqualsExpression(final BinaryExpr expr, final List<BinaryExpr> results) {
    // Assume that both sides of the binary expression are the same type
    final Type leftType = expr.left.accept(typeReconstructor);
    if (leftType instanceof ArrayType) {
        flattenArrayEquality(expr, (ArrayType) leftType, results);
    } else if (leftType instanceof RecordType) {
        flattenRecordEquality(expr, (RecordType) leftType, results);
    } else if (leftType instanceof NamedType) {
        // Flatten both sides of the expression
        final Expr newLeft = flattenExpression(expr.left);
        final Expr newRight = flattenExpression(expr.right);
        if (newLeft != null && newRight != null) {
            results.add(new BinaryExpr(newLeft, expr.op, newRight));
        }
    }
}
Also used : ArrayType(jkind.lustre.ArrayType) NamedType(jkind.lustre.NamedType) RecordType(jkind.lustre.RecordType) Type(jkind.lustre.Type) ArrayType(jkind.lustre.ArrayType) RecordType(jkind.lustre.RecordType) BinaryExpr(jkind.lustre.BinaryExpr) RecordAccessExpr(jkind.lustre.RecordAccessExpr) ArrayAccessExpr(jkind.lustre.ArrayAccessExpr) RecordUpdateExpr(jkind.lustre.RecordUpdateExpr) ArrayUpdateExpr(jkind.lustre.ArrayUpdateExpr) ArrayExpr(jkind.lustre.ArrayExpr) Expr(jkind.lustre.Expr) RecordExpr(jkind.lustre.RecordExpr) IntExpr(jkind.lustre.IntExpr) NamedType(jkind.lustre.NamedType) BinaryExpr(jkind.lustre.BinaryExpr)

Example 2 with RecordType

use of jkind.lustre.RecordType 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 RecordType

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

the class AgreeUtils method getInitValueFromType.

public static Expr getInitValueFromType(Type type) {
    if (type instanceof NamedType) {
        return getInitValueFromType((NamedType) type);
    }
    if (type instanceof RecordType) {
        RecordType recordType = (RecordType) type;
        Map<String, Expr> fieldMap = new HashMap<>();
        for (Entry<String, Type> entry : recordType.fields.entrySet()) {
            Expr subExpr = getInitValueFromType(entry.getValue());
            fieldMap.put(entry.getKey(), subExpr);
        }
        return new RecordExpr(recordType.id, fieldMap);
    }
    throw new AgreeException("AGREE cannot figure out an initial type for Lustre type: " + type.getClass());
}
Also used : RecordType(jkind.lustre.RecordType) EnumType(jkind.lustre.EnumType) ComponentType(org.osate.aadl2.ComponentType) Type(jkind.lustre.Type) NamedType(jkind.lustre.NamedType) RecordType(jkind.lustre.RecordType) RecordAccessExpr(jkind.lustre.RecordAccessExpr) Expr(jkind.lustre.Expr) IntExpr(jkind.lustre.IntExpr) RecordExpr(jkind.lustre.RecordExpr) BoolExpr(jkind.lustre.BoolExpr) RealExpr(jkind.lustre.RealExpr) IdExpr(jkind.lustre.IdExpr) HashMap(java.util.HashMap) NamedType(jkind.lustre.NamedType) RecordExpr(jkind.lustre.RecordExpr)

Example 4 with RecordType

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

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

the class PrettyPrintVisitor method writeType.

private void writeType(Type type) {
    if (type instanceof RecordType) {
        RecordType recordType = (RecordType) type;
        write("struct {");
        Iterator<Entry<String, Type>> iterator = recordType.fields.entrySet().iterator();
        while (iterator.hasNext()) {
            Entry<String, Type> entry = iterator.next();
            write(entry.getKey());
            write(" : ");
            write(entry.getValue());
            if (iterator.hasNext()) {
                write("; ");
            }
        }
        write("}");
    } else if (type instanceof EnumType) {
        EnumType enumType = (EnumType) type;
        write("enum {");
        Iterator<String> iterator = enumType.values.iterator();
        while (iterator.hasNext()) {
            write(iterator.next());
            if (iterator.hasNext()) {
                write(", ");
            }
        }
        write("}");
    } else {
        write(type);
    }
}
Also used : Entry(java.util.Map.Entry) RecordType(jkind.lustre.RecordType) Type(jkind.lustre.Type) EnumType(jkind.lustre.EnumType) NamedType(jkind.lustre.NamedType) RecordType(jkind.lustre.RecordType) EnumType(jkind.lustre.EnumType) Iterator(java.util.Iterator)

Aggregations

RecordType (jkind.lustre.RecordType)11 Type (jkind.lustre.Type)9 NamedType (jkind.lustre.NamedType)8 ArrayList (java.util.ArrayList)5 EnumType (jkind.lustre.EnumType)5 Expr (jkind.lustre.Expr)5 RecordAccessExpr (jkind.lustre.RecordAccessExpr)5 Entry (java.util.Map.Entry)4 ArrayType (jkind.lustre.ArrayType)3 BinaryExpr (jkind.lustre.BinaryExpr)3 BoolExpr (jkind.lustre.BoolExpr)3 IdExpr (jkind.lustre.IdExpr)3 AgreeNode (com.rockwellcollins.atc.agree.analysis.ast.AgreeNode)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ArrayAccessExpr (jkind.lustre.ArrayAccessExpr)2 IntExpr (jkind.lustre.IntExpr)2 Node (jkind.lustre.Node)2 NodeCallExpr (jkind.lustre.NodeCallExpr)2 RecordExpr (jkind.lustre.RecordExpr)2