//----< depth first search from specific node >------------------------

        public void walk(CsNode <V, E> node)
        {
            // process this node

            gop.doNodeOp(node);
            node.visited = true;

            // visit children
            do
            {
                CsEdge <V, E> childEdge = node.getNextUnmarkedChild();
                if (childEdge == null)
                {
                    return;
                }
                else
                {
                    gop.doEdgeOp(childEdge.edgeValue);
                    walk(childEdge.targetNode);
                    if (node.hasUnmarkedChild() || showBackTrack)
                    {                         // popped back to predecessor node
                        gop.doNodeOp(node);   // more edges to visit so announce
                    }                         // location and next edge
                }
            } while (true);
        }
 //------------<build graph's nodes>--------------------------------
 public void BuildGraph(List <File> files)
 {
     foreach (File file in files)
     {
         string filename = file.Substring(file.LastIndexOf('\\') + 1);
         CsNode <string, string> node = new CsNode <string, string>(filename);
         csgraph.addNode(node);
     }
     if (csgraph.adjList.Count > 0)
     {
         csgraph.startNode = csgraph.adjList[0];
     }
 }
        //----< add child vertex and its associated edge value to vertex >-----

        public void addChild(CsNode <V, E> childNode, E edgeVal)
        {
            if (name == childNode.name)
            {
                return;
            }
            foreach (CsEdge <V, E> edge in children)
            {
                if (edge.targetNode.name == childNode.name)
                {
                    return;
                }
            }
            children.Add(new CsEdge <V, E>(childNode, edgeVal));
        }
        //----------------<Analyze dependency>---------------------------------------
        public void ConnectNode(TypeAnalysis typea, string fqf)
        {
            List <string>           namestore = new List <string>();
            string                  filename  = fqf.Substring(fqf.LastIndexOf('\\') + 1);
            CsNode <string, string> node      = csgraph.findNode(filename);
            Toker toker = new Toker();

            toker.doReturnComments = false;
            if (!toker.open(fqf))
            {
                Console.Write("\n can't open {0}\n", fqf);
            }
            //else
            //{
            //    Console.Write("\n  processing file: {0}\n", fqf);
            //}
            while (!toker.isDone())
            {
                Token tok = toker.getTok();
                if (tok == null)
                {
                    continue;
                }
                if (typea.typetable_.table.ContainsKey(tok))//the key exist in the type table.
                {
                    if (typea.typetable_.table[tok][0].namesp == "")
                    {
                        namestore.Add(tok);
                    }
                    else
                    {
                        List <TypeItem> list_it = typea.typetable_.table[tok];
                        foreach (TypeItem it in list_it)
                        {
                            if (namestore.Contains(it.namesp))
                            {
                                //connect the node
                                node.addChild(csgraph.findNode(it.file), "");
                            }
                        }
                    }
                }
            }
            toker.close();
        }
        //---------< Build Type Table >------------------------------------------------------
        public static void BuildTypeTable(string[] args, List <string> files, Repository repo)
        {
            BuildTypeAnalyzer builder = new BuildTypeAnalyzer(repo);
            Parser            parser  = builder.build();

            foreach (string file in files)
            {
                //Console.Write("\n  Processing file {0}", System.IO.Path.GetFileName(file));
                if (file.Contains("TemporaryGeneratedFile") || file.Contains("AssemblyInfo"))
                {
                    continue;
                }

                if (!repo.semi.open(file as string))
                {
                    Console.Write("\n  Can't open {0}\n\n", args[0]);
                    return;
                }


                try
                {
                    while (repo.semi.get().Count > 0)
                    {
                        parser.parse(repo.semi);
                    }
                }
                catch (Exception ex)
                {
                    Console.Write("\n\n  {0}\n", ex.Message);
                }

                repo.clearScopeStack();
                repo.semi.close();

                CsNode <FileNode, string> fileNode = new CsNode <FileNode, string>(repo.semi.filePath);
                fileNode.nodeValue = new FileNode(repo.semi.filePath);
                repo.nodeTable.Add(repo.semi.filePath, fileNode);
                repo.depGraph.addNode(repo.nodeTable[repo.semi.filePath]);
            }
        }
        public void TestGraph()
        {
            Console.Write("\n  Testing CsGraph class");
            Console.Write("\n =======================");

            CsNode <string, string> node1 = new CsNode <string, string>("node1");
            CsNode <string, string> node2 = new CsNode <string, string>("node2");
            CsNode <string, string> node3 = new CsNode <string, string>("node3");
            CsNode <string, string> node4 = new CsNode <string, string>("node4");
            CsNode <string, string> node5 = new CsNode <string, string>("node5");

            node1.addChild(node2, "edge12");
            node1.addChild(node3, "edge13");
            node2.addChild(node3, "edge23");
            node2.addChild(node4, "edge24");
            node3.addChild(node1, "edge31");
            node5.addChild(node1, "edge51");
            node5.addChild(node4, "edge54");

            CsGraph <string, string> graph = new CsGraph <string, string>("Fred");

            graph.addNode(node1);
            graph.addNode(node2);
            graph.addNode(node3);
            graph.addNode(node4);
            graph.addNode(node5);

            graph.startNode = node1;
            Console.Write("\n\n  starting walk at {0}", graph.startNode.name);
            Console.Write("\n  not showing backtracks");
            graph.walk();

            graph.startNode = node2;
            Console.Write("\n\n  starting walk at {0}", graph.startNode.name);
            graph.showBackTrack = true;
            Console.Write("\n  show backtracks");
            //graph.setOperation(new demoOperation());
            graph.walk();

            Console.Write("\n\n");
        }
 public CsEdge(CsNode <V, E> node, E value)
 {
     targetNode = node;
     edgeValue  = value;
 }
 override public bool doNodeOp(CsNode <string, string> node)
 {
     Console.Write("\n -- {0}", node.name);
     return(true);
 }
        //----< register an Operation with the graph >-------------------------

        /*public Operation<V, E> setOperation(Operation<V, E> newOp)
         * {
         *  Operation<V, E> temp = gop;
         *  gop = newOp;
         *  return temp;
         * }*/
        //----< add vertex to graph adjacency list >---------------------------

        public void addNode(CsNode <V, E> node)
        {
            adjList.Add(node);
        }
        //----< graph.walk() calls this on every node >------------------------

        virtual public bool doNodeOp(CsNode <V, E> node)
        {
            Console.Write("\n  {0}", node.ToString());
            return(true);
        }