Search in sources :

Example 21 with ClassB

use of ast.ExpCore.ClassB in project L42 by ElvisResearchGroup.

the class UsedPaths method usedPathsL.

//- usedPathsL(L, Cs1..Csn)=usedInnerL(L(Cs1),Cs1) U ... U usedInnerL(L(Csn),Csn)
private static Paths usedPathsL(Program pForError, ClassB l, List<List<Ast.C>> css, Phase phase0) {
    Paths result = Paths.empty();
    for (List<Ast.C> csi : css) {
        assert !csi.isEmpty();
        ClassB li;
        try {
            li = l.getClassB(csi);
        } catch (ErrorMessage.PathMetaOrNonExistant pne) {
            //.withWherePathWasWritten(p);
            throw pne.withListOfNodeNames(csi).withCb(l);
        }
        ClassB liTop = li;
        if (csi.size() != 0) {
            liTop = l.getClassB(Collections.singletonList(csi.get(0)));
        }
        assert IsCompiled.of(liTop);
        //checked after for newPaths: when the offending value is produced, so we have more context for error message
        //  throw new ErrorMessage.PathMetaOrNonExistant(true, Collections.singletonList(csi.get(0)), l, null,null);
        Paths newPaths = usedInnerL(li, csi, phase0);
        try {
            newPaths.checkAllDefined(pForError);
        } catch (ErrorMessage.PathMetaOrNonExistant pne) {
            Position p = FindPathUsage._locate(pForError, li, Path.outer(csi.size() + 1, /*TODO we need to fix this crap for real*/
            pne.getListOfNodeNames()));
            throw pne.withWherePathWasWritten(p);
        }
        result = result.union(newPaths);
    }
    return result;
}
Also used : PathMetaOrNonExistant(ast.ErrorMessage.PathMetaOrNonExistant) C(ast.Ast.C) Position(ast.Ast.Position) ErrorMessage(ast.ErrorMessage) ClassB(ast.ExpCore.ClassB)

Example 22 with ClassB

use of ast.ExpCore.ClassB in project L42 by ElvisResearchGroup.

the class UsedPaths method usedPathsE.

static PathsPaths usedPathsE(Program p, ExpCore e) {
    //- usedPathsE(p,eC)= <reorganize(Ps); usedPathsFix(p,paths, empty)>
    //assert that the result includes paths in usedPathsFix(p,paths, empty)  
    //Ps,Ps'={P|P inside eC}//arbitrary split of the set; heuristic will apply in the implementation.
    //collect all paths
    List<Ast.Path> psBoth = CollectPaths0.of(e);
    List<Ast.Path> ps1;
    try {
        ps1 = collectNotAnyPaths(p, e);
    } catch (ErrorMessage.PathMetaOrNonExistant pne) {
        throw Assertions.codeNotReachable();
    }
    //L1..Ln={L| L inside eC}//in path not prime// not repeat check stage
    List<ClassB> l1n = CollectClassBs0.of(e);
    //paths'=usedPathsFix(p,reorganize(Ps'), empty,Coherent)
    Paths paths1 = Paths.reorganize(ps1);
    paths1 = usedPathsFix(p, paths1, Collections.emptyList(), Phase.Coherent);
    assert paths1.checkAllDefined(p);
    //paths0=reorganize(Ps,Ps') U paths' U (deepImplements(L1)U..U deepImplements(Ln)).pop()
    //paths=usedPathsFix(p,paths0, empty,Typed)
    Paths paths0 = Paths.reorganize(psBoth).union(paths1);
    Paths acc = Paths.empty();
    for (ClassB li : l1n) {
        acc = acc.union(deepImplements(li));
    }
    paths0 = paths0.union(acc.pop());
    Paths paths = usedPathsFix(p, paths0, Collections.emptyList(), Phase.Typed);
    assert paths.checkAllDefined(p);
    PathsPaths result = new PathsPaths(paths.setMinus(paths1), paths1);
    System.out.println("UsedPaths:\npaths:" + result.left + "\npaths':" + result.right + "\n-----------------\n");
    return result;
}
Also used : Path(ast.Ast.Path) PathMetaOrNonExistant(ast.ErrorMessage.PathMetaOrNonExistant) ErrorMessage(ast.ErrorMessage) ClassB(ast.ExpCore.ClassB)

Example 23 with ClassB

use of ast.ExpCore.ClassB in project L42 by ElvisResearchGroup.

the class UsedPaths method usedInnerM.

