Beispiel #1
0
        //----< Test Stub >--------------------------------------------------

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

            ShowCommandLine(args);

            //THIS RETURNS A LIST OF FILES THAT THE USER PASSED IN
            List <string> files = TestParser.ProcessCommandline(args);

            for (int i = 0; i < files.Count; i++)
            {
                Console.Write(files[i] + "\n");
            }

            //sh - preprocess all user input files to get all user defined types
            UserType.parseUserDefinedTypes(files);
            HashSet <string> definedSet = UserType.getUserDefinedSet();

            Console.Write("Parser size of definedset" + definedSet.Count.ToString());

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

                CSsemi.CSemiExp semi = new CSsemi.CSemiExp();
                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 ----------------------------");

                BuildCodeAnalyzer builder = new BuildCodeAnalyzer(semi);
                Parser            parser  = builder.build();

                try
                {
                    while (semi.getSemi())
                    {
                        parser.parse(semi);
                    }
                    Console.Write("\n  locations table contains:");
                }
                catch (Exception ex)
                {
                    Console.Write("\n\n  {0}\n", ex.Message);
                }

                //all data is stored in table object
                Repository  rep   = Repository.getInstance();
                List <Elem> table = rep.locations;
                Console.Write(
                    "\n  {0,10}, {1,25}, {2,5}, {3,5}, {4,5}, {5,5}, {6,5}, {7,5}, {8,10}, {9, 10}, {10,6}",
                    "category", "name", "bLine", "eLine", "bScop", "eScop", "size", "cmplx", "coupling", "cohesion", "M-Index"
                    );
                Console.Write(
                    "\n  {0,10}, {1,25}, {2,5}, {3,5}, {4,5}, {5,5}, {6,5}, {7,5}, {8,10}, {9,10}, {10,6}",
                    "--------", "----", "-----", "-----", "-----", "-----", "----", "-----", "--------", "--------", "-------"
                    );
                foreach (Elem e in table)
                {
                    if (e.type == "class" || e.type == "struct")
                    {
                        Console.Write("\n");

                        //get the maintainibility index
                        e.mIndex = getMaintainibilityIndex(e);

                        Console.Write(
                            "\n  {0,10}, {1,25}, {2,5}, {3,5}, {4,5}, {5,5}, {6,5}, {7,5}, {8,10}, {9,10}, {10,6}",
                            e.type, e.name, e.beginLine, e.endLine, e.beginScopeCount, e.endScopeCount + 1,
                            e.endLine - e.beginLine + 1, e.endScopeCount - e.beginScopeCount + 1, e.coupling, e.cohesion, e.mIndex
                            );
                    }
                    else
                    {
                        Console.Write(
                            "\n  {0,10}, {1,25}, {2,5}, {3,5}, {4,5}, {5,5}, {6,5}, {7,5}, {8,10}, {9,10}",
                            e.type, e.name, e.beginLine, e.endLine, e.beginScopeCount, e.endScopeCount + 1,
                            e.endLine - e.beginLine + 1, e.endScopeCount - e.beginScopeCount + 1, e.coupling, e.cohesion
                            );
                    }
                }

                Console.Write("\n\n");

                semi.close();
            }
            Console.Write("\n\n");
        }
