Search in sources :

Example 41 with Expression

use of ast.Expression in project L42 by ElvisResearchGroup.

the class InjectionOnSugar method visit.

@Override
public Expression visit(MCall s) {
    ast.Expression receiver = lift(s.getInner());
    String name = s.getS().nameToS();
    Doc docs = s.getDoc();
    List<String> xs = s.getS().getNames();
    List<ast.ExpCore> es1 = s.getEs();
    List<ast.Expression> es = new ArrayList<ast.Expression>();
    for (ast.ExpCore e : es1) {
        es.add(lift(e));
    }
    ast.Ast.Parameters ps = new ast.Ast.Parameters(Optional.<ast.Expression>empty(), xs, es);
    Position pos = s.getP();
    return new Expression.MCall(receiver, name, docs, ps, pos);
}
Also used : ExpCore(ast.ExpCore) Ast(ast.Ast) Position(ast.Ast.Position) ArrayList(java.util.ArrayList) ExpCore(ast.ExpCore) Expression(ast.Expression) Expression(ast.Expression) MCall(ast.ExpCore.MCall) Doc(ast.Ast.Doc)

Example 42 with Expression

use of ast.Expression in project L42 by ElvisResearchGroup.

the class InjectionOnSugar method visit.

@Override
public Expression visit(Block s) {
    Doc docs = s.getDoc();
    Expression inner = lift(s.getInner());
    List<VarDec> decs = new ArrayList<VarDec>();
    for (int i = 0; i < s.getDecs().size(); i++) {
        Optional<Type> t = s.getDecs().get(i).getT();
        String x = s.getDecs().get(i).getX();
        Expression e = lift(s.getDecs().get(i).getInner());
        decs.add(new VarDecXE(s.getDecs().get(i).isVar(), t, x, e));
    }
    List<Expression.Catch> _catch = injectionCatch(s.getOns());
    List<Expression.BlockContent> contents = new ArrayList<>();
    if (!decs.isEmpty() || !_catch.isEmpty()) {
        contents.add(new Expression.BlockContent(decs, _catch));
    }
    Expression.Position pos = s.getP();
    Expression.RoundBlock result = new Expression.RoundBlock(pos, docs, inner, contents);
    //assert WellFormedness.blockCheck(result);, no it can actually get wrong?
    return result;
}
Also used : ArrayList(java.util.ArrayList) Type(ast.Ast.Type) MethodType(ast.Ast.MethodType) Expression(ast.Expression) VarDec(ast.Ast.VarDec) Doc(ast.Ast.Doc) VarDecXE(ast.Ast.VarDecXE)

Example 43 with Expression

use of ast.Expression in project L42 by ElvisResearchGroup.

the class Desugar method liftKs.

protected List<Catch> liftKs(List<Catch> ks) {
    List<Catch> result = new ArrayList<>();
    String x = Functions.freshName("catched", usedVars);
    for (Catch k : ks) {
        if (k instanceof DesugarCatchDefault.CatchToComplete) {
            Catch k2 = this.liftK(((DesugarCatchDefault.CatchToComplete) k).catch1);
            result.add(new DesugarCatchDefault.CatchToComplete((Catch1) k2));
            continue;
        }
        k.match(k1 -> result.add(liftK(k1)), kM -> {
            for (Type t : kM.getTs()) {
                result.add(liftK(new Expression.Catch1(kM.getP(), kM.getKind(), t, x, kM.getInner())));
            }
            return false;
        }, kP -> {
            for (Type t : kP.getTs()) {
                Expression inner = kP.getInner();
                inner = new Expression.FCall(kP.getP(), inner, Doc.empty(), new ast.Ast.Parameters(Optional.of(new X(kP.getP(), x)), Collections.emptyList(), Collections.emptyList()));
                inner = new Expression.Signal(kP.getKind(), inner);
                result.add(liftK(new Expression.Catch1(kP.getP(), SignalKind.Exception, t, x, inner)));
            }
            return false;
        });
    }
    return result;
}
Also used : Parameters(ast.Ast.Parameters) Catch(ast.Expression.Catch) ArrayList(java.util.ArrayList) Type(ast.Ast.Type) MethodWithType(ast.Expression.ClassB.MethodWithType) MethodType(ast.Ast.MethodType) Expression(ast.Expression) Catch1(ast.Expression.Catch1) FCall(ast.Expression.FCall) X(ast.Expression.X) MethodSelectorX(ast.Ast.MethodSelectorX)

Example 44 with Expression

use of ast.Expression in project L42 by ElvisResearchGroup.

the class Desugar method getBlock.

static RoundBlock getBlock(Position p, Expression xe, List<Expression.Catch> ks, Expression inner) {
    List<Expression.BlockContent> bc = new ArrayList<>();
    List<VarDec> decs = new ArrayList<VarDec>();
    decs.add(new VarDecE(xe));
    bc.add(new Expression.BlockContent(decs, ks));
    return new RoundBlock(p, Doc.empty(), inner, bc);
}
Also used : Expression(ast.Expression) VarDec(ast.Ast.VarDec) ArrayList(java.util.ArrayList) RoundBlock(ast.Expression.RoundBlock) VarDecE(ast.Ast.VarDecE)

Example 45 with Expression

use of ast.Expression in project L42 by ElvisResearchGroup.

the class Desugar method visit1Step.

public MCall visit1Step(Literal s) {
    //(b=r.builder() b.a() b.b() b.c() .... b)
    List<VarDec> vd = new ArrayList<>();
    Expression k = getMCall(s.getP(), s.getReceiver(), "#builder", getPs());
    String x = Functions.freshName("b", usedVars);
    X b = new X(s.getP(), x);
    vd.add(new VarDecXE(false, Optional.empty(), x, k));
    for (char ch : s.getInner().toCharArray()) {
        String name = Character.toString(ch);
        if (!Character.isAlphabetic(ch) && !Character.isDigit(ch)) {
            name = desugarSymbol(name);
        }
        vd.add(new VarDecE(getMCall(s.getP(), b, "#" + name, getPs())));
    }
    Expression inner = getBlock(s.getP(), vd, b);
    Parameters ps = new Parameters(Optional.empty(), Collections.singletonList("builder"), Collections.singletonList(inner));
    return getMCall(s.getP(), s.getReceiver(), "#from", ps);
}
Also used : Parameters(ast.Ast.Parameters) Expression(ast.Expression) VarDec(ast.Ast.VarDec) ArrayList(java.util.ArrayList) X(ast.Expression.X) MethodSelectorX(ast.Ast.MethodSelectorX) VarDecE(ast.Ast.VarDecE) VarDecXE(ast.Ast.VarDecXE)

Aggregations

Expression (ast.Expression)66 ArrayList (java.util.ArrayList)24 VarDec (ast.Ast.VarDec)14 X (ast.Expression.X)13 Type (ast.Ast.Type)11 VarDecXE (ast.Ast.VarDecXE)11 ExpCore (ast.ExpCore)11 Catch (ast.Expression.Catch)11 RoundBlock (ast.Expression.RoundBlock)11 VarDecE (ast.Ast.VarDecE)10 Doc (ast.Ast.Doc)8 Position (ast.Ast.Position)8 MethodSelectorX (ast.Ast.MethodSelectorX)7 Parameters (ast.Ast.Parameters)7 MethodWithType (ast.Expression.ClassB.MethodWithType)7 MethodType (ast.Ast.MethodType)6 ClassB (ast.ExpCore.ClassB)6 InjectionOnCore (sugarVisitors.InjectionOnCore)6 Ast (ast.Ast)5 Path (ast.Ast.Path)4