import edu.neu.ccs.demeterf.ID; import edu.neu.ccs.demeterf.IDf; import edu.neu.ccs.demeterf.Traversal; import edu.neu.ccs.demeterf.control.EdgeControl; import edu.neu.ccs.demeterf.control.Edge; import edu.neu.ccs.demeter.Ident; public class Translate extends ID{ static class Fix extends IDf{ static Traversal trav = new Traversal(new Translate(), EdgeControl.builtIns(Ident.class, Type.class, EmptyList.class, SymMethExp.class, SymExp.class)); Exp apply(Exp e){ return trav.traverse(e); } MethodBody apply(DefCons c){ Def d = c.first; return new RevDef(d.exp, new RevDefRest(d.type, d.id, c.rest)); } } static Main fixExps(Main m){ return new Traversal(new Fix(), EdgeControl.builtIns(Exp.class)).traverse(m); } Exp combine(Exp h, Exp left, EmptyList el){ return left; } Exp combine(ConsList h, Exp left, EmptyList el){ return left; } Exp combine(ConjunctI h, Exp left, Exp right){ return new AndExp(left, right); } Exp combine(CompareI h, Exp left, Exp right){ return new LessExp(left, right); } Exp combine(FactorI h, Exp left, Exp right){ return new MultExp(left, right); } Exp combine(TermI h, Exp left, Exp right){ return new AddExp(left, right); } Exp combine(Negate h, Exp e){ return new NegExp(e); } Exp combine(IfExp h, Exp c, Exp t, Exp e){ return new IfExp(c, t, e); } Exp combine(MethCall h, Exp e, Meth m){ return new CallExp(e, m.meth, (ExpList)m.args); } Meth combine(Meth h, MethExp me, ExpList a){ return new Meth(me,a); } NewExp combine(NewExp h, Type t, FExpList args){ return new NewExp(t, args); } ExpList combine(ConsList c, Exp f, ExpList r){ return new ExpCons(f,r); } EmptyList combine(ExpEmpty e){ return e; } EmptyList combine(FExpEmpty e){ return new ExpEmpty(); } EmptyList combine(EmptyList e){ return e; } Exp combine(IntLit l){ return l; } Exp combine(BoolLit l){ return l; } Exp combine(ParenExp pe, Exp e){ return e; } }