Search in sources :

Example 1 with ExpCore

use of ast.ExpCore in project L42 by ElvisResearchGroup.

the class IsRedex method visit.

public static Redex visit(Program p, MCall s) {
    if (!IsValue.of(p, s.getInner())) {
        return Redex.invalid();
    }
    for (ExpCore ei : s.getEs()) {
        if (!IsValue.of(p, ei)) {
            return Redex.invalid();
        }
    }
    //after the first approximation//TODO: it is really slow, can we use this idea to redo the whole ctxExtract?, note, it is only needed for garbage
    Garbage g = IsValue.nestedGarbage(s.getInner());
    if (g != null) {
        return new Garbage(s.withInner(g.getThatLessGarbage()));
    }
    List<ExpCore> newEs = esNestedGarbage(s.getEs());
    if (newEs != null) {
        return new Garbage(s.withEs(newEs));
    }
    return new Redex.MethCall(s);
/*MethodWithType mwt=p.method(path, ms);
    if(!IsValue.isAtom(s.getReceiver())){
      return Optional.of(new Redex.PrimCallRec(s));
      }
    for(int i=0;i<s.getEs().size();i++){
      if(!IsValue.isAtom(s.getEs().get(i))){
        return Optional.of(new Redex.PrimCallArg(s,i));
        }}
    return Optional.of(new Redex.);*/
}
Also used : Garbage(ast.Redex.Garbage) ExpCore(ast.ExpCore)

Example 2 with ExpCore

use of ast.ExpCore in project L42 by ElvisResearchGroup.

the class IsRedex method visit.

public static Redex visit(Program p, Block s) {
    for (int i = 0; i < s.getDecs().size(); i++) {
        ExpCore ei = s.getDecs().get(i).getInner();
        Type ti = s.getDecs().get(i).getT().get();
        //if(!(ri instanceof Redex.NoRedex)){return ri;}
        if (new IsValue(p).validDv(s.getDecs().get(i))) {
            continue;
        }
        //return ri;
        return redexDec(p, s, i, ei, ti);
    }
    //end of for members
    Block s2 = Functions.garbage(s, s.getDecs().size());
    if (!s2.equals(s)) {
        return new Redex.Garbage(s2);
    }
    if (!s.getOns().isEmpty()) {
        return new Redex.NoThrowRemoveOn(s);
    }
    return Redex.invalid();
}
Also used : Garbage(ast.Redex.Garbage) ExpCore(ast.ExpCore) MethodWithType(ast.ExpCore.ClassB.MethodWithType)

Example 3 with ExpCore

use of ast.ExpCore in project L42 by ElvisResearchGroup.

the class IsValue method validRightValue.

public boolean validRightValue(ExpCore ec) {
    if (!(ec instanceof MCall))
        return false;
    MCall s = (MCall) ec;
    if (!(s.getInner() instanceof EPath)) {
        return false;
    }
    MethodSelector ms = s.getS();
    MethodWithType mwt = (MethodWithType) p.extractClassB(((EPath) s.getInner()).getInner())._getMember(ms);
    if (mwt.get_inner().isPresent()) {
        return false;
    }
    if (mwt.getMt().getMdf() != ast.Ast.Mdf.Class) {
        return false;
    }
    for (ExpCore ei : s.getEs()) {
        if (!isAtom(ei)) {
            return false;
        }
    }
    return true;
}
Also used : ExpCore(ast.ExpCore) MethodSelector(ast.Ast.MethodSelector)

Example 4 with ExpCore

use of ast.ExpCore in project L42 by ElvisResearchGroup.

the class Move method visit.

public Ctx<List<Block.Dec>> visit(Using s) {
    for (ExpCore ei : s.getEs()) {
        if (!IsCtx.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);
        });
    }
    return null;
}
Also used : ExpCore(ast.ExpCore) ArrayList(java.util.ArrayList)

Example 5 with ExpCore

use of ast.ExpCore in project L42 by ElvisResearchGroup.

the class PropagatorVisitor method visit.

public Void visit(Using s) {
    liftP(s.getPath());
    liftMs(s.getS());
    liftDoc(s.getDoc());
    for (ExpCore e : s.getEs()) {
        lift(e);
    }
    lift(s.getInner());
    return null;
}
Also used : ExpCore(ast.ExpCore)

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