use of ast.ExpCore.ClassB.MethodWithType in project L42 by ElvisResearchGroup.
the class PlgWrapperGenerator method updateTemplateUsing.
private static MethodWithType updateTemplateUsing(UsingInfo ui, MethodWithType mwt) {
MCall e = templateUsingExc;
MethodType mt = mwt.getMt();
ExpCore.Block b = (Block) e.getEs().get(0);
if (mwt.getMt().getExceptions().isEmpty()) {
b = b.withOns(Collections.emptyList());
}
ExpCore.Using u = (Using) b.getDecs().get(0).getInner();
//parameter expressions
ExpCore.MCall p0 = (MCall) u.getEs().get(0);
//e#mcall.inner<-mwt.retType.path
e = e.withInner(ExpCore.EPath.wrap(mt.getReturnType().getPath()));
//u=u.withS(ui.usingMs);
List<ExpCore> ues = new ArrayList<>();
if (mt.getMdf() != Mdf.Class) {
ues.add(p0.withInner(new ExpCore.X(mwt.getP(), "this")));
}
{
int i = -1;
for (String x : mwt.getMs().getNames()) {
i++;
ExpCore pi = new ExpCore.X(mwt.getP(), x);
boolean needAddBinaryRepr = true;
Type ti = mwt.getMt().getTs().get(i);
if (ti.equals(Type.immLibrary)) {
needAddBinaryRepr = false;
}
if (ti.getMdf() == Mdf.Class) {
needAddBinaryRepr = false;
}
if (needAddBinaryRepr) {
pi = p0.withInner(pi);
}
ues.add(pi);
}
}
u = new Using(u.getPath(), ui.usingMs, u.getDoc(), ues, u.getInner());
String errorS = "plugin string: " + ui.plgInfo.plgString + "\n" + "plugin part: " + ui.plgInfo.plgName + "\n" + "method name: " + mwt.getMs() + "\n" + "java method: " + ui.plgInfo.plgClass.getName() + "." + ui.usingMs + "\n";
//u.inner#mcall.es(0)<-EncodingHelper.wrapStringU()
List<ExpCore> errorEs = Collections.singletonList(EncodingHelper.wrapStringU(errorS));
Signal tmpS = (Signal) u.getInner();
MCall tmpMc = ((MCall) tmpS.getInner()).withEs(errorEs);
u = u.withInner(tmpS.withInner(tmpMc));
b = b.withDecs(Collections.singletonList(b.getDecs().get(0).withInner(u)));
//--
if (!mwt.getMt().getExceptions().isEmpty()) {
On on = b.getOns().get(0);
Dec k0 = ((Block) on.getInner()).getDecs().get(0);
List<Dec> ks = new ArrayList<>();
{
int i = -1;
for (Type ti : mt.getExceptions()) {
i++;
MCall mci = ((MCall) k0.getInner()).withInner(ExpCore.EPath.wrap(ti.getPath()));
ks.add(k0.withInner(mci).withX(k0.getX() + i));
}
}
on = on.withInner(((Block) on.getInner()).withDecs(ks));
b = b.withOns(Collections.singletonList(on));
//k0=b.k(0).inner#block.decs(0)
//k0 add more on need
//ki.inner#mcall.inner<-Pi
}
if (ui.isVoid) {
b = b.withDecs(Collections.singletonList(b.getDecs().get(0).withT(Optional.of(Type.immVoid))));
}
if (!ui.isVoid && !mwt.getMt().getReturnType().equals(Type.immLibrary)) {
e = e.withEs(Collections.singletonList(b));
mwt = mwt.withInner(e);
} else {
mwt = mwt.withInner(b);
}
return mwt;
}
use of ast.ExpCore.ClassB.MethodWithType in project L42 by ElvisResearchGroup.
the class Compose method alradyRefreshedCompose.
public static ClassB alradyRefreshedCompose(PData p, ClassB a, ClassB b) {
if (a.isInterface() || b.isInterface()) {
assert false;
}
List<Type> impls = new ArrayList<>(a.getSupertypes());
for (Type ti : b.getSupertypes()) {
impls.remove(ti);
}
impls.addAll(b.getSupertypes());
List<MethodWithType> mwts = new ArrayList<>(a.mwts());
for (MethodWithType mwti : b.mwts()) {
Functions._findAndRemove(mwts, mwti.getMs());
}
for (MethodWithType mwti : b.mwts()) {
mwts.add(sumMwt(_extractMwt(mwti, a.mwts()), mwti));
}
List<NestedClass> ncs = new ArrayList<>(a.ns());
for (NestedClass nci : b.ns()) {
Functions._findAndRemove(ncs, nci.getName());
}
for (NestedClass nci : b.ns()) {
NestedClass ncj = _extractNc(nci, a.ns());
if (ncj == null) {
ncs.add(nci);
} else {
ClassB l = alradyRefreshedCompose(p, (ClassB) nci.getE(), (ClassB) ncj.getE());
ncs.add(nci.withE(l));
}
}
return new ClassB(a.getDoc1().sum(b.getDoc1()), false, impls, mwts, ncs, a.getP().sum(b.getP()), Phase.Norm, p.p.getFreshId());
}
use of ast.ExpCore.ClassB.MethodWithType 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);
}
use of ast.ExpCore.ClassB.MethodWithType in project L42 by ElvisResearchGroup.
the class Rename method userForMethod.
public static UserForMethodResult userForMethod(Program p, ClassB cb, List<Ast.C> path, MethodSelector src, boolean checkMethExists) {
if (checkMethExists) {
Member mem = Errors42.checkExistsPathMethod(cb, path, Optional.of(src));
assert mem instanceof MethodWithType;
}
Member mem = new ExpCore.ClassB.MethodImplemented(Doc.empty(), src, new ExpCore._void(), Position.noInfo);
CollectedLocatorsMap maps = CollectedLocatorsMap.from(Path.outer(0, path), mem, src);
HashSet<PathMx> result1 = new HashSet<>();
HashSet<MethodSelector> result2 = new HashSet<>();
MethodPathCloneVisitor ren = new RenameUsage(cb, maps, p) {
public Ast.Type liftT(Ast.Type t) {
return t;
}
@Override
protected MethodSelector liftMs(MethodSelector ms) {
return ms;
}
@Override
protected MethodSelector liftMsInMetDec(MethodSelector ms) {
return ms;
}
public ExpCore visit(MCall s) {
List<Ast.C> localPath = this.getLocator().getClassNamesPath();
if (!localPath.equals(path)) {
return super.visit(s);
}
if (s.getInner().equals(Path.outer(0)) || s.getInner().equals(new ExpCore.X(Position.noInfo, "this"))) {
result2.add(s.getS());
return s.withInner(s.getInner().accept(this)).withEs(Map.of(e -> e.accept(this), s.getEs()));
}
return super.visit(s);
}
@Override
public MethodSelector visitMS(MethodSelector original, Path src) {
MethodSelector toCollect = this.mSToReplaceOrNull(original, src);
if (toCollect == null) {
return original;
}
Member m = this.getLocator().getLastMember();
assert !(m instanceof NestedClass) : "";
MethodSelector msUser = m.match(nc -> {
throw Assertions.codeNotReachable();
}, mi -> mi.getS(), mt -> mt.getMs());
Path pathUser = Path.outer(0, this.getLocator().getClassNamesPath());
result1.add(new PathMx(pathUser, msUser));
return original;
}
};
ren.visit(cb);
return new UserForMethodResult() {
{
asClient = new ArrayList<>(result1);
asThis = new ArrayList<>(result2);
}
};
}
use of ast.ExpCore.ClassB.MethodWithType in project L42 by ElvisResearchGroup.
the class TranslateClass method getPhNestedNotIntantiable.
private static void getPhNestedNotIntantiable(String s, ClassB cb, StringBuilder res, boolean isInterface) {
if (isInterface) {
res.append("public static final class Ph implements ");
res.append(s + ", platformSpecific.javaTranslation.Resources.PhI<" + s + ">{\n");
} else {
res.append("public static final class Ph extends ");
res.append(s + " implements platformSpecific.javaTranslation.Resources.PhI<" + s + ">{\n");
}
res.append(" private final java.util.ArrayList<java.util.function.Consumer<" + s + ">> actions=new java.util.ArrayList<>();\n");
res.append(" public void commit(" + s + " val){ for(java.util.function.Consumer<" + s + "> r:actions){r.accept(val);} }");
res.append(" public void addAction(java.util.function.Consumer<" + s + "> r){actions.add(r);}");
res.append(" public ast.ExpCore revert()");
res.append("{throw new Error(\"PhInvocation\");}\n");
for (Member m : cb.getMs()) {
MethodWithType mt = (MethodWithType) m;
getMethodHeader(mt, res);
res.append("{throw new Error(\"PhInvocation\");}\n");
}
res.append(" public Ph(){ }\n }\n");
}
Aggregations