Search in sources :

Example 21 with Path

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

the class MethodPathCloneVisitor method visit.

public ExpCore visit(MCall s) {
    Program ep = p;
    for (ClassB cbi : this.getLocator().getCbs()) {
        if (cbi != null) {
            ep = ep.evilPush(cbi);
        }
    }
    MethodSelector ms = s.getS();
    Path guessed = null;
    try {
        TIn in = TIn.top(Phase.Typed, ep, s.getInner());
        in = in.withG(varEnv.entrySet().stream().collect(Collectors.toMap(me -> me.getKey(), me -> new java.util.AbstractMap.SimpleEntry<>(false, me.getValue()))));
        Type tGuessed = newTypeSystem.GuessTypeCore._of(in.p, in, s.getInner());
        if (tGuessed == null) {
            return super.visit(s);
        }
        guessed = tGuessed.getPath();
        assert guessed != null;
    } catch (NormImpossible ignored) {
        return super.visit(s);
    }
    MethodSelector ms2 = visitMS(ms, guessed);
    if (ms2.equals(ms)) {
        return super.visit(s);
    }
    s = new MCall(s.getInner(), ms2, s.getDoc(), s.getEs(), s.getP());
    return super.visit(s);
}
Also used : Path(ast.Ast.Path) From(coreVisitors.From) GuessTypeCore(newTypeSystem.GuessTypeCore) Program(programReduction.Program) Ast(ast.Ast) MCall(ast.ExpCore.MCall) Map(tools.Map) Type(ast.Ast.Type) Configuration(facade.Configuration) HashMap(java.util.HashMap) Assertions(tools.Assertions) MethodWithType(ast.ExpCore.ClassB.MethodWithType) MethodSelector(ast.Ast.MethodSelector) ArrayList(java.util.ArrayList) ClassB(ast.ExpCore.ClassB) NormImpossible(ast.ErrorMessage.NormImpossible) Norm(programReduction.Norm) On(ast.ExpCore.Block.On) Path(ast.Ast.Path) Doc(ast.Ast.Doc) Phase(ast.ExpCore.ClassB.Phase) MethodSelectorX(ast.Ast.MethodSelectorX) ExpCore(ast.ExpCore) Member(ast.ExpCore.ClassB.Member) Collectors(java.util.stream.Collectors) Block(ast.ExpCore.Block) Functions(auxiliaryGrammar.Functions) List(java.util.List) TIn(newTypeSystem.TIn) Optional(java.util.Optional) Dec(ast.ExpCore.Block.Dec) Collections(java.util.Collections) MethodImplemented(ast.ExpCore.ClassB.MethodImplemented) MethodSelector(ast.Ast.MethodSelector) Type(ast.Ast.Type) MethodWithType(ast.ExpCore.ClassB.MethodWithType) Program(programReduction.Program) MCall(ast.ExpCore.MCall) TIn(newTypeSystem.TIn) NormImpossible(ast.ErrorMessage.NormImpossible) ClassB(ast.ExpCore.ClassB)

Example 22 with Path

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

the class Plugin method Mredirect£xthat£xsrc£xdest.

@ActionType({ ActionType.NormType.Library, ActionType.NormType.Library, ActionType.NormType.Library, ActionType.NormType.TypeAny })
public Object Mredirect£xthat£xsrc£xdest(Object _that, Object _src, Object _dest) {
    ClassB that = ensureExtractClassB(_that);
    List<Ast.C> src = PathAux.parseValidCs(ensureExtractStringU(_src));
    Path dest = ensureExtractPathFromJava(_dest);
    assert dest.isCore() || dest.isPrimitive() : dest;
    //TODO: see if extractPath should be changed
    if (dest.isCore()) {
        dest = dest.setNewOuter(dest.outerNumber() + 1);
    }
    return Redirect.redirect(Resources.getP(), that, Path.outer(0, src), dest);
}
Also used : Path(ast.Ast.Path) ClassB(ast.ExpCore.ClassB) EncodingHelper.ensureExtractClassB(auxiliaryGrammar.EncodingHelper.ensureExtractClassB) ActionType(platformSpecific.fakeInternet.ActionType)

