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");
}
}
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");
}
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);
}
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;
}
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;
}
Aggregations