private static Paths usedInnerM(Member m, Phase phase0) {
    if (m instanceof NestedClass) {
        NestedClass nc = (NestedClass) m;
        return usedInnerL((ClassB) nc.getInner(), Collections.emptyList(), phase0).pop();
    }
    List<Path> result1;
    List<ClassB> l1n = Collections.emptyList();
    if (m instanceof MethodWithType) {
        MethodWithType mwt = (MethodWithType) m;
        result1 = CollectPaths0.of(mwt);
        if (phase0 == Phase.Typed && mwt.get_inner().isPresent()) {
            l1n = CollectClassBs0.of(m.getInner());
        }
    } else {
        assert m instanceof MethodImplemented;
        result1 = CollectPaths0.of(m.getInner());
    }
    Paths result2 = Paths.reorganize(result1);
    Paths acc = Paths.empty();
    for (ClassB li : l1n) {
        acc = acc.union(usedInnerL(li, Collections.emptyList(), phase0));
    }
    return result2.union(acc.pop());
}
Also used : Path(ast.Ast.Path) MethodImplemented(ast.ExpCore.ClassB.MethodImplemented) NestedClass(ast.ExpCore.ClassB.NestedClass) MethodWithType(ast.ExpCore.ClassB.MethodWithType) ClassB(ast.ExpCore.ClassB)

Example 24 with ClassB

use of ast.ExpCore.ClassB in project L42 by ElvisResearchGroup.

the class Resources method getRes.

public static Object getRes(String key, int... ks) {
    Object o = usedRes.get(key);
    if (o == null) {
        throw new Error("Invalid resource " + key + " Valid resources are: " + usedRes.keySet());
    }
    if (!(o instanceof ClassB)) {
        return o;
    }
    int[] newK = pKeys();
    int common = 0;
    while (common < newK.length && common < ks.length) {
        if (newK[common] == ks[common]) {
            common++;
        } else {
            break;
        }
    }
    int shift = newK.length - common;
    int padding = ks.length - common;
    if (shift == 0 && padding == 0) {
        return o;
    }
    List<Ast.C> csPadding = new ArrayList<>();
    for (int i = 0; i < padding; i++) {
        csPadding.add(C.of("Padding" + i));
    }
    ClassB cb = (ClassB) FromInClass.of((ClassB) o, Path.outer(shift, csPadding));
    //Configuration.typeSystem.computeStage(p, cb);
    return cb;
}
Also used : C(ast.Ast.C) ArrayList(java.util.ArrayList) Error(platformSpecific.javaTranslation.Resources.Error) TypeError(ast.ErrorMessage.TypeError) UserLevelError(ast.ErrorMessage.UserLevelError) ClassB(ast.ExpCore.ClassB)

Example 25 with ClassB

use of ast.ExpCore.ClassB in project L42 by ElvisResearchGroup.

the class RefreshUniqueNames method refreshTopLevel.

public static ClassB refreshTopLevel(ClassB e) {
    HashMap<Long, Long> map = new HashMap<>();
    return (ClassB) e.accept(new coreVisitors.CloneVisitor() {

        protected MethodSelector liftMs(MethodSelector ms) {
            return ms.withUniqueNum(newN(map, ms.getUniqueNum()));
        }

        public ClassB.NestedClass visit(ClassB.NestedClass nc) {
            long newN = newN(map, nc.getName().getUniqueNum());
            return super.visit(nc.withName(nc.getName().withUniqueNum(newN)));
        //I need to collect the DECLARED C,ms and those are the only that I need to refresh.
        //refresh all can work only at top level
        }

        @Override
        protected Path liftP(Path s) {
            if (s.isPrimitive()) {
                return s;
            }
            List<C> cs = s.getCBar();
            List<C> newCs = new ArrayList<>();
            for (C c : cs) {
                newCs.add(c.withUniqueNum(newN(map, c.getUniqueNum())));
            }
            return Path.outer(s.outerNumber(), newCs);
        }
    });
}
Also used : Path(ast.Ast.Path) MethodSelector(ast.Ast.MethodSelector) C(ast.Ast.C) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) NestedClass(ast.Expression.ClassB.NestedClass) ClassB(ast.ExpCore.ClassB)

Aggregations

ClassB (ast.ExpCore.ClassB)107 ArrayList (java.util.ArrayList)33 Path (ast.Ast.Path)30 ExpCore (ast.ExpCore)25 Member (ast.ExpCore.ClassB.Member)25 EncodingHelper.ensureExtractClassB (auxiliaryGrammar.EncodingHelper.ensureExtractClassB)20 Program (programReduction.Program)20 Ast (ast.Ast)19 MethodWithType (ast.ExpCore.ClassB.MethodWithType)19 MethodSelector (ast.Ast.MethodSelector)18 NestedClass (ast.ExpCore.ClassB.NestedClass)18 List (java.util.List)17 ActionType (platformSpecific.fakeInternet.ActionType)16 Doc (ast.Ast.Doc)12 Type (ast.Ast.Type)12 ErrorMessage (ast.ErrorMessage)12 Optional (java.util.Optional)10 C (ast.Ast.C)9 MethodType (ast.Ast.MethodType)8 Phase (ast.ExpCore.ClassB.Phase)8