Search in sources :

Example 56 with ExpCore

use of ast.ExpCore in project L42 by ElvisResearchGroup.

the class Executor method metaMethod.

protected ClassB metaMethod(Program p, ClassB cb, Member m) {
    log("---meta2--");
    //get cb-->ct
    //get p'
    Program p1 = p.evilPush(cb);
    //extract e
    ExpCore e = m.getInner();
    //extract cb
    Ctx<ClassB> ctxC = ExtractCtxCompiled.of(e);
    //run cb1-->cb2
    ClassB cb2 = (ClassB) step(new PData(p1), ctxC.hole);
    ExpCore e2 = ReplaceCtx.of(ctxC.ctx, cb2);
    //compose cb with new member
    return cb.withMember(m.withInner(e2));
}
Also used : ExpCore(ast.ExpCore) Program(programReduction.Program) PData(facade.PData) ClassB(ast.ExpCore.ClassB)

Example 57 with ExpCore

use of ast.ExpCore in project L42 by ElvisResearchGroup.

the class Rename method userForMethod.

public static UserForMethodResult userForMethod(Program p, ClassB cb, List<Ast.C> path, MethodSelector src, boolean checkMethExists) {
    if (checkMethExists) {
        Member mem = Errors42.checkExistsPathMethod(cb, path, Optional.of(src));
        assert mem instanceof MethodWithType;
    }
    Member mem = new ExpCore.ClassB.MethodImplemented(Doc.empty(), src, new ExpCore._void(), Position.noInfo);
    CollectedLocatorsMap maps = CollectedLocatorsMap.from(Path.outer(0, path), mem, src);
    HashSet<PathMx> result1 = new HashSet<>();
    HashSet<MethodSelector> result2 = new HashSet<>();
    MethodPathCloneVisitor ren = new RenameUsage(cb, maps, p) {

        public Ast.Type liftT(Ast.Type t) {
            return t;
        }

        @Override
        protected MethodSelector liftMs(MethodSelector ms) {
            return ms;
        }

        @Override
        protected MethodSelector liftMsInMetDec(MethodSelector ms) {
            return ms;
        }

        public ExpCore visit(MCall s) {
            List<Ast.C> localPath = this.getLocator().getClassNamesPath();
            if (!localPath.equals(path)) {
                return super.visit(s);
            }
            if (s.getInner().equals(Path.outer(0)) || s.getInner().equals(new ExpCore.X(Position.noInfo, "this"))) {
                result2.add(s.getS());
                return s.withInner(s.getInner().accept(this)).withEs(Map.of(e -> e.accept(this), s.getEs()));
            }
            return super.visit(s);
        }

        @Override
        public MethodSelector visitMS(MethodSelector original, Path src) {
            MethodSelector toCollect = this.mSToReplaceOrNull(original, src);
            if (toCollect == null) {
                return original;
            }
            Member m = this.getLocator().getLastMember();
            assert !(m instanceof NestedClass) : "";
            MethodSelector msUser = m.match(nc -> {
                throw Assertions.codeNotReachable();
            }, mi -> mi.getS(), mt -> mt.getMs());
            Path pathUser = Path.outer(0, this.getLocator().getClassNamesPath());
            result1.add(new PathMx(pathUser, msUser));
            return original;
        }
    };
    ren.visit(cb);
    return new UserForMethodResult() {

        {
            asClient = new ArrayList<>(result1);
            asThis = new ArrayList<>(result2);
        }
    };
}
Also used : PathMx(ast.Util.PathMx) Stage(ast.Ast.Stage) PathPath(ast.Util.PathPath) Program(programReduction.Program) Ast(ast.Ast) Map(tools.Map) Configuration(facade.Configuration) CloneVisitorWithProgram(coreVisitors.CloneVisitorWithProgram) Assertions(tools.Assertions) MethodWithType(ast.ExpCore.ClassB.MethodWithType) MethodSelector(ast.Ast.MethodSelector) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) CloneVisitor(coreVisitors.CloneVisitor) PathMxMx(ast.Util.PathMxMx) NestedClass(ast.ExpCore.ClassB.NestedClass) Path(ast.Ast.Path) Doc(ast.Ast.Doc) Phase(ast.ExpCore.ClassB.Phase) ExpCore(ast.ExpCore) Member(ast.ExpCore.ClassB.Member) Functions(auxiliaryGrammar.Functions) List(java.util.List) Position(ast.Ast.Position) PathMx(ast.Util.PathMx) Optional(java.util.Optional) FromInClass(coreVisitors.FromInClass) C(ast.Ast.C) Collections(java.util.Collections) L42(facade.L42) MethodImplemented(ast.ExpCore.ClassB.MethodImplemented) PathPath(ast.Util.PathPath) Path(ast.Ast.Path) ExpCore(ast.ExpCore) MethodImplemented(ast.ExpCore.ClassB.MethodImplemented) MethodSelector(ast.Ast.MethodSelector) Ast(ast.Ast) C(ast.Ast.C) NestedClass(ast.ExpCore.ClassB.NestedClass) MethodWithType(ast.ExpCore.ClassB.MethodWithType) MethodWithType(ast.ExpCore.ClassB.MethodWithType) Member(ast.ExpCore.ClassB.Member) HashSet(java.util.HashSet)

