use of ast.Expression in project L42 by ElvisResearchGroup.
the class Desugar method visit.
public Expression visit(While s) {
Expression cond = Desugar.getMCall(s.getP(), s.getCond(), "#checkTrue", Desugar.getPs());
RoundBlock b = Desugar.getBlock(s.getP(), cond, s.getThen());
Loop l = new Loop(b);
Type _void = Type.immVoid;
Expression.Catch k = Desugar.getK(s.getP(), SignalKind.Exception, "", _void, Expression._void.instance);
RoundBlock b2 = Desugar.getBlock(s.getP(), l, Collections.singletonList(k), Expression._void.instance);
return b2.accept(this);
}
use of ast.Expression in project L42 by ElvisResearchGroup.
the class Desugar method visit.
public Expression visit(ClassB s) {
Position pos = s.getP();
assert !(s.getH() instanceof ConcreteHeader);
if (!s.getFields().isEmpty()) {
List<Member> ms = s.getFields().stream().flatMap(f -> Desugar.field(pos, f)).collect(Collectors.toList());
ms.addAll(s.getMs());
s = s.withMs(ms).withH(new Ast.TraitHeader());
}
Set<String> oldUsedVars = this.usedVars;
HashMap<String, Type> oldVarEnv = this.varEnv;
try {
s = (ClassB) super.visit(s);
s = FlatFirstLevelLocalNestedClasses.of(s, this);
s = DesugarCatchDefault.of(s);
return s;
} finally {
this.usedVars = oldUsedVars;
this.varEnv = oldVarEnv;
}
}
use of ast.Expression in project L42 by ElvisResearchGroup.
the class ReplState method add.
public ReplState add(String code) {
Expression.ClassB cbEmpty = new ClassB(Doc.empty(), new ast.Ast.InterfaceHeader(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Position.noInfo);
try {
//parse
Expression.ClassB codeTmp = (ClassB) Parser.parse("Repl", "{" + code + "}");
//new original
ClassReuse newOriginal = this.originalL;
List<ast.Expression.ClassB.Member> newOriginalMs = newOriginal.getInner().getMs();
newOriginalMs.addAll(codeTmp.getMs());
newOriginal.withInner(newOriginal.getInner().withMs(newOriginalMs));
//new src to desugar
List<ClassB.Member> newMs = new ArrayList<>();
int nestedAdded = 0;
for (Member m : this.desugaredL.getMs()) {
if (!(m instanceof NestedClass)) {
continue;
}
NestedClass nc = (NestedClass) m;
newMs.add(new ClassB.NestedClass(Doc.empty(), nc.getName(), cbEmpty, nc.getP()));
nestedAdded += 1;
}
newMs.addAll(codeTmp.getMs());
codeTmp = codeTmp.withMs(newMs);
Expression code2 = Desugar.of(codeTmp);
ExpCore.ClassB code3 = (ExpCore.ClassB) code2.accept(new InjectionOnCore());
// TODO: will die after new reduction Refresh of position identities, it is used to generate correct Java code.
code3 = (ExpCore.ClassB) code3.accept(new CloneVisitor() {
@Override
public ExpCore visit(ExpCore.ClassB cb) {
Position p = cb.getP();
cb = cb.withP(new Position(p.getFile(), p.getLine1(), p.getPos1(), p.getLine2(), p.getPos2(), p.get_next()));
return super.visit(cb);
}
});
//integrate new desugared src with old desugared code
List<Member> resultMs = new ArrayList<>(this.desugaredL.getMs());
for (int i = nestedAdded; i < code3.getMs().size(); i++) {
resultMs.add(code3.getMs().get(i));
}
code3 = code3.withMs(resultMs);
//call the repl and return
ExpCore.ClassB result = ProgramReduction.allSteps(code3);
return new ReplState(this.originalS + "\n" + code, newOriginal, result);
} catch (ParseCancellationException parser) {
System.out.println(parser.getMessage());
return null;
} catch (ErrorMessage msg) {
ErrorFormatter.topFormatErrorMessage(msg);
return null;
}
}
use of ast.Expression in project L42 by ElvisResearchGroup.
the class DesugarVars method of.
public static Expression of(Set<String> usedVars, Expression e) {
DesugarVars d = new DesugarVars();
d.usedVars = usedVars;
Expression result = e.accept(d);
return result;
}
use of ast.Expression in project L42 by ElvisResearchGroup.
the class DesugarW method castT.
private VarDecXE castT(Position pos, Type t, String y, String x) {
assert t instanceof Type;
Type nt = t;
String z = Functions.freshName("casted", usedVars);
List<Catch> ks = new ArrayList<>();
Type t2 = new Type(nt.getMdf(), Path.Any(), Doc.empty());
ks.add(new //case return captured
Expression.Catch1(//case return captured
pos, //case return captured
SignalKind.Return, //case return captured
t, //case return captured
z, //return it
new X(pos, z)));
ks.add(new //else
Expression.Catch1(//else
pos, //else
SignalKind.Return, //else
t2, //else
z, // exception void
new Signal(SignalKind.Exception, Expression._void.instance)));
RoundBlock block = Desugar.getBlock(pos, new Signal(SignalKind.Return, new X(pos, x)), ks, Desugar.errorMsg("CastT-Should be unreachable code"));
return new VarDecXE(false, Optional.of(t), y, block);
}
Aggregations