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;
}
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));
}
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;
}
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;
}
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;
}
Aggregations