use of jkind.lustre.Type in project AGREE by loonwerks.
the class RemoveCondacts method clockArrowsAndPres.
private Node clockArrowsAndPres(Node node, final IdExpr clock) {
final VarDecl init = new VarDecl(namePrefix + "init", NamedType.BOOL);
final List<Equation> preEquations = new ArrayList<>();
final List<VarDecl> preLocals = new ArrayList<>();
node = (Node) node.accept(new AstMapVisitor() {
private int counter = 0;
@Override
public Expr visit(BinaryExpr e) {
if (e.op == BinaryOp.ARROW) {
return new IfThenElseExpr(new IdExpr(init.id), e.left.accept(this), e.right.accept(this));
} else {
return super.visit(e);
}
}
@Override
public Expr visit(UnaryExpr e) {
if (e.op == UnaryOp.PRE) {
String state = namePrefix + "state" + counter++;
Type type = e.expr.accept(typeReconstructor);
preLocals.add(new VarDecl(state, type));
// state = if clock then expr else pre state
preEquations.add(new Equation(new IdExpr(state), new IfThenElseExpr(clock, e.expr.accept(this), new UnaryExpr(UnaryOp.PRE, new IdExpr(state)))));
return new UnaryExpr(UnaryOp.PRE, new IdExpr(state));
} else {
return super.visit(e);
}
}
});
NodeBuilder builder = new NodeBuilder(node);
builder.addLocals(preLocals);
builder.addLocal(init);
builder.addEquations(preEquations);
// init = true -> if pre clock then false else pre init
builder.addEquation(new Equation(new IdExpr(init.id), new BinaryExpr(new BoolExpr(true), BinaryOp.ARROW, new IfThenElseExpr(new UnaryExpr(UnaryOp.PRE, clock), new BoolExpr(false), new UnaryExpr(UnaryOp.PRE, new IdExpr(init.id))))));
return builder.build();
}
use of jkind.lustre.Type in project AGREE by loonwerks.
the class TcgXmlWriter method writeSignal.
private void writeSignal(int k, Signal<Value> signal) throws Exception {
String name = escapeXml(signal.getName());
// TODO: fix this with the type map!
Type type;
if (signal.getValues().isEmpty()) {
throw new TcgException("Unable to assertain signal type in XmlWriter");
} else {
Map.Entry<Integer, Value> entry = signal.getValues().entrySet().iterator().next();
Value v = entry.getValue();
if (v instanceof IntegerValue) {
type = NamedType.INT;
} else if (v instanceof RealValue) {
type = NamedType.REAL;
} else if (v instanceof BooleanValue) {
type = NamedType.BOOL;
} else {
throw new TcgException("Unexpected signal type in XmlWriter");
}
}
out.println(" <Signal name=\"" + name + "\" type=\"" + type + "\">");
for (int i = 0; i < k; i++) {
out.println(" <Value time=\"" + i + "\">" + formatValue(signal.getValue(i)) + "</Value>");
}
out.println(" </Signal>");
}
use of jkind.lustre.Type 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.Type in project AGREE by loonwerks.
the class VariableMap method addEquality.
private void addEquality(final Expr idExpr1, final Expr idExpr2) {
Objects.requireNonNull(idExpr1, "id1 must not be null");
Objects.requireNonNull(idExpr2, "id2 must not be null");
markVariableMapAsDirty();
final Type id1ExprType = idExpr1.accept(typeReconstructor);
if (id1ExprType instanceof NamedType) {
// Named type equality
final String id1 = idExpr1.toString();
final String id2 = idExpr2.toString();
final Variable var1 = variables.get(id1);
final Variable var2 = variables.get(id2);
if (var1 == null && var2 == null) {
final Variable newVar = new Variable((NamedType) id1ExprType);
newVar.ids.add(id1);
newVar.ids.add(id2);
variables.put(id1, newVar);
variables.put(id2, newVar);
} else if (var1 == null) {
var2.ids.add(id1);
variables.put(id1, var2);
} else if (var2 == null) {
var1.ids.add(id2);
variables.put(id2, var1);
} else {
// Decide which variable to keep
final Variable keepVar;
final Variable removeVar;
if (var1.ids.size() <= var2.ids.size()) {
keepVar = var1;
removeVar = var2;
} else {
keepVar = var2;
removeVar = var1;
}
// Merge the remove var fields into the keep var
keepVar.ids.addAll(removeVar.ids);
keepVar.relatedExpressions.addAll(removeVar.relatedExpressions);
// Update the variable map to only reference the keep var
for (final String removeId : removeVar.ids) {
variables.put(removeId, keepVar);
}
}
}
}
use of jkind.lustre.Type in project AGREE by loonwerks.
the class AgreeASTBuilder method caseUninterpretedFnDef.
@Override
public Expr caseUninterpretedFnDef(UninterpretedFnDef uFnDef) {
String functionName = AgreeUtils.getNodeName(uFnDef).replace("::", "__");
for (Function function : uninterpretedFunc) {
if (function.id.equals(functionName)) {
return null;
}
}
List<VarDecl> inputs = agreeVarsFromArgs(uFnDef.getArgs(), null);
Type outType = symbolTable.updateLustreTypeMap(AgreeTypeSystem.typeDefFromType(uFnDef.getType()));
if (outType != null) {
VarDecl outVar = new VarDecl("_outvar", outType);
List<VarDecl> outputs = Collections.singletonList(outVar);
Function function = new Function(functionName, inputs, outputs);
addToFunctionList(function);
}
return null;
}
Aggregations