// genuniversal.beh -- generate code for UniversalVisitor. // $Id: genuniversal.beh,v 1.4 2000/10/13 19:36:21 dougo Exp $ Program { /** Add a "UniversalVisitor" class to the set of class definitions. Don't call this until after buildClassDefTable()! */ void addUniversalVisitor(ClassName name) (@ addClassDef(ClassDef.parse("notparsed visitor " + name + " : .")); @) /** Generate the behavior file for UniversalVisitor. */ void generateUniversalVisitor(ClassName name, File file) = allParts { (@ boolean first = true; String all = ""; // the names of all classes and parts Hashtable partnames = new Hashtable(); Hashtable builtins = new Hashtable(); @) before Program (@ host.openOutputFile(file); @) (@ ClassName classname; @) around ClassDef (@ if (!host.isVisitor()) { classname = host.get_classname(); if (first) first = false; else all += ","; all += "\n " + classname; subtraversal.apply(); } @) before Part (@ if (host.isFinal() || host.isStatic() /* || host.isDerived() */) return; PartName name = host.get_partname(); ClassName type = host.get_classname(); all += ", -> " + classname + "," + name + "," + type; /* Bah. Fix this. if (type.isBuiltinType()) { String key = name + " " + type; if (builtins.get(key) == null) { builtins.put(key, key); all += ", -> *," + name + "," + type; } } else if (partnames.get(name) == null) { partnames.put(name, name); all += ", -> *," + name + ",*"; } */ @) after Program (@ Program.out.println( "// This file is automatically generated by DemeterJ.\n" +"\n" + name + " {\n" +" start " + Text.begin + " " + Text.end + "\n" +" before { " + all + "\n } " + Text.begin + " " + Text.end + "\n" /* +" around { " + all + "\n } " + Text.begin + " subtraversal.apply(); " + Text.end + "\n" */ +" after { " + all + "\n } " + Text.begin + " " + Text.end + "\n" +" finish " + Text.begin + " " + Text.end + "\n" +"}\n"); host.closeOutputFile(); @) } /** Generate a traversal that traverses every class and construction edge. */ void expandUniversalTraversal(String trav, ClassName vis) (@ TraversalParms parms = TraversalParms.parse("(" + vis + " _v_)"); makeTraversalMethods(new UniversalTraversalGraph(), new TraversalMethodName(trav + "_trv0"), parms, "_v_", false); @) } UniversalTraversalGraph { public boolean hasVertex(NameI name) (@ return true; @) public Enumeration vertices() (@ return Program.prog.classnames(); @) public boolean hasConstructionEdge(NameI source, NameI name, NameI dest) (@ return true; @) public boolean hasAlternationEdge(NameI source, NameI dest) (@ return true; @) public boolean hasInheritanceEdge(NameI source, NameI dest) (@ return true; @) }