Example 23 with Path

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

the class Push method pushOne.

//never wrong
//assumes s well formed class name
static ClassB pushOne(ClassB in, Ast.C s) {
    Path p = Path.outer(1);
    ClassB cb = (ClassB) FromInClass.of(in, p);
    List<Member> ms = Collections.singletonList(new ClassB.NestedClass(Doc.empty(), s, cb, null));
    return ClassB.membersClass(ms, cb.getP(), cb.getPhase());
}
Also used : Path(ast.Ast.Path) Member(ast.ExpCore.ClassB.Member) ClassB(ast.ExpCore.ClassB)

Example 24 with Path

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

the class Redirect method plusEqual.

private static void plusEqual(List<PathSPath> ambiguities, Path pif, List<Path> extPs) {
    assert ambiguitiesOk(ambiguities);
    try {
        assert !extPs.isEmpty();
        assert !extPs.contains(null);
        assert !pif.isPrimitive() && pif.outerNumber() == 0;
        for (PathSPath psp : ambiguities) {
            if (psp.getPath().equals(pif)) {
                psp.setPathsSet(new HashSet<>(psp.getPathsSet()));
                assert !psp.getPathsSet().isEmpty();
                Path forErr = psp.getPathsSet().iterator().next();
                psp.getPathsSet().retainAll(extPs);
                if (psp.getPathsSet().isEmpty()) {
                    List<Path> psErr = Arrays.asList(forErr, extPs.get(0));
                    throw Errors42.errorIncoherentRedirectMapping(Redirect.verifiedForErrorMsg, ambiguities, psp.getPath(), psErr);
                }
                return;
            }
        }
        ambiguities.add(new PathSPath(pif, new HashSet<>(extPs)));
    } finally {
        assert ambiguitiesOk(ambiguities);
    }
}
Also used : PathPath(ast.Util.PathPath) PathSPath(ast.Util.PathSPath) SPathSPath(ast.Util.SPathSPath) CloneWithPath(coreVisitors.CloneWithPath) Path(ast.Ast.Path) PathSPath(ast.Util.PathSPath) SPathSPath(ast.Util.SPathSPath) HashSet(java.util.HashSet)

Example 25 with Path

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

the class ToAst method visitUsing.

@Override
public Expression visitUsing(UsingContext ctx) {
    Path path = Ast.Path.sugarParse(nameU(ctx.Path()));
    Expression inner = ctx.eTop().accept(this);
    String name = nameL(ctx.mCall().m());
    Parameters parameters = this.parseMParameters(ctx.mCall().round().ps());
    Doc docs = parseDoc(ctx.mCall().round().docsOpt());
    return new Expression.Using(path, name, docs, parameters, inner);
}
Also used : Path(ast.Ast.Path) Parameters(ast.Ast.Parameters) Expression(ast.Expression) Doc(ast.Ast.Doc)

Aggregations

Path (ast.Ast.Path)56 ClassB (ast.ExpCore.ClassB)28 ArrayList (java.util.ArrayList)23 Ast (ast.Ast)14 PathPath (ast.Util.PathPath)13 Type (ast.Ast.Type)12 MethodWithType (ast.ExpCore.ClassB.MethodWithType)12 Doc (ast.Ast.Doc)11 Member (ast.ExpCore.ClassB.Member)11 List (java.util.List)11 ExpCore (ast.ExpCore)10 NestedClass (ast.ExpCore.ClassB.NestedClass)8 PathSPath (ast.Util.PathSPath)8 CloneWithPath (coreVisitors.CloneWithPath)8 Collections (java.util.Collections)8 HashSet (java.util.HashSet)8 Program (programReduction.Program)8 Map (tools.Map)8 MethodSelector (ast.Ast.MethodSelector)7 SPathSPath (ast.Util.SPathSPath)7