Search in sources :

Example 36 with ExpCore

use of ast.ExpCore in project L42 by ElvisResearchGroup.

the class Functions method neededX.

private static HashSet<String> neededX(Block e, int n) {
    HashSet<String> neededX = new HashSet<String>();
    for (int i = n; i < e.getDecs().size(); i++) {
        ExpCore ei = e.getDecs().get(i).getInner();
        neededX.addAll(FreeVariables.of(ei));
    }
    for (int i = n; i < e.getDecs().size(); i++) {
        neededX.remove(e.getDecs().get(i).getX());
    }
    neededX.addAll(FreeVariables.of(e.getInner()));
    return neededX;
}
Also used : ExpCore(ast.ExpCore) HashSet(java.util.HashSet)

Example 37 with ExpCore

use of ast.ExpCore in project L42 by ElvisResearchGroup.

the class Functions method iterateAddNeeded.

private static boolean iterateAddNeeded(Block e, int n, HashSet<String> needX, HashSet<Integer> needKeep) {
    int size = needKeep.size();
    for (int i : needKeep) {
        ExpCore ei = e.getDecs().get(i).getInner();
        needX.addAll(FreeVariables.of(ei));
    }
    for (int i = 0; i < n; i++) {
        if (!needX.contains(e.getDecs().get(i).getX())) {
            continue;
        }
        needKeep.add(i);
    }
    assert size <= needKeep.size();
    return size != needKeep.size();
}
Also used : ExpCore(ast.ExpCore)

Example 38 with ExpCore

use of ast.ExpCore in project L42 by ElvisResearchGroup.

the class Functions method replace.

public static List<Block.Dec> replace(List<Block.Dec> dvs, MCall mc) {
    String x = ((ExpCore.X) mc.getInner()).getInner();
    List<Block.Dec> result = new ArrayList<>();
    for (Block.Dec dv : dvs) {
        if (!dv.getX().equals(x)) {
            result.add(dv);
            continue;
        }
        MCall inner = (MCall) dv.getInner();
        String fieldName = mc.getS().nameToS();
        int mIndex = inner.getS().getNames().indexOf(fieldName);
        assert mIndex != -1 : fieldName + " / " + ToFormattedText.of(inner);
        List<ExpCore> es2 = new ArrayList<>(inner.getEs());
        ExpCore parameterAtom = mc.getEs().get(0);
        es2.set(mIndex, parameterAtom);
        result.add(dv.withInner(inner.withEs(es2)));
    }
    return result;
}
Also used : ExpCore(ast.ExpCore) ArrayList(java.util.ArrayList)

Example 39 with ExpCore

use of ast.ExpCore in project L42 by ElvisResearchGroup.

the class ExtractCtxCompiled method visit.

public Ctx<ClassB> visit(Using s) {
    for (ExpCore ei : s.getEs()) {
        if (IsCompiled.of(ei)) {
            continue;
        }
        return lift(ei.accept(this), ctx -> {
            List<ExpCore> es = new ArrayList<ExpCore>(s.getEs());
            es.set(es.indexOf(ei), ctx);
            return s.withEs(es);
        });
    }
    assert !IsCompiled.of(s.getInner());
    return lift(s.getInner().accept(this), s::withInner);
}
Also used : ExpCore(ast.ExpCore) Assertions(tools.Assertions) ArrayList(java.util.ArrayList)

Example 40 with ExpCore

use of ast.ExpCore in project L42 by ElvisResearchGroup.

the class Move method visit.

public Ctx<List<Block.Dec>> visit(MCall s) {
    if (IsCtx.of(s.getInner())) {
        return lift(s.getInner().accept(this), ctx -> s.withInner(ctx));
    }
    for (ExpCore ei : s.getEs()) {
        if (!IsCtx.of(ei)) {
            continue;
        }
        return lift(ei.accept(this), ctx -> {
            List<ExpCore> es = new ArrayList<>(s.getEs());
            es.set(es.indexOf(ei), ctx);
            return s.withEs(es);
        });
    }
    return null;
}
Also used : ExpCore(ast.ExpCore) ArrayList(java.util.ArrayList)

Aggregations

ExpCore (ast.ExpCore)62 ArrayList (java.util.ArrayList)25 ClassB (ast.ExpCore.ClassB)18 Member (ast.ExpCore.ClassB.Member)11 MethodWithType (ast.ExpCore.ClassB.MethodWithType)10 Expression (ast.Expression)10 Block (ast.ExpCore.Block)9 MethodType (ast.Ast.MethodType)8 Doc (ast.Ast.Doc)7 Path (ast.Ast.Path)7 Assertions (tools.Assertions)7 MethodSelector (ast.Ast.MethodSelector)6 Position (ast.Ast.Position)6 Program (programReduction.Program)6 InjectionOnCore (sugarVisitors.InjectionOnCore)6 Ast (ast.Ast)5 Type (ast.Ast.Type)5 ErrorMessage (ast.ErrorMessage)5 CloneVisitor (coreVisitors.CloneVisitor)5 List (java.util.List)5