Search in sources :

Example 11 with ErrorMessage

use of ast.ErrorMessage 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)

Example 12 with ErrorMessage

use of ast.ErrorMessage in project L42 by ElvisResearchGroup.

the class Resources method isValid.

public static boolean isValid(Program p, Object res, Object[] xs) {
    if (L42.trustPluginsAndFinalProgram) {
        return true;
    }
    ExpCore ec0 = Revertable.doRevert(res);
    List<ExpCore> es = new ArrayList<>();
    for (Object o : xs) {
        es.add(Revertable.doRevert(o));
    }
    boolean strict = true;
    for (ExpCore ec : es) {
        List<ClassB> cbs = CollectClassBs0.of(ec);
        List<Path> ps = CollectPaths0.of(ec);
        for (ClassB cb : cbs) {
            if (!cb.getPhase().subtypeEq(Phase.Typed)) {
                strict = false;
            }
        }
        for (Path path : ps) {
            if (path.isPrimitive()) {
                continue;
            }
            ClassB extracted = p.extractClassB(path);
            if (!extracted.getPhase().subtypeEq(Phase.Typed)) {
                strict = false;
            }
        }
    }
    List<ClassB> cbs = CollectClassBs0.of(ec0);
    for (ClassB cb : cbs) {
        try {
            newTypeSystem.TypeSystem.instance().topTypeLib(Phase.Typed, p.evilPush(cb));
        } catch (ErrorMessage msg) {
            System.err.println("__________PLUGIN error identified_________");
            //to breakpoint here
            throw msg;
        }
    }
    return true;
}
Also used : Path(ast.Ast.Path) ExpCore(ast.ExpCore) ArrayList(java.util.ArrayList) ErrorMessage(ast.ErrorMessage) ClassB(ast.ExpCore.ClassB)

Example 13 with ErrorMessage

use of ast.ErrorMessage 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 14 with ErrorMessage

use of ast.ErrorMessage in project L42 by ElvisResearchGroup.

the class TestDummyCode method main.

public static void main(String[] arg) throws IOException {
    L42.setRootPath(Paths.get("dummy"));
    System.out.println(Paths.get("dummy").toUri());
    TestHelper.configureForTest();
    try {
        Path path = Paths.get("dummy", "dummy.l42");
        FinalResult res = L42.runSlow(path.toString(), L42.pathToString(path));
        System.out.println("------------------------------");
        System.out.println("END: " + res.getErrCode());
    } catch (ErrorMessage msg) {
        //System.out.println(L42.record.toString());
        msg.printStackTrace();
        //Executor.reportError(msg);
        System.out.println(ErrorFormatter.formatError(Program.empty(), msg).getErrorTxt());
    }
/*    try{
      FinalResult res = L42.runSlow(L42.pathToString(Paths.get("dummy","dummy.l42")));
      System.out.println(L42.record.toString());
      if(res.getResult()!=0){
        System.out.println(res);
        Executor.reportError(null);
        }
      }
    catch(ErrorMessage msg){
      System.out.println(L42.record.toString());
      msg.printStackTrace();
      Executor.reportError(msg);
      }*/
}
Also used : Path(java.nio.file.Path) FinalResult(ast.ErrorMessage.FinalResult) ErrorMessage(ast.ErrorMessage)

Example 15 with ErrorMessage

use of ast.ErrorMessage in project L42 by ElvisResearchGroup.

the class TestL42SuperSlow method test15.

@Test
public void test15() throws IOException {
    String s = TestHelper.multiLine("", "{reuse L42.is/microBase", "A:{() method Bool m(Void v) True() }", //,"NList:Collections.list(N)"
    "AList:Collections.list(A)", "Util:{()", "  class method A max(AList that){", //,"    var N candidate=that.top()"
    "    with ei in that.vals() (", "        void", //,"      if ei>candidate (candidate:=ei)"
    "      )", //,"    return candidate"
    "    return A()", "    }", "  }", "C:{", "  list=AList[A();]", "  if Util.max(list).m(v:void) (return ExitCode.normal())", "  return ExitCode.failure()", "  }", "}");
    try {
        FinalResult res = L42.runSlow(null, s);
        System.out.println(L42.record.toString());
        if (res.getResult() != 0) {
            System.out.println(res);
            TestHelper.reportError(null);
        }
    } catch (ErrorMessage msg) {
        System.out.println(L42.record.toString());
        msg.printStackTrace();
        TestHelper.reportError(msg);
    }
}
Also used : FinalResult(ast.ErrorMessage.FinalResult) ErrorMessage(ast.ErrorMessage) Test(org.junit.Test)

Aggregations

ErrorMessage (ast.ErrorMessage)17 FinalResult (ast.ErrorMessage.FinalResult)12 Test (org.junit.Test)5 ExpCore (ast.ExpCore)4 Position (ast.Ast.Position)3 ClassB (ast.ExpCore.ClassB)3 ArrayList (java.util.ArrayList)3 ParseCancellationException (org.antlr.v4.runtime.misc.ParseCancellationException)3 InjectionOnCore (sugarVisitors.InjectionOnCore)3 Expression (ast.Expression)2 ClassB (ast.Expression.ClassB)2 ClassReuse (ast.Expression.ClassReuse)2 CloneVisitor (coreVisitors.CloneVisitor)2 Path (java.nio.file.Path)2 Ast (ast.Ast)1 Path (ast.Ast.Path)1 Kind (ast.ErrorMessage.UserLevelError.Kind)1 Member (ast.ExpCore.ClassB.Member)1 NestedClass (ast.ExpCore.ClassB.NestedClass)1