Search in sources :

Example 1 with MethodSelector

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

the class InjectionOnSugar method visit.

@Override
public Expression visit(ClassB s) {
    Doc doc1 = s.getDoc1();
    Header h = (s.isInterface()) ? new Ast.InterfaceHeader() : new Ast.TraitHeader();
    List<Type> supertypes = s.getSupertypes();
    List<Member> members = new ArrayList<>();
    for (ast.ExpCore.ClassB.Member mi : s.getMs()) {
        members.add(mi.match(nc -> new Expression.ClassB.NestedClass(nc.getDoc(), nc.getName(), lift(nc.getInner()), nc.getP()), mimpl -> new Expression.ClassB.MethodImplemented(mimpl.getDoc(), mimpl.getS(), lift(mimpl.getInner()), mimpl.getP()), mwt -> {
            Doc idoc = mwt.getDoc();
            MethodSelector is = mwt.getMs();
            MethodType mt = mwt.getMt();
            return new Expression.ClassB.MethodWithType(idoc, is, mt, lift(mwt.get_inner()), mwt.getP());
        }));
    }
    return new Expression.ClassB(doc1, h, Collections.emptyList(), supertypes, members, s.getP());
}
Also used : VarDecXE(ast.Ast.VarDecXE) UpdateVar(ast.ExpCore.UpdateVar) Ast(ast.Ast) Header(ast.Ast.Header) MCall(ast.ExpCore.MCall) Type(ast.Ast.Type) Member(ast.Expression.ClassB.Member) WellFormedness(auxiliaryGrammar.WellFormedness) MethodType(ast.Ast.MethodType) Loop(ast.ExpCore.Loop) MethodSelector(ast.Ast.MethodSelector) ArrayList(java.util.ArrayList) Visitor(coreVisitors.Visitor) ClassB(ast.ExpCore.ClassB) WalkBy(ast.ExpCore.WalkBy) Mdf(ast.Ast.Mdf) X(ast.ExpCore.X) VarDec(ast.Ast.VarDec) Path(ast.Ast.Path) Signal(ast.ExpCore.Signal) Match(tools.Match) Doc(ast.Ast.Doc) ExpCore._void(ast.ExpCore._void) ExpCore(ast.ExpCore) Block(ast.ExpCore.Block) Expression(ast.Expression) List(java.util.List) Position(ast.Ast.Position) Using(ast.ExpCore.Using) Optional(java.util.Optional) Collections(java.util.Collections) MethodType(ast.Ast.MethodType) MethodSelector(ast.Ast.MethodSelector) Ast(ast.Ast) ArrayList(java.util.ArrayList) Type(ast.Ast.Type) MethodType(ast.Ast.MethodType) Header(ast.Ast.Header) Expression(ast.Expression) Doc(ast.Ast.Doc) Member(ast.Expression.ClassB.Member) ClassB(ast.ExpCore.ClassB)

Example 2 with MethodSelector

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

the class IsValue method validRightValue.

public boolean validRightValue(ExpCore ec) {
    if (!(ec instanceof MCall))
        return false;
    MCall s = (MCall) ec;
    if (!(s.getInner() instanceof EPath)) {
        return false;
    }
    MethodSelector ms = s.getS();
    MethodWithType mwt = (MethodWithType) p.extractClassB(((EPath) s.getInner()).getInner())._getMember(ms);
    if (mwt.get_inner().isPresent()) {
        return false;
    }
    if (mwt.getMt().getMdf() != ast.Ast.Mdf.Class) {
        return false;
    }
    for (ExpCore ei : s.getEs()) {
        if (!isAtom(ei)) {
            return false;
        }
    }
    return true;
}
Also used : ExpCore(ast.ExpCore) MethodSelector(ast.Ast.MethodSelector)

Example 3 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)

Example 4 with MethodSelector

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

the class RenameUsage method mSToReplaceOrNull.

public MethodSelector mSToReplaceOrNull(MethodSelector original, Path src) {
    assert src != null;
    List<Locator> filtered = new ArrayList<>();
    for (Locator pMx : maps.selectors) {
        MethodSelector mii = pMx.getLastMember().match(nc -> {
            throw Assertions.codeNotReachable();
        }, mi -> mi.getS(), mt -> mt.getMs());
        if (original.equals(mii)) {
            filtered.add(pMx);
        }
    }
    if (filtered.isEmpty()) {
        return null;
    }
    Locator pathOriginal = this.getLocator().copy();
    pathOriginal.toFormerNodeLocator();
    //for both ms in methods and in htypes
    boolean isIn = pathOriginal.auxMoveInPath(src);
    if (!isIn) {
        return null;
    }
    for (Locator pMx : filtered) {
        Locator pathDef = pMx.copy();
        pathDef.toFormerNodeLocator();
        if (!pathDef.equals(pathOriginal)) {
            continue;
        }
        return (MethodSelector) pMx.getAnnotation();
    }
    return null;
}
Also used : Locator(auxiliaryGrammar.Locator) MethodSelector(ast.Ast.MethodSelector) ArrayList(java.util.ArrayList)

Example 5 with MethodSelector

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

the class PlgWrapperGenerator method hasPluginUnresponsive.

public static boolean hasPluginUnresponsive(ClassB l) {
    //class method T #pluginUnresponsive(Library binaryRepr)
    MethodSelector ms = MethodSelector.of("#pluginUnresponsive", 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().getMdf().equals(Mdf.Immutable)) {
        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)

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