Search in sources :

Example 41 with MethodWithType

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

the class TranslateClass method getType.

private static void getType(String s, List<MethodWithType> ctors, StringBuilder res) {
    res.append("public static final " + s + " type=new " + s + "(");
    StringBuilders.formatSequence(res, ctors.get(0).getMs().getNames().iterator(), ", ", n -> res.append("null"));
    res.append(");\n");
    for (MethodWithType cti : ctors) {
        getMethodHeader(cti, res);
        res.append("{return new " + s + "(");
        StringBuilders.formatSequence(res, cti.getMs().getNames().iterator(), ", ", n -> res.append("P" + Resources.nameOf(n)));
        res.append(");}\n");
    }
}
Also used : MethodWithType(ast.ExpCore.ClassB.MethodWithType)

Example 42 with MethodWithType

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

the class TranslateClass method getIType.

private static void getIType(String s, ClassB cb, StringBuilder res) {
    res.append("public static final " + s + " type=new " + s + "(){\n");
    getITReverter(s, res);
    for (Member m : cb.getMs()) {
        MethodWithType mt = (MethodWithType) m;
        getMethodHeader(mt, res);
        res.append("{throw new Error(\"" + "Calling an interface method" + ":" + mt.getMs() + "\");}\n");
    }
    res.append("};\n");
}
Also used : MethodWithType(ast.ExpCore.ClassB.MethodWithType) Member(ast.ExpCore.ClassB.Member)

Example 43 with MethodWithType

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

the class Abstract method auxToAbstract.

private static ClassB auxToAbstract(Program p, ClassB cb, List<Ast.C> pathForError, MethodSelector sel, MethodSelector newSel) {
    List<Member> newMs = new ArrayList<>(cb.getMs());
    Member m = Functions.getIfInDom(newMs, sel).get();
    //make m abstract
    if (m instanceof MethodWithType) {
        MethodWithType mwt = (MethodWithType) m;
        mwt = mwt.with_inner(Optional.empty());
        Functions.replaceIfInDom(newMs, mwt);
    } else {
        //it is method implemented
        Functions.removeIfInDom(newMs, sel);
    }
    //create new class
    if (newSel == null) {
        return cb.withMs(newMs);
    }
    MethodWithType mwt1 = (MethodWithType) cb._getMember(sel);
    assert mwt1 != null;
    if (newSel != null) {
        Errors42.checkCompatibleMs(pathForError, mwt1, newSel);
    }
    Optional<MethodWithType> mwt2 = Optional.ofNullable((MethodWithType) cb._getMember(newSel));
    //never refine, see under
    mwt1 = mwt1.withMs(newSel).withDoc(Doc.empty()).withMt(mwt1.getMt().withRefine(false));
    if (mwt2.isPresent()) {
        //Never there, so will never implement interfaces (on normalized classb)
        throw Errors42.errorMethodClash(pathForError, mwt1, mwt2.get(), false, Collections.emptyList(), false, false, false);
    }
    newMs.add(mwt1);
    return cb.withMs(newMs);
}
Also used : ArrayList(java.util.ArrayList) MethodWithType(ast.ExpCore.ClassB.MethodWithType) Member(ast.ExpCore.ClassB.Member)

Example 44 with MethodWithType

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

the class _Aux method isConsistent.

static boolean isConsistent(ClassB cb) {
    int countWalkBy = 0;
    HashSet<String> keys = new HashSet<String>();
    for (Member m : cb.getMs()) {
        if (m instanceof MethodWithType) {
            MethodWithType mwt = (MethodWithType) m;
            String key = mwt.getMs().toString();
            assert !keys.contains(key);
            keys.add(key);
        //assert mwt.getMt().getTDocs().size() == mwt.getMt().getTs().size();
        }
        if (m instanceof NestedClass) {
            NestedClass nc = (NestedClass) m;
            String key = nc.getName().toString();
            assert !keys.contains(key);
            keys.add(key);
            if (nc.getInner() instanceof ExpCore.WalkBy) {
                countWalkBy += 1;
            }
        }
        if (m instanceof MethodImplemented) {
            MethodImplemented mi = (MethodImplemented) m;
            String key = mi.getS().toString();
            assert !keys.contains(key);
            keys.add(key);
        }
    }
    //     || ((cb.getPhase()!=ast.ExpCore.ClassB.Phase.None && !cb.getUniqueId().isEmpty()) );
    assert countWalkBy <= 1 : cb;
    return true;
}
Also used : MethodImplemented(ast.ExpCore.ClassB.MethodImplemented) NestedClass(ast.ExpCore.ClassB.NestedClass) ToString(lombok.ToString) MethodWithType(ast.ExpCore.ClassB.MethodWithType) Member(ast.ExpCore.ClassB.Member) HashSet(java.util.HashSet)

Example 45 with MethodWithType

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

the class ExtractInfo method isParTypeOk.

/*
  static java.util.Map<Path,List<MethodSelector>> implementedInterfacesMethods(Program p,Path path){
    java.util.Map<Path,List<MethodSelector>> accumulator=new HashMap<>();
    fillImplementedInterfacesMethods(accumulator,p,path);
    return accumulator;
  }
  static void fillImplementedInterfacesMethods(java.util.Map<Path,List<MethodSelector>> accumulator,Program p,Path path){
    //assume p have all the cb present,we do not use ct here
    ClassB cb=p.extractCb(path);
    if(cb.isInterface()){accumulateCb(accumulator,path,cb);}
    for(Path pi:cb.getSupertypes()){
      pi=From.fromP(pi,path);
      fillImplementedInterfacesMethods(accumulator, p, pi);
    }
  }
*/
static List<Integer> isParTypeOk(MethodWithType mta, MethodWithType mtb) {
    List<Integer> res = new ArrayList<>();
    int maxLen = Math.max(mta.getMt().getTs().size(), mtb.getMt().getTs().size());
    for (int i = 0; i < maxLen; i++) {
        Type ta;
        Type tb;
        try {
            ta = mta.getMt().getTs().get(i);
            tb = mtb.getMt().getTs().get(i);
        } catch (ArrayIndexOutOfBoundsException out) {
            res.add(i);
            continue;
        }
        if (!ta.equals(tb)) {
            res.add(i);
        }
    }
    return res;
}
Also used : Type(ast.Ast.Type) MethodType(ast.Ast.MethodType) MethodWithType(ast.ExpCore.ClassB.MethodWithType) ArrayList(java.util.ArrayList)

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