Пример #1
0
    //----< Test Stub >--------------------------------------------------

#if(TEST_PARSER)

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

      //Repository rep_global;
      //List<Elem> table_global;

      ShowCommandLine(args);

      List<string> files = TestParser.ProcessCommandline(args);
      foreach (object file in files)
      {
        Console.Write("\n  Processing file {0}\n", file as string);

        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 ----------------------------\n");

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

        try
        {
          while (semi.getSemi())
            parser.parse(semi);
          Console.Write("\n\n  locations table contains:");
        }
        catch (Exception ex)
        {
          Console.Write("\n\n  {0}\n", ex.Message);
        }
        Repository rep = Repository.getInstance();
        List<Elem> table = rep.locations;
////////
        ComplexityAnalyzer comxAna = new ComplexityAnalyzer();
        foreach (Elem e in table)
        {
            if (e.type == "function")
                e.complexity = comxAna.complexityAnalysis(e, file);
        }

        RelationshipAnalyzer relshAna = new RelationshipAnalyzer();
        foreach (Elem e in table)
        {
            if (e.type == "class" || e.type == "struct" || e.type == "interface")
                relshAna.relationshipanalysis(e, file);

        }
/////////
        foreach (Elem e in table)
        {
          Console.Write("\n  {0,10}, {1,25}, {2,5}, {3,5}, {4,50}", e.type, e.name, e.end-e.begin+1, e.complexity, e.relationship);
        }
        Console.WriteLine();
        Console.Write("\n\n  That's all folks!\n\n");
        semi.close();
      }
    }
        // function that parse each file, detect class relationship, function size and complexity
        static void secondAnalysis(string[] files, List<Elem> fileSetInfo, List<Elem> summaryTAB, bool relation, bool xml)
        {
            foreach (object file in files)
            {
                CSsemi.CSemiExp semi = new CSsemi.CSemiExp();
                semi.displayNewLines = false;
                if (!semi.open(file as string))
                {
                    Console.Write("\n  Can't open {0}\n\n", file);
                    return;
                }
                BuildCodeAnalyzer builder = new BuildCodeAnalyzer(semi);
                Parser parser = builder.build();
                try
                {
                    while (semi.getSemi())
                        parser.parse(semi);                    
                }
                catch (Exception ex)
                {
                    Console.Write("\n\n  {0}\n", ex.Message);
                }
                Repository rep = Repository.getInstance();
                List<Elem> table = rep.locations;
                ComplexityAnalyzer comxAna = new ComplexityAnalyzer();
                foreach (Elem e in table)                                   // analysis each element's complexity if it is a function
                {
                    if (e.type == "function")
                        e.complexity = comxAna.complexityAnalysis(e, file, fileSetInfo);
                }

                summaryTAB.AddRange(table);

                RelationshipAnalyzer relshAna = new RelationshipAnalyzer();
                foreach (Elem e in table)                                   // analysis each element's relationship if it is a class or struct or interface
                {
                    if (e.type == "class" || e.type == "struct" || e.type == "interface")
                        relshAna.relationshipanalysis(e, file, fileSetInfo);
                }
                display(table, file, relation, xml);              
                semi.close();
            }// all the files in file set had been parsed

            summary(summaryTAB, relation);           
        }