Search in sources :

Example 1 with Map

use of tools.Map in project L42 by ElvisResearchGroup.

the class TsBlock method dsType.

default default TOutDs dsType(TIn in, List<Dec> _ds) {
    if (_ds.isEmpty()) {
        return new TOkDs(Tr.instance, _ds, G.instance.addGG(in));
    }
    int i = splitDs(in, _ds);
    assert i + 1 <= _ds.size();
    List<Dec> ds = _ds.subList(i + 1, _ds.size());
    //G'
    List<Dec> ds0n = GuessTypeCore.guessedDs(in.p, in, _ds.subList(0, i + 1));
    List<String> fve0n = new ArrayList<>();
    for (Dec di : _ds.subList(0, i + 1)) {
        fve0n.addAll(FreeVariables.of(di.getInner()));
    }
    assert !fve0n.stream().anyMatch(x -> ds.stream().anyMatch(d -> d.getX().equals(x)));
    List<Dec> dsFiltered = ds0n.stream().filter(d -> {
        Mdf m = d.getT().get().getMdf();
        return m == Mdf.Immutable || m == Mdf.Mutable;
    }).map(d -> d.withVar(false).withT(Optional.of(TypeManipulation.fwd(d.getT().get())))).collect(Collectors.toList());
    //G1
    TIn in1 = in.addGds(in.p, dsFiltered);
    Tr trAcc = Tr.instance;
    List<Dec> ds1 = new ArrayList<>();
    List<Dec> ds1FwdP = new ArrayList<>();
    for (Dec di : ds0n) {
        Type nt = di.getT().get();
        Type ntFwdP = TypeManipulation.fwdP(nt);
        TOut _out = type(in1.withE(di.getInner(), ntFwdP));
        if (!_out.isOk()) {
            return _out.toError();
        }
        TOk ok = _out.toOk();
        trAcc = trAcc.trUnion(ok);
        Dec di1 = di.withInner(ok.annotated);
        if (TypeManipulation.fwd_or_fwdP_in(nt.getMdf())) {
            //building G2
            ds1.add(di1.withT(Optional.of(ok.computed)));
        } else {
            ds1.add(di1.withT(Optional.of(TypeManipulation.noFwd(ok.computed))));
        }
        ds1FwdP.add(di1.withVar(false).withT(Optional.of(TypeManipulation.fwdP(ok.computed))));
    }
    if (TypeManipulation.fwd_or_fwdP_in(trAcc.returns)) {
        boolean xInCommon = fve0n.stream().anyMatch(x -> ds0n.stream().anyMatch(d -> d.getX().equals(x)));
        if (xInCommon) {
            return new TErr(in, "", null, ErrorKind.AttemptReturnFwd);
        }
    }
    List<Type> _nts = new ArrayList<>();
    for (String x : fve0n) {
        Type t = in._g(x);
        if (t != null) {
            _nts.add(t);
        }
    }
    TIn inG0;
    if (TypeManipulation.fwd_or_fwdP_in(_nts)) {
        inG0 = in.addGds(in.p, ds1FwdP);
    } else {
        inG0 = in.addGds(in.p, ds1);
    }
    TOutDs _res = dsType(inG0, ds);
    if (!_res.isOk()) {
        return _res.toError();
    }
    TOkDs res = _res.toOkDs();
    //safe? locally created, not leaked yet.
    ds1.addAll(res.ds);
    if (res.trAcc != null) {
        trAcc = trAcc.trUnion(res.trAcc);
    }
    return new TOkDs(trAcc, ds1, res.g);
}
Also used : On(ast.ExpCore.Block.On) Path(ast.Ast.Path) Map(tools.Map) Doc(ast.Ast.Doc) Type(ast.Ast.Type) Set(java.util.Set) FreeVariables(coreVisitors.FreeVariables) Assertions(tools.Assertions) ExpCore(ast.ExpCore) Collectors(java.util.stream.Collectors) Block(ast.ExpCore.Block) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) List(java.util.List) Stream(java.util.stream.Stream) SignalKind(ast.Ast.SignalKind) Optional(java.util.Optional) Collector(java.util.stream.Collector) Dec(ast.ExpCore.Block.Dec) Norm(programReduction.Norm) Mdf(ast.Ast.Mdf) Dec(ast.ExpCore.Block.Dec) ArrayList(java.util.ArrayList) Mdf(ast.Ast.Mdf) Type(ast.Ast.Type)

Example 2 with Map

use of tools.Map 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 3 with Map

use of tools.Map 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)3 ExpCore (ast.ExpCore)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Optional (java.util.Optional)3 Collectors (java.util.stream.Collectors)3 Map (tools.Map)3 Ast (ast.Ast)2 Doc (ast.Ast.Doc)2 MethodType (ast.Ast.MethodType)2 Type (ast.Ast.Type)2 ClassB (ast.ExpCore.ClassB)2 MethodWithType (ast.ExpCore.ClassB.MethodWithType)2 NestedClass (ast.ExpCore.ClassB.NestedClass)2 Phase (ast.ExpCore.ClassB.Phase)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 Stream (java.util.stream.Stream)2 Assertions (tools.Assertions)2 Mdf (ast.Ast.Mdf)1