Search in sources :

Example 71 with Type

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

the class Test212_or_170_MethodTypes method recLeft.

MethodType recLeft(MethodType mt) {
    List<Type> newTs = mt.getTs().subList(1, mt.getTs().size());
    Mdf mdf = mt.getTs().get(0).getMdf();
    if (TypeManipulation.fwd_or_fwdP_in(mdf)) {
        return null;
    }
    return mt.withMdf(mdf).withTs(newTs);
}
Also used : Type(ast.Ast.Type) MethodType(ast.Ast.MethodType) Mdf(ast.Ast.Mdf)

Example 72 with Type

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

the class Test212_or_170_MethodTypes method test1.

@Test
public void test1() {
    assert dataSet.size() == 170 : dataSet.size();
    //Lent,ImmutableFwd->ImmutablePFwd
    Type _t = Path.Any().toImmNT();
    MethodType proto = new MethodType(true, Mdf.Capsule, Arrays.asList(_t.withMdf(Mdf.Mutable), _t.withMdf(Mdf.ImmutableFwd)), _t.withMdf(Mdf.ImmutablePFwd), Collections.emptyList());
    proto = _mVp(proto, 1);
    System.out.println(mtToS(proto));
}
Also used : MethodType(ast.Ast.MethodType) Type(ast.Ast.Type) MethodType(ast.Ast.MethodType) Test(org.junit.Test)

Example 73 with Type

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

the class SumMethods method mtU.

static MethodType mtU(int index, MethodType mt1, MethodType mt2) {
    Mdf mdfU = mdfU(mt1.getMdf(), mt2.getMdf());
    if (mdfU == null) {
        return null;
    }
    Type removed = mt2.getTs().get(index);
    boolean isRemovedPh = !Functions.isComplete(removed);
    List<Type> totTypes;
    if (isRemovedPh) {
        totTypes = new ArrayList<>(mt1.getTs());
    } else {
        totTypes = mt1.getTs().stream().map(t -> TypeManipulation.noFwd(t)).collect(Collectors.toList());
    }
    totTypes.addAll(mt2.getTs());
    int toRemove = mt1.getTs().size() + index;
    totTypes.remove(toRemove);
    List<Type> exU = new ArrayList<>(mt1.getExceptions());
    exU.addAll(mt2.getExceptions());
    MethodType mtU = new MethodType(false, mdfU, totTypes, mt2.getReturnType(), exU);
    return mtU;
}
Also used : MethodType(ast.Ast.MethodType) Type(ast.Ast.Type) MethodType(ast.Ast.MethodType) MethodWithType(ast.ExpCore.ClassB.MethodWithType) Mdf(ast.Ast.Mdf)

Example 74 with Type

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

the class Redirect method redirectOkMember.

private static void redirectOkMember(List<PathSPath> ambiguities, List<SPathSPath> exceptions, Member mi, Member miGet, PathSPath current) {
    if (mi instanceof NestedClass) {
        assert miGet instanceof NestedClass;
        assert ((NestedClass) mi).getName().equals(((NestedClass) miGet).getName());
        Path src = current.getPath().pushC(((NestedClass) mi).getName());
        Path dest = current.getPathsSet().iterator().next().pushC(((NestedClass) mi).getName());
        plusEqual(ambiguities, src, Arrays.asList(dest));
        return;
    }
    assert mi.getClass().equals(miGet.getClass());
    assert mi instanceof MethodWithType : mi;
    MethodWithType mwtSrc = (MethodWithType) mi;
    MethodWithType mwtDest = (MethodWithType) miGet;
    //this is what happens in p.method
    mwtSrc = From.from(mwtSrc, current.getPath());
    mwtDest = From.from(mwtDest, current.getPathsSet().iterator().next());
    assert mwtSrc.getMs().equals(mwtDest.getMs());
    boolean thisMdfOk = mwtSrc.getMt().getMdf().equals(mwtDest.getMt().getMdf());
    boolean retOk = redirectOkT(ambiguities, mwtSrc.getMt().getReturnType(), mwtDest.getMt().getReturnType());
    List<Integer> parWrong = new ArrayList<Integer>();
    {
        int i = -1;
        for (Type tSrc : mwtSrc.getMt().getTs()) {
            i += 1;
            Type tDest = mwtDest.getMt().getTs().get(i);
            if (!redirectOkT(ambiguities, tSrc, tDest)) {
                parWrong.add(i);
            }
            ;
        }
    }
    boolean excOk = plusEqualAndExc(ambiguities, exceptions, current.getPath(), mwtSrc, mwtDest);
    if (thisMdfOk && retOk && excOk && parWrong.isEmpty()) {
        return;
    }
    throw Errors42.errorMethodClash(current.getPath().getCBar(), mwtSrc, mwtDest, excOk, parWrong, retOk, thisMdfOk, false);
}
Also used : PathPath(ast.Util.PathPath) PathSPath(ast.Util.PathSPath) SPathSPath(ast.Util.SPathSPath) CloneWithPath(coreVisitors.CloneWithPath) Path(ast.Ast.Path) Type(ast.Ast.Type) MethodWithType(ast.ExpCore.ClassB.MethodWithType) ArrayList(java.util.ArrayList) NestedClass(ast.ExpCore.ClassB.NestedClass) MethodWithType(ast.ExpCore.ClassB.MethodWithType)

Example 75 with Type

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

the class ToAst method parseType.

private Type parseType(TContext t) {
    if (t.concreteT() != null) {
        ConcreteTContext tt = t.concreteT();
        Doc d = parseDoc(tt.docsOpt());
        Ast.Type nt = new Ast.Type(Mdf.fromString((tt.Mdf() == null) ? "" : nameK(tt.Mdf())), Ast.Path.sugarParse(nameU(tt.Path())), d);
        if (tt.Ph() == null) {
            return nt;
        }
        return Functions.toPh(nt);
    }
    if (t.historicalT() != null) {
        HistoricalTContext tt = t.historicalT();
        Doc d = parseDoc(tt.docsOpt());
        Path p = ast.Ast.Path.sugarParse(nameU(tt.Path()));
        List<MethodSelectorX> mss = new ArrayList<MethodSelectorX>();
        for (HistoricalSeqContext ms : tt.historicalSeq()) {
            mss.add(parseMethSelectorX(ms));
        }
        //return new ast.Ast.HistoricType(p,mss,d);
        throw Assertions.codeNotReachable();
    }
    throw Assertions.codeNotReachable();
}
Also used : Path(ast.Ast.Path) Type(ast.Ast.Type) Ast(ast.Ast) MethodSelectorX(ast.Ast.MethodSelectorX) Doc(ast.Ast.Doc) Type(ast.Ast.Type)

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