Search in sources :

Example 1 with InjectionOnSugar

use of coreVisitors.InjectionOnSugar in project L42 by ElvisResearchGroup.

the class ErrorFormatter method errorFormat.

public static String errorFormat(Object obj, ArrayList<Ast.Position> ps) {
    if (obj instanceof ast.Ast.HasPos) {
        ps.add(((ast.Ast.HasPos) obj).getP());
    }
    if (obj instanceof String) {
        return (String) obj;
    }
    if (obj instanceof Integer) {
        return obj.toString();
    }
    if (obj instanceof Expression) {
        Ast.Position p = CollapsePositions.of((Expression) obj);
        ps.add(p);
        return ToFormattedText.ofCompact((Expression) obj);
    }
    if (obj instanceof ExpCore) {
        //thanks to Path, this have to be after Expression
        Ast.Position p = CollapsePositions.of((ExpCore) obj);
        ps.add(p);
        ExpCore exp = (ExpCore) obj;
        Expression expression = exp.accept(new InjectionOnSugar());
        return errorFormat(expression, ps);
    }
    if (obj instanceof Ast.MethodSelector) {
        return formatSelectorCompact((Ast.MethodSelector) obj);
    }
    if (obj instanceof ExpCore.ClassB.MethodWithType) {
        return ToFormattedText.of((MethodWithType) obj).trim().replace("\n", " ");
    }
    //    }
    if (obj instanceof Reporter) {
        return ((Reporter) obj).toReport(ps);
    }
    if (obj instanceof Collection<?>) {
        Collection<?> c = (Collection<?>) obj;
        if (c.size() == 0) {
            return "[]";
        }
        if (c.size() == 1) {
            return "[" + errorFormat(c.iterator().next(), ps) + "]";
        }
        String res = "[\n";
        for (Object o : c) {
            res += "  " + errorFormat(o, ps) + "\n";
        }
        return res + "  ]\n";
    }
    if (obj instanceof Ast.Type) {
        return obj.toString();
    }
    if (obj instanceof ClassB.Member) {
        return ToFormattedText.of((ClassB.Member) obj);
    }
    //if(obj instanceof Expression){return ToFormattedText.of((Expression)obj);}
    if (obj instanceof Expression.ClassB.Member) {
        return ToFormattedText.of((Expression.ClassB.Member) obj);
    }
    if (obj instanceof java.nio.file.Path) {
        return obj.toString();
    }
    if (obj instanceof Ast.Position) {
        return obj.toString();
    }
    if (obj instanceof HashMap) {
        return obj.toString();
    }
    if (obj instanceof Collection) {
        return obj.toString();
    }
    if (obj instanceof ast.Util.PathMwt) {
        return obj.toString();
    }
    if (obj instanceof ast.Ast.C) {
        return obj.toString();
    }
    if (obj instanceof Boolean) {
        return obj.toString();
    }
    if (obj instanceof ast.Ast.Path) {
        return obj.toString();
    }
    return "unknown kind " + obj.getClass().getName();
}
Also used : Position(ast.Ast.Position) HashMap(java.util.HashMap) Member(ast.ExpCore.ClassB.Member) ClassB(ast.ExpCore.ClassB) Path(ast.Ast.Path) ExpCore(ast.ExpCore) Ast(ast.Ast) Position(ast.Ast.Position) MethodWithType(ast.ExpCore.ClassB.MethodWithType) InjectionOnSugar(coreVisitors.InjectionOnSugar) MethodWithType(ast.ExpCore.ClassB.MethodWithType) Expression(ast.Expression) Collection(java.util.Collection)

Example 2 with InjectionOnSugar

use of coreVisitors.InjectionOnSugar in project L42 by ElvisResearchGroup.

the class BigStep method executeAtomicStep.

protected ExpCore executeAtomicStep(PData p1, ExpCore _e1) {
    if (!IsCompiled.of(_e1)) {
        return step(p1, _e1);
    }
    return Resources.withPDo(p1, () -> {
        ExpCore e1 = _e1;
        boolean runned = false;
        e1 = NormalizeBlocks.of(e1);
        try {
            while (!(e1 instanceof ClassB)) {
                log(ToFormattedText.ofCompact(e1.accept(new InjectionOnSugar()), false));
                e1 = step(p1, e1);
                e1 = NormalizeBlocks.of(e1);
                runned = true;
            }
        } catch (Throwable t) {
            if (!runned) {
                throw t;
            }
        }
        log(ToFormattedText.ofCompact(e1.accept(new InjectionOnSugar()), false));
        return e1;
    });
}
Also used : ExpCore(ast.ExpCore) InjectionOnSugar(coreVisitors.InjectionOnSugar) ClassB(ast.ExpCore.ClassB)

Example 3 with InjectionOnSugar

use of coreVisitors.InjectionOnSugar in project L42 by ElvisResearchGroup.

the class ToFormattedText method of.

public static String of(ExpCore.ClassB.Member m) {
    List<ExpCore.ClassB.Member> ms = new ArrayList<>();
    ms.add(m);
    ExpCore e = ExpCore.ClassB.membersClass(ms, m.getP(), Phase.None);
    Expression.ClassB es = (ClassB) e.accept(new InjectionOnSugar());
    ToFormattedText tft = new ToFormattedText();
    //for the injection
    tft.formatMembers(es.getMs());
    return tft.result.toString();
}
Also used : ExpCore(ast.ExpCore) InjectionOnSugar(coreVisitors.InjectionOnSugar) Expression(ast.Expression) ClassB(ast.Expression.ClassB) ArrayList(java.util.ArrayList) Member(ast.Expression.ClassB.Member) ClassB(ast.Expression.ClassB)

Aggregations

ExpCore (ast.ExpCore)3 InjectionOnSugar (coreVisitors.InjectionOnSugar)3 ClassB (ast.ExpCore.ClassB)2 Expression (ast.Expression)2 Ast (ast.Ast)1 Path (ast.Ast.Path)1 Position (ast.Ast.Position)1 Member (ast.ExpCore.ClassB.Member)1 MethodWithType (ast.ExpCore.ClassB.MethodWithType)1 ClassB (ast.Expression.ClassB)1 Member (ast.Expression.ClassB.Member)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1