use of ast.Ast.Path 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 ast.Ast.Path in project L42 by ElvisResearchGroup.
the class PlgWrapperGenerator method isOkAsReturn.
private static void isOkAsReturn(Program p, Path csTop, Type ti) throws ClassUnfit, MethodUnfit {
Path pi = ti.getPath();
if (pi.equals(Path.Void())) {
return;
}
//We will need to generate a simpler returning expression
if (pi.equals(Path.Library())) {
return;
}
Path op = _pathForOutside(csTop.getCBar().size(), pi);
if (op == null) {
checkForInside(p.top(), csTop, pi);
return;
}
ClassB l = p.extractClassB(op);
boolean hasIt = hasFrom(l);
boolean phOk = Functions.isComplete(ti);
if (ti.getMdf() == Mdf.Class && !ti.equals(Type.classAny)) {
throw new RefactorErrors.MethodUnfit().msg("Return type can be 'class' only if is exactly 'class any'");
}
if (!hasIt) {
throw new RefactorErrors.ClassUnfit().msg("Class " + op + " has no method #from(binaryRepr)");
}
if (!phOk) {
//TODO: why this limitation?
throw new RefactorErrors.MethodUnfit().msg("Return type can not be fwd");
}
}
use of ast.Ast.Path in project L42 by ElvisResearchGroup.
the class PlgWrapperGenerator method checkForInside.
private static void checkForInside(ClassB lTop, Path csTop, Path originalPath) throws ClassUnfit, MethodUnfit {
if (originalPath.isPrimitive()) {
throw new RefactorErrors.MethodUnfit().msg("Method signature not supported:\n parameters can not be Void/Any/fwd.\n" + "returns can not be Any/fwd\n" + "exceptions can not be Any/Void/Library");
}
Path cs = From.fromP(originalPath, csTop);
assert cs.outerNumber() == 0;
List<Ast.C> cBar = cs.getCBar();
ClassB lPointed = lTop.getClassB(cBar);
Doc d = lPointed.getDoc1();
if (d._getParameterForPlugin() == null || d._getParameterForPluginPart() == null) {
throw new RefactorErrors.ClassUnfit().msg("Class " + cBar + " doesnot have @pluginPart annotation");
}
}
use of ast.Ast.Path in project L42 by ElvisResearchGroup.
the class PlgWrapperGenerator method isOkAsException.
private static void isOkAsException(Program p, Path csTop, Path pi) throws ClassUnfit, MethodUnfit {
Path op = _pathForOutside(csTop.getCBar().size(), pi);
if (op == null) {
checkForInside(p.top(), csTop, pi);
return;
}
ClassB l = p.extractClassB(op);
if (!hasExceptionIf(l)) {
throw new RefactorErrors.ClassUnfit().msg("Class " + op + " has no method #exceptionIf(binaryRepr)");
}
}
use of ast.Ast.Path in project L42 by ElvisResearchGroup.
the class Translator method useFrom.
//this should take a class, strip out nested and 'from' it so that it is as at top level
static ClassB useFrom(ClassB ct, Path p) {
ArrayList<Member> ms = new ArrayList<Member>();
for (Member m : ct.getMs()) {
m.match(nc -> null, mi -> {
throw Assertions.codeNotReachable();
}, mt -> ms.add(From.from(mt, p)));
}
//for(PathMwt pmwt:ct.getStage().getInherited()){
for (PathMwt pmwt : Collections.<PathMwt>emptyList()) {
if (Functions.getIfInDom(ms, pmwt.getMwt().getMs()).isPresent()) {
continue;
}
ms.add(From.from(pmwt.getMwt(), p));
}
List<Path> sup = tools.Map.of(ti -> (Path) From.fromP(ti.getPath(), p), ct.getSupertypes());
//tools.Map.of(pi->(Path)From.fromP(pi,p),ct.getStage().getInheritedPaths());
List<Path> supAll = sup;
ClassB res = ct.withMs(ms).withSupertypes(tools.Map.of(pi -> pi.toImmNT(), sup));
return res;
}
Aggregations