Search in sources :

Example 6 with InjectionOnCore

use of sugarVisitors.InjectionOnCore in project L42 by ElvisResearchGroup.

the class TestLibrary method test.

@Test()
public void test() {
    Program p = TestProgram.p(sProg);
    ClassB cb1Pre = (ClassB) Desugar.of(Parser.parse(null, s1)).accept(new InjectionOnCore());
    cb1Pre = new programReduction.Norm().norm(p.evilPush(cb1Pre));
    TOut out;
    try {
        out = TypeSystem.instance().type(TIn.top(Phase.Coherent, p, cb1Pre));
    } catch (NotOkToStar coh) {
        assert s2 == ErrorKind.LibraryNotCoherent;
        return;
    }
    if (s2 instanceof ErrorKind) {
        assert !out.isOk();
        ErrorKind kind = out.toError().kind;
        assert kind == s2;
    } else {
        assert out.isOk() : "";
        ClassB cb1 = (ClassB) out.toOk().annotated;
        ClassB cbExpected = s2 == sameAsFormer ? cb1Pre : (ClassB) Desugar.of(Parser.parse(null, (String) s2)).accept(new InjectionOnCore());
        TestHelper.assertEqualExp(cb1, cbExpected);
    }
}
Also used : TestProgram(programReduction.TestProgram) Program(programReduction.Program) NotOkToStar(ast.ErrorMessage.NotOkToStar) ClassB(ast.ExpCore.ClassB) InjectionOnCore(sugarVisitors.InjectionOnCore) Test(org.junit.Test)

Example 7 with InjectionOnCore

use of sugarVisitors.InjectionOnCore in project L42 by ElvisResearchGroup.

the class L42 method runSlow.

public static ErrorMessage.FinalResult runSlow(String fileName, String code) {
    try {
        L42.setExecutionStage(ExecutionStage.Parsing);
        Expression code1 = Parser.parse(fileName, code);
        assert code1 instanceof Expression.ClassB || code1 instanceof Expression.ClassReuse;
        L42.setExecutionStage(ExecutionStage.CheckingWellFormedness);
        auxiliaryGrammar.WellFormedness.checkAll(code1);
        L42.setExecutionStage(ExecutionStage.Desugaring);
        Expression code2 = Desugar.of(code1);
        assert auxiliaryGrammar.WellFormedness.checkAll(code2);
        ExpCore.ClassB code3 = (ExpCore.ClassB) code2.accept(new InjectionOnCore());
        assert coreVisitors.CheckNoVarDeclaredTwice.of(code3);
        // L42.usedNames.addAll(CollectDeclaredVarsAndCheckNoDeclaredTwice.of(code2));
        //L42.usedNames.addAll(CollectDeclaredClassNamesAndMethodNames.of(code2));
        L42.setExecutionStage(ExecutionStage.MetaExecution);
        //ClassB result= (ClassB)Executor.stepStar(exe,code3);
        //Refresh of position identities, it is used to generate correct Java code.
        code3 = (ClassB) code3.accept(new CloneVisitor() {

            @Override
            public ExpCore visit(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);
            }
        });
        //ClassB result= Configuration.reduction.of(code3);
        ClassB result = ProgramReduction.allSteps(code3);
        //System.out.println("--------------------------");
        return checkFinalError(result);
    } finally {
        L42.setExecutionStage(ExecutionStage.None);
    }
}
Also used : ExpCore(ast.ExpCore) Expression(ast.Expression) Position(ast.Ast.Position) CloneVisitor(coreVisitors.CloneVisitor) ClassB(ast.ExpCore.ClassB) ClassB(ast.ExpCore.ClassB) InjectionOnCore(sugarVisitors.InjectionOnCore)

Example 8 with InjectionOnCore

use of sugarVisitors.InjectionOnCore in project L42 by ElvisResearchGroup.

the class TestTypeSystemOk method runTypeSystem.

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

Example 9 with InjectionOnCore

use of sugarVisitors.InjectionOnCore in project L42 by ElvisResearchGroup.

the class TestCoherentClass method testCoherence.

@Test
public void testCoherence() {
    ClassB cb1 = (ClassB) (Parser.parse(null, e).accept(new InjectionOnCore()));
    Program p = Program.emptyLibraryProgram();
    MethodWithType mwt = (MethodWithType) cb1.getMs().get(0);
//boolean res=Functions.coherent(p, mdf, path, mwt);
//Assert.assertEquals(res,ok);
//TODO: disabled for now
}
Also used : Program(programReduction.Program) MethodWithType(ast.ExpCore.ClassB.MethodWithType) ClassB(ast.ExpCore.ClassB) InjectionOnCore(sugarVisitors.InjectionOnCore) Test(org.junit.Test)

Example 10 with InjectionOnCore

use of sugarVisitors.InjectionOnCore in project L42 by ElvisResearchGroup.

the class TestShortPrograms method tp.

public static void tp(String... code) {
    TestHelper.configureForTest();
    FinalResult res0;
    try {
        res0 = facade.L42.runSlow(null, TestHelper.multiLine(code));
    } catch (ErrorMessage msg) {
        ErrorFormatter.topFormatErrorMessage(msg);
        throw msg;
    }
    ClassB res = res0.getTopLevelProgram();
    ClassB.NestedClass nc = (ClassB.NestedClass) res.getMs().get(res.getMs().size() - 1);
    ExpCore ee2 = Desugar.of(Parser.parse(null, "{//@exitStatus\n//0\n\n}")).accept(new InjectionOnCore());
    TestHelper.assertEqualExp(nc.getInner(), ee2);
}
Also used : ExpCore(ast.ExpCore) FinalResult(ast.ErrorMessage.FinalResult) ErrorMessage(ast.ErrorMessage) 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