Search in sources :

Example 36 with Member

use of ast.ExpCore.ClassB.Member 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)

Example 37 with Member

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

the class PlgWrapperGenerator method plgComplete.

public static ClassB plgComplete(List<Ast.C> cs, Program p, ClassB l) throws UnresolvedOverloading, ClassUnfit, MethodUnfit {
    //p.top() is topL
    List<Member> ms = new ArrayList<>();
    for (Member m : l.getMs()) {
        if (!(m instanceof NestedClass)) {
            ms.add(m);
            continue;
        }
        NestedClass nc = (NestedClass) m;
        List<Ast.C> csc = new ArrayList<>(cs);
        csc.add(nc.getName());
        ms.add(nc.withInner(plgComplete(csc, p, (ClassB) nc.getInner())));
    }
    return plgComplete1(cs, p, l.withMs(ms));
//forall nested c in l
// l=l[with c=plgComplete(cs:c, p,l.c)
//return plgComplete1(cs,p,l)
}
Also used : ArrayList(java.util.ArrayList) NestedClass(ast.ExpCore.ClassB.NestedClass) Member(ast.ExpCore.ClassB.Member)

Example 38 with Member

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

the class Translator method useFrom.

//this should take a class, strip out nested and 'from' it so that it is as at top level
static ClassB useFrom(ClassB ct, Path p) {
    ArrayList<Member> ms = new ArrayList<Member>();
    for (Member m : ct.getMs()) {
        m.match(nc -> null, mi -> {
            throw Assertions.codeNotReachable();
        }, mt -> ms.add(From.from(mt, p)));
    }
    //for(PathMwt pmwt:ct.getStage().getInherited()){
    for (PathMwt pmwt : Collections.<PathMwt>emptyList()) {
        if (Functions.getIfInDom(ms, pmwt.getMwt().getMs()).isPresent()) {
            continue;
        }
        ms.add(From.from(pmwt.getMwt(), p));
    }
    List<Path> sup = tools.Map.of(ti -> (Path) From.fromP(ti.getPath(), p), ct.getSupertypes());
    //tools.Map.of(pi->(Path)From.fromP(pi,p),ct.getStage().getInheritedPaths());
    List<Path> supAll = sup;
    ClassB res = ct.withMs(ms).withSupertypes(tools.Map.of(pi -> pi.toImmNT(), sup));
    return res;
}
Also used : Path(ast.Ast.Path) From(coreVisitors.From) Stage(ast.Ast.Stage) Arrays(java.util.Arrays) Program(programReduction.Program) Ast(ast.Ast) Configuration(facade.Configuration) Type(ast.Ast.Type) HashMap(java.util.HashMap) Assertions(tools.Assertions) ArrayList(java.util.ArrayList) CompilationError(platformSpecific.inMemoryCompiler.InMemoryJavaCompiler.CompilationError) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) ClassB(ast.ExpCore.ClassB) InterfaceHeader(ast.Ast.InterfaceHeader) Map(java.util.Map) Facade(reduction.Facade) PathMwt(ast.Util.PathMwt) MapClassLoader(platformSpecific.inMemoryCompiler.InMemoryJavaCompiler.MapClassLoader) Method(java.lang.reflect.Method) IsCompiled(coreVisitors.IsCompiled) NestedClass(ast.ExpCore.ClassB.NestedClass) Files(java.nio.file.Files) Path(ast.Ast.Path) Doc(ast.Ast.Doc) Phase(ast.ExpCore.ClassB.Phase) IOException(java.io.IOException) ExpCore(ast.ExpCore) Member(ast.ExpCore.ClassB.Member) Functions(auxiliaryGrammar.Functions) InvocationTargetException(java.lang.reflect.InvocationTargetException) Util(ast.Util) Consumer(java.util.function.Consumer) List(java.util.List) EmptyProgram(programReduction.Program.EmptyProgram) Paths(java.nio.file.Paths) Optional(java.util.Optional) SourceFile(platformSpecific.inMemoryCompiler.InMemoryJavaCompiler.SourceFile) Timer(profiling.Timer) InMemoryJavaCompiler(platformSpecific.inMemoryCompiler.InMemoryJavaCompiler) Collections(java.util.Collections) L42(facade.L42) ArrayList(java.util.ArrayList) Member(ast.ExpCore.ClassB.Member) PathMwt(ast.Util.PathMwt) ClassB(ast.ExpCore.ClassB)

