Search in sources :

Example 31 with Path

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

the class Functions method originDecOf.

public static Path originDecOf(Program p, MethodSelector ms, ClassB cb) /*normalized*/
{
    assert cb.getPhase().subtypeEq(Phase.Norm);
    for (Path pi : cb.getSuperPaths()) {
        ClassB cbi = p.extractClassB(pi);
        MethodWithType m = (MethodWithType) cbi._getMember(ms);
        if (m != null && !m.getMt().isRefine()) {
            return pi;
        }
    }
    throw Assertions.codeNotReachable();
}
Also used : Path(ast.Ast.Path) ClassB(ast.ExpCore.ClassB)

Example 32 with Path

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

the class FindPathUsage method liftT.

public Type liftT(Type s) {
    Path inner = s.getPath();
    if (s.toString().endsWith("Location")) {
        System.out.println(s);
    }
    Ast.Position pos = ctxPos();
    locate(inner, pos);
    return s;
//add using
}
Also used : Path(ast.Ast.Path) Ast(ast.Ast)

Example 33 with Path

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

the class Norm method norm.

public ExpCore.ClassB norm(Program p) {
    //-norm(p)={interface? implements Ps' norm(p,Ms') }
    //p.top()={interface? implements Ps Ms} //Ms is free var and is ok
    ClassB l = p.top();
    //Ps'=collect(p,Ps)
    List<Path> ps1 = Methods.collect(p, l.getSuperPaths());
    //Ms'=methods(p,This0), {C:e in Ms} //norm now put all the nested classes in the back.
    List<ClassB.Member> ms1 = Stream.concat(p.methods(Path.outer(0)).stream(), l.getMs().stream().filter(m -> m instanceof ClassB.NestedClass)).map(m -> norm(p, m)).collect(Collectors.toList());
    //return l.withSupertypes(ps1).withMs(ms1).withUniqueId(p.getFreshId()).withPhase(Phase.Norm);
    return new ClassB(l.getDoc1(), l.isInterface(), Map.of(pi -> pi.toImmNT(), ps1), ms1, l.getP(), Phase.Norm, p.getFreshId());
}
Also used : Path(ast.Ast.Path) NestedClass(ast.ExpCore.ClassB.NestedClass) Ast(ast.Ast) Path(ast.Ast.Path) Map(tools.Map) Type(ast.Ast.Type) Phase(ast.ExpCore.ClassB.Phase) Assertions(tools.Assertions) ExpCore(ast.ExpCore) MethodWithType(ast.ExpCore.ClassB.MethodWithType) MethodType(ast.Ast.MethodType) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) CloneVisitor(coreVisitors.CloneVisitor) List(java.util.List) Stream(java.util.stream.Stream) ClassB(ast.ExpCore.ClassB) Optional(java.util.Optional) NestedClass(ast.ExpCore.ClassB.NestedClass) ClassB(ast.ExpCore.ClassB)

Example 34 with Path

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

the class Resources method isValid.

public static boolean isValid(Program p, Object res, Object[] xs) {
    if (L42.trustPluginsAndFinalProgram) {
        return true;
    }
    ExpCore ec0 = Revertable.doRevert(res);
    List<ExpCore> es = new ArrayList<>();
    for (Object o : xs) {
        es.add(Revertable.doRevert(o));
    }
    boolean strict = true;
    for (ExpCore ec : es) {
        List<ClassB> cbs = CollectClassBs0.of(ec);
        List<Path> ps = CollectPaths0.of(ec);
        for (ClassB cb : cbs) {
            if (!cb.getPhase().subtypeEq(Phase.Typed)) {
                strict = false;
            }
        }
        for (Path path : ps) {
            if (path.isPrimitive()) {
                continue;
            }
            ClassB extracted = p.extractClassB(path);
            if (!extracted.getPhase().subtypeEq(Phase.Typed)) {
                strict = false;
            }
        }
    }
    List<ClassB> cbs = CollectClassBs0.of(ec0);
    for (ClassB cb : cbs) {
        try {
            newTypeSystem.TypeSystem.instance().topTypeLib(Phase.Typed, p.evilPush(cb));
        } catch (ErrorMessage msg) {
            System.err.println("__________PLUGIN error identified_________");
            //to breakpoint here
            throw msg;
        }
    }
    return true;
}
Also used : Path(ast.Ast.Path) ExpCore(ast.ExpCore) ArrayList(java.util.ArrayList) ErrorMessage(ast.ErrorMessage) ClassB(ast.ExpCore.ClassB)

Example 35 with Path

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

the class _Sum method sumMethod.

static MethodWithType sumMethod(MethodWithType ma, MethodWithType mb) {
    Set<Path> pa = new HashSet<Path>(Map.of(t -> t.getPath(), ma.getMt().getExceptions()));
    Set<Path> pb = new HashSet<Path>(Map.of(t -> t.getPath(), mb.getMt().getExceptions()));
    Set<Path> pc = new HashSet<>(pa);
    pc.retainAll(pb);
    Doc doc = ma.getDoc().sum(mb.getDoc());
    MethodType mt = ma.getMt();
    List<Ast.Type> opc = pc.stream().map(pi -> (Ast.Type) pi.toImmNT()).collect(Collectors.toList());
    Collections.sort(opc, (p1, p2) -> p1.toString().compareTo(p2.toString()));
    mt = mt.withExceptions(opc);
    MethodWithType mwt = ma.withMt(mt).withDoc(doc);
    //now mwt has min exceptions and summed docs
    assert !ma.get_inner().isPresent() || !mb.get_inner().isPresent();
    if (mb.get_inner().isPresent()) {
        mwt = mwt.withInner(mb.getInner());
    }
    return mwt;
}
Also used : Resources(platformSpecific.javaTranslation.Resources) From(coreVisitors.From) Stage(ast.Ast.Stage) Program(programReduction.Program) Ast(ast.Ast) Map(tools.Map) Configuration(facade.Configuration) ErrorMessage(ast.ErrorMessage) MethodType(ast.Ast.MethodType) MethodWithType(ast.ExpCore.ClassB.MethodWithType) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) RefreshUniqueNames(privateMangling.RefreshUniqueNames) ClassB(ast.ExpCore.ClassB) PathMwt(ast.Util.PathMwt) ClassKind(is.L42.connected.withSafeOperators.ExtractInfo.ClassKind) CloneVisitor(sugarVisitors.CloneVisitor) NestedClass(ast.ExpCore.ClassB.NestedClass) Path(ast.Ast.Path) Doc(ast.Ast.Doc) Phase(ast.ExpCore.ClassB.Phase) Set(java.util.Set) ExpCore(ast.ExpCore) Member(ast.ExpCore.ClassB.Member) Collectors(java.util.stream.Collectors) Functions(auxiliaryGrammar.Functions) CollapsePositions(sugarVisitors.CollapsePositions) List(java.util.List) Optional(java.util.Optional) Collections(java.util.Collections) MethodImplemented(ast.ExpCore.ClassB.MethodImplemented) Path(ast.Ast.Path) MethodType(ast.Ast.MethodType) MethodType(ast.Ast.MethodType) MethodWithType(ast.ExpCore.ClassB.MethodWithType) Doc(ast.Ast.Doc) MethodWithType(ast.ExpCore.ClassB.MethodWithType) HashSet(java.util.HashSet)

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