Search in sources :

Example 21 with ExpCore._void

use of ast.ExpCore._void 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)

Example 22 with ExpCore._void

use of ast.ExpCore._void 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;
    }
}
Also used : ExpCore(ast.ExpCore) Position(ast.Ast.Position) ClassB(ast.Expression.ClassB) ArrayList(java.util.ArrayList) NestedClass(ast.ExpCore.ClassB.NestedClass) CloneVisitor(coreVisitors.CloneVisitor) NestedClass(ast.ExpCore.ClassB.NestedClass) Expression(ast.Expression) ParseCancellationException(org.antlr.v4.runtime.misc.ParseCancellationException) ClassReuse(ast.Expression.ClassReuse) ErrorMessage(ast.ErrorMessage) Member(ast.ExpCore.ClassB.Member) ClassB(ast.Expression.ClassB) InjectionOnCore(sugarVisitors.InjectionOnCore)

Example 23 with ExpCore._void

use of ast.ExpCore._void in project L42 by ElvisResearchGroup.

the class CtxSplitter method visit.

//method call: if receiver, otherwise a point in parameters
public CtxC visit(MCall s) {
    ExpCore r = s.getInner();
    if (!IsCompiled.of(r)) {
        return new CtxCInner<MCall>(s, r.accept(this));
    }
    int pos = firstNotCompiled(s.getEs());
    return new CtxCMCallPos(s, pos, s.getEs().get(pos).accept(this));
}
Also used : ExpCore(ast.ExpCore)

Example 24 with ExpCore._void

use of ast.ExpCore._void in project L42 by ElvisResearchGroup.

the class CtxSplitter method _equals.

default default boolean _equals(Object obj) {
    if (this == obj)
        return true;
    if (obj == null)
        return false;
    if (getClass() != obj.getClass())
        return false;
    CtxC other = (CtxC) obj;
    ExpCore oE = other.fillHole(new ExpCore.WalkBy());
    ExpCore thisE = this.fillHole(new ExpCore.WalkBy());
    return thisE.equals(oE);
}
Also used : ExpCore(ast.ExpCore) WalkBy(ast.ExpCore.WalkBy)

Example 25 with ExpCore._void

use of ast.ExpCore._void in project L42 by ElvisResearchGroup.

the class InjectionOnCore method visit.

public ExpCore visit(Expression.Using s) {
    assert !s.getPs().getE().isPresent();
    List<String> xs = s.getPs().getXs();
    List<ExpCore> es = new ArrayList<>();
    for (Expression e : s.getPs().getEs()) {
        es.add(e.accept(this));
    }
    return new Using(s.getPath(), MethodSelector.of(s.getName(), xs), s.getDocs(), es, s.getInner().accept(this));
}
Also used : ExpCore(ast.ExpCore) Expression(ast.Expression) ArrayList(java.util.ArrayList)

Aggregations

ExpCore (ast.ExpCore)62 ArrayList (java.util.ArrayList)25 ClassB (ast.ExpCore.ClassB)18 Member (ast.ExpCore.ClassB.Member)11 MethodWithType (ast.ExpCore.ClassB.MethodWithType)10 Expression (ast.Expression)10 Block (ast.ExpCore.Block)9 MethodType (ast.Ast.MethodType)8 Doc (ast.Ast.Doc)7 Path (ast.Ast.Path)7 Assertions (tools.Assertions)7 MethodSelector (ast.Ast.MethodSelector)6 Position (ast.Ast.Position)6 Program (programReduction.Program)6 InjectionOnCore (sugarVisitors.InjectionOnCore)6 Ast (ast.Ast)5 Type (ast.Ast.Type)5 ErrorMessage (ast.ErrorMessage)5 CloneVisitor (coreVisitors.CloneVisitor)5 List (java.util.List)5