Search in sources :

Example 11 with Doc

use of ast.Ast.Doc in project L42 by ElvisResearchGroup.

the class InjectionOnSugar method visit.

@Override
public Expression visit(Block s) {
    Doc docs = s.getDoc();
    Expression inner = lift(s.getInner());
    List<VarDec> decs = new ArrayList<VarDec>();
    for (int i = 0; i < s.getDecs().size(); i++) {
        Optional<Type> t = s.getDecs().get(i).getT();
        String x = s.getDecs().get(i).getX();
        Expression e = lift(s.getDecs().get(i).getInner());
        decs.add(new VarDecXE(s.getDecs().get(i).isVar(), t, x, e));
    }
    List<Expression.Catch> _catch = injectionCatch(s.getOns());
    List<Expression.BlockContent> contents = new ArrayList<>();
    if (!decs.isEmpty() || !_catch.isEmpty()) {
        contents.add(new Expression.BlockContent(decs, _catch));
    }
    Expression.Position pos = s.getP();
    Expression.RoundBlock result = new Expression.RoundBlock(pos, docs, inner, contents);
    //assert WellFormedness.blockCheck(result);, no it can actually get wrong?
    return result;
}
Also used : ArrayList(java.util.ArrayList) Type(ast.Ast.Type) MethodType(ast.Ast.MethodType) Expression(ast.Expression) VarDec(ast.Ast.VarDec) Doc(ast.Ast.Doc) VarDecXE(ast.Ast.VarDecXE)

Example 12 with Doc

use of ast.Ast.Doc in project L42 by ElvisResearchGroup.

the class OnLineCodeHelper method plugin.

public static PluginType plugin(Program p, ExpCore.Using u) {
    Doc d = p.extractClassB(u.getPath()).getDoc1();
    PluginType pt = _isPluginWithPart(d);
    if (pt != null) {
        return pt;
    }
    pt = _isWellKnownPlugin(d);
    if (pt != null) {
        return pt;
    }
    throw Assertions.codeNotReachable("Other plugings not supported yet");
}
Also used : Doc(ast.Ast.Doc)

Example 13 with Doc

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

use of ast.Ast.Doc in project L42 by ElvisResearchGroup.

the class _Sum method sumMethod.

static MethodWithType sumMethod(MethodWithType ma, MethodWithType mb) {
    Set<Path> pa = new HashSet<Path>(Map.of(t -> t.getPath(), ma.getMt().getExceptions()));
    Set<Path> pb = new HashSet<Path>(Map.of(t -> t.getPath(), mb.getMt().getExceptions()));
    Set<Path> pc = new HashSet<>(pa);
    pc.retainAll(pb);
    Doc doc = ma.getDoc().sum(mb.getDoc());
    MethodType mt = ma.getMt();
    List<Ast.Type> opc = pc.stream().map(pi -> (Ast.Type) pi.toImmNT()).collect(Collectors.toList());
    Collections.sort(opc, (p1, p2) -> p1.toString().compareTo(p2.toString()));
    mt = mt.withExceptions(opc);
    MethodWithType mwt = ma.withMt(mt).withDoc(doc);
    //now mwt has min exceptions and summed docs
    assert !ma.get_inner().isPresent() || !mb.get_inner().isPresent();
    if (mb.get_inner().isPresent()) {
        mwt = mwt.withInner(mb.getInner());
    }
    return mwt;
}
Also used : Resources(platformSpecific.javaTranslation.Resources) From(coreVisitors.From) Stage(ast.Ast.Stage) Program(programReduction.Program) Ast(ast.Ast) Map(tools.Map) Configuration(facade.Configuration) ErrorMessage(ast.ErrorMessage) MethodType(ast.Ast.MethodType) MethodWithType(ast.ExpCore.ClassB.MethodWithType) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) RefreshUniqueNames(privateMangling.RefreshUniqueNames) ClassB(ast.ExpCore.ClassB) PathMwt(ast.Util.PathMwt) ClassKind(is.L42.connected.withSafeOperators.ExtractInfo.ClassKind) CloneVisitor(sugarVisitors.CloneVisitor) NestedClass(ast.ExpCore.ClassB.NestedClass) Path(ast.Ast.Path) Doc(ast.Ast.Doc) Phase(ast.ExpCore.ClassB.Phase) Set(java.util.Set) ExpCore(ast.ExpCore) Member(ast.ExpCore.ClassB.Member) Collectors(java.util.stream.Collectors) Functions(auxiliaryGrammar.Functions) CollapsePositions(sugarVisitors.CollapsePositions) List(java.util.List) Optional(java.util.Optional) Collections(java.util.Collections) MethodImplemented(ast.ExpCore.ClassB.MethodImplemented) Path(ast.Ast.Path) MethodType(ast.Ast.MethodType) MethodType(ast.Ast.MethodType) MethodWithType(ast.ExpCore.ClassB.MethodWithType) Doc(ast.Ast.Doc) MethodWithType(ast.ExpCore.ClassB.MethodWithType) HashSet(java.util.HashSet)

Example 15 with Doc

use of ast.Ast.Doc in project L42 by ElvisResearchGroup.

the class _Sum method matchNC.

private static Void matchNC(Program p, ClassB topA, ClassB topB, NestedClass nca, List<Member> ms, NestedClass ncb, List<Ast.C> current) {
    List<Ast.C> innerCurrent = new ArrayList<>(current);
    innerCurrent.add(nca.getName());
    ClassB newInner = normalizedSum(p, topA, topB, (ClassB) nca.getInner(), (ClassB) ncb.getInner(), innerCurrent);
    Doc doc = nca.getDoc().sum(ncb.getDoc());
    ms.add(nca.withInner(newInner).withDoc(doc));
    return null;
}
Also used : ArrayList(java.util.ArrayList) Doc(ast.Ast.Doc) ClassB(ast.ExpCore.ClassB)

Aggregations

Doc (ast.Ast.Doc)27 ArrayList (java.util.ArrayList)11 Ast (ast.Ast)9 ClassB (ast.ExpCore.ClassB)9 Expression (ast.Expression)9 Path (ast.Ast.Path)8 MethodType (ast.Ast.MethodType)7 Type (ast.Ast.Type)7 ExpCore (ast.ExpCore)7 MethodSelector (ast.Ast.MethodSelector)5 List (java.util.List)5 Optional (java.util.Optional)5 VarDec (ast.Ast.VarDec)4 Member (ast.ExpCore.ClassB.Member)4 Catch (ast.Expression.Catch)4 Mdf (ast.Ast.Mdf)3 Position (ast.Ast.Position)3 Block (ast.ExpCore.Block)3 MethodWithType (ast.ExpCore.ClassB.MethodWithType)3 Phase (ast.ExpCore.ClassB.Phase)3