use of ast.Ast.Type in project L42 by ElvisResearchGroup.
the class Desugar method cfGetter.
private static void cfGetter(Expression.Position pos, FieldDec f, Doc doc, List<Member> result) {
if (!(f.getT() instanceof Type)) {
return;
}
MethodWithType mwt = generateGetter(pos, f, doc);
result.add(mwt);
}
use of ast.Ast.Type in project L42 by ElvisResearchGroup.
the class Desugar method visit.
public MethodWithType visit(MethodWithType mt) {
this.usedVars = new HashSet<String>();
this.varEnv = new HashMap<String, Type>();
String mName = desugarName(mt.getMs().nameToS());
mt = mt.withMs(mt.getMs().withName(mName));
if (!mt.getInner().isPresent()) {
return super.visit(mt);
}
{
int i = -1;
for (String name : mt.getMs().getNames()) {
i += 1;
this.usedVars.add(name);
this.varEnv.put(name, mt.getMt().getTs().get(i));
}
}
usedVars.add("this");
varEnv.put("this", new Type(mt.getMt().getMdf(), Path.outer(0), mt.getDoc()));
usedVars.addAll(CollectDeclaredVars.of(mt.getInner().get()));
//final restrictions
final MethodWithType mt2 = mt;
return withExpectedType(liftT(mt.getMt().getReturnType()), () -> super.visit(mt2));
}
use of ast.Ast.Type in project L42 by ElvisResearchGroup.
the class PlgWrapperGenerator method addMwt.
private static void addMwt(Program p, PlgInfo plgInfo, Method[] jms, Constructor<?>[] jcs, List<Member> msResult, Path pTop, MethodWithType mwt) throws UnresolvedOverloading, ClassUnfit, MethodUnfit {
//checks
try {
isOkAsReturn(p, pTop, mwt.getMt().getReturnType());
for (Type ti : mwt.getMt().getExceptions()) {
isOkAsException(p, pTop, ti.getPath());
}
for (Type ti : mwt.getMt().getTs()) {
isOkAsParameter(p, pTop, ti);
}
//TODO: we may want to cache those tests if performance is needed
} catch (ClassUnfit | MethodUnfit e) {
e.setMessage("While examining Class " + pTop + " method " + mwt.getMs() + ":\n" + e.getMessage());
throw e;
}
//add to msResult
//TODO: add behaviour if mwt have special comment to define specific ms for use
String name = mwt.getMs().nameToS();
if (name.startsWith("#")) {
name = name.substring(1);
}
UsingInfo ui;
if (!name.equals("new") && !name.equals("apply"))
ui = usingMethod(plgInfo, jms, mwt, name);
else
ui = usingConstructor(plgInfo, jcs, mwt, name);
MethodWithType tu = updateTemplateUsing(ui, mwt);
msResult.add(tu);
}
use of ast.Ast.Type 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.Ast.Type 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());
}
Aggregations