use of jkind.lustre.EnumType 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;
}
use of jkind.lustre.EnumType 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);
}
}
use of jkind.lustre.EnumType in project AGREE by loonwerks.
the class TypeTable method getLustreType.
public Type getLustreType(AgreeTypeSystem.TypeDef agreeType) {
if (agreeType == AgreeTypeSystem.Prim.IntTypeDef) {
return NamedType.INT;
} else if (agreeType == AgreeTypeSystem.Prim.RealTypeDef) {
return NamedType.REAL;
} else if (agreeType == AgreeTypeSystem.Prim.BoolTypeDef) {
return NamedType.BOOL;
} else if (agreeType instanceof AgreeTypeSystem.RangeIntTypeDef) {
return NamedType.INT;
} else if (agreeType instanceof AgreeTypeSystem.RangeRealTypeDef) {
return NamedType.REAL;
} else if (agreeType instanceof AgreeTypeSystem.RecordTypeDef) {
String name = ((AgreeTypeSystem.RecordTypeDef) agreeType).name.replace("::", "__").replace(".", "__");
Map<String, AgreeTypeSystem.TypeDef> agreeFields = ((AgreeTypeSystem.RecordTypeDef) agreeType).fields;
Map<String, Type> lustreFields = new HashMap<>();
for (Entry<String, AgreeTypeSystem.TypeDef> entry : agreeFields.entrySet()) {
String key = entry.getKey();
Type lt = updateLustreTypeMap(entry.getValue());
if (lt != null) {
lustreFields.put(key, lt);
}
}
RecordType lustreRecType = new RecordType(name, lustreFields);
return lustreRecType;
} else if (agreeType instanceof AgreeTypeSystem.EnumTypeDef) {
String name = ((AgreeTypeSystem.EnumTypeDef) agreeType).name.replace("::", "__").replace(".", "__");
List<String> enumValues = new ArrayList<String>();
for (String raw : ((AgreeTypeSystem.EnumTypeDef) agreeType).values) {
String enumValue = raw.replace("::", "__").replace(".", "__");
enumValues.add(enumValue);
}
EnumType lustreEnumType = new EnumType(name, enumValues);
return lustreEnumType;
} else if (agreeType instanceof AgreeTypeSystem.ArrayTypeDef) {
AgreeTypeSystem.TypeDef agreeBaseType = ((AgreeTypeSystem.ArrayTypeDef) agreeType).stemType;
int dimension = ((AgreeTypeSystem.ArrayTypeDef) agreeType).size;
Type lustreBaseType = updateLustreTypeMap(agreeBaseType);
if (lustreBaseType != null) {
ArrayType lustreArrayType = new ArrayType(lustreBaseType, dimension);
return lustreArrayType;
}
}
// Jkind does not reason over this.
return null;
}
use of jkind.lustre.EnumType 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;
}
Aggregations