Example 58 with ExpCore

use of ast.ExpCore in project L42 by ElvisResearchGroup.

the class TranslateExpression method visit.

@Override
public Void visit(Using s) {
    List<String> es = new ArrayList<>();
    StringBuilder resOld = res;
    res = new StringBuilder();
    s.getInner().accept(this);
    String e = res.toString();
    for (ExpCore ei : s.getEs()) {
        res = new StringBuilder();
        ei.accept(this);
        es.add(res.toString());
    }
    res = resOld;
    PluginType pt = platformSpecific.fakeInternet.OnLineCode.plugin(Resources.getP(), s);
    res.append(pt.executableJ(Resources.getP(), s, e, es, TranslateExpression.labels));
    return null;
}
Also used : ExpCore(ast.ExpCore) ArrayList(java.util.ArrayList) PluginType(platformSpecific.fakeInternet.PluginType)

Example 59 with ExpCore

use of ast.ExpCore in project L42 by ElvisResearchGroup.

the class SmallStep method meta1.

protected ClassB meta1(Program p, ClassB cb, NestedClass m) {
    log("---meta1--");
    ExpCore e1 = m.getInner();
    //get p'
    try {
        Program p1 = p.evilPush(cb);
        ErrorFormatter.printType(p1);
        //check p'
        //Configuration.typeSystem.checkAll(p1);
        //e1=Norm.of(p1,e1);
        //check e1
        //Configuration.typeSystem.checkMetaExpr(p1.getExecutableStar(),e1);
        //run m.e1-->e2
        ExpCore e2 = executeAtomicStep(new PData(p1), e1, m.getName());
        //if(!(e2 instanceof ClassB)){Configuration.typeSystem.checkMetaExpr(p1.getExecutableStar(),e2);}//TODO: as assert
        ClassB cbRes = cb.withMember(m.withInner(e2));
        //replace cb[m.e2]
        return cbRes;
    } finally {
    }
}
Also used : ExpCore(ast.ExpCore) Program(programReduction.Program) PData(facade.PData) ClassB(ast.ExpCore.ClassB)

Example 60 with ExpCore

use of ast.ExpCore in project L42 by ElvisResearchGroup.

the class ToFormattedText method of.

public static String of(ExpCore.ClassB.Member m) {
    List<ExpCore.ClassB.Member> ms = new ArrayList<>();
    ms.add(m);
    ExpCore e = ExpCore.ClassB.membersClass(ms, m.getP(), Phase.None);
    Expression.ClassB es = (ClassB) e.accept(new InjectionOnSugar());
    ToFormattedText tft = new ToFormattedText();
    //for the injection
    tft.formatMembers(es.getMs());
    return tft.result.toString();
}
Also used : ExpCore(ast.ExpCore) InjectionOnSugar(coreVisitors.InjectionOnSugar) Expression(ast.Expression) ClassB(ast.Expression.ClassB) ArrayList(java.util.ArrayList) Member(ast.Expression.ClassB.Member) ClassB(ast.Expression.ClassB)

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