Search in sources :

Example 6 with TypeDef

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

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

the class AGREESimulationStateElementFactory method createStateElements.

/**
 * Creates and returns the root state elements for a specified simulation program.
 * @param program
 * @return
 */
public static List<AGREESimulationStateElement> createStateElements(final SimulationProgram program) {
    Objects.requireNonNull(program, "program must not be null");
    // Build a component instance to simulation variable collection map
    final Map<ComponentInstance, Collection<SimulationVariable>> componentInstanceToVariablesMap = new HashMap<ComponentInstance, Collection<SimulationVariable>>();
    for (final SimulationVariable var : program.getVariables()) {
        if (!componentInstanceToVariablesMap.containsKey(var.getComponentInstance())) {
            componentInstanceToVariablesMap.put(var.getComponentInstance(), new ArrayList<SimulationVariable>());
        }
        componentInstanceToVariablesMap.get(var.getComponentInstance()).add(var);
    }
    // Build a type id to type map
    final Map<String, jkind.lustre.Type> typeIdToTypeMap = new HashMap<String, jkind.lustre.Type>();
    for (final TypeDef typeDef : program.getLustreProgram().types) {
        typeIdToTypeMap.put(typeDef.id, typeDef.type);
    }
    return Collections.unmodifiableList(createVariableStateElements(null, program.getType(), program.getComponentInstance(), null, componentInstanceToVariablesMap, typeIdToTypeMap, program.getComponentInstanceToAgreeNodeMap(), true));
}
Also used : SimulationProgramType(edu.uah.rsesc.aadlsimulator.agree.SimulationProgramType) RecordType(jkind.lustre.RecordType) Type(jkind.lustre.Type) NamedType(jkind.lustre.NamedType) ArrayType(jkind.lustre.ArrayType) TypeDef(jkind.lustre.TypeDef) HashMap(java.util.HashMap) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) Collection(java.util.Collection) SimulationVariable(edu.uah.rsesc.aadlsimulator.agree.SimulationVariable)

Example 8 with TypeDef

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

the class AgreeUtils method getTypeSynonmyms.

private static Collection<? extends TypeDef> getTypeSynonmyms() {
    List<TypeDef> types = new ArrayList<>();
    types.add(new TypeDef("Base_Types__Boolean", NamedType.BOOL));
    types.add(new TypeDef("Base_Types__Unsigned", NamedType.INT));
    types.add(new TypeDef("Base_Types__Unsigned_64", NamedType.INT));
    types.add(new TypeDef("Base_Types__Unsigned_32", NamedType.INT));
    types.add(new TypeDef("Base_Types__Unsigned_16", NamedType.INT));
    types.add(new TypeDef("Base_Types__Unsigned_8", NamedType.INT));
    types.add(new TypeDef("Base_Types__Integer", NamedType.INT));
    types.add(new TypeDef("Base_Types__Integer_64", NamedType.INT));
    types.add(new TypeDef("Base_Types__Integer_32", NamedType.INT));
    types.add(new TypeDef("Base_Types__Integer_16", NamedType.INT));
    types.add(new TypeDef("Base_Types__Integer_8", NamedType.INT));
    types.add(new TypeDef("Base_Types__Float", NamedType.REAL));
    types.add(new TypeDef("Base_Types__Float_32", NamedType.REAL));
    types.add(new TypeDef("Base_Types__Float_64", NamedType.REAL));
    return types;
}
Also used : TypeDef(jkind.lustre.TypeDef) ArrayList(java.util.ArrayList)

Example 9 with TypeDef

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

the class AgreeUtils method getLustreTypes.

public static List<TypeDef> getLustreTypes(AgreeProgram agreeProgram) {
    List<TypeDef> types = new ArrayList<>();
    for (Type type : agreeProgram.globalTypes) {
        String typeName;
        if (type instanceof RecordType) {
            typeName = ((RecordType) type).id;
        } else if (type instanceof EnumType) {
            typeName = ((EnumType) type).id;
        } else {
            throw new AgreeException("Unable to handle type of type '" + type.getClass() + "'");
        }
        types.add(new TypeDef(typeName, type));
    }
    // add synonym types
    types.addAll(getTypeSynonmyms());
    return types;
}
Also used : RecordType(jkind.lustre.RecordType) EnumType(jkind.lustre.EnumType) ComponentType(org.osate.aadl2.ComponentType) Type(jkind.lustre.Type) NamedType(jkind.lustre.NamedType) TypeDef(jkind.lustre.TypeDef) RecordType(jkind.lustre.RecordType) EnumType(jkind.lustre.EnumType) ArrayList(java.util.ArrayList)

Example 10 with TypeDef

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

the class PrettyPrintVisitor method visit.

@Override
public Void visit(Program program) {
    main = program.main;
    if (!program.types.isEmpty()) {
        for (TypeDef typeDef : program.types) {
            typeDef.accept(this);
            newline();
        }
        newline();
    }
    if (!program.constants.isEmpty()) {
        for (Constant constant : program.constants) {
            constant.accept(this);
            newline();
        }
        newline();
    }
    Iterator<Node> iterator = program.nodes.iterator();
    while (iterator.hasNext()) {
        iterator.next().accept(this);
        newline();
        if (iterator.hasNext()) {
            newline();
        }
    }
    return null;
}
Also used : TypeDef(jkind.lustre.TypeDef) Constant(jkind.lustre.Constant) Node(jkind.lustre.Node)

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