コード例 #1
0
ファイル: Analyzer.cs プロジェクト: KodeFu/cse681
        //----< show formatted analysis output >-----------------
        static void showOutput()
        {
            Repository  rep   = Repository.getInstance();
            List <Elem> table = rep.locations;

            Console.WriteLine();

            Console.WriteLine(
                "  {0,13}  {1,24}  {2,5}  {3,5}  {4,5}  {5,5}  {6,5}",
                "category", "name", "loc", "cmplx", "cohsn", "coupl", "main"
                );
            Console.WriteLine(
                "  {0,13}  {1,24}  {2,5}  {3,5}  {4,5}  {5,5}  {6,5}",
                "--------", "----", "---", "-----", "-----", "-----", "-----"
                );

            foreach (Elem e in table)
            {
                bool isClass         = false;
                int  locValue        = optLOC ? optLOCCoefficient * (e.endLine - e.beginLine + 1) : 0;
                int  complexityValue = optComplexity ? optComplexityCoefficient * (e.endScopeCount - e.beginScopeCount + 1) : 0;
                int  couplingValue   = 0;
                int  cohesionValue   = 0;
                int  mainIndex       = 0;

                if (e.type == "class" || e.type == "struct")
                {
                    isClass = true;
                    CClassInfo classInfo = rep.parsedData.getClassInfo(e.name);
                    couplingValue = optCoupling ? optCouplingCoefficient * CCalculateMetrics.calculateCoupling(classInfo) : 0;
                    cohesionValue = optCohesion ? optCohesionCoefficient * CCalculateMetrics.calculateCohesion(classInfo) : 0;
                    mainIndex     = locValue + complexityValue + couplingValue + cohesionValue;

                    Console.WriteLine();
                }

                Console.WriteLine(
                    "  {0,13}  {1,24}  {2,5}  {3,5}  {4,5}  {5,5}  {6,5}",
                    e.type,
                    e.name,
                    optLOC ? locValue.ToString() : string.Empty,
                    optComplexity ? complexityValue.ToString() : string.Empty,
                    optCohesion ? (isClass ? cohesionValue.ToString() : string.Empty) : string.Empty,
                    optCoupling ? (isClass ? couplingValue.ToString() : string.Empty) : string.Empty,
                    isClass ? mainIndex.ToString() : string.Empty
                    );

                totalLOC        += locValue;
                totalComplexity += complexityValue;
                totalCohesion   += cohesionValue;
                totalCoupling   += couplingValue;
                totalMainIndex  += mainIndex;
            }
        }
コード例 #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");
        }