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