Search in sources :

Example 1 with MethodWithType

use of ast.ExpCore.ClassB.MethodWithType in project L42 by ElvisResearchGroup.

the class Errors42 method checkCompatibleMs.

public static void checkCompatibleMs(List<Ast.C> pathForError, MethodWithType mem, MethodSelector dest) {
    int sizeA = mem.getMs().getNames().size();
    int sizeB = dest.getNames().size();
    if (sizeA == sizeB) {
        return;
    }
    List<Integer> parsWrong = new ArrayList<>();
    int min = Math.min(sizeA, sizeB);
    int max = Math.max(sizeA, sizeB);
    for (int i = min; i < max; i++) {
        parsWrong.add(i);
    }
    List<Type> ts = new ArrayList<>(mem.getMt().getTs());
    for (int i = sizeA; i < sizeB; i++) {
        ts.add(ast.Ast.Type.immVoid);
    }
    if (sizeA > sizeB) {
        ts = ts.subList(0, sizeB);
    }
    MethodWithType memb = mem.withMs(dest).withMt(mem.getMt().withTs(ts));
    throw errorMethodClash(pathForError, mem, memb, true, parsWrong, true, true, false);
}
Also used : Type(ast.Ast.Type) MethodWithType(ast.ExpCore.ClassB.MethodWithType) ArrayList(java.util.ArrayList) MethodWithType(ast.ExpCore.ClassB.MethodWithType)

Example 2 with MethodWithType

use of ast.ExpCore.ClassB.MethodWithType in project L42 by ElvisResearchGroup.

the class ExtractInfo method isModule.

public static boolean isModule(ClassB cb) {
    for (Member m : cb.getMs()) {
        if (!(m instanceof MethodWithType)) {
            continue;
        }
        MethodWithType mwt = (MethodWithType) m;
        if (mwt.getMt().getMdf() != Mdf.Class) {
            return false;
        }
        Type rt = mwt.getMt().getReturnType();
        if (!(rt instanceof Type)) {
            continue;
        }
        Type nt = (Type) rt;
        if (nt.getPath().equals(Path.outer(0))) {
            return false;
        }
    }
    return true;
}
Also used : Type(ast.Ast.Type) MethodType(ast.Ast.MethodType) MethodWithType(ast.ExpCore.ClassB.MethodWithType) MethodWithType(ast.ExpCore.ClassB.MethodWithType) Member(ast.ExpCore.ClassB.Member)

Example 3 with MethodWithType

use of ast.ExpCore.ClassB.MethodWithType in project L42 by ElvisResearchGroup.

the class ExtractInfo method accumulateCb.

/*   private static Set<MethodSelector> intersection(Collection<MethodSelector>ams, Collection<MethodSelector>bms){
    if( ams==null || ams.isEmpty() || bms==null || bms.isEmpty()){return  Collections.emptySet();}
    Set<MethodSelector> result = new HashSet<>(ams);
    result.retainAll(bms);
    return result;
  }*/
static void accumulateCb(java.util.Map<Path, List<MethodSelector>> accumulator, Path path, ClassB cb) {
    assert cb.isInterface();
    if (accumulator.containsKey(path)) {
        return;
    }
    List<MethodSelector> defined = new ArrayList<>();
    for (Member m : cb.getMs()) {
        if (!(m instanceof MethodWithType)) {
            continue;
        }
        defined.add(((MethodWithType) m).getMs());
    }
    accumulator.put(path, defined);
}
Also used : MethodSelector(ast.Ast.MethodSelector) ArrayList(java.util.ArrayList) MethodWithType(ast.ExpCore.ClassB.MethodWithType) Member(ast.ExpCore.ClassB.Member)

Example 4 with MethodWithType

use of ast.ExpCore.ClassB.MethodWithType in project L42 by ElvisResearchGroup.

the class LiftValue method liftValue.

