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);
}
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;
}
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;
}
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);
}
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);
}
Aggregations