Search in sources :

Example 21 with Doc

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

the class ToAst method visitClassBReuse.

@Override
public Expression visitClassBReuse(ClassBReuseContext ctx) {
    Doc doc1 = Doc.empty();
    if (ctx.docsOpt().size() >= 1) {
        doc1 = parseDoc(ctx.docsOpt().get(0));
    }
    //Note: if exists ctx.docsOpt().get(1)) it is ignored.
    assert ctx.getChild(0).getText().equals("{");
    assert ctx.getChild(2).getText().startsWith("reuse");
    String url = ctx.getChild(2).getText();
    url = url.trim();
    List<Member> ms = visitMembers(ctx.member());
    ClassB inner = new ClassB(doc1, new Ast.TraitHeader(), Collections.emptyList(), Collections.emptyList(), ms, position(ctx));
    return new Expression.ClassReuse(inner, url, null);
}
Also used : Ast(ast.Ast) TraitHeader(ast.Ast.TraitHeader) Doc(ast.Ast.Doc) ClassB(ast.Expression.ClassB)

Example 22 with Doc

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

the class ToAst method parseType.

private Type parseType(TContext t) {
    if (t.concreteT() != null) {
        ConcreteTContext tt = t.concreteT();
        Doc d = parseDoc(tt.docsOpt());
        Ast.Type nt = new Ast.Type(Mdf.fromString((tt.Mdf() == null) ? "" : nameK(tt.Mdf())), Ast.Path.sugarParse(nameU(tt.Path())), d);
        if (tt.Ph() == null) {
            return nt;
        }
        return Functions.toPh(nt);
    }
    if (t.historicalT() != null) {
        HistoricalTContext tt = t.historicalT();
        Doc d = parseDoc(tt.docsOpt());
        Path p = ast.Ast.Path.sugarParse(nameU(tt.Path()));
        List<MethodSelectorX> mss = new ArrayList<MethodSelectorX>();
        for (HistoricalSeqContext ms : tt.historicalSeq()) {
            mss.add(parseMethSelectorX(ms));
        }
        //return new ast.Ast.HistoricType(p,mss,d);
        throw Assertions.codeNotReachable();
    }
    throw Assertions.codeNotReachable();
}
Also used : Path(ast.Ast.Path) Type(ast.Ast.Type) Ast(ast.Ast) MethodSelectorX(ast.Ast.MethodSelectorX) Doc(ast.Ast.Doc) Type(ast.Ast.Type)

Example 23 with Doc

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

the class ToAst method visitRoundBlockAux.

private Expression visitRoundBlockAux(ParserRuleContext ctx, DocsOptContext docsOpt, List<BbContext> bB, ETopContext eTop) {
    Doc doc = parseDoc(docsOpt);
    List<BlockContent> contents = new ArrayList<BlockContent>();
    for (BbContext b : bB) {
        List<VarDec> decs = new ArrayList<VarDec>();
        for (DContext d : b.d()) {
            decs.add(parseVDec(d));
        }
        assert b.ks() != null;
        List<Catch> _catch = parseKs(b.ks());
        contents.add(new BlockContent(decs, _catch));
    }
    Expression inner = eTop.accept(this);
    return new Expression.RoundBlock(position(ctx), doc, inner, contents);
}
Also used : Expression(ast.Expression) Catch(ast.Expression.Catch) VarDec(ast.Ast.VarDec) BlockContent(ast.Expression.BlockContent) Doc(ast.Ast.Doc)

Example 24 with Doc

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

the class ToAst method visitClassB.

@Override
public Expression visitClassB(ClassBContext ctx) {
    //the number 1 if present is ignored
    Doc doc1 = parseDoc(ctx.docsOpt().get(0));
    Header h = parseHeader(ctx.header());
    List<Type> supertypes = new ArrayList<>();
    ImplsContext impl = ctx.impls();
    if (impl != null) {
        {
            int i = -1;
            for (TerminalNode p : impl.Path()) {
                i += 1;
                supertypes.add(Path.sugarParse(nameU(p)).toImmNT().withDoc(parseDoc(impl.docsOpt().get(0))));
            }
        }
    }
    List<Member> ms = visitMembers(ctx.member());
    List<Ast.FieldDec> fs = new ArrayList<>();
    for (FieldDecContext f : ctx.fieldDec()) {
        fs.add(parseFieldDec(f));
    }
    return new Expression.ClassB(doc1, h, fs, supertypes, ms, position(ctx));
}
Also used : Type(ast.Ast.Type) FieldDec(ast.Ast.FieldDec) Header(ast.Ast.Header) ConcreteHeader(ast.Ast.ConcreteHeader) InterfaceHeader(ast.Ast.InterfaceHeader) TraitHeader(ast.Ast.TraitHeader) Doc(ast.Ast.Doc) ClassB(ast.Expression.ClassB)

Example 25 with Doc

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

the class Errors42 method errorIncoherentRedirectMapping.

/* static void checkCoherentMapping(List<PathPath> setVisited) {
    // setVisited is a set of individual redirected classes,
    // created by walking the sub-tree under each cascade redirect.
    // getPath1() is the path in the library before redirecting.
    // getPath2() is the proposed path in the redirected library.
    // We will allow many paths to be redirected into a single new path,
    // but not vice-versa.
    for(PathPath p1:setVisited){
      for(PathPath p2:setVisited){
        if(p1.equals(p2)){continue;}
        if(p1.getPath1().equals(p2.getPath1())){
          throw errorIncoherentRedirectMapping(setVisited, p1.getPath1(),p1.getPath2(),p2.getPath2());
          }
      }
    }
    return;
  }*/
static Error errorIncoherentRedirectMapping(List<PathPath> verified, List<PathSPath> ambiguities, Path incoSrc, List<Path> _incoDest) {
    Doc src = Doc.empty();
    Doc dest = Doc.empty();
    //Doc ambig=Doc.empty();
    for (PathPath v : verified) {
        src = src.sum(formatPathIn(v.getPath1().getCBar()));
        dest = dest.sum(formatPathOut(v.getPath2()));
    }
    for (PathSPath a : ambiguities) {
        //if(a.getPaths().size()!=1){
        //  ambig=ambig.sum(formatPathIn(a.getPath().getCBar()));
        //  ambig=ambig.sum(Doc.factory("@"+a.getPaths().size()));
        //  }
        Doc srci = formatPathIn(a.getPath().getCBar());
        for (Path pij : a.getPathsSet()) {
            src = src.sum(srci);
            dest = dest.sum(formatPathOut(pij));
        }
    }
    Doc incoDest = Doc.empty();
    for (Path pi : _incoDest) {
        incoDest = incoDest.sum(formatPathOut(pi));
    }
    return Resources.Error.multiPartStringError("IncoherentRedirectMapping", "Src", src.formatNewLinesAsList(), "Dest", dest.formatNewLinesAsList(), //"Ambiguities",ambig.formatNewLinesAsList(),
    "IncoherentSrc", incoSrc == null ? Doc.empty() : formatPathIn(incoSrc.getCBar()), "IncoherentDest", incoDest.formatNewLinesAsList());
}
Also used : PathPath(ast.Util.PathPath) PathSPath(ast.Util.PathSPath) Path(ast.Ast.Path) PathSPath(ast.Util.PathSPath) PathPath(ast.Util.PathPath) Doc(ast.Ast.Doc)

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