use of ast.Ast.Type in project L42 by ElvisResearchGroup.
the class TIn method addGds.
public This addGds(Program p, List<ExpCore.Block.Dec> ds) {
Map<String, Map.Entry<Boolean, Type>> newG = new HashMap<>(g);
for (ExpCore.Block.Dec d : ds) {
assert !g.containsKey(d.getX());
Type nt = d.getT().get();
assert !d.isVar() || !TypeManipulation.fwd_or_fwdP_in(nt.getMdf());
assert !d.isVar() || nt.getMdf() != Mdf.Capsule;
newG.put(d.getX(), p(d.isVar(), nt));
}
return this.withG(newG);
}
use of ast.Ast.Type in project L42 by ElvisResearchGroup.
the class TsBlock method kTypeCatch.
// T0 is the declared caught type, which contributes only a path
// T1 is the actual caught type, based on the types which can be thrown in context
// T2 is the type of the expression, based on x being bound T1
default default TOutK kTypeCatch(TIn in, Tr tr1, On k) {
if (k.getKind() == SignalKind.Return && tr1.returns.isEmpty()) {
return new TErr(in, "No returns in scope", null, ErrorKind.NoMostGeneralMdf);
}
Mdf mdf1 = TypeManipulation._mostGeneralMdf(k.getKind(), tr1);
if (mdf1 == null) {
return new TErr(in, "Contrasting mdf expected for return", null, ErrorKind.NoMostGeneralMdf);
}
Type T1 = k.getT().withMdf(mdf1);
TOut _out = type(in.addG(k.getX(), false, T1).withE(k.getE(), in.expected));
if (!_out.isOk()) {
return _out.toError();
}
TOk out = _out.toOk();
TOkK res = new TOkK(Tr.instance.trUnion(out), k.withE(out.annotated).withT(T1), out.computed);
return res;
/* Phase| p| G| Tr' |- catch throw T0 x e ~> catch throw T1.P x e' :T2 <= T | Tr
mdf1 = mostGeneralMdf(throw,Tr') //set of Mdfs admits no single most general mdf, or mdfs is empty
//inconsistent set of thrown things, which do not share a most
//general modifier [list of line numbers of the throws]
T1 = mdf1 resolve (p, T0).P //resolve can fail
not catchRethrow(catch throw T1 x e)
Phase| p| G[x:T1]|- e ~> e' : T2 <= T | Tr
*/
}
use of ast.Ast.Type in project L42 by ElvisResearchGroup.
the class TsOperations method tsClassB.
default default TOut tsClassB(TIn in, ClassB s) {
//D |- L ~> L' : imm Library <= T | emptyTr
//D.p|-imm Library <= T
//D.Phase |- D.p.evilPush(L) ~> L'
Type t = Path.Library().toImmNT();
ErrorKind subErr = TypeSystem.subtype(in.p, t, in.expected);
if (subErr != null) {
TErr out = new TErr(in, "-----------", t, subErr);
return out;
}
TOut out = typeLib(in.withP(in.p.evilPush(s)));
if (out.isOk()) {
return new TOk(in, out.toOk().annotated, t);
}
return out.toError().enrich(in);
}
use of ast.Ast.Type in project L42 by ElvisResearchGroup.
the class TsOperations method tsSignal.
default default TOut tsSignal(TIn in, Signal s) {
//D |- throw[_,_] e~> throw[T0,T3] e' : T0 <= T0 | Tr
// T1 = resolve(D.p,guessType(D.G,e))// Note, resolves and guessTypes can go in error, and need to become a type error here
// if throw=exception, T2= imm T1.P and Tr=Ts;Ps,P
// if throw=error, T2= imm T1.P and Tr=Ts;Ps
// if throw=return, T2= (fwd T1) and Tr=(Ts,T3);Ps
// D|- e~> e' : T3 <=T2|Ts;Ps
Type T1 = GuessTypeCore._of(in.p, in, s.getInner());
Type T2;
if (s.getKind() != SignalKind.Return) {
T2 = T1.getPath().toImmNT();
} else {
T2 = TypeManipulation.fwd(T1);
}
TOut innerT = type(in.withE(s.getInner(), T2));
if (!innerT.isOk()) {
return innerT.toError();
}
TOk res = innerT.toOk();
Type T3 = res.computed;
if (s.getKind() == SignalKind.Return) {
res = res.returnsAdd(T3);
}
if (s.getKind() == SignalKind.Exception) {
res = res.exceptionsAdd(T3.getPath());
}
s = s.withInner(res.annotated).withTypeIn(T3).withTypeOut(in.expected);
return res.withAC(s, in.expected);
}
use of ast.Ast.Type in project L42 by ElvisResearchGroup.
the class SumMethods method isReplacedParOk.
static boolean isReplacedParOk(int index, MethodType mt1, MethodType mt2) {
if (mt2.getTs().isEmpty()) {
return false;
}
Type p1 = mt2.getTs().get(index);
Type r = mt1.getReturnType();
return p1.equals(r);
}
Aggregations