Search in sources :

Example 21 with MethodSelector

use of ast.Ast.MethodSelector in project L42 by ElvisResearchGroup.

the class PlgWrapperGenerator method hasFrom.

public static boolean hasFrom(ClassB l) {
    //   class method mut This0 #from(Library binaryRepr)
    MethodSelector ms = MethodSelector.of("#from", Collections.singletonList("binaryRepr"));
    MethodWithType mwt = (MethodWithType) l._getMember(ms);
    //must be an mwt since normalized
    if (mwt == null) {
        return false;
    }
    MethodType mt = mwt.getMt();
    if (!mt.getMdf().equals(Mdf.Class)) {
        return false;
    }
    if (!mt.getTs().get(0).equals(Type.immLibrary)) {
        return false;
    }
    if (!mt.getExceptions().isEmpty()) {
        return false;
    }
    if (!mt.getReturnType().equals(Type.mutThis0)) {
        return false;
    }
    return true;
}
Also used : MethodType(ast.Ast.MethodType) MethodSelector(ast.Ast.MethodSelector) MethodWithType(ast.ExpCore.ClassB.MethodWithType)

Example 22 with MethodSelector

use of ast.Ast.MethodSelector in project L42 by ElvisResearchGroup.

the class PlgWrapperGenerator method hasBinaryRepr.

public static boolean hasBinaryRepr(ClassB l) {
    //read method Library #binaryRepr()
    MethodSelector ms = MethodSelector.of("#binaryRepr", Collections.emptyList());
    MethodWithType mwt = (MethodWithType) l._getMember(ms);
    //must be an mwt since normalized
    if (mwt == null) {
        return false;
    }
    MethodType mt = mwt.getMt();
    if (!mt.getMdf().equals(Mdf.Readable)) {
        return false;
    }
    if (!mt.getTs().isEmpty()) {
        return false;
    }
    if (!mt.getExceptions().isEmpty()) {
        return false;
    }
    if (!mt.getReturnType().equals(Type.immLibrary)) {
        return false;
    }
    return true;
}
Also used : MethodType(ast.Ast.MethodType) MethodSelector(ast.Ast.MethodSelector) MethodWithType(ast.ExpCore.ClassB.MethodWithType)

Example 23 with MethodSelector

use of ast.Ast.MethodSelector in project L42 by ElvisResearchGroup.

the class PlgWrapperGenerator method hasExceptionIf.

public static boolean hasExceptionIf(ClassB l) {
    //class method Void #exceptionIf(Library binaryRepr) exception This
    MethodSelector ms = MethodSelector.of("#exceptionIf", Collections.singletonList("binaryRepr"));
    MethodWithType mwt = (MethodWithType) l._getMember(ms);
    //must be an mwt since normalized
    if (mwt == null) {
        return false;
    }
    MethodType mt = mwt.getMt();
    if (!mt.getMdf().equals(Mdf.Class)) {
        return false;
    }
    if (!mt.getTs().get(0).equals(Type.immLibrary)) {
        return false;
    }
    if (mt.getExceptions().size() != 1) {
        return false;
    }
    if (!mt.getExceptions().get(0).equals(Path.outer(0))) {
        return false;
    }
    if (!mt.getReturnType().equals(Type.immVoid)) {
        return false;
    }
    //no need to check return type, since is just thrown as error
    return true;
}
Also used : MethodType(ast.Ast.MethodType) MethodSelector(ast.Ast.MethodSelector) MethodWithType(ast.ExpCore.ClassB.MethodWithType)

Example 24 with MethodSelector

use of ast.Ast.MethodSelector 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 25 with MethodSelector

use of ast.Ast.MethodSelector in project L42 by ElvisResearchGroup.

the class AddDocumentation method addDocumentationOnMethod.

public static ClassB addDocumentationOnMethod(Program p, ClassB cb, List<Ast.C> cs, MethodSelector sel, Doc doc) {
    Errors42.checkExistsPathMethod(cb, cs, Optional.of(sel));
    if (cs.isEmpty()) {
        cb = auxAddDocOnMethod(p, cb, sel, doc);
    } else {
        Program p1 = p.evilPush(cb);
        if (cs.size() > 1) {
            p1 = p1.navigate(cs.subList(0, cs.size() - 1));
        }
        Program p2 = p1;
        cb = cb.onClassNavigateToPathAndDo(cs, cbi -> auxAddDocOnMethod(p2, cbi, sel, doc));
    }
    return cb;
}
Also used : Resources(platformSpecific.javaTranslation.Resources) Program(programReduction.Program) Ast(ast.Ast) Doc(ast.Ast.Doc) InvalidMwtAsState(ast.Util.InvalidMwtAsState) Configuration(facade.Configuration) Assertions(tools.Assertions) Member(ast.ExpCore.ClassB.Member) MethodWithType(ast.ExpCore.ClassB.MethodWithType) Collectors(java.util.stream.Collectors) MethodSelector(ast.Ast.MethodSelector) Functions(auxiliaryGrammar.Functions) ArrayList(java.util.ArrayList) List(java.util.List) ClassB(ast.ExpCore.ClassB) Optional(java.util.Optional) Mdf(ast.Ast.Mdf) Program(programReduction.Program)

Aggregations

MethodSelector (ast.Ast.MethodSelector)31 ClassB (ast.ExpCore.ClassB)17 MethodType (ast.Ast.MethodType)11 ArrayList (java.util.ArrayList)11 Path (ast.Ast.Path)9 MethodWithType (ast.ExpCore.ClassB.MethodWithType)9 Type (ast.Ast.Type)8 EncodingHelper.ensureExtractClassB (auxiliaryGrammar.EncodingHelper.ensureExtractClassB)8 ActionType (platformSpecific.fakeInternet.ActionType)8 Ast (ast.Ast)6 Doc (ast.Ast.Doc)6 ExpCore (ast.ExpCore)6 List (java.util.List)6 Member (ast.ExpCore.ClassB.Member)5 MethodWithType (ast.Expression.ClassB.MethodWithType)5 Collections (java.util.Collections)5 Optional (java.util.Optional)5 Program (programReduction.Program)5 C (ast.Ast.C)4 Mdf (ast.Ast.Mdf)4