Search in sources :

Example 46 with Path

use of ast.Ast.Path 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);
        }
    };
}
Also used : PathMx(ast.Util.PathMx) Stage(ast.Ast.Stage) PathPath(ast.Util.PathPath) Program(programReduction.Program) Ast(ast.Ast) Map(tools.Map) Configuration(facade.Configuration) CloneVisitorWithProgram(coreVisitors.CloneVisitorWithProgram) Assertions(tools.Assertions) MethodWithType(ast.ExpCore.ClassB.MethodWithType) MethodSelector(ast.Ast.MethodSelector) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) CloneVisitor(coreVisitors.CloneVisitor) PathMxMx(ast.Util.PathMxMx) NestedClass(ast.ExpCore.ClassB.NestedClass) Path(ast.Ast.Path) Doc(ast.Ast.Doc) Phase(ast.ExpCore.ClassB.Phase) ExpCore(ast.ExpCore) Member(ast.ExpCore.ClassB.Member) Functions(auxiliaryGrammar.Functions) List(java.util.List) Position(ast.Ast.Position) PathMx(ast.Util.PathMx) Optional(java.util.Optional) FromInClass(coreVisitors.FromInClass) C(ast.Ast.C) Collections(java.util.Collections) L42(facade.L42) MethodImplemented(ast.ExpCore.ClassB.MethodImplemented) PathPath(ast.Util.PathPath) Path(ast.Ast.Path) ExpCore(ast.ExpCore) MethodImplemented(ast.ExpCore.ClassB.MethodImplemented) MethodSelector(ast.Ast.MethodSelector) Ast(ast.Ast) C(ast.Ast.C) NestedClass(ast.ExpCore.ClassB.NestedClass) MethodWithType(ast.ExpCore.ClassB.MethodWithType) MethodWithType(ast.ExpCore.ClassB.MethodWithType) Member(ast.ExpCore.ClassB.Member) HashSet(java.util.HashSet)

Example 47 with Path

use of ast.Ast.Path in project L42 by ElvisResearchGroup.

the class TranslateClass method getClassOpen.

private static boolean getClassOpen(String s, ClassB ct, StringBuilder res) {
    boolean isInterface = ct.isInterface();
    res.append("public ");
    if (isInterface) {
        res.append("interface ");
        if (!ct.getDoc1().isEmpty()) {
            res.append("/*" + ct.getDoc1().toString() + "*/");
        }
    } else {
        res.append("class ");
    }
    res.append(s);
    System.out.println("creating class " + s);
    if (isInterface) {
        res.append(" extends ");
    } else {
        res.append(" implements ");
    }
    res.append("platformSpecific.javaTranslation.Resources.Revertable");
    Set<String> supt = new HashSet<>();
    for (Path pi : ct.getSuperPaths()) /*getStage().getInheritedPaths()*/
    {
        if (pi.equals(Path.Any())) {
            continue;
        }
        assert !pi.isPrimitive();
        String resName = Resources.nameOf(pi);
        if (resName.equals("Object")) {
            continue;
        }
        boolean notThere = supt.add(resName);
        if (notThere) {
            res.append(", ");
            res.append(resName);
        }
    }
    return isInterface;
}
Also used : Path(ast.Ast.Path) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 48 with Path

use of ast.Ast.Path in project L42 by ElvisResearchGroup.

the class TranslateExpression method visit.

//not a propagator visitor. 
@Override
public Void visit(ExpCore.EPath s) {
    Path ss = s.getInner();
    if (ss.isPrimitive()) {
        if (ss.equals(Path.Any())) {
            res.append("platformSpecific.javaTranslation.Resources.Any.type");
        }
        if (ss.equals(Path.Library())) {
            res.append("platformSpecific.javaTranslation.Resources.Library.type");
        }
        if (ss.equals(Path.Void())) {
            res.append("platformSpecific.javaTranslation.Resources.Void.type");
        }
        return null;
    }
    ClassB cbs = Resources.getP().extractClassB(ss);
    if (cbs.getPhase() == Phase.Coherent && IsCompiled.of(cbs)) {
        res.append(Resources.nameOf(ss) + ".type ");
    } else {
        Position pos = Resources.getP().get(ss.outerNumber()).getP();
        int hash = System.identityHashCode(pos);
        String cs = s.toString();
        int dotPos = cs.indexOf(".");
        assert dotPos >= 0;
        cs = cs.substring(dotPos);
        res.append("platformSpecific.javaTranslation.Resources.fromHash(" + hash + ",\"" + cs + "\")");
    }
    return null;
}
Also used : Path(ast.Ast.Path) Position(ast.Ast.Position) ClassB(ast.ExpCore.ClassB)

Example 49 with Path

use of ast.Ast.Path in project L42 by ElvisResearchGroup.

the class TestRename method testNormalizePath.

@Test
public void testNormalizePath() {
    Path res = ClassOperations.normalizePath(Arrays.asList(), 0, Arrays.asList());
    Assert.assertEquals(res, Path.outer(0));
    res = ClassOperations.normalizePath(Arrays.asList(C.of("A")), 1, Arrays.asList(C.of("B")));
    Assert.assertEquals(res, Path.parse("This1.B"));
    res = ClassOperations.normalizePath(Arrays.asList(C.of("B")), 1, Arrays.asList(C.of("B")));
    Assert.assertEquals(res, Path.parse("This0"));
}
Also used : Path(ast.Ast.Path) Test(org.junit.Test)

Example 50 with Path

use of ast.Ast.Path in project L42 by ElvisResearchGroup.

the class Abstract method checkPrivacyCoupuled.

static void checkPrivacyCoupuled(ClassB cbFull, ClassB cbClear, List<Ast.C> path) {
    //start from a already cleared out of private states
    //check if all private nested classes are USED using IsUsed on cbClear
    //this also verify that no private nested classes are used as
    //type in public methods of public classes.
    //collect all PublicPath.privateMethod
    //use main->introspection.FindUsage
    List<Path> prPath = ExtractInfo.collectPrivatePathsAndSubpaths(cbFull, path);
    List<PathMx> prMeth = ExtractInfo.collectPrivateMethodsOfPublicPaths(cbFull, path);
    List<Path> coupuledPaths = new ArrayList<>();
    for (Path pi : prPath) {
        Set<Path> used = ExtractInfo.IsUsed.of(cbClear, pi);
        if (used.isEmpty()) {
            continue;
        }
        coupuledPaths.add(pi);
    }
    List<PathMx> ordered = new ArrayList<>();
    try {
        //FindUsage.of(Program.empty(),prMeth, cbClear);
        Set<PathMx> usedPrMeth = findUsage(prMeth, cbClear);
        if (coupuledPaths.isEmpty() && usedPrMeth.isEmpty()) {
            return;
        }
        ordered.addAll(usedPrMeth);
    } catch (PathMetaOrNonExistant pne) {
        assert !coupuledPaths.isEmpty();
    }
    Collections.sort(ordered, (px1, px2) -> px1.toString().compareTo(px2.toString()));
    throw Errors42.errorPrivacyCoupuled(coupuledPaths, ordered);
}
Also used : Path(ast.Ast.Path) PathMx(ast.Util.PathMx) ArrayList(java.util.ArrayList) PathMetaOrNonExistant(ast.ErrorMessage.PathMetaOrNonExistant)

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