// CTGsubgraph.beh // created: Binoy : 1998/2/11 // modified - binoy : June 10 '98 /** Uses the tg package(from Doug) to compute the subgraph. */ UGraph{ traversal toUEdgeVertex(TGCreateVisitor tg){ to {UConstEdge, UAltEdge, UExtendEdge, UImplEdge , UVertex}; } /** computes the subgraph input - StrategyGraph object output - true/false if success/failure Marks the UGraph object with tags corresponding to the subgraph */ boolean computeSubgraph(StrategyGraph sg) (@ TraversalGraph tg = new TraversalGraph(); initialize(); //create new hashtables hashinit(get_idToVertexTable(),get_idToEdgeTable()); //fill 'em makeTgGraph(tg); if(!markSubgraph(sg,tg)) return false; updateUGraph(); return true; @) void makeTgGraph(TraversalGraph g) = toUEdgeVertex(TGCreateVisitor); boolean markSubgraph(StrategyGraph sg, TraversalGraph tg) (@ tg.makeCopies(sg.size()); tg.addIntercopyEdges(sg); sg.markReachableForwardFromSources(tg); sg.markReachableBackwardFromTargets(tg); if (!sg.allSourcesAndTargetsMarked(tg)) { System.err.println("Error: No path found."); return false; } return true; @) void updateUGraph() = toVertEdge(TGUpdateVisitor); } TGCreateVisitor{ before UGraph (@ vtable = host.get_idToVertexTable(); @) before UConstEdge (@ TGEdge e= new TGCEdge(); UID uidSrc = host.get_fromVertex(); UID uidDest = host.get_toVertex(); UVertex vsrc = (UVertex)vtable.get(uidSrc); UVertex vdest = (UVertex)vtable.get(uidDest); //System.out.println("debug 1 " + vsrc.get_vertexname().get_name() + vdest.get_vertexname().get_name() ); ClassName csrc = new ClassName(vsrc.get_vertexname().get_name()); ClassName cdest = new ClassName(vdest.get_vertexname().get_name()); //System.out.println("debug 2"); TGVertex s = g.findVertex(csrc, true); //e.source //(adds it if not already there) TGVertex d = g.findVertex(cdest,true); //e.dest e.set_source(s); e.set_dest(d); //System.out.println("debug 2"); if(host.get_edgename() != null) ((TGCEdge)e).set_name(new PartName(host.get_edgename().get_name())); //(set name for const edge) else ((TGCEdge)e).set_name(new PartName(new Ident("_"))); //System.out.println("debug 3"); g.addEdge(e); vsrc.set_tgv(s); vdest.set_tgv(d); //System.out.println("debug 4"); host.set_tge((TGCEdge)e); //System.out.println("debug "); @) before {UAltEdge,UExtendEdge } (@ TGEdge e= new TGAEdge(); UID uidSrc = host.get_fromVertex(); UID uidDest = host.get_toVertex(); UVertex vsrc = (UVertex)vtable.get(uidSrc); UVertex vdest = (UVertex)vtable.get(uidDest); ClassName csrc = new ClassName(vsrc.get_vertexname().get_name()); ClassName cdest = new ClassName(vdest.get_vertexname().get_name()); TGVertex d = g.findVertex(csrc, true); //e.dest //(adds it if not already there) TGVertex s = g.findVertex(cdest,true); //e.source e.set_source(s); e.set_dest(d); g.addEdge(e); vsrc.set_tgv(s); vdest.set_tgv(d); host.set_tge((TGAEdge)e); @) before UImplEdge (@ TGEdge e= new TGIEdge(); UID uidSrc = host.get_fromVertex(); UID uidDest = host.get_toVertex(); UVertex vsrc = (UVertex)vtable.get(uidSrc); UVertex vdest = (UVertex)vtable.get(uidDest); ClassName csrc = new ClassName(vsrc.get_vertexname().get_name()); ClassName cdest = new ClassName(vdest.get_vertexname().get_name()); TGVertex s = g.findVertex(csrc, true); //e.source //(adds it if not already there) TGVertex d = g.findVertex(cdest,true); //e.dest e.set_source(s); //if error when apstudio implements this, e.set_dest(d); //interchange (s)rc & (d)est g.addEdge(e); vsrc.set_tgv(s); vdest.set_tgv(d); host.set_tge((TGIEdge)e); @) before UVertex (@ //want to prevent the possibility that there is a UVertex thats //not associated with any UEdge, and hence doesnt //get the initialised ClassName cthis = new ClassName(host.get_vertexname().get_name()); TGVertex s = g.findVertex(cthis , true); host.set_tgv(s); @) } TGUpdateVisitor{ before UVertex (@ // System.out.println("debug 1"); if(host.get_vdeco() == null){ // System.out.println("debug 1a"); host.set_vdeco(new Decorator()); // System.out.println("debug 1b"); } if(host.get_tgv() == null) System.out.println("how come no tgv for - " + host.get_vertexname().get_name()); if(host.get_tgv().is_in_trav()){ // System.out.println("debug 2"); host.get_vdeco().setMarked(3);//host.set tag } else{ // System.out.println("debug 3"); host.get_vdeco().setMarked(0);//host.reset tag } // System.out.println("debug 4"); host.set_tgv(null); @) before UConstEdge (@ if(host.get_edeco() == null) host.set_edeco(new Decorator()); if(host.get_tge().is_in_trav()){ host.get_edeco().setMarked(3);//host.set tag } else host.get_edeco().setMarked(0);//host.reset tag host.set_tge(null); @) before {UAltEdge,UExtendEdge} (@ if(host.get_edeco() == null) host.set_edeco(new Decorator()); if(host.get_tge().is_in_trav()){ host.get_edeco().setMarked(3);//host.set tag } else host.get_edeco().setMarked(0);//host.reset tag host.set_tge(null); @) before UImplEdge (@ if(host.get_edeco() == null) host.set_edeco(new Decorator()); if(host.get_tge().is_in_trav()){ host.get_edeco().setMarked(3);//host.set tag } else host.get_edeco().setMarked(0);//host.reset tag host.set_tge(null); @) }