Beispiel #2
0
        //----< Test Stub >--------------------------------------------------

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

            ShowCommandLine(args);

            Parser            parser;
            List <string>     files   = TestParser.ProcessCommandline(args);
            BuildCodeAnalyzer builder = null;

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

                CSsemi.CSemiExp semi = new CSsemi.CSemiExp();
                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 ----------------------------");

                builder = new BuildCodeAnalyzer(semi);
                parser  = builder.build(true);

                try
                {
                    while (semi.getSemi())
                    {
                        parser.parse(semi);
                    }
                    Console.Write("\n  locations table contains:");
                }
                catch (Exception ex)
                {
                    Console.Write("\n\n  {0}\n", ex.Message);
                }

                Repository  rep   = Repository.getInstance();
                List <Elem> table = rep.locations;
                Console.Write(
                    "\n  {0,10}, {1,25}, {2,5}, {3,5}, {4,5}, {5,5}, {6,5}, {7,5}",
                    "category", "name", "bLine", "eLine", "bScop", "eScop", "size", "cmplx"
                    );
                Console.Write(
                    "\n  {0,10}, {1,25}, {2,5}, {3,5}, {4,5}, {5,5}, {6,5}, {7,5}",
                    "--------", "----", "-----", "-----", "-----", "-----", "----", "-----"
                    );
                foreach (Elem e in table)
                {
                    if (e.type == "class" || e.type == "struct")
                    {
                        Console.Write("\n");
                    }
                    Console.Write(
                        "\n  {0,10}, {1,25}, {2,5}, {3,5}, {4,5}, {5,5}, {6,5}, {7,5}",
                        e.type, e.name, e.beginLine, e.endLine, e.beginScopeCount, e.endScopeCount + 1,
                        e.endLine - e.beginLine + 1, e.endScopeCount - e.beginScopeCount + 1
                        );
                }

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



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

                CSsemi.CSemiExp semi = new CSsemi.CSemiExp();
                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 ----------------------------");

                builder = new BuildCodeAnalyzer(semi);
                parser  = builder.build(false);

                try
                {
                    while (semi.getSemi())
                    {
                        parser.parse(semi);
                    }
                    Console.Write("\n  locations table contains:");
                }
                catch (Exception ex)
                {
                    Console.Write("\n\n  {0}\n", ex.Message);
                }

                Repository  rep   = Repository.getInstance();
                List <Elem> table = rep.locations;
                Console.Write(
                    "\n  {0,10}, {1,25}, {2,5}, {3,5}, {4,5}, {5,5}, {6,5}, {7,5}",
                    "category", "name", "bLine", "eLine", "bScop", "eScop", "size", "cmplx"
                    );
                Console.Write(
                    "\n  {0,10}, {1,25}, {2,5}, {3,5}, {4,5}, {5,5}, {6,5}, {7,5}",
                    "--------", "----", "-----", "-----", "-----", "-----", "----", "-----"
                    );
                foreach (Elem e in table)
                {
                    if (e.type == "class" || e.type == "struct")
                    {
                        Console.Write("\n");
                    }

                    Console.Write(
                        "\n  {0,10}, {1,25}, {2,5}, {3,5}, {4,5}, {5,5}, {6,5}, {7,5}",
                        e.type, e.name, e.beginLine, e.endLine, e.beginScopeCount, e.endScopeCount + 1,
                        e.endLine - e.beginLine + 1, e.endScopeCount - e.beginScopeCount + 1
                        );

                    if (e.type == "class" || e.type == "struct")
                    {
                        CClassInfo classInfo = rep.parsedData.getClassInfo(e.name);
                        Console.WriteLine("Coupling: {0}", CCalculateMetrics.calculateCoupling(classInfo));
                        Console.WriteLine("Cohesion: {0}", CCalculateMetrics.calculateCohesion(classInfo));
                    }
                }

                Console.Write("\n");
                semi.close();
            }
            Console.Write("\n\n");
        }
        public void show_result(string[] args)
        {
            Console.WriteLine("below is the all processing files : ");
            Console.WriteLine("\n");
            foreach (var csfile in args)
            {
                Console.WriteLine(csfile);
            }
            Console.Write("\n ======================\n");
            TestParser tp = new TestParser();

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

                CSsemi.CSemiExp semi = new CSsemi.CSemiExp();
                semi.displayNewLines = false;
                if (!semi.open(file as string))
                {
                    Console.Write("\n  Can't open {0}\n\n", args[0]);
                }
                Console.Write("\n  Type and Function Analysis");
                Console.Write("\n ----------------------------");
                BuildCodeAnalyzer builder = new BuildCodeAnalyzer(semi);
                Parser            parser  = builder.build();
                try
                {
                    while (semi.getSemi())
                    {
                        parser.parse(semi);
                    }
                    Console.Write("\n  locations table contains:");
                }
                catch (Exception ex)
                {
                    Console.Write("\n\n  {0}\n", ex.Message);
                }
                Repository  rep   = Repository.getInstance();
                List <Elem> table = rep.locations;
                Console.Write(
                    "\n  {0,10}, {1,25}, {2,5}, {3,5}, {4,5}, {5,5}, {6,5}, {7,5}",
                    "category", "name", "bLine", "eLine", "bScop", "eScop", "size", "cmplx"
                    );
                Console.Write(
                    "\n  {0,10}, {1,25}, {2,5}, {3,5}, {4,5}, {5,5}, {6,5}, {7,5}",
                    "--------", "----", "-----", "-----", "-----", "-----", "----", "-----"
                    );
                foreach (Elem e in table)
                {
                    if (e.type == "class" || e.type == "struct")
                    {
                        Console.Write("\n");
                    }
                    Console.Write(
                        "\n  {0,10}, {1,25}, {2,5}, {3,5}, {4,5}, {5,5}, {6,5}, {7,5}",
                        e.type, e.name, e.beginLine, e.endLine, e.beginScopeCount, e.endScopeCount + 1,
                        e.endLine - e.beginLine + 1, e.endScopeCount - e.beginScopeCount + 1
                        );
                }
                Console.Write("\n");
                semi.close();
            }
        }