Search in sources :

Example 71 with ClassB

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

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

the class OnLineCodeHelper method getL42Code.

static Expression.ClassB getL42Code(String url) {
    try {
        //can be classB or classBReuse
        Expression data = load(url);
        //TODO: can be removed later, but now allows librares to be real source code
        data = Desugar.of(data);
        //    Configuration.reduction.of((ClassB) data.accept(new InjectionOnCore()));
        return (Expression.ClassB) data;
    } catch (org.antlr.v4.runtime.misc.ParseCancellationException pce) {
        System.err.println("Url is: " + url);
        throw pce;
    }
}
Also used : Expression(ast.Expression) ClassB(ast.ExpCore.ClassB)

Example 73 with ClassB

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

the class ProgramReduction method top.

private static Program top(Program p, NestedClass nc) {
    ExpCore ec = nc.getInner();
    assert IsCompiled.of(ec);
    assert !(ec instanceof ClassB);
    System.out.println("Top running on nc:" + nc.getName());
    PathsPaths pair = UsedPaths.usedPathsECatchErrors(p, ec);
    Paths paths = pair.left;
    Paths paths1 = pair.right;
    Program p0 = Norm.multiNorm(p, paths.union(paths1));
    Program p1 = MultiTypeSystem.typeProgram(paths, paths1, p0);
    ExpCore annEc1 = MultiTypeSystem.typeMetaExp(p1, MultiTypeSystem.toAny(paths, ec));
    ClassB res = reduceE(p1, annEc1, C.of("NameDebug_" + nc.getName()));
    res = privateMangling.RefreshUniqueNames.refresh(res);
    ClassB top = p1.top();
    //would actually fail if not there
    assert top.getNested(Collections.singletonList(nc.getName())) != null;
    top = top.withMember(nc.withE(res));
    return p1.updateTop(top);
}
Also used : ExpCore(ast.ExpCore) ClassB(ast.ExpCore.ClassB)

Example 74 with ClassB

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

the class UsedPaths method deepImplements.

private static Paths deepImplements(ClassB l) {
    Paths res = Paths.reorganize(l.getSuperPaths());
    Paths acc = Paths.empty();
    for (Member mi : l.getMs()) {
        if (mi instanceof MethodWithType && !((MethodWithType) mi).get_inner().isPresent()) {
            continue;
        }
        ExpCore e = mi.getInner();
        for (ClassB cbij : CollectClassBs0.of(e)) {
            acc = acc.union(deepImplements(cbij));
        }
    }
    return res.union(acc.pop());
}
Also used : ExpCore(ast.ExpCore) MethodWithType(ast.ExpCore.ClassB.MethodWithType) Member(ast.ExpCore.ClassB.Member) ClassB(ast.ExpCore.ClassB)

Example 75 with ClassB

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

the class _Sum method normalizedSum.

/*
  private static void interfaceClash(Program p, ClassB candidate) {
   try{
     Configuration.typeSystem.computeStage(p,candidate);
   }catch(ErrorMessage.IncoherentMwts i){
     List<Path>ps=new ArrayList<>();
     List<Member>mems=new ArrayList<>();
     Path ph=Path.outer(0,i.getExploredPath());
     for(PathMwt e:i.getIncoherent()){
       ps.add(From.fromP(e.getOriginal(),ph));
     }
     assert !ps.isEmpty();
     Member  notInterf=null;
     Program p1=p.addAtTop(candidate);
     for(Path pi:ps){
       ClassB cb=p1.extractCb(pi);
       System.out.println(pi);
       System.out.println(i);
       System.out.println(cb.getStage());
       System.out.println(candidate.getStage());
       Optional<Member> currentOpt=Program.getIfInDom(cb.getMs(),i.getGuilty());
       Member current=currentOpt.get();

       if(cb.isInterface()){
         mems.add(current);
       }
       else notInterf=current;
     }
     if(notInterf==null){
       throw Errors42.errorClassClash(i.getExploredPath(), ps);
     }
     Member mb=mems.get(0);
     throw Errors42.errorMethodClash(i.getExploredPath(), notInterf,mb, true,Collections.emptyList(),true,true,true);

   }
  }
*/
static ClassB normalizedSum(Program p, ClassB topA, ClassB topB, ClassB a, ClassB b, List<Ast.C> current) {
    List<Member> ms = doubleSimetricalMatch(p, topA, topB, a, b, current);
    List<ast.Ast.Type> superT = new ArrayList<>(a.getSupertypes());
    superT.addAll(b.getSupertypes());
    superT = Collections.unmodifiableList(superT);
    Doc doc1 = a.getDoc1().sum(b.getDoc1());
    //Sum.checkClassClash(p, current, topA, topB, a, b);
    boolean isInterface = a.isInterface() || b.isInterface();
    Phase accPhase = a.getPhase().acc(b.getPhase());
    ExpCore.ClassB res = new ClassB(doc1, isInterface, superT, ms, CollapsePositions.accumulatePos(a.getP(), b.getP()), accPhase, accPhase == Phase.None ? 0 : 1);
    res = (ClassB) res.accept(new coreVisitors.CloneVisitor() {

        public ExpCore visit(ClassB s) {
            if (s.getPhase() == Phase.None) {
                return super.visit(s);
            }
            return super.visit(s.withPhase(accPhase));
        }
    });
    //TODO: remove after new reduction introduced
    return res;
}
Also used : ExpCore(ast.ExpCore) Phase(ast.ExpCore.ClassB.Phase) ArrayList(java.util.ArrayList) MethodType(ast.Ast.MethodType) MethodWithType(ast.ExpCore.ClassB.MethodWithType) Doc(ast.Ast.Doc) ClassB(ast.ExpCore.ClassB) 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