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);
});
}
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);
}
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;
}
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());
}
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());
}
Aggregations