import edu.neu.ccs.demeterf.ID; import edu.neu.ccs.demeterf.Traversal; import edu.neu.ccs.demeterf.control.EdgeControl; import edu.neu.ccs.demeter.Ident; // Create method Refs public class Methods{ static ClassMethList methEnv(ClassList cl) { return Methods.build(cl, new MethCollect(), Method.class); } static ConDescList conEnv(ClassList cl) { return Methods.build(cl, new ConCollect(), MethodList.class); } static T build(ClassList cl, ID collect, Class skip){ Traversal t = new Traversal(collect, EdgeControl.builtIns(skip, Constr.class, Ident.class, Type.class, FieldList.class, Extend.class)); return t.traverse(cl, 0); } } class MethCollect extends ID{ MethDescList combine(MethodDefs d, Constr c, MethDescList r){ return r; } MethDescList combine(ClassDecl c, Ident n, Extend e, FieldList f, MethDescList m){ return m; } ClassMethList combine(ClassEmpty cl){ return new ClassMethEmpty(); } ClassMethList combine(ClassCons cl, MethDescList f, ClassMethList r){ return r.push(new ClassMeth(""+cl.first.id, f)); } MethDesc apply(Method m){ return new MethDesc(""+m.id, new MethType(m.type, m.args.types()), m.args, m.body); } MethDescList combine(MethodCons e, MethDesc f, MethDescList r) { return new MethDescCons(f,r); } MethDescList combine(MethodEmpty e){ return new MethDescEmpty(); } } class ConCollect extends ID{ Type update(ClassDecl c, Object o){ return new UserT(c.id); } ConDesc combine(MethodDefs d, ConDesc c){ return c; } ConDesc combine(ClassDecl c, Ident n, Extend e, FieldList f, ConDesc d){ return d; } ConDescList combine(ClassEmpty cl){ return new ConDescEmpty(); } ConDescList combine(ClassCons cl, ConDesc f, ConDescList r){ return r.push(f); } ConDesc apply(Constr c, Type n){ if(!c.id.toString().equals(""+n)) throw new TransErr("Constructor/ClassName Mismatch!!"); return new ConDesc(""+n, new MethType(n, c.args.types()), ValueList.nulls(c.args.length()), c.args, c.body); } }