// subgraph.beh -- Subgraph calculation // $Id: subgraph.beh,v 1.6 2000/09/19 21:08:21 dougo Exp $ ClassGraph { (@ edu.neu.ccs.demeter.common.tg.ClassGraph ccg; @) } Program { /** Build a cyclic object from the class graph, using the tg package. */ void buildCyclicClassGraph() = allEdges { (@ edu.neu.ccs.demeter.common.tg.ClassGraph ccg; @) before ClassGraph (@ host.ccg = ccg = new edu.neu.ccs.demeter.common.tg.ClassGraph(); @) (@ ClassName source; @) before ClassDef (@ source = host.get_classname(); @) (@ ClassName dest; @) before { Part, Subclass, Superclass } (@ dest = host.get_classname(); @) after Part (@ PartName name = host.get_partname(); ccg.addConstructionEdge(source, name, dest); @) after Subclass (@ ccg.addAlternationEdge(source, dest); @) after Superclass (@ ccg.addInheritanceEdge(source, dest); @) } } StrategyGraph { /** Compute the traversal graph determined by this strategy in the class graph. Return null iff they are not compatible. */ TraversalGraph computeTraversalGraph(ClassGraph cg) to NameMap { (@ Dictionary nameMap = null; @) before NameMap (@ nameMap = host.get_dict(); @) after StrategyGraph (@ return_val = cg.ccg.computeTraversalGraph(host, nameMap); // TBD: check compatibility // For now, just sanity check... if (return_val.get_vertices().isEmpty()) return_val = null; @) } } ClassDef { void printTraversalEdges(TraversalGraph tg, PrintWriter out) to { ConstructionClass, AlternationClass, CommonKeyword, Part, Subclass, Superclass } { (@ ClassName source; @) before ClassDef (@ source = host.get_classname(); out.print(source + " "); @) before ConstructionClass (@ out.print("= "); @) (@ boolean need_bar; @) before AlternationClass (@ out.print(": "); need_bar = false; @) before CommonKeyword (@ out.print(host); @) (@ boolean in_opt; @) before OptionalPart (@ in_opt = true; @) after OptionalPart (@ in_opt = false; @) before Part (@ if (tg.hasConstructionEdge(source, host.get_partname(), host.get_classname())) { if (in_opt) out.print("[ "); out.print(host + " "); if (in_opt) out.print("] "); } @) before Subclass (@ if (tg.hasAlternationEdge(source, host.get_classname())) { if (need_bar) { out.print("| "); } else { need_bar = true; } out.print(host + " "); } @) before Superclass (@ if (tg.hasInheritanceEdge(source, host.get_classname())) { out.print("extends " + host); } @) after ClassDef (@ out.println("."); @) } }