Search in sources :

Example 11 with X

use of ast.Expression.X in project L42 by ElvisResearchGroup.

the class Desugar method cfNameK.

//private static final Doc consistentDoc=Doc.factory("@consistent\n");
/* public static List<Member> cfType(ConcreteHeader h,Doc doc){
    //doc=Doc.factory("@private");
    List<Member> result=new  ArrayList<Member>();
    MethodWithType k = cfMutK(doc,h);
    Mdf nameMdf=mdfForNamedK(h);
    if(nameMdf==Mdf.Lent){k=cfLentK(k);}
    MethodWithType kOut =cfNameK(doc, nameMdf, h, k.getMs());
    result.add(k);
    result.add(kOut);
    //cfType1(h,doc, result);
    for(FieldDec f:h.getFs()){
      Doc fDoc=doc.sum(f.getDoc());
      cfSetter(h.getP(),f,fDoc,result);
      cfExposer(h.getP(),f,fDoc,result);
      cfGetter(h.getP(),f,fDoc,result);
    }
    return result;
  }
*/
private static MethodWithType cfNameK(Doc doc, Mdf mdf, ast.Ast.ConcreteHeader h, MethodSelector called) {
    List<Type> ts = new ArrayList<Type>();
    for (FieldDec fi : h.getFs()) {
        Type ti = fi.getT();
        ts.add(ti.withDoc(ti.getDoc().sum(fi.getDoc())));
    }
    MethodSelector ms = called.withName(h.getName());
    Type resT = new ast.Ast.Type(mdf, ast.Ast.Path.outer(0), Doc.empty());
    MethodType mt = new MethodType(false, ast.Ast.Mdf.Class, ts, resT, Collections.emptyList());
    Parameters ps = new Parameters(Optional.empty(), called.getNames(), called.getNames().stream().map(n -> new X(Position.noInfo, n)).collect(Collectors.toList()));
    MCall body = new MCall(new Expression.EPath(h.getP(), Path.outer(0)), called.nameToS(), Doc.empty(), ps, h.getP());
    return new MethodWithType(doc, ms, mt, Optional.of(body), h.getP());
}
Also used : MethodType(ast.Ast.MethodType) MethodSelector(ast.Ast.MethodSelector) Parameters(ast.Ast.Parameters) ArrayList(java.util.ArrayList) MethodWithType(ast.Expression.ClassB.MethodWithType) Type(ast.Ast.Type) MethodWithType(ast.Expression.ClassB.MethodWithType) MethodType(ast.Ast.MethodType) FieldDec(ast.Ast.FieldDec) Expression(ast.Expression) MCall(ast.Expression.MCall) X(ast.Expression.X) MethodSelectorX(ast.Ast.MethodSelectorX)

Example 12 with X

use of ast.Expression.X in project L42 by ElvisResearchGroup.

the class DesugarVars method _blockVarClass.

private RoundBlock _blockVarClass(RoundBlock s) {
    if (s.getContents().isEmpty()) {
        return s;
    }
    List<VarDec> varDecs = new ArrayList<VarDec>(s.getContents().get(0).getDecs());
    int pos = firstVar(varDecs);
    if (pos == -1) {
        return s;
    }
    VarDecXE varDec = (VarDecXE) varDecs.get(pos);
    varDecs.set(pos, varDec.withVar(false));
    VarDecCE ce = getClassBForVar(varDec);
    VarDecXE d = getDecForVar(ce.getInner().getName(), varDec);
    X x = new X(s.getP(), varDec.getX());
    X z = new X(s.getP(), d.getX());
    int d3First = findD2(x, pos, varDecs);
    RoundBlock fake = getFakeBlock(x, z, s, varDecs, d3First);
    List<VarDec> trueDecs = new ArrayList<VarDec>();
    trueDecs.add(ce);
    if (d3First != -1) {
        trueDecs.addAll(varDecs.subList(0, d3First));
    } else {
        trueDecs.addAll(varDecs);
    }
    trueDecs.add(d);
    trueDecs.addAll(fake.getContents().get(0).getDecs());
    List<Expression.BlockContent> trueContent = new ArrayList<>();
    trueContent.add(new Expression.BlockContent(trueDecs, fake.getContents().get(0).get_catch()));
    return fake.withContents(trueContent);
}
Also used : Expression(ast.Expression) VarDec(ast.Ast.VarDec) ArrayList(java.util.ArrayList) X(ast.Expression.X) BlockContent(ast.Expression.BlockContent) VarDecCE(ast.Ast.VarDecCE) RoundBlock(ast.Expression.RoundBlock) VarDecXE(ast.Ast.VarDecXE) BlockContent(ast.Expression.BlockContent)

Example 13 with X

use of ast.Expression.X in project L42 by ElvisResearchGroup.

the class DesugarVars method getDecForVar.

private VarDecXE getDecForVar(Ast.C cName, VarDecXE varDec) {
    Type nt = new Type(Mdf.Mutable, Path.outer(0).pushC(cName), Doc.empty());
    Position pos = Desugar.getPosition(varDec.getInner());
    MCall right = new MCall(new Expression.EPath(pos, nt.getPath()), "#apply", Doc.empty(), Desugar.getPs("inner", new X(pos, varDec.getX())), pos);
    String nameZ = Functions.freshName(nt.getPath(), usedVars);
    //usedVars.add(nameZ);
    return new VarDecXE(false, Optional.of(nt), nameZ, right);
}
Also used : Type(ast.Ast.Type) MethodWithType(ast.Expression.ClassB.MethodWithType) Position(ast.Ast.Position) Expression(ast.Expression) MCall(ast.Expression.MCall) X(ast.Expression.X) VarDecXE(ast.Ast.VarDecXE)

Example 14 with X

use of ast.Expression.X 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 15 with X

use of ast.Expression.X 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)

Aggregations

Expression (ast.Expression)15 X (ast.Expression.X)15 ArrayList (java.util.ArrayList)10 VarDecXE (ast.Ast.VarDecXE)7 Catch (ast.Expression.Catch)7 MethodSelectorX (ast.Ast.MethodSelectorX)6 Type (ast.Ast.Type)6 VarDec (ast.Ast.VarDec)6 MethodWithType (ast.Expression.ClassB.MethodWithType)6 Parameters (ast.Ast.Parameters)5 VarDecE (ast.Ast.VarDecE)5 RoundBlock (ast.Expression.RoundBlock)5 BlockContent (ast.Expression.BlockContent)3 MCall (ast.Expression.MCall)3 Signal (ast.Expression.Signal)3 MethodType (ast.Ast.MethodType)2 Position (ast.Ast.Position)2 Catch1 (ast.Expression.Catch1)2 FieldDec (ast.Ast.FieldDec)1 MethodSelector (ast.Ast.MethodSelector)1