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);
}
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());
}
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;
}
Aggregations