Search in sources :

Example 36 with Path

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();
    }
}
Also used : Path(ast.Ast.Path) Program(programReduction.Program) ErrorMessage(ast.ErrorMessage) ClassB(ast.ExpCore.ClassB)

Example 37 with Path

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");
    }
}
Also used : Path(ast.Ast.Path) ClassUnfit(is.L42.connected.withSafeOperators.pluginWrapper.RefactorErrors.ClassUnfit) MethodUnfit(is.L42.connected.withSafeOperators.pluginWrapper.RefactorErrors.MethodUnfit) ClassB(ast.ExpCore.ClassB)

Example 38 with Path

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");
    }
}
Also used : Path(ast.Ast.Path) Doc(ast.Ast.Doc) ClassUnfit(is.L42.connected.withSafeOperators.pluginWrapper.RefactorErrors.ClassUnfit) MethodUnfit(is.L42.connected.withSafeOperators.pluginWrapper.RefactorErrors.MethodUnfit) ClassB(ast.ExpCore.ClassB)

Example 39 with Path

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)");
    }
}
Also used : Path(ast.Ast.Path) ClassUnfit(is.L42.connected.withSafeOperators.pluginWrapper.RefactorErrors.ClassUnfit) ClassB(ast.ExpCore.ClassB)

Example 40 with Path

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;
}
Also used : Path(ast.Ast.Path) From(coreVisitors.From) Stage(ast.Ast.Stage) Arrays(java.util.Arrays) Program(programReduction.Program) Ast(ast.Ast) Configuration(facade.Configuration) Type(ast.Ast.Type) HashMap(java.util.HashMap) Assertions(tools.Assertions) ArrayList(java.util.ArrayList) CompilationError(platformSpecific.inMemoryCompiler.InMemoryJavaCompiler.CompilationError) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) ClassB(ast.ExpCore.ClassB) InterfaceHeader(ast.Ast.InterfaceHeader) Map(java.util.Map) Facade(reduction.Facade) PathMwt(ast.Util.PathMwt) MapClassLoader(platformSpecific.inMemoryCompiler.InMemoryJavaCompiler.MapClassLoader) Method(java.lang.reflect.Method) IsCompiled(coreVisitors.IsCompiled) NestedClass(ast.ExpCore.ClassB.NestedClass) Files(java.nio.file.Files) Path(ast.Ast.Path) Doc(ast.Ast.Doc) Phase(ast.ExpCore.ClassB.Phase) IOException(java.io.IOException) ExpCore(ast.ExpCore) Member(ast.ExpCore.ClassB.Member) Functions(auxiliaryGrammar.Functions) InvocationTargetException(java.lang.reflect.InvocationTargetException) Util(ast.Util) Consumer(java.util.function.Consumer) List(java.util.List) EmptyProgram(programReduction.Program.EmptyProgram) Paths(java.nio.file.Paths) Optional(java.util.Optional) SourceFile(platformSpecific.inMemoryCompiler.InMemoryJavaCompiler.SourceFile) Timer(profiling.Timer) InMemoryJavaCompiler(platformSpecific.inMemoryCompiler.InMemoryJavaCompiler) Collections(java.util.Collections) L42(facade.L42) ArrayList(java.util.ArrayList) Member(ast.ExpCore.ClassB.Member) PathMwt(ast.Util.PathMwt) ClassB(ast.ExpCore.ClassB)

Aggregations

Path (ast.Ast.Path)56 ClassB (ast.ExpCore.ClassB)28 ArrayList (java.util.ArrayList)23 Ast (ast.Ast)14 PathPath (ast.Util.PathPath)13 Type (ast.Ast.Type)12 MethodWithType (ast.ExpCore.ClassB.MethodWithType)12 Doc (ast.Ast.Doc)11 Member (ast.ExpCore.ClassB.Member)11 List (java.util.List)11 ExpCore (ast.ExpCore)10 NestedClass (ast.ExpCore.ClassB.NestedClass)8 PathSPath (ast.Util.PathSPath)8 CloneWithPath (coreVisitors.CloneWithPath)8 Collections (java.util.Collections)8 HashSet (java.util.HashSet)8 Program (programReduction.Program)8 Map (tools.Map)8 MethodSelector (ast.Ast.MethodSelector)7 SPathSPath (ast.Util.SPathSPath)7