Search in sources :

Example 1 with Op

use of ast.Ast.Op 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));
}
Also used : BinOp(ast.Expression.BinOp) Op(ast.Ast.Op) UnOp(ast.Expression.UnOp) Expression(ast.Expression) BinOp(ast.Expression.BinOp) X(ast.Expression.X)

Aggregations

Op (ast.Ast.Op)1 Expression (ast.Expression)1 BinOp (ast.Expression.BinOp)1 UnOp (ast.Expression.UnOp)1 X (ast.Expression.X)1