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