/* This goes through the portals defined and sets up any undefined extends links. It does this by using the classgraph to find the closest ancestor that has a portal for each class. */ // still a bit unimplemented. RIDL { public static ClassName find_closest_superportal(ClassName cn, edu.neu.ccs.demeter.tools.generate.Program prog) (@ // start by finding the superclass edu.neu.ccs.demeter.tools.generate.ClassDef cd = prog.public_findClassDef(edu.neu.ccs.demeter.tools.generate.ClassName.parse(cn.toString())); if (cd==null) { return null; // As per counter-example found by John Sung -- extending external class // System.err.println("Failed to find a class def for portal "+cn); // System.exit(1); } edu.neu.ccs.demeter.tools.generate.ClassName cn2 = cd.public_get_superclass_name(); // cn2 is the superclass of the cn. if (cn2 == null) { // dbg(cn.toString()+" has no superclass"); return null; } else { // so we had a superclass ClassName cn3 = ClassName.parse(cn2.toString()); // dbg(cn.toString()+" has superclass "+cn3.toString()); Portal p = get_portal(cn3); // does it have a portal? if (p == null) { // no //dbg(cn3.toString()+" has no portal"); return find_closest_superportal(cn3,prog); } else { // yup it does. //dbg(cn3.toString()+" has a portal"); return cn3; // we're done } } @) public void makeinheritancelinks(edu.neu.ccs.demeter.tools.generate.Program prog) to Portal { /* The idea: at a portal, find the portal for the closest superclass and make thisportal extend that portal if no superportal exists, set the extends to RIDL_Runtime.RIDL_Object and remove the default from extendstoString We will overwrite any existing portal defintion. */ // (@ RIDL ridl; @) // before RIDL (@ ridl = host;@) before Portal (@ ClassName cn = RIDL.find_closest_superportal(host.get_classname(), prog); // cn is the closest superclass with a portal. Whatever value was assigned to extends in the input is // overwritten. if (cn == null) cn = ClassName.parse("RIDL_Runtime.RIDL_Object"); Extends ext = Extends.parse("subclasses "+cn.toString()); if (host.get_subclasses() != null) System.err.println("Portal "+host.get_classname().toString()+" had an explicit subclasses clause that was overwritten\n"+ "it used to be "+host.get_subclasses().toString()+" but now is "+ext.toString()); host.set_subclasses(ext); @) } }