Search in sources :

Example 6 with MethodSelector

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

the class Plugin method MrenameMethod£xthat£xpath£xsrc£xdest.

@ActionType({ ActionType.NormType.Library, ActionType.NormType.Library, ActionType.NormType.Library, ActionType.NormType.Library, ActionType.NormType.Library })
public Object MrenameMethod£xthat£xpath£xsrc£xdest(Object _that, Object _path, Object _src, Object _dest) {
    ClassB that = ensureExtractClassB(_that);
    List<Ast.C> path = PathAux.parseValidCs(ensureExtractStringU(_path));
    MethodSelector src = MethodSelector.parse(ensureExtractStringU(_src));
    MethodSelector dest = MethodSelector.parse(ensureExtractStringU(_dest));
    return Rename.renameMethod(Resources.getP(), that, path, src, dest);
}
Also used : MethodSelector(ast.Ast.MethodSelector) ClassB(ast.ExpCore.ClassB) EncodingHelper.ensureExtractClassB(auxiliaryGrammar.EncodingHelper.ensureExtractClassB) ActionType(platformSpecific.fakeInternet.ActionType)

Example 7 with MethodSelector

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

the class RefreshUniqueNames method refreshTopLevel.

public static ClassB refreshTopLevel(ClassB e) {
    HashMap<Long, Long> map = new HashMap<>();
    return (ClassB) e.accept(new coreVisitors.CloneVisitor() {

        protected MethodSelector liftMs(MethodSelector ms) {
            return ms.withUniqueNum(newN(map, ms.getUniqueNum()));
        }

        public ClassB.NestedClass visit(ClassB.NestedClass nc) {
            long newN = newN(map, nc.getName().getUniqueNum());
            return super.visit(nc.withName(nc.getName().withUniqueNum(newN)));
        //I need to collect the DECLARED C,ms and those are the only that I need to refresh.
        //refresh all can work only at top level
        }

        @Override
        protected Path liftP(Path s) {
            if (s.isPrimitive()) {
                return s;
            }
            List<C> cs = s.getCBar();
            List<C> newCs = new ArrayList<>();
            for (C c : cs) {
                newCs.add(c.withUniqueNum(newN(map, c.getUniqueNum())));
            }
            return Path.outer(s.outerNumber(), newCs);
        }
    });
}
Also used : Path(ast.Ast.Path) MethodSelector(ast.Ast.MethodSelector) C(ast.Ast.C) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) NestedClass(ast.Expression.ClassB.NestedClass) ClassB(ast.ExpCore.ClassB)

Example 8 with MethodSelector

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

the class RefreshUniqueNames method refresh.

@SuppressWarnings("unchecked")
public static <T extends ExpCore> T refresh(T e) {
    HashMap<Long, Long> map = new HashMap<>();
    //load up maps
    e.accept(new coreVisitors.PropagatorVisitor() {

        public void visit(ClassB.MethodWithType mwt) {
            MethodSelector ms = mwt.getMs();
            newN(map, ms.getUniqueNum());
            super.visit(mwt);
            return;
        }

        public void visit(ClassB.NestedClass nc) {
            newN(map, nc.getName().getUniqueNum());
            super.visit(nc);
        }
    });
    return (T) e.accept(new coreVisitors.CloneVisitor() {

        protected MethodSelector liftMs(MethodSelector ms) {
            return ms.withUniqueNum(mappedN(map, ms.getUniqueNum()));
        }

        public ClassB.NestedClass visit(ClassB.NestedClass nc) {
            C name = nc.getName().withUniqueNum(mappedN(map, nc.getName().getUniqueNum()));
            return super.visit(nc.withName(name));
        }

        @Override
        protected Path liftP(Path s) {
            if (s.isPrimitive()) {
                return s;
            }
            List<C> cs = s.getCBar();
            List<C> newCs = new ArrayList<>();
            for (C c : cs) {
                newCs.add(c.withUniqueNum(mappedN(map, c.getUniqueNum())));
            }
            return Path.outer(s.outerNumber(), newCs);
        }
    });
}
Also used : Path(ast.Ast.Path) MethodWithType(ast.Expression.ClassB.MethodWithType) MethodSelector(ast.Ast.MethodSelector) C(ast.Ast.C) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) NestedClass(ast.Expression.ClassB.NestedClass) NestedClass(ast.Expression.ClassB.NestedClass) ClassB(ast.ExpCore.ClassB)

Example 9 with MethodSelector

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

the class Desugar method generateGetter.

private static MethodWithType generateGetter(Expression.Position pos, FieldDec f, Doc doc) {
    Type fieldNt = (Type) f.getT();
    fieldNt = TypeManipulation.noFwd(fieldNt);
    Mdf mdf = fieldNt.getMdf();
    if (mdf == Mdf.Capsule || mdf == Mdf.Mutable || mdf == Mdf.Lent) {
        fieldNt = fieldNt.withMdf(Mdf.Readable);
    }
    MethodType mti = new MethodType(false, Mdf.Readable, Collections.emptyList(), fieldNt, Collections.emptyList());
    String name = f.getName();
    //if(name.startsWith("#")){name=name.substring(1);}
    MethodSelector msi = MethodSelector.of(name, Collections.emptyList());
    MethodWithType mwt = new MethodWithType(doc, msi, mti, Optional.empty(), pos);
    return mwt;
}
Also used : MethodType(ast.Ast.MethodType) Type(ast.Ast.Type) MethodWithType(ast.Expression.ClassB.MethodWithType) MethodType(ast.Ast.MethodType) MethodSelector(ast.Ast.MethodSelector) MethodWithType(ast.Expression.ClassB.MethodWithType) Mdf(ast.Ast.Mdf)

Example 10 with MethodSelector

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

the class RenameAlsoDefinition method potentiallyRenameMethodImplementedHeader.

private MethodWithType potentiallyRenameMethodImplementedHeader(MethodWithType mi) {
    assert mi.getMt().isRefine();
    ClassB currentCb = this.getLocator().getLastCb();
    Program ep = p;
    for (ClassB cbi : this.getLocator().getCbs()) {
        ep = ep.evilPush(cbi);
    }
    //List<Path> supers = Program.getAllSupertypes(ep, currentCb);
    Path origin = Functions.originDecOf(ep, mi.getMs(), currentCb);
    Locator original = this.getLocator().copy();
    boolean isOut = original.moveInPath(origin);
    if (isOut) {
        return mi;
    }
    for (Locator pMx : maps.selectors) {
        assert pMx.kind() == Kind.Method;
        MethodSelector s = pMx.getLastMember().match(nc -> {
            throw Assertions.codeNotReachable();
        }, mimpl -> mimpl.getS(), mt -> mt.getMs());
        if (!mi.getMs().equals(s)) {
            continue;
        }
        Locator renamed = pMx.copy();
        renamed.toFormerNodeLocator();
        if (!original.equals(renamed)) {
            return mi;
        }
        MethodSelector ms2 = (MethodSelector) pMx.getAnnotation();
        return mi.withMs(ms2);
    }
    return mi;
}
Also used : Path(ast.Ast.Path) Locator(auxiliaryGrammar.Locator) MethodSelector(ast.Ast.MethodSelector) Program(programReduction.Program) ClassB(ast.ExpCore.ClassB)

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