Search in sources :

Example 56 with Expression

use of ast.Expression in project L42 by ElvisResearchGroup.

the class DesugarW method with_C_A.

private Expression with_C_A(Position pos, List<String> xs, With.On on0, Expression continuation) {
    List<String> ys = new ArrayList<String>();
    for (String x : xs) {
        ys.add(Functions.freshName(x, usedVars));
    }
    //(
    List<VarDec> decs = new ArrayList<>();
    //TODO:?? now is very strange and requires the mdf to propagate it to the locally introduced var?
    //casts: every cast is a block content e+catch
    {
        int i = -1;
        for (Type ti : on0.getTs()) {
            i += 1;
            String xi = xs.get(i);
            String yi = ys.get(i);
            decs.add(castT(pos, ti, yi, xi));
        }
    }
    //catch exception Void recursive call
    Catch k = Desugar.getK(pos, SignalKind.Exception, "", Type.immVoid, continuation);
    //main expression with 'T' renaming
    Expression e0 = on0.getInner();
    {
        int i = -1;
        for (Type ti : on0.getTs()) {
            i += 1;
            String xi = xs.get(i);
            String yi = ys.get(i);
            e0 = renameT(e0, new Expression.X(pos, xi), ti, new Expression.X(pos, yi));
        }
    }
    BlockContent content = new BlockContent(decs, Collections.singletonList(k));
    List<BlockContent> contents = new ArrayList<BlockContent>();
    contents.add(content);
    contents.add(Desugar.getBlockContent(e0));
    //void)
    return new RoundBlock(pos, Doc.empty(), Expression._void.instance, contents);
}
Also used : Type(ast.Ast.Type) MethodWithType(ast.Expression.ClassB.MethodWithType) Expression(ast.Expression) Catch(ast.Expression.Catch) VarDec(ast.Ast.VarDec) ArrayList(java.util.ArrayList) BlockContent(ast.Expression.BlockContent) RoundBlock(ast.Expression.RoundBlock) X(ast.Expression.X)

Example 57 with Expression

use of ast.Expression in project L42 by ElvisResearchGroup.

the class DesugarW method withE1CatchExceptionOnVoidE2elseE3.

private static RoundBlock withE1CatchExceptionOnVoidE2elseE3(Position pos, Expression e1, Expression e2, Expression e3) {
    Expression.Catch k = Desugar.getK(pos, SignalKind.Exception, "", Type.immVoid, e2);
    List<Expression.BlockContent> cs = new ArrayList<>();
    cs.add(Desugar.getBlockContent(e1, k));
    return new RoundBlock(pos, Doc.empty(), e3, cs);
}
Also used : Expression(ast.Expression) ArrayList(java.util.ArrayList) BlockContent(ast.Expression.BlockContent) RoundBlock(ast.Expression.RoundBlock) Catch(ast.Expression.Catch)

Example 58 with Expression

use of ast.Expression in project L42 by ElvisResearchGroup.

the class Desugar method visit.

public Expression visit(If s) {
    if (!s.get_else().isPresent()) {
        return visit(s.with_else(Optional.of(Expression._void.instance)));
    }
    Position p = s.getP();
    if (!(s.getCond() instanceof Ast.Atom)) {
        String x = Functions.freshName("cond", usedVars);
        return visit(getBlock(p, x, s.getCond(), s.withCond(new X(p, x))));
    }
    MCall check = getMCall(p, s.getCond(), "#checkTrue", getPs());
    Expression.Catch k = getK(p, SignalKind.Exception, "", Type.immVoid, s.get_else().get());
    return visit(getBlock(p, check, Collections.singletonList(k), s.getThen()));
}
Also used : Position(ast.Ast.Position) Expression(ast.Expression) MCall(ast.Expression.MCall) X(ast.Expression.X) MethodSelectorX(ast.Ast.MethodSelectorX) Catch(ast.Expression.Catch)

Example 59 with Expression

use of ast.Expression in project L42 by ElvisResearchGroup.

the class Desugar method getBlock.

static RoundBlock getBlock(Position p, Expression xe, 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, Collections.emptyList()));
    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 60 with Expression

use of ast.Expression in project L42 by ElvisResearchGroup.

the class PlgWrapperGenerator method parseAndDesugar.

private static ExpCore parseAndDesugar(String s) {
    Expression code1 = Parser.parse("PlgWrapperGenerator", s);
    Expression code2 = Desugar.of(code1);
    return code2.accept(new InjectionOnCore());
}
Also used : Expression(ast.Expression) InjectionOnCore(sugarVisitors.InjectionOnCore)

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