use of ast.Ast.Position in project L42 by ElvisResearchGroup.
the class ReplState method start.
public static ReplState start(String code) {
try {
Expression.ClassReuse code1 = (ClassReuse) Parser.parse("Repl", code);
auxiliaryGrammar.WellFormedness.checkAll(code1);
Expression.ClassReuse code2 = (ClassReuse) Desugar.of(code1);
assert auxiliaryGrammar.WellFormedness.checkAll(code2);
ExpCore.ClassB code3 = (ExpCore.ClassB) code2.accept(new InjectionOnCore());
assert coreVisitors.CheckNoVarDeclaredTwice.of(code3);
// 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);
}
});
ExpCore.ClassB result = ProgramReduction.allSteps(code3);
return new ReplState(code, code2, result);
} catch (org.antlr.v4.runtime.misc.ParseCancellationException parser) {
System.out.println(parser.getMessage());
return null;
} catch (ErrorMessage msg) {
ErrorFormatter.topFormatErrorMessage(msg);
return null;
}
}
use of ast.Ast.Position in project L42 by ElvisResearchGroup.
the class DesugarW method visit.
public Expression visit(With e) {
Position pos = e.getP();
//case a
e = with_A_applyDefault(e);
if (e.getIs().isEmpty() && e.getDecs().isEmpty()) {
//case c
return with_C_resolveXsBaseCase(pos, e.getXs(), e.getOns(), e.getDefaultE().get()).accept(this);
}
//case b
if (e.getIs().isEmpty()) {
return with_B_noI_makeBlock(e).accept(this);
}
//assert !e.getIs().isEmpty();
if (e.getXs().isEmpty() && e.getDecs().isEmpty() && e.getOns().isEmpty()) {
//case e
Expression b = e.getDefaultE().get();
//NOTE WELL: needed to avoid xs that can not be replaced in with xs... this is also the reason we need DesugarW in the first place.
b = b.accept(this);
return with_E_handleIs(pos, e.getIs(), b).accept(this);
}
//case d
return with_D_replace_XID_with_InestedDwithX(e).accept(this);
}
use of ast.Ast.Position 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()));
}
use of ast.Ast.Position in project L42 by ElvisResearchGroup.
the class TranslateExpression method visit.
//not a propagator visitor.
@Override
public Void visit(ExpCore.EPath s) {
Path ss = s.getInner();
if (ss.isPrimitive()) {
if (ss.equals(Path.Any())) {
res.append("platformSpecific.javaTranslation.Resources.Any.type");
}
if (ss.equals(Path.Library())) {
res.append("platformSpecific.javaTranslation.Resources.Library.type");
}
if (ss.equals(Path.Void())) {
res.append("platformSpecific.javaTranslation.Resources.Void.type");
}
return null;
}
ClassB cbs = Resources.getP().extractClassB(ss);
if (cbs.getPhase() == Phase.Coherent && IsCompiled.of(cbs)) {
res.append(Resources.nameOf(ss) + ".type ");
} else {
Position pos = Resources.getP().get(ss.outerNumber()).getP();
int hash = System.identityHashCode(pos);
String cs = s.toString();
int dotPos = cs.indexOf(".");
assert dotPos >= 0;
cs = cs.substring(dotPos);
res.append("platformSpecific.javaTranslation.Resources.fromHash(" + hash + ",\"" + cs + "\")");
}
return null;
}
Aggregations