Search in sources :

Example 1 with InjectionOnCore

use of sugarVisitors.InjectionOnCore in project L42 by ElvisResearchGroup.

the class TranslationTest method runTypeSystem.

private static Program runTypeSystem(String scb1) {
    ClassB cb1 = (ClassB) Desugar.of(Parser.parse(null, scb1)).accept(new InjectionOnCore());
    Program p = Program.emptyLibraryProgram();
    ClassB cb = newTypeSystem.TypeSystem.instance().topTypeLib(Phase.Coherent, p.evilPush(cb1));
    return p.evilPush(cb);
}
Also used : Program(programReduction.Program) ClassB(ast.ExpCore.ClassB) InjectionOnCore(sugarVisitors.InjectionOnCore)

Example 2 with InjectionOnCore

use of sugarVisitors.InjectionOnCore in project L42 by ElvisResearchGroup.

the class ReplState method add.

public ReplState add(String code) {
    Expression.ClassB cbEmpty = new ClassB(Doc.empty(), new ast.Ast.InterfaceHeader(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Position.noInfo);
    try {
        //parse
        Expression.ClassB codeTmp = (ClassB) Parser.parse("Repl", "{" + code + "}");
        //new original
        ClassReuse newOriginal = this.originalL;
        List<ast.Expression.ClassB.Member> newOriginalMs = newOriginal.getInner().getMs();
        newOriginalMs.addAll(codeTmp.getMs());
        newOriginal.withInner(newOriginal.getInner().withMs(newOriginalMs));
        //new src to desugar
        List<ClassB.Member> newMs = new ArrayList<>();
        int nestedAdded = 0;
        for (Member m : this.desugaredL.getMs()) {
            if (!(m instanceof NestedClass)) {
                continue;
            }
            NestedClass nc = (NestedClass) m;
            newMs.add(new ClassB.NestedClass(Doc.empty(), nc.getName(), cbEmpty, nc.getP()));
            nestedAdded += 1;
        }
        newMs.addAll(codeTmp.getMs());
        codeTmp = codeTmp.withMs(newMs);
        Expression code2 = Desugar.of(codeTmp);
        ExpCore.ClassB code3 = (ExpCore.ClassB) code2.accept(new InjectionOnCore());
        // 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);
            }
        });
        //integrate new desugared src with old desugared code
        List<Member> resultMs = new ArrayList<>(this.desugaredL.getMs());
        for (int i = nestedAdded; i < code3.getMs().size(); i++) {
            resultMs.add(code3.getMs().get(i));
        }
        code3 = code3.withMs(resultMs);
        //call the repl and return
        ExpCore.ClassB result = ProgramReduction.allSteps(code3);
        return new ReplState(this.originalS + "\n" + code, newOriginal, result);
    } catch (ParseCancellationException parser) {
        System.out.println(parser.getMessage());
        return null;
    } catch (ErrorMessage msg) {
        ErrorFormatter.topFormatErrorMessage(msg);
        return null;
    }
}
Also used : ExpCore(ast.ExpCore) Position(ast.Ast.Position) ClassB(ast.Expression.ClassB) ArrayList(java.util.ArrayList) NestedClass(ast.ExpCore.ClassB.NestedClass) CloneVisitor(coreVisitors.CloneVisitor) NestedClass(ast.ExpCore.ClassB.NestedClass) Expression(ast.Expression) ParseCancellationException(org.antlr.v4.runtime.misc.ParseCancellationException) ClassReuse(ast.Expression.ClassReuse) ErrorMessage(ast.ErrorMessage) Member(ast.ExpCore.ClassB.Member) ClassB(ast.Expression.ClassB) InjectionOnCore(sugarVisitors.InjectionOnCore)

Example 3 with InjectionOnCore

use of sugarVisitors.InjectionOnCore in project L42 by ElvisResearchGroup.

the class TestHelper method getExpCore.

public static ExpCore getExpCore(String source, String _e1) {
    Expression code1 = Parser.parse("GeneratedByTestHelper_", _e1);
    Expression code2 = Desugar.of(code1);
    ExpCore e1 = code2.accept(new InjectionOnCore());
    return e1;
}
Also used : ExpCore(ast.ExpCore) Expression(ast.Expression) InjectionOnCore(sugarVisitors.InjectionOnCore)

Example 4 with InjectionOnCore

use of sugarVisitors.InjectionOnCore in project L42 by ElvisResearchGroup.

the class TestHelper method getProgram.

public static Program getProgram(/*List<Path> paths,*/
String[] code) {
    Program p0 = Program.emptyLibraryProgram();
    Integer outerCount = code.length;
    for (String s : code) {
        Expression e = Parser.parse("This" + outerCount, s);
        --outerCount;
        ClassB ec = (ClassB) Desugar.of(e).accept(new InjectionOnCore());
        p0 = p0.evilPush(ec);
    }
    return p0;
}
Also used : Program(programReduction.Program) Expression(ast.Expression) ClassB(ast.ExpCore.ClassB) InjectionOnCore(sugarVisitors.InjectionOnCore)

Example 5 with InjectionOnCore

use of sugarVisitors.InjectionOnCore in project L42 by ElvisResearchGroup.

the class TestHelper method getClassB.

public static ClassB getClassB(String source, String e1) {
    Expression code1 = Parser.parse("GeneratedByTestHelper_" + source, e1);
    auxiliaryGrammar.WellFormedness.checkAll(code1);
    Expression code2 = Desugar.of(code1);
    assert auxiliaryGrammar.WellFormedness.checkAll(code2);
    ExpCore.ClassB code3 = (ExpCore.ClassB) code2.accept(new InjectionOnCore());
    assert coreVisitors.CheckNoVarDeclaredTwice.of(code3);
    return code3;
}
Also used : ExpCore(ast.ExpCore) Expression(ast.Expression) ClassB(ast.ExpCore.ClassB) ClassB(ast.ExpCore.ClassB) 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