Example 39 with Member

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

the class Translator method add.

public static void add(int level, List<Ast.C> cs, ClassB cb, Map<String, ClassB> map, Program original) {
    Ast.Path p = Ast.Path.outer(level, cs);
    if (cb.getPhase() == Phase.Coherent && IsCompiled.of(cb)) {
        //otherwise is "meta"
        //assert cb.getStage().getInheritedPaths()!=null;
        ClassB cbUF = useFrom(cb, p);
        if (!cs.isEmpty()) {
            //ok to ignore empty ones, since not complete?
            map.put(Resources.nameOf(level, cs), cbUF);
        }
    } else {
    //generate only for metaprogramming //Can be ignored now with typemap
    /*ExpCore.ClassB cbMP = new ExpCore.ClassB(
          Doc.factory("##@DebugInfo: is interface since (cb.getStage()!=Stage.Star :"
            +(cb.getStage().getStage()!=Stage.Star)+") or since !IsCompiled.of(cb) :"+!IsCompiled.of(cb)+")"
          ),Doc.empty(),true,Collections.emptyList(),Collections.emptyList(),new Util.CachedStage());
      cbMP.getStage().setInheritedPaths(Collections.emptyList());
      cbMP.getStage().setInherited(Collections.emptyList());
      assert cbMP.getStage().getInheritedPaths()!=null;
      map.put(Resources.nameOf(level,cs),cbMP);
      */
    }
    for (Member m : cb.getMs()) {
        if (!(m instanceof NestedClass)) {
            continue;
        }
        NestedClass nc = (NestedClass) m;
        if (!(nc.getInner() instanceof ClassB)) {
            continue;
        }
        if (cs.isEmpty() && level > 0) {
            if (nc.getInner() == original.get(level - 1)) {
                continue;
            }
        //avoid generation of multiple versions of the same thing
        }
        ArrayList<Ast.C> newCs = new ArrayList<>(cs);
        newCs.add(nc.getName());
        add(level, newCs, (ClassB) nc.getInner(), map, original);
    }
}
Also used : Ast(ast.Ast) Path(ast.Ast.Path) ArrayList(java.util.ArrayList) NestedClass(ast.ExpCore.ClassB.NestedClass) Member(ast.ExpCore.ClassB.Member) ClassB(ast.ExpCore.ClassB)

Example 40 with Member

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

the class Rename method redirectDefinition.

private static ClassB redirectDefinition(List<Ast.C> src, List<Ast.C> dest, ClassB lprime) {
    assert !src.isEmpty();
    assert !dest.isEmpty();
    NestedClass nsCb = lprime.getNested(src);
    Path toFrom = Path.outer(dest.size() - 1, src.subList(0, src.size() - 1));
    ClassB cb = (ClassB) FromInClass.of((ClassB) nsCb.getInner(), toFrom);
    List<Member> ms = new ArrayList<>();
    ms.add(Functions.encapsulateIn(dest, cb, nsCb.getDoc()));
    return ClassB.membersClass(ms, Position.noInfo, lprime.getPhase());
}
Also used : PathPath(ast.Util.PathPath) Path(ast.Ast.Path) ArrayList(java.util.ArrayList) NestedClass(ast.ExpCore.ClassB.NestedClass) Member(ast.ExpCore.ClassB.Member)

Aggregations

Member (ast.ExpCore.ClassB.Member)54 ArrayList (java.util.ArrayList)32 ClassB (ast.ExpCore.ClassB)21 MethodWithType (ast.ExpCore.ClassB.MethodWithType)21 NestedClass (ast.ExpCore.ClassB.NestedClass)20 Ast (ast.Ast)14 ExpCore (ast.ExpCore)11 Path (ast.Ast.Path)10 List (java.util.List)7 Doc (ast.Ast.Doc)5 MethodSelector (ast.Ast.MethodSelector)5 MethodType (ast.Ast.MethodType)5 Collections (java.util.Collections)5 C (ast.Ast.C)4 MethodImplemented (ast.ExpCore.ClassB.MethodImplemented)4 Phase (ast.ExpCore.ClassB.Phase)4 HashSet (java.util.HashSet)4 Optional (java.util.Optional)4 Assertions (tools.Assertions)4 Position (ast.Ast.Position)3