Search in sources :

Example 6 with Path

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);
        }
    }
}
Also used : Path(ast.Ast.Path) MethodSelector(ast.Ast.MethodSelector) Resources(platformSpecific.javaTranslation.Resources) TestHelper.getClassB(helpers.TestHelper.getClassB) ClassB(ast.ExpCore.ClassB) Test(org.junit.Test)

Example 7 with Path

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");
}
Also used : Path(ast.Ast.Path)

Example 8 with Path

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");
}
Also used : Path(ast.Ast.Path)

Example 9 with Path

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 ");
}
Also used : Path(ast.Ast.Path) Type(ast.Ast.Type) PluginType(platformSpecific.fakeInternet.PluginType)

Example 10 with Path

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);
}
Also used : Path(ast.Ast.Path) ExpCore(ast.ExpCore) PathMetaOrNonExistant(ast.ErrorMessage.PathMetaOrNonExistant) PropagatorVisitor(coreVisitors.PropagatorVisitor) MCall(ast.ExpCore.MCall) Block(ast.ExpCore.Block) ArrayList(java.util.ArrayList) List(java.util.List) ErrorMessage(ast.ErrorMessage) ClassB(ast.ExpCore.ClassB)

Aggregations

Path (ast.Ast.Path)56 ClassB (ast.ExpCore.ClassB)28 ArrayList (java.util.ArrayList)23 Ast (ast.Ast)14 PathPath (ast.Util.PathPath)13 Type (ast.Ast.Type)12 MethodWithType (ast.ExpCore.ClassB.MethodWithType)12 Doc (ast.Ast.Doc)11 Member (ast.ExpCore.ClassB.Member)11 List (java.util.List)11 ExpCore (ast.ExpCore)10 NestedClass (ast.ExpCore.ClassB.NestedClass)8 PathSPath (ast.Util.PathSPath)8 CloneWithPath (coreVisitors.CloneWithPath)8 Collections (java.util.Collections)8 HashSet (java.util.HashSet)8 Program (programReduction.Program)8 Map (tools.Map)8 MethodSelector (ast.Ast.MethodSelector)7 SPathSPath (ast.Util.SPathSPath)7