Search in sources :

Example 31 with ClassB

use of ast.ExpCore.ClassB in project L42 by ElvisResearchGroup.

the class Translator method translateProgram.

public static Translator translateProgram(Program p, ExpCore e) {
    Translator t = new Translator();
    t.map = new HashMap<>();
    //Resources.clearRes();
    Map<String, ClassB> map = new LinkedHashMap<String, ClassB>();
    Map<String, ClassB> mapNorm = new LinkedHashMap<String, ClassB>();
    addP(0, p, map, p);
    {
        StringBuilder res = new StringBuilder();
        t.mainName = Functions.freshName("Execute_", L42.usedNames);
        res.append("package generated;");
        res.append("@SuppressWarnings(\"all\")");
        res.append("public class " + t.mainName + "{\n");
        res.append("public static Object execute0()");
        TranslateExpression.of(e, res, Collections.emptyList());
        res.append("\n");
        res.append("}");
        t.map.put(t.mainName, res.toString());
    }
    MapClassLoader cl = ((Facade) Configuration.reduction).getLastLoader();
    for (String s : map.keySet()) {
        if (cl != null && cl.map().containsKey("generated." + s)) {
            continue;
        //ClassB cb=map.get(s);
        //if(!cb.getDoc1().getS().contains("##@")){continue;}
        }
        if (map.get(s).getPhase() != Phase.Coherent) {
            continue;
        }
        //Hope it work, it was normalized before
        ClassB cbNorm = map.get(s);
        assert cbNorm.getPhase() == Phase.Coherent;
        mapNorm.put(s, cbNorm);
    }
    for (String s : mapNorm.keySet()) {
        StringBuilder resi = new StringBuilder();
        resi.append("package generated;");
        resi.append("@SuppressWarnings(\"all\")");
        ClassB cbNorm = mapNorm.get(s);
        assert cbNorm.getPhase() == Phase.Coherent;
        TranslateClass.of(p, s, mapNorm.get(s), resi);
        String resiS = resi.toString();
        t.map.put(s, resiS);
    }
    return t;
}
Also used : Facade(reduction.Facade) MapClassLoader(platformSpecific.inMemoryCompiler.InMemoryJavaCompiler.MapClassLoader) ClassB(ast.ExpCore.ClassB) LinkedHashMap(java.util.LinkedHashMap)

Example 32 with ClassB

use of ast.ExpCore.ClassB in project L42 by ElvisResearchGroup.

the class Executor method meta1Prop.

protected ClassB meta1Prop(Program p, ClassB cb, NestedClass m) {
    log("---meta1Prop--");
    //get cb-->ct
    //get p'
    Program p1 = p.evilPush(cb);
    //extract e
    ExpCore e = m.getInner();
    //extract cb
    Ctx<ClassB> ctxC = ExtractCtxCompiled.of(e);
    //run cb1-->cb2
    ClassB cb2 = (ClassB) step(new PData(p1), ctxC.hole);
    ExpCore e2 = ReplaceCtx.of(ctxC.ctx, cb2);
    //compose cb with new member
    return cb.withMember(m.withInner(e2));
}
Also used : ExpCore(ast.ExpCore) Program(programReduction.Program) PData(facade.PData) ClassB(ast.ExpCore.ClassB)

Example 33 with ClassB

use of ast.ExpCore.ClassB in project L42 by ElvisResearchGroup.

the class TestHelper method _dbgCompact.

/*
  static class LoggedPrintStream extends PrintStream {
    final StringBuilder buf;
    final PrintStream underlying;
    LoggedPrintStream(StringBuilder sb, OutputStream os, PrintStream ul) {
        super(os);
        this.buf = sb;
        this.underlying = ul;
    }
  public static LoggedPrintStream create(PrintStream toLog) {//from http://stackoverflow.com/questions/4334808/how-could-i-read-java-console-output-into-a-string-buffer
    try {
      final StringBuilder sb = new StringBuilder();
      Field f = FilterOutputStream.class.getDeclaredField("out");
      f.setAccessible(true);
      OutputStream psout = (OutputStream) f.get(toLog);
      return new LoggedPrintStream(sb, new FilterOutputStream(psout) {
        public void write(int b) throws IOException {
          super.write(b);
          sb.append((char) b);
          }
        }, toLog);
      }
    catch (NoSuchFieldException|IllegalArgumentException |IllegalAccessException e) {
      throw Assertions.codeNotReachable();
      }}}*/
public static void _dbgCompact(ExpCore e) {
    assert e instanceof ClassB;
    ClassB cb = (ClassB) e;
    ArrayList<Member> ms = new ArrayList<>();
    for (Member m : cb.getMs()) {
        if (!(m instanceof NestedClass)) {
            continue;
        }
        NestedClass nc = (NestedClass) m;
        if ((nc.getInner() instanceof ClassB)) {
            continue;
        }
        ms.add(nc);
        break;
    }
    cb = cb.withMs(ms);
    System.out.println(ToFormattedText.of(cb));
}
Also used : ArrayList(java.util.ArrayList) NestedClass(ast.ExpCore.ClassB.NestedClass) Member(ast.ExpCore.ClassB.Member) ClassB(ast.ExpCore.ClassB)

Example 34 with ClassB

use of ast.ExpCore.ClassB 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 35 with ClassB

use of ast.ExpCore.ClassB in project L42 by ElvisResearchGroup.

the class TestHelper method reportError.

public static void reportError(ErrorMessage e) {
    if (Executor.last1 == null || Executor.last2 == null) {
        throw e;
    }
    ClassB c1 = (ClassB) Executor.last1;
    ClassB c2 = (ClassB) Executor.last2;
    ArrayList<Member> ms1 = new ArrayList<>();
    ArrayList<Member> ms2 = new ArrayList<>();
    {
        int i = -1;
        for (Member e1 : c1.getMs()) {
            i += 1;
            Member e2 = c2.getMs().get(i);
            if (e1.equals(e2)) {
                continue;
            }
            ms1.add(e1);
            ms2.add(e2);
        }
    }
    c1 = c1.withMs(ms1);
    c2 = c2.withMs(ms2);
//TestHelper.assertEqualExp(c1, c2);
}
Also used : ArrayList(java.util.ArrayList) Member(ast.ExpCore.ClassB.Member) ClassB(ast.ExpCore.ClassB)

Aggregations

ClassB (ast.ExpCore.ClassB)107 ArrayList (java.util.ArrayList)33 Path (ast.Ast.Path)30 ExpCore (ast.ExpCore)25 Member (ast.ExpCore.ClassB.Member)25 EncodingHelper.ensureExtractClassB (auxiliaryGrammar.EncodingHelper.ensureExtractClassB)20 Program (programReduction.Program)20 Ast (ast.Ast)19 MethodWithType (ast.ExpCore.ClassB.MethodWithType)19 MethodSelector (ast.Ast.MethodSelector)18 NestedClass (ast.ExpCore.ClassB.NestedClass)18 List (java.util.List)17 ActionType (platformSpecific.fakeInternet.ActionType)16 Doc (ast.Ast.Doc)12 Type (ast.Ast.Type)12 ErrorMessage (ast.ErrorMessage)12 Optional (java.util.Optional)10 C (ast.Ast.C)9 MethodType (ast.Ast.MethodType)8 Phase (ast.ExpCore.ClassB.Phase)8