use of ast.Expression.BinOp in project L42 by ElvisResearchGroup.
the class Desugar method visit.
public Expression visit(BinOp s) {
Op op = s.getOp();
if (op == Op.ColonEqual) {
//TODO: set the right expect type?
return s.withRight(lift(s.getRight()));
}
if (op.kind == Ast.OpKind.EqOp) {
//go from, for example a++=b into a:=a ++b
Op op2 = Op.fromString(s.getOp().inner.substring(0, s.getOp().inner.length() - 1));
BinOp s2 = s.withOp(op2);
//NO!s2=s2.withLeft(getMCall(s.getP(),s.getLeft(),"#inner",getPs()));
return visit(new BinOp(s.getP(), s.getLeft(), Op.ColonEqual, Doc.empty(), s2));
}
if (op.negated) {
BinOp s2 = s.withOp(op.nonNegatedVersion());
return visit(getMCall(s.getP(), s2, desugarName(Op.Bang.inner), getPs()));
}
if (op.normalized) {
return visit(getMCall(s.getP(), s.getLeft(), desugarName(s.getOp().inner), getPs(s.getRight())));
}
String x = Functions.freshName("opNorm", usedVars);
BinOp s2 = new BinOp(s.getP(), s.getRight(), op.normalizedVersion(), s.getDoc(), new Expression.X(s.getP(), x));
return visit(getBlock(s.getP(), x, s.getLeft(), s2));
}
use of ast.Expression.BinOp in project L42 by ElvisResearchGroup.
the class DesugarVars method findD2.
private int findD2(X x, int pos, List<VarDec> decs) {
for (VarDec _dec : decs.subList(pos + 1, decs.size())) {
pos += 1;
Expression[] inner = { null };
_dec.match(xe -> inner[0] = xe.getInner(), e -> inner[0] = e.getInner(), ce -> null);
if (inner[0] == null) {
continue;
}
boolean isAssigned = Exists.of(inner[0], e -> {
if (!(e instanceof BinOp)) {
return false;
}
BinOp bo = (BinOp) e;
if (bo.getOp().kind != Ast.OpKind.EqOp) {
return false;
}
return bo.getLeft().equals(x);
});
if (isAssigned) {
return pos;
}
}
return -1;
}