static ExpCore.ClassB liftValue(ExpCore val, Ast.MethodSelector sel, ExpCore.ClassB context) {
    List<Member> ms = new ArrayList<>(context.getMs());
    MethodType mt = new MethodType(false, Mdf.Class, Collections.emptyList(), Ast.Type.immAny, Collections.emptyList());
    //need to insert a "cast", or to return Any, and then fwd to a cast
    //lib={ T:{} class method Any val()  class method T cast() {with val=this.val() (on T return val) error ....}
    //lib:=redirect T ->... <<lib
    //lib:=liftValue  val
    Optional<Member> optMt = Functions.getIfInDom(ms, sel);
    ExpCore.ClassB.MethodWithType mwt = new ExpCore.ClassB.MethodWithType(Doc.empty(), sel, mt, Optional.of(val), context.getP());
    if (!optMt.isPresent()) {
        ms.add(mwt);
        return context.withMs(ms);
    }
    if (!(optMt.get() instanceof MethodWithType)) {
        throw Errors42.errorMethodClash(Collections.emptyList(), optMt.get(), mwt, true, Collections.emptyList(), true, true, false);
    }
    Errors42.checkMethodClash(Collections.emptyList(), (MethodWithType) optMt.get(), mwt, false);
    Functions.replaceIfInDom(ms, mwt);
    return context.withMs(ms);
}
Also used : MethodType(ast.Ast.MethodType) ExpCore(ast.ExpCore) ArrayList(java.util.ArrayList) MethodWithType(ast.ExpCore.ClassB.MethodWithType) MethodWithType(ast.ExpCore.ClassB.MethodWithType) Member(ast.ExpCore.ClassB.Member)

Example 5 with MethodWithType

use of ast.ExpCore.ClassB.MethodWithType in project L42 by ElvisResearchGroup.

the class UsedPaths method usedInnerM.

private static Paths usedInnerM(Member m, Phase phase0) {
    if (m instanceof NestedClass) {
        NestedClass nc = (NestedClass) m;
        return usedInnerL((ClassB) nc.getInner(), Collections.emptyList(), phase0).pop();
    }
    List<Path> result1;
    List<ClassB> l1n = Collections.emptyList();
    if (m instanceof MethodWithType) {
        MethodWithType mwt = (MethodWithType) m;
        result1 = CollectPaths0.of(mwt);
        if (phase0 == Phase.Typed && mwt.get_inner().isPresent()) {
            l1n = CollectClassBs0.of(m.getInner());
        }
    } else {
        assert m instanceof MethodImplemented;
        result1 = CollectPaths0.of(m.getInner());
    }
    Paths result2 = Paths.reorganize(result1);
    Paths acc = Paths.empty();
    for (ClassB li : l1n) {
        acc = acc.union(usedInnerL(li, Collections.emptyList(), phase0));
    }
    return result2.union(acc.pop());
}
Also used : Path(ast.Ast.Path) MethodImplemented(ast.ExpCore.ClassB.MethodImplemented) NestedClass(ast.ExpCore.ClassB.NestedClass) MethodWithType(ast.ExpCore.ClassB.MethodWithType) ClassB(ast.ExpCore.ClassB)

Aggregations

MethodWithType (ast.ExpCore.ClassB.MethodWithType)46 Member (ast.ExpCore.ClassB.Member)21 MethodType (ast.Ast.MethodType)18 ArrayList (java.util.ArrayList)16 Type (ast.Ast.Type)13 Path (ast.Ast.Path)10 ClassB (ast.ExpCore.ClassB)10 NestedClass (ast.ExpCore.ClassB.NestedClass)9 ExpCore (ast.ExpCore)8 MethodSelector (ast.Ast.MethodSelector)7 MethodImplemented (ast.ExpCore.ClassB.MethodImplemented)7 Ast (ast.Ast)4 Phase (ast.ExpCore.ClassB.Phase)4 HashSet (java.util.HashSet)4 List (java.util.List)4 Program (programReduction.Program)4 Mdf (ast.Ast.Mdf)3 Functions (auxiliaryGrammar.Functions)3 From (coreVisitors.From)3 Collections (java.util.Collections)3