Search in sources :

Example 41 with Type

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

the class GuessTypeCore method visit.

@Override
public Type visit(MCall s) {
    Type former = s.getInner().accept(this);
    if (former == null) {
        return null;
    }
    Path path = former.getPath();
    assert path != null;
    List<MethodSelectorX> msl = new ArrayList<>();
    MethodSelectorX msx = new MethodSelectorX(s.getS(), "");
    msl.add(msx);
    MethodWithType meth = (MethodWithType) p.extractClassB(path)._getMember(s.getS());
    if (meth == null) {
        return null;
    }
    return (Type) From.fromT(meth.getMt().getReturnType(), path);
}
Also used : Path(ast.Ast.Path) Type(ast.Ast.Type) MethodWithType(ast.ExpCore.ClassB.MethodWithType) MethodSelectorX(ast.Ast.MethodSelectorX) ArrayList(java.util.ArrayList) MethodWithType(ast.ExpCore.ClassB.MethodWithType)

Example 42 with Type

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

the class TIn method toRead.

//onlyMutOrImm(G)={x:G(x) | G(x) only mut or imm}
public This toRead() {
    //toRead(G)(x)=toRead(G(x)) //thus undefined where toRead undefined
    Map<String, Map.Entry<Boolean, Type>> newG = new HashMap<>(g);
    for (String xi : gDom()) {
        Type ti = g(xi);
        assert ti != null;
        ti = TypeManipulation._toRead(ti);
        if (ti == null) {
            continue;
        }
        newG.put(xi, p(false, ti));
    }
    return this.withG(newG);
}
Also used : Entry(java.util.Map.Entry) Type(ast.Ast.Type) MethodType(ast.Ast.MethodType) MethodWithType(ast.ExpCore.ClassB.MethodWithType) HashMap(java.util.HashMap)

Example 43 with Type

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

the class TIn method freshGFromMt.

public TIn freshGFromMt(MethodWithType mwt) {
    MethodType mt = mwt.getMt();
    assert mwt.get_inner().isPresent();
    Map<String, Map.Entry<Boolean, Type>> newG = new HashMap<>(g);
    newG.put("this", p(false, new Type(mt.getMdf(), Path.outer(0), Doc.empty())));
    {
        int i = -1;
        for (String x : mwt.getMs().getNames()) {
            i += 1;
            Type ntx = mt.getTs().get(i);
            newG.put(x, p(false, ntx));
        }
    }
    return new TIn(Phase.Typed, this.p, mwt.getInner(), TypeManipulation.fwdP(mt.getReturnType()), newG);
}
Also used : MethodType(ast.Ast.MethodType) Entry(java.util.Map.Entry) Type(ast.Ast.Type) MethodType(ast.Ast.MethodType) MethodWithType(ast.ExpCore.ClassB.MethodWithType) HashMap(java.util.HashMap)

Example 44 with Type

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

the class TOkK method trCapture.

public This trCapture(Program p, On k) {
    //(Ts;Ps).capture(catch return P x e)={T| T in Ts, not p|-T.P<=P};Ps
    if (k.getKind() == SignalKind.Error) {
        return self();
    }
    This result = trClean();
    if (k.getKind() == SignalKind.Exception) {
        result.exceptions = new ArrayList<>();
        for (Path pi : exceptions) {
            if (null != TypeSystem.subtype(p, pi, k.getT().getPath())) {
                result.exceptions.add(pi);
            }
        }
    }
    //otherwise, is return
    result.returns = new ArrayList<>();
    for (Type ti : returns) {
        if (null != TypeSystem.subtype(p, ti.getPath(), k.getT().getPath())) {
            result.returns.add(ti);
        }
    }
    return result;
}
Also used : Path(ast.Ast.Path) Type(ast.Ast.Type)

Example 45 with Type

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

the class TsBlock method promotionMakesSense.

default default boolean promotionMakesSense(TIn in, TErr tErr) {
    Type expected = in.expected;
    Type obtained = tErr._computed;
    if (expected == null || obtained == null) {
        return false;
    }
    if (null != TypeSystem.subtype(in.p, obtained.getPath(), expected.getPath())) {
        return false;
    }
    Mdf eM = expected.getMdf();
    Mdf oM = obtained.getMdf();
    boolean acceptableEM = eM == Mdf.Capsule || eM == Mdf.Immutable || eM == Mdf.ImmutableFwd || eM == Mdf.ImmutablePFwd;
    return acceptableEM && oM == Mdf.Mutable;
}
Also used : Type(ast.Ast.Type) Mdf(ast.Ast.Mdf)

Aggregations

Type (ast.Ast.Type)81 MethodType (ast.Ast.MethodType)50 MethodWithType (ast.ExpCore.ClassB.MethodWithType)28 MethodWithType (ast.Expression.ClassB.MethodWithType)24 ArrayList (java.util.ArrayList)24 Mdf (ast.Ast.Mdf)16 Expression (ast.Expression)15 Path (ast.Ast.Path)13 Doc (ast.Ast.Doc)11 Ast (ast.Ast)10 MethodSelector (ast.Ast.MethodSelector)10 HashMap (java.util.HashMap)10 MethodSelectorX (ast.Ast.MethodSelectorX)8 VarDecXE (ast.Ast.VarDecXE)8 ExpCore (ast.ExpCore)8 Catch (ast.Expression.Catch)8 X (ast.Expression.X)8 VarDec (ast.Ast.VarDec)7 Block (ast.ExpCore.Block)7 List (java.util.List)7