use of ast.Ast.Path in project L42 by ElvisResearchGroup.
the class TestSumMethod method test.
@Test
public void test() {
TestHelper.configureForTest();
ClassB cb = getClassB(_cb);
Path path = Path.parse(_path);
MethodSelector ms1 = MethodSelector.parse(_ms1);
MethodSelector ms2 = MethodSelector.parse(_ms2);
MethodSelector ms3 = MethodSelector.parse(_ms3);
ClassB expected = getClassB(_expected);
if (!isError) {
ClassB res = SumMethods.sumMethods(cb, path.getCBar(), ms1, ms2, ms3, name);
TestHelper.assertEqualExp(expected, res);
} else {
try {
ClassB res = SumMethods.sumMethods(cb, path.getCBar(), ms1, ms2, ms3, name);
fail("error expected");
} catch (Resources.Error err) {
ClassB res = (ClassB) err.unbox;
TestHelper.assertEqualExp(expected, res);
}
}
}
use of ast.Ast.Path in project L42 by ElvisResearchGroup.
the class TranslateClass method pathReverter.
private static void pathReverter(String s, StringBuilder res) {
Path path = Path.parse(Resources.name42Of(s));
int hash = path.outerNumber();
String cs = path.toString();
assert cs.contains(".") : cs;
cs = cs.substring(cs.indexOf("."));
res.append("return platformSpecific.javaTranslation.Resources.fromHash(" + hash + ",\"" + cs + "\").revert();\n");
res.append("}\n");
}
use of ast.Ast.Path in project L42 by ElvisResearchGroup.
the class TranslateClass method getReverter.
private static void getReverter(String s, MethodWithType ctor, StringBuilder res) {
res.append("public ast.ExpCore revert(){\n");
//pathReverter(s, res);//no, much worst here
Path path = Path.parse(Resources.name42Of(s));
int hash = path.outerNumber();
String cs = path.toString();
cs = cs.substring(cs.indexOf("."));
res.append("ast.ExpCore receiver= (ast.ExpCore)platformSpecific.javaTranslation.Resources.fromHash(" + hash + ",\"" + cs + "\").revert();\n");
res.append("if(this==type){return receiver;}\n");
//res.append("java.util.ArrayList<String> xs=new java.util.ArrayList<>(java.util.Arrays.asList(");
List<String> ns = ctor.getMs().getNames();
//StringBuilders.formatSequence(res,ns.iterator(),
// ", ",n->res.append("\""+n+"\""));
//res.append("));\n");
res.append("java.util.ArrayList<ast.ExpCore> es=new java.util.ArrayList<>(java.util.Arrays.asList(");
StringBuilders.formatSequence(res, ns.iterator(), ", ", n -> res.append("platformSpecific.javaTranslation.Resources.Revertable.doRevert(this.F" + Resources.nameOf(n) + ")"));
res.append("));\n");
res.append("return new ast.ExpCore.MCall(receiver," + ctor.getMs().toSrcEquivalent() + ",ast.Ast.Doc.empty(),es,null);\n");
res.append("}\n");
}
use of ast.Ast.Path in project L42 by ElvisResearchGroup.
the class TranslateExpression method getCatch.
private void getCatch(String kVar, On on, String asReturn, String kLab) {
Path p = ((Type) on.getT()).getPath();
String tn = Resources.nameOf(p);
if (p.equals(Path.Library())) {
res.append(getCatchHeaderForLibrary(kVar));
} else if (!p.isPrimitive() && tn.equals("Object")) {
res.append(getCatchHeaderForPathNotStar(kVar, p));
} else {
res.append("if(" + kVar + ".unbox instanceof " + tn + "){\n");
}
res.append(" " + tn + "[] P" + on.getX() + "={(" + tn + ")" + kVar + ".unbox};\n");
res.append(asReturn);
on.getInner().accept(this);
res.append(";");
if (asReturn.contains("=")) {
res.append("break " + kLab + ";");
}
res.append("\n }\nelse ");
}
use of ast.Ast.Path in project L42 by ElvisResearchGroup.
the class UsedPaths method collectNotAnyPaths.
private static List<Ast.Path> collectNotAnyPaths(Program p, ExpCore e) {
class HeuristicForNotAnyPathsSplit extends PropagatorVisitor {
public Void visit(ClassB s) {
return null;
}
protected List<Path> paths = new ArrayList<Path>();
private void add(Path p) {
this.paths.add(p);
}
//non determinism heuristic:
//**if P.m(_) inside e, P not Any
public Void visit(MCall s) {
Path p = justPath(s.getInner());
if (p != null) {
add(p);
}
return super.visit(s);
}
//**if ( _ T x=P _ _) inside e and T!=class Any, P not Any.
//**if (mdf P x=_ _) inside e, P not Any
protected void liftDec(Block.Dec s) {
if (s.getT().isPresent()) {
Path pt = s.getT().get().getPath();
if (!pt.isPrimitive()) {
add(pt);
}
}
Path p = justPath(s.getInner());
if (p != null) {
add(p);
}
super.liftDec(s);
}
private Path justPath(ExpCore e) {
if (e instanceof ExpCore.EPath) {
if (!((ExpCore.EPath) e).getInner().isPrimitive()) {
return ((ExpCore.EPath) e).getInner();
}
}
if (e instanceof ExpCore.Block) {
return justPath(((ExpCore.Block) e).getInner());
}
return null;
}
//**if p(Pi).Cache=Typed, Pi is not Any
@Override
protected void liftP(Path s) {
if (s.isPrimitive()) {
return;
}
try {
if (p.extractClassB(s).getPhase() == Phase.Typed) {
super.liftP(s);
return;
}
} catch (ErrorMessage.PathMetaOrNonExistant pne) {
/*we do not rise this error while computing the heuristic*/
}
}
//**if using P _ _ inside e, P not Any
public Void visit(ExpCore.Using s) {
if (!s.getPath().isPrimitive()) {
add(s.getPath());
}
return super.visit(s);
}
//**if catch T inside e, T.P not Any
protected void liftO(ExpCore.Block.On on) {
Path pOn = on.getT().getPath();
if (!pOn.isPrimitive()) {
add(pOn);
}
super.liftO(on);
}
List<Path> result(ExpCore e) {
e.accept(this);
return this.paths;
}
}
return new HeuristicForNotAnyPathsSplit().result(e);
}
Aggregations