Search in sources :

Example 1 with Doc

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

the class MakeMethod method addMethod.

public static ClassB addMethod(ClassB _lib, List<Ast.C> path, MethodSelector ms, String mdfs, int excNumber) {
    Errors42.checkExistsPathMethod(_lib, path, Optional.empty());
    ClassB innerLib = _lib.getClassB(path);
    String[] _mdfs = mdfs.split(" ");
    assert _mdfs.length == ms.getNames().size() + 2;
    List<String> nc = new ArrayList<>();
    Type retT = new Type(Mdf.valueOf(_mdfs[1]), Path.outer(0, Arrays.asList(C.of("$0"))), Doc.empty());
    nc.add("$0");
    List<Type> ts = new ArrayList<>();
    List<Doc> docs = new ArrayList<>();
    int count = 1;
    for (String n : ms.getNames()) {
        String cn = "$" + count;
        ts.add(new Type(Mdf.valueOf(_mdfs[count + 1]), Path.outer(0, Arrays.asList(C.of(cn))), Doc.empty()));
        nc.add(cn);
        count++;
    }
    List<Path> exceptions = new ArrayList<>();
    for (int i = 0; i < excNumber; i++) {
        String cn = "$" + count++;
        exceptions.add(Path.outer(0, Arrays.asList(C.of(cn))));
        nc.add(cn);
    }
    MethodType mt = new MethodType(false, Mdf.valueOf(_mdfs[0]), ts, retT, Map.of(pi -> pi.toImmNT(), exceptions));
    MethodWithType mwt = new MethodWithType(Doc.empty(), ms, mt, Optional.empty(), innerLib.getP());
    Optional<Member> optM = Functions.getIfInDom(innerLib.getMs(), ms);
    if (optM.isPresent()) {
        throw Errors42.errorMethodClash(path, mwt, optM.get(), false, Collections.emptyList(), false, false, false);
    }
    ClassB emptyCb = ClassB.membersClass(Collections.emptyList(), innerLib.getP(), innerLib.getPhase());
    return _lib.onClassNavigateToPathAndDo(path, cbi -> {
        List<Member> mem = new ArrayList<>(cbi.getMs());
        mem.add(mwt);
        for (String s : nc) {
            mem.add(new NestedClass(Doc.empty(), C.of(s), emptyCb, cbi.getP()));
        }
        return cbi.withMs(mem);
    });
}
Also used : Path(ast.Ast.Path) Stage(ast.Ast.Stage) Arrays(java.util.Arrays) Program(programReduction.Program) Ast(ast.Ast) Path(ast.Ast.Path) Map(tools.Map) Doc(ast.Ast.Doc) Type(ast.Ast.Type) MethodType(ast.Ast.MethodType) MethodSelector(ast.Ast.MethodSelector) Functions(auxiliaryGrammar.Functions) ArrayList(java.util.ArrayList) List(java.util.List) ClassB(ast.ExpCore.ClassB) Optional(java.util.Optional) C(ast.Ast.C) Collections(java.util.Collections) Mdf(ast.Ast.Mdf) MethodType(ast.Ast.MethodType) ArrayList(java.util.ArrayList) Type(ast.Ast.Type) MethodType(ast.Ast.MethodType) Doc(ast.Ast.Doc) ClassB(ast.ExpCore.ClassB)

Example 2 with Doc

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

the class ToAst method visitUsing.

@Override
public Expression visitUsing(UsingContext ctx) {
    Path path = Ast.Path.sugarParse(nameU(ctx.Path()));
    Expression inner = ctx.eTop().accept(this);
    String name = nameL(ctx.mCall().m());
    Parameters parameters = this.parseMParameters(ctx.mCall().round().ps());
    Doc docs = parseDoc(ctx.mCall().round().docsOpt());
    return new Expression.Using(path, name, docs, parameters, inner);
}
Also used : Path(ast.Ast.Path) Parameters(ast.Ast.Parameters) Expression(ast.Expression) Doc(ast.Ast.Doc)

Example 3 with Doc

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

the class InjectionOnCore method visit.

public ExpCore visit(Expression.ClassB s) {
    Doc doc1 = s.getDoc1();
    List<Ast.Type> supertypes = s.getSupertypes();
    boolean isInterface = false;
    if (s.getH() instanceof Ast.ConcreteHeader) {
        throw Assertions.codeNotReachable();
    }
    if (s.getH() instanceof Ast.InterfaceHeader) {
        isInterface = true;
    }
    List<Member> members = new ArrayList<>();
    for (ast.Expression.ClassB.Member mi : s.getMs()) {
        members.add(mi.match(m -> new ClassB.NestedClass(m.getDoc(), m.getName(), lift(m.getInner()), m.getP()), m -> new ClassB.MethodImplemented(m.getDoc(), m.getS(), lift(m.getInner()), m.getP()), m -> {
            Doc mdoc = m.getDoc();
            Ast.MethodSelector ms = m.getMs();
            MethodType mt = m.getMt();
            return new ClassB.MethodWithType(mdoc, ms, mt, lift(m.getInner()), m.getP());
        }));
    }
    ClassB result = new ClassB(doc1, isInterface, supertypes, members, s.getP(), Phase.None, 0);
    return result;
}
Also used : Ast(ast.Ast) Path(ast.Ast.Path) Catch(ast.Expression.Catch) Match(tools.Match) Doc(ast.Ast.Doc) Type(ast.Ast.Type) Phase(ast.ExpCore.ClassB.Phase) Assertions(tools.Assertions) MethodType(ast.Ast.MethodType) ExpCore(ast.ExpCore) Member(ast.ExpCore.ClassB.Member) MethodSelector(ast.Ast.MethodSelector) Block(ast.ExpCore.Block) Expression(ast.Expression) WalkBy(ast.Expression.WalkBy) ArrayList(java.util.ArrayList) List(java.util.List) SignalKind(ast.Ast.SignalKind) ContextId(ast.Expression.ContextId) Position(ast.Ast.Position) ClassReuse(ast.Expression.ClassReuse) Optional(java.util.Optional) Visitor(sugarVisitors.Visitor) Collections(java.util.Collections) MethodType(ast.Ast.MethodType) MethodSelector(ast.Ast.MethodSelector) ArrayList(java.util.ArrayList) Type(ast.Ast.Type) MethodType(ast.Ast.MethodType) Doc(ast.Ast.Doc) Member(ast.ExpCore.ClassB.Member)

Example 4 with Doc

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

the class InjectionOnCore method visit.

public ExpCore visit(Expression.MCall s) {
    assert !s.getPs().getE().isPresent() : s;
    ExpCore receiver = s.getReceiver().accept(this);
    String name = s.getName();
    Doc doc = s.getDoc();
    List<String> xs = s.getPs().getXs();
    List<ExpCore> es = new ArrayList<>();
    for (Expression e : s.getPs().getEs()) {
        es.add(e.accept(this));
    }
    return new MCall(receiver, MethodSelector.of(name, xs), doc, es, s.getP());
}
Also used : ExpCore(ast.ExpCore) Expression(ast.Expression) ArrayList(java.util.ArrayList) Doc(ast.Ast.Doc)

Example 5 with Doc

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

the class InjectionOnSugar method visit.

@Override
public Expression visit(ClassB s) {
    Doc doc1 = s.getDoc1();
    Header h = (s.isInterface()) ? new Ast.InterfaceHeader() : new Ast.TraitHeader();
    List<Type> supertypes = s.getSupertypes();
    List<Member> members = new ArrayList<>();
    for (ast.ExpCore.ClassB.Member mi : s.getMs()) {
        members.add(mi.match(nc -> new Expression.ClassB.NestedClass(nc.getDoc(), nc.getName(), lift(nc.getInner()), nc.getP()), mimpl -> new Expression.ClassB.MethodImplemented(mimpl.getDoc(), mimpl.getS(), lift(mimpl.getInner()), mimpl.getP()), mwt -> {
            Doc idoc = mwt.getDoc();
            MethodSelector is = mwt.getMs();
            MethodType mt = mwt.getMt();
            return new Expression.ClassB.MethodWithType(idoc, is, mt, lift(mwt.get_inner()), mwt.getP());
        }));
    }
    return new Expression.ClassB(doc1, h, Collections.emptyList(), supertypes, members, s.getP());
}
Also used : VarDecXE(ast.Ast.VarDecXE) UpdateVar(ast.ExpCore.UpdateVar) Ast(ast.Ast) Header(ast.Ast.Header) MCall(ast.ExpCore.MCall) Type(ast.Ast.Type) Member(ast.Expression.ClassB.Member) WellFormedness(auxiliaryGrammar.WellFormedness) MethodType(ast.Ast.MethodType) Loop(ast.ExpCore.Loop) MethodSelector(ast.Ast.MethodSelector) ArrayList(java.util.ArrayList) Visitor(coreVisitors.Visitor) ClassB(ast.ExpCore.ClassB) WalkBy(ast.ExpCore.WalkBy) Mdf(ast.Ast.Mdf) X(ast.ExpCore.X) VarDec(ast.Ast.VarDec) Path(ast.Ast.Path) Signal(ast.ExpCore.Signal) Match(tools.Match) Doc(ast.Ast.Doc) ExpCore._void(ast.ExpCore._void) ExpCore(ast.ExpCore) Block(ast.ExpCore.Block) Expression(ast.Expression) List(java.util.List) Position(ast.Ast.Position) Using(ast.ExpCore.Using) Optional(java.util.Optional) Collections(java.util.Collections) MethodType(ast.Ast.MethodType) MethodSelector(ast.Ast.MethodSelector) Ast(ast.Ast) ArrayList(java.util.ArrayList) Type(ast.Ast.Type) MethodType(ast.Ast.MethodType) Header(ast.Ast.Header) Expression(ast.Expression) Doc(ast.Ast.Doc) Member(ast.Expression.ClassB.Member) 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