use of programReduction.Program in project L42 by ElvisResearchGroup.
the class Type method refTo.
default default TypeRefTo refTo(PData pData) {
Path path = type().getPath();
Path whereP = Path.outer(0, locationLib().path);
path = From.fromP(path, whereP);
if (path.outerNumber() == 0) {
return new TypeRefTo.Lib(locationLib().root(), path);
}
Program p = pData.p.evilPush(locationLib().root().inner);
//will be evilPush
try {
ClassB cb = p.extractClassB(path);
//if(coreVisitors.IsCompiled.of(cb)){
if (cb.getPhase() != Phase.None) {
//norm,typed,coherent
return new TypeRefTo.Binded(path);
}
//TODO: borderline ok?
return new TypeRefTo.Unavailable();
} catch (ErrorMessage.PathMetaOrNonExistant pne) {
if (pne.isMeta()) {
return new TypeRefTo.Unavailable();
}
return new TypeRefTo.Missing();
}
}
use of programReduction.Program in project L42 by ElvisResearchGroup.
the class Executor method metaMethod.
protected ClassB metaMethod(Program p, ClassB cb, Member m) {
log("---meta2--");
//get cb-->ct
//get p'
Program p1 = p.evilPush(cb);
//extract e
ExpCore e = m.getInner();
//extract cb
Ctx<ClassB> ctxC = ExtractCtxCompiled.of(e);
//run cb1-->cb2
ClassB cb2 = (ClassB) step(new PData(p1), ctxC.hole);
ExpCore e2 = ReplaceCtx.of(ctxC.ctx, cb2);
//compose cb with new member
return cb.withMember(m.withInner(e2));
}
use of programReduction.Program 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 programReduction.Program in project L42 by ElvisResearchGroup.
the class SmallStep method meta1.
protected ClassB meta1(Program p, ClassB cb, NestedClass m) {
log("---meta1--");
ExpCore e1 = m.getInner();
//get p'
try {
Program p1 = p.evilPush(cb);
ErrorFormatter.printType(p1);
//check p'
//Configuration.typeSystem.checkAll(p1);
//e1=Norm.of(p1,e1);
//check e1
//Configuration.typeSystem.checkMetaExpr(p1.getExecutableStar(),e1);
//run m.e1-->e2
ExpCore e2 = executeAtomicStep(new PData(p1), e1, m.getName());
//if(!(e2 instanceof ClassB)){Configuration.typeSystem.checkMetaExpr(p1.getExecutableStar(),e2);}//TODO: as assert
ClassB cbRes = cb.withMember(m.withInner(e2));
//replace cb[m.e2]
return cbRes;
} finally {
}
}
use of programReduction.Program in project L42 by ElvisResearchGroup.
the class AddDocumentation method addDocumentationOnMethod.
public static ClassB addDocumentationOnMethod(Program p, ClassB cb, List<Ast.C> cs, MethodSelector sel, Doc doc) {
Errors42.checkExistsPathMethod(cb, cs, Optional.of(sel));
if (cs.isEmpty()) {
cb = auxAddDocOnMethod(p, cb, sel, doc);
} else {
Program p1 = p.evilPush(cb);
if (cs.size() > 1) {
p1 = p1.navigate(cs.subList(0, cs.size() - 1));
}
Program p2 = p1;
cb = cb.onClassNavigateToPathAndDo(cs, cbi -> auxAddDocOnMethod(p2, cbi, sel, doc));
}
return cb;
}
Aggregations