void TypeAnalys(List <string> files, string displaytokenfile, bool check)
        {
            if (check)
            {
                Console.Write("\n  Type Analysis");
                Console.Write("\n ---------------");

                Console.Write(
                    "\n  {0,10}  {1,25}  {2,25}",
                    "category", "name", "file"
                    );
                Console.Write(
                    "\n  {0,10}  {1,25}  {2,25}",
                    "--------", "----", "----"
                    );
            }
            ITokenCollection  semi    = Factory.create();
            BuildTypeAnalyzer builder = new BuildTypeAnalyzer(semi);
            Parser            parser  = builder.build();
            Repository        repo    = Repository.getInstance();

            foreach (string file in files)
            {
                if (file.Contains("TemporaryGeneratedFile"))
                {
                    continue;
                }
                if (!semi.open(file as string))
                {
                    //Console.Write("\n  Can't open {0}\n\n", args[0]);
                    continue;
                }

                repo.currentFile = file;
                repo.locations.Clear();

                try
                {
                    while (semi.get().Count > 0)
                    {
                        parser.parse(semi);
                    }
                }
                catch (Exception ex)
                {
                    Console.Write("\n\n  {0}\n", ex.Message);
                }
                Repository  rep   = Repository.getInstance();
                List <Elem> table = rep.locations;
                if (check)
                {
                    Display.showMetricsTable(table);
                    Console.Write("\n");
                    TypeAnalysWrittenFile(displaytokenfile, table);
                }
                semi.close();
            }
        }
        //----< Test Stub >--------------------------------------------------

#if (TEST_PARSER)
        static void Main(string[] args)
        {
            TypeTable tb = new TypeTable();

            Console.Write("\n  Demonstrating Parser");
            Console.Write("\n ======================\n");

            ShowCommandLine(args);

            List <string> files = TestParser.ProcessCommandline(args);

            foreach (string file in files)
            {
                Console.Write("\n  Processing file {0}\n", System.IO.Path.GetFileName(file));

                ITokenCollection semi = Factory.create();
                //semi.displayNewLines = false;
                if (!semi.open(file as string))
                {
                    Console.Write("\n  Can't open {0}\n\n", args[0]);
                    return;
                }

                Console.Write("\n  Type and Function Analysis");
                Console.Write("\n ----------------------------");
                string name = "";
                for (int i = file.Length - 1; file[i] != '/' && file[i] != '\\'; --i)
                {
                    name = file[i] + name;
                }
                Console.WriteLine("FILE:    {0}", name);
                BuildTypeAnalyzer builder = new BuildTypeAnalyzer(semi, name);
                Parser            parser  = builder.build();
                try
                {
                    while (semi.get().Count > 0)
                    {
                        parser.parse(semi);
                    }
                }
                catch (Exception ex)
                {
                    Console.Write("\n\n  {0}\n", ex.Message);
                }
                Repository  rep   = Repository.getInstance();
                List <Elem> table = rep.locations;
                Display.showMetricsTable(table);
                Console.Write("\n");

                semi.close();
            }
            Console.Write("\n\n");

            tb.print();
            Console.ReadLine();
        }
Exemplo n.º 3
0
        //----< Test Stub >--------------------------------------------------

#if (TEST_PARSER)
        private static void Main(string[] args)
        {
            Console.Write("\n  Demonstrating Parser");
            Console.Write("\n ======================\n");

            ShowCommandLine(args);
            var files = ProcessCommandline(args);

            var repo    = Repository.getInstance();
            var semi    = Factory.create();
            var builder = new BuildTypeAnalyzer(semi);
            var parser  = builder.build();

            foreach (var file in files)
            {
                Console.Write("\n  Processing file {0}\n", Path.GetFileName(file));
                repo.currentFile = file;

                //ITokenCollection semi = Factory.create();
                //semi.displayNewLines = false;
                if (!semi.open(file))
                {
                    Console.Write("\n  Can't open {0}\n\n", args[0]);
                    return;
                }

                Console.Write("\n  Type and Function Analysis");
                Console.Write("\n ----------------------------");

                //BuildCodeAnalyzer builder = new BuildCodeAnalyzer(semi);
                //Parser parser = builder.build();
                //repo.currentFile = file;

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

                var rep   = Repository.getInstance();
                var table = rep.locations;
                Display.showMetricsTable(table);
                Console.Write("\n");

                semi.close();
            }

            Console.Write("\n\n");
        }
        //----< build type table by parsing files for type defs >--------

        public void typeAnalysis(List <string> files)
        {
            Console.Write("\n  Type Analysis");
            Console.Write("\n ---------------------");

            Console.Write(
                "\n  {0,10}  {1,23}  {2,30}",
                "category", "name", "file"
                );
            Console.Write(
                "\n  {0,10}  {1,30}  {2,30}",
                "--------------", "---------------------", "-----------------------"
                );

            var semi    = Factory.create();
            var builder = new BuildTypeAnalyzer(semi);
            var parser  = builder.build();
            var repo    = Repository.getInstance();

            foreach (var file in files)
            {
                if (file.Contains("TemporaryGeneratedFile"))
                {
                    continue;
                }
                if (!semi.open(file))
                {
                    continue;
                }

                repo.currentFile = file;
                repo.locations.Clear();

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

                var rep   = Repository.getInstance();
                var table = rep.locations;
                Display.showMetricsTable(table);
                Console.Write("\n");

                semi.close();
            }
        }
        public void displaytok(List <string> arguments, string displaytokenfile)
        {
            ITokenCollection  semi    = Factory.create();
            BuildTypeAnalyzer builder = new BuildTypeAnalyzer(semi);
            Parser            parser  = builder.build();
            Repository        repo    = Repository.getInstance();

            foreach (string file in arguments)
            {
                List <string> Tokencollection = new List <string>();
                if (file.Contains("TemporaryGeneratedFile"))
                {
                    continue;
                }
                if (!semi.open(file as string))
                {
                    //Console.Write("\n  Can't open {0}\n\n", args[0]);
                    continue;
                }

                repo.currentFile = file;
                repo.locations.Clear();

                try
                {
                    while (semi.get().Count > 0)
                    {
                        foreach (var toker in semi)
                        {
                            Console.WriteLine(toker);
                            Tokencollection.Add(toker);
                        }
                    }
                    parser.parse(semi);
                }
                catch (Exception ex)
                {
                    Console.Write("\n\n  {0}\n", ex.Message);
                }
                WriteFile(displaytokenfile, Tokencollection);
            }
        }
        public void TokResultFile(List <string> arguments, string tokresult)
        {
            ITokenCollection  semi    = Factory.create();
            BuildTypeAnalyzer builder = new BuildTypeAnalyzer(semi);
            Parser            parser  = builder.build();
            Repository        repo    = Repository.getInstance();

            foreach (string file in arguments)
            {
                List <string> ListofToks = new List <string>();
                if (file.Contains("TemporaryGeneratedFile"))
                {
                    continue;
                }
                if (!semi.open(file as string))
                {
                    //Console.Write("\n  Can't open {0}\n\n", args[0]);
                    continue;
                }

                repo.currentFile = file;
                repo.locations.Clear();

                try
                {
                    while (semi.get().Count > 0)
                    {
                        foreach (var tok in semi)
                        {
                            Console.WriteLine(tok);
                            ListofToks.Add(tok);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.Write("\n\n  {0}\n", ex.Message);
                }
                showalltoks(tokresult, ListofToks);
            }
        }