예제 #1
0
        public void ModifyGraph()
        {
            DirectedGraphImpl <string> gr = CreateAcyclicGraph();

            gr.AddNode("3");
            gr.AddEdge("0", "3");
            gr.AddEdge("1", "3");

            gr.RemoveEdge("1", "2");

            string sExp = "(0 s:(1 2 3 ) p:( )) (1 s:(3 ) p:( 0 2 )) (2 s:(1 ) p:( 0 )) (3 s:() p:( 0 1 )) ";

            string s = DumpGraph(gr);

            Assert.AreEqual(sExp, s);

            gr.RemoveEdge("2", "1");
            gr.RemoveEdge("0", "1");
            gr.RemoveEdge("0", "2");

            sExp = "(0 s:(3 ) p:( )) (1 s:(3 ) p:( )) (2 s:() p:( )) (3 s:() p:( 0 1 )) ";

            s = DumpGraph(gr);
            Assert.AreEqual(sExp, s);
        }
예제 #2
0
        public void PostOrderGraph2()
        {
            DirectedGraphImpl <string> graph = new DirectedGraphImpl <string>();

            graph.AddNode("a");
            graph.AddNode("b");
            graph.AddEdge("a", "a");
            graph.AddEdge("a", "b");
            DumpPostOrderIterator("a", CreateGraphIterator <string>(graph));
            Assert.AreEqual("b,a", sb.ToString());
        }
예제 #3
0
		private DirectedGraphImpl<string> CreateAcyclicGraph()
		{
			DirectedGraphImpl<string> gr = new DirectedGraphImpl<string>();
			gr.AddNode("0");
			gr.AddNode("1");
			gr.AddNode("2");

			gr.AddEdge("0", "1");
			gr.AddEdge("0", "2");
			gr.AddEdge("1", "2");
			gr.AddEdge("2", "1");
		
			return gr;
		}
예제 #4
0
		private DirectedGraphImpl<string> CreateAcyclicGraph()
		{
			DirectedGraphImpl<string> gr = new DirectedGraphImpl<string>();
			gr.AddNode("0");
			gr.AddNode("1");
			gr.AddNode("2");

			gr.AddEdge("0", "1");
			gr.AddEdge("0", "2");
			gr.AddEdge("1", "2");
			gr.AddEdge("2", "1");
		
			return gr;
		}
예제 #5
0
        private DerivedGraph BuildNextOrderGraph(DerivedGraph gr)
        {
            DirectedGraph <StructureNode> newGraph = new DirectedGraphImpl <StructureNode>();
            StructureNode newEntry = gr.Intervals[0];

            foreach (Interval interval in gr.Intervals)
            {
                newGraph.Nodes.Add(interval);
            }

            foreach (Interval interval in gr.Intervals)
            {
                foreach (StructureNode node in interval.Nodes)
                {
                    foreach (StructureNode succ in gr.Graph.Successors(node))
                    {
                        if (succ.Interval != interval && !newGraph.ContainsEdge(interval, succ.Interval))
                        {
                            newGraph.AddEdge(interval, succ.Interval);
                        }
                    }
                }
            }
            return(new DerivedGraph(newGraph, newEntry, ib.BuildIntervals(newGraph, newEntry)));
        }
예제 #6
0
파일: CallGraph.cs 프로젝트: smx-smx/reko
        public void AddEdge(Statement stmCaller, Procedure callee)
        {
            graphProcs.AddNode(stmCaller.Block.Procedure);
            graphProcs.AddNode(callee);
            graphProcs.AddEdge(stmCaller.Block.Procedure, callee);

            graphStms.AddNode(stmCaller);
            graphStms.AddNode(callee);
            graphStms.AddEdge(stmCaller, callee);
        }
예제 #7
0
        public void EdgeCountAfterAdd()
        {
            DirectedGraphImpl <string> gr = new DirectedGraphImpl <string>();

            gr.AddNode("a");
            gr.AddNode("b");
            Assert.AreEqual(0, gr.Successors("a").Count);
            gr.AddEdge("a", "b");
            Assert.AreEqual(1, gr.Successors("a").Count);
            Assert.AreEqual(1, gr.Predecessors("b").Count);
        }
예제 #8
0
        public void TwoItems()
        {
            graph.AddNode("b");
            graph.AddNode("a");
            graph.AddEdge("b", "a");

            CompileTest(graph, "b");
            Assert.AreEqual("b", pdg.ImmediateDominator("a"));
            Assert.IsNull(pdg.ImmediateDominator("b"));
        }
예제 #9
0
 public void EdgeCountAfterRemove()
 {
     DirectedGraphImpl<string> gr = new DirectedGraphImpl<string>();
     gr.AddNode("a");
     gr.AddNode("b");
     Assert.AreEqual(0, gr.Successors("a").Count);
     gr.AddEdge("a", "b");
     gr.RemoveEdge("a", "b");
     Assert.AreEqual(0, gr.Successors("a").Count);
     Assert.AreEqual(0, gr.Predecessors("b").Count);
 }