Search in sources :

Example 6 with ClassB

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

the class ErrorFormatter method whyIsNotExecutable.

private static String whyIsNotExecutable(ClassB cb) {
    /*if(cb.getH() instanceof Ast.TraitHeader){
      return "\n  The requested path is a trait";
    }*/
    for (Member m : cb.getMs()) {
        if (!(m instanceof MethodWithType)) {
            continue;
        }
    /*MethodWithType mt=(MethodWithType)m;
      if (!mt.getInner().isPresent() && !mt.isFieldGenerated()){
        return "\n  The method "+mt.getMs()+" of the requested path is abstract";
      }*/
    }
    for (Member m : cb.getMs()) {
        if (!(m instanceof NestedClass)) {
            continue;
        }
        NestedClass nc = (NestedClass) m;
        if (!(nc.getInner() instanceof ClassB)) {
            return "\n  The nested class " + nc.getName() + " of the requested path is not compiled yet";
        }
        String nestedRes = whyIsNotExecutable((ClassB) nc.getInner());
        if (nestedRes != null) {
            return "." + nc.getName() + nestedRes;
        }
    }
    return null;
}
Also used : NestedClass(ast.ExpCore.ClassB.NestedClass) MethodWithType(ast.ExpCore.ClassB.MethodWithType) Member(ast.ExpCore.ClassB.Member) ClassB(ast.ExpCore.ClassB)

Example 7 with ClassB

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

the class EncodingHelper method _extractStringU.

public static String _extractStringU(Object e) {
    if (e instanceof String) {
        return (String) e;
    }
    if (!(e instanceof ClassB)) {
        return null;
    }
    ClassB cb = (ClassB) e;
    String code = extractCode(cb, "@stringU\n");
    if (code == null) {
        return null;
    }
    return EncodingHelper.parseStringUnicode(code);
}
Also used : ClassB(ast.ExpCore.ClassB)

Example 8 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 9 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 10 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)

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