Search in sources :

Example 11 with InjectionOnCore

use of sugarVisitors.InjectionOnCore in project L42 by ElvisResearchGroup.

the class TranslationTest method tester.

public void tester(String cbStr, String eStr, String nameRes) {
    TestHelper.configureForTest();
    Program p = runTypeSystem(cbStr);
    ExpCore _e = Desugar.of(Parser.parse(null, eStr)).accept(new InjectionOnCore());
    ExpCore e = newTypeSystem.TypeSystem.instance().topTypeExpVoid(p, _e);
    Translator code = Resources.withPDo(new PData(p), () -> Translator.translateProgram(p, e));
    System.out.println(code);
    Object o = Resources.withPDo(new PData(p), () -> code.runMap());
    Assert.assertEquals(o.getClass().getName(), nameRes);
}
Also used : ExpCore(ast.ExpCore) Program(programReduction.Program) Translator(platformSpecific.javaTranslation.Translator) PData(facade.PData) InjectionOnCore(sugarVisitors.InjectionOnCore)

Example 12 with InjectionOnCore

use of sugarVisitors.InjectionOnCore in project L42 by ElvisResearchGroup.

the class ReplState method start.

public static ReplState start(String code) {
    try {
        Expression.ClassReuse code1 = (ClassReuse) Parser.parse("Repl", code);
        auxiliaryGrammar.WellFormedness.checkAll(code1);
        Expression.ClassReuse code2 = (ClassReuse) Desugar.of(code1);
        assert auxiliaryGrammar.WellFormedness.checkAll(code2);
        ExpCore.ClassB code3 = (ExpCore.ClassB) code2.accept(new InjectionOnCore());
        assert coreVisitors.CheckNoVarDeclaredTwice.of(code3);
        // TODO: will die after new reduction Refresh of position identities, it is used to generate correct Java code.
        code3 = (ExpCore.ClassB) code3.accept(new CloneVisitor() {

            @Override
            public ExpCore visit(ExpCore.ClassB cb) {
                Position p = cb.getP();
                cb = cb.withP(new Position(p.getFile(), p.getLine1(), p.getPos1(), p.getLine2(), p.getPos2(), p.get_next()));
                return super.visit(cb);
            }
        });
        ExpCore.ClassB result = ProgramReduction.allSteps(code3);
        return new ReplState(code, code2, result);
    } catch (org.antlr.v4.runtime.misc.ParseCancellationException parser) {
        System.out.println(parser.getMessage());
        return null;
    } catch (ErrorMessage msg) {
        ErrorFormatter.topFormatErrorMessage(msg);
        return null;
    }
}
Also used : ExpCore(ast.ExpCore) ParseCancellationException(org.antlr.v4.runtime.misc.ParseCancellationException) Position(ast.Ast.Position) CloneVisitor(coreVisitors.CloneVisitor) Expression(ast.Expression) ClassReuse(ast.Expression.ClassReuse) ErrorMessage(ast.ErrorMessage) ClassReuse(ast.Expression.ClassReuse) ClassB(ast.Expression.ClassB) InjectionOnCore(sugarVisitors.InjectionOnCore)

Example 13 with InjectionOnCore

use of sugarVisitors.InjectionOnCore in project L42 by ElvisResearchGroup.

the class PlgWrapperGenerator method parseAndDesugar.

private static ExpCore parseAndDesugar(String s) {
    Expression code1 = Parser.parse("PlgWrapperGenerator", s);
    Expression code2 = Desugar.of(code1);
    return code2.accept(new InjectionOnCore());
}
Also used : Expression(ast.Expression) InjectionOnCore(sugarVisitors.InjectionOnCore)

Aggregations

InjectionOnCore (sugarVisitors.InjectionOnCore)13 ClassB (ast.ExpCore.ClassB)8 ExpCore (ast.ExpCore)7 Expression (ast.Expression)7 Program (programReduction.Program)6 Position (ast.Ast.Position)3 ErrorMessage (ast.ErrorMessage)3 CloneVisitor (coreVisitors.CloneVisitor)3 ClassB (ast.Expression.ClassB)2 ClassReuse (ast.Expression.ClassReuse)2 ParseCancellationException (org.antlr.v4.runtime.misc.ParseCancellationException)2 Test (org.junit.Test)2 FinalResult (ast.ErrorMessage.FinalResult)1 NotOkToStar (ast.ErrorMessage.NotOkToStar)1 Member (ast.ExpCore.ClassB.Member)1 MethodWithType (ast.ExpCore.ClassB.MethodWithType)1 NestedClass (ast.ExpCore.ClassB.NestedClass)1 PData (facade.PData)1 ArrayList (java.util.ArrayList)1 Translator (platformSpecific.javaTranslation.Translator)1