public void Requirement4_5(string[] args)
        {
            Console.Write("\n\t \tOutput of Requirement4\n");
            Console.Write("-----------------------------------------------------------------------------\n");
            Console.Write("This Project3 implements packages that evaluate all the dependencies between files in a specified file set");
            ShowCommandLine(args);
            List <string> files = ProcessCommandline(args);
            Executive     test  = new Executive();

            test.Execute_Parser(files);
            test.Execute_TypeAnalyzer();
            DepAnalysis.DepAnalysis dep = new DepAnalysis.DepAnalysis();
            StrongComp.filesGraphs = files;
            StrongComp.filenumber  = files.Count();
            StrongComp.setGraph();
            DepAnalysis.DepAnalysis.filesDepAnalysis = files;
            StrongComp.filesGraph = files;
            DepAnalysis.DepAnalysis.setDictionary();
            StrongComp.setGraphDictionary();
            Console.Write("\nDemonstrating Output Of Dependency Analysis");
            Console.Write("\n ==========================================");

            foreach (string file in files)
            {
                ITokenCollection semi = Factory.create();
                if (!semi.open(file as string))
                {
                    Console.Write("\n  Can't open {0}\n\n", files[0]);
                    return;
                }
                try {
                    while (semi.get().Count > 0)
                    {
                        dep.HoldUsingValue(semi);
                    }
                }
                catch (Exception ex) { Console.Write("\n\n  {0}\n", ex.Message); }
                semi.close();
                ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                if (!semi.open(file as string))
                {
                    Console.Write("\n  Can't open {0}\n\n", files[0]);
                    return;
                }
                try {
                    while (semi.get().Count > 0)
                    {
                        dep.analyze(semi, file);
                    }
                }
                catch (Exception ex) { Console.Write("\n\n  {0}\n", ex.Message); }
                StrongComp.addGraph();
                semi.close();
            }
            Console.Write("\n\n");
        }
 public static void checkDependency(List <string> files)
 {
     foreach (var file in files)
     {
         List <Typetab.TypeItem> tempList = new List <Typetab.TypeItem>();
         ITokenCollection        semi     = Factory.create();
         //semi.displayNewLines = false;
         if (!semi.open(file as string))    //------<Opens the file>---------------
         {
             Console.Write("\n  Can't open {0}\n\n", file);
             return;
         }
         else
         {
             while (semi.get().Count > 0)
             {
                 foreach (var sems in semi)
                 {
                     if (typeTableItems.ContainsKey(sems))
                     {
                         checkTable(sems, tempList, file);
                     }
                     else
                     {
                         checkUsingTable(tempList, (Path.GetFileName(file)));
                     }
                 }
             }
         }
     }
 }
        public void Execute_Parser(List <string> files)
        {
            foreach (string file in files)
            {
                ITokenCollection semi = Factory.create();
                if (!semi.open(file as string))
                {
                    Console.Write("\n  Can't open {0}\n\n", files[0]);
                    return;
                }
                BuildCodeAnalyzer builder = new BuildCodeAnalyzer(semi);
                Parser            parser  = builder.build();

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

                semi.close();
            }
        }
예제 #4
0
 //-----------------------<Construct dependency information and deposit in repository>-----------
 public void ConstructDependency(string path)
 {
     AddFile(path);
     foreach (string filepath in files_)
     {
         ITokenCollection semi = Factory.create();
         if (!semi.open(filepath))
         {
             Console.WriteLine("Cannot open file {0}", filepath);
             continue;
         }
         string filename = Filename(filepath);
         Console.WriteLine("Constructed filename: {0}", filename);
         BuildDependencyAnalyzer depAnalyzer = new BuildDependencyAnalyzer(semi, filename);
         Parser depParser = depAnalyzer.build();
         try
         {
             while (semi.get().Count > 0)
             {
                 depParser.parse(semi);
             }
         }
         catch (Exception ex)
         {
             Console.Write("\n\n  {0}\n", ex.Message);
         }
     }
 }
예제 #5
0
        //---------------<Exetract type information from collection of files>------------
        public void AnalyzeFiles()
        {
            foreach (string filepath in files_)
            {
                ITokenCollection semi = Factory.create();
                if (!semi.open(filepath))
                {
                    Console.WriteLine("Cannot open file {0}", filepath);
                    continue;
                }
                string filename = Filename(filepath);

                BuildTypeAnalyzer typeAnalysis = new BuildTypeAnalyzer(semi, filename);
                Parser            typeParser   = typeAnalysis.build();
                try
                {
                    while (semi.get().Count > 0)
                    {
                        typeParser.parse(semi);
                    }
                }
                catch (Exception ex)
                {
                    Console.Write("\n\n  {0}\n", ex.Message);
                }
            }
            Repository repo = Repository.getInstance();

            repo.MapAlias();
        }
예제 #6
0
        /// <summary>
        /// Performs comparisons to identify the existence of dependencies among files
        /// </summary>
        /// <param name="typeName"></param>
        /// <param name="filename"></param>
        /// <param name="tables"></param>
        /// <param name="dicRes"></param>
        public void DoComparison(string typeName, string filename, Dictionary <string, List <Elem> > tables, ref Dictionary <string, HashSet <string> > dicRes)
        {
            ITokenCollection semi = Factory.create();

            foreach (KeyValuePair <string, List <Elem> > table in tables)
            {
                if (table.Key != filename)
                {
                    semi.open(table.Key as string);
                    while (semi.get().Count > 0)
                    {
                        if (semi.Contains(typeName))
                        {
                            if (!dicRes.ContainsKey(table.Key))
                            {
                                HashSet <string> valDic = new HashSet <string>();
                                dicRes.Add(table.Key, valDic);
                                dicRes[table.Key].Add(filename);
                                break;
                            }
                            else
                            {
                                dicRes[table.Key].Add(filename);
                                break;
                            }
                        }
                    }
                }
            }
        }
예제 #7
0
        static void Main(string[] args)
        {
            Console.Write("\n  testing Semi");
            Console.Write("\n ==============");

            // Access Semi through interface and object factory.
            // That isolates client from any changes that may occur to Semi
            // as long as ITokenCollection doesn't change.

            ITokenCollection semi = Factory.create();

            string source = "../../semi.cs";
            if (!semi.open(source))
            {
                Console.Write("\n  Can't { 0}\n", source);
              return;
            }
            while (!semi.isDone())
            {
                semi.get();
                semi.show();
            }
            Console.Write("\n");

            Console.Write("\n  demonstrating semi operations");
            Console.Write("\n -------------------------------");

            ITokenCollection test = Factory.create();
            checkSemiTest(test);

            Console.Write("\n\n");
        }
예제 #8
0
        //-----------------------<Generates Type Table by performing type analysis>--------------------------
        static public List <List <Elem> > TypeTableGenerator(List <string> files)
        {
            List <List <Elem> > tableList = new List <List <Elem> >();

            foreach (string file in files)
            {
                ITokenCollection semi = Factory.create();
                if (!semi.open(file as string))
                {
                    Console.Write("\n  Can't open {0}\n\n", file);
                }
                BuildCodeAnalyzer builder = new BuildCodeAnalyzer(semi, System.IO.Path.GetFileName(file));
                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;
                tableList.Add(table);
                semi.close();
            }
            return(tableList);
        }
예제 #9
0
        /// <summary>
        /// Performs type analysis and generates type table for every file.
        /// </summary>
        /// <param name="files"></param>
        /// <returns>type tabeles for every file</returns>
        public Dictionary <string, List <Elem> > DoTypeAnalysis(List <string> files)
        {
            Dictionary <string, List <Elem> > dicTables = new Dictionary <string, List <Elem> >();

            foreach (string file in files)
            {
                ITokenCollection semi = Factory.create();
                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.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;
                dicTables.Add(file, table);
                semi.close();
            }
            return(dicTables);
        }
        static void Main(string[] args)
        {
            ShowCommandLine(args);
            Executive test = new Executive();

            test.requirementOne();
            test.requirementTwo();
            test.requirementThree();
            test.requirementFour();
            List <string> files = ProcessCommandline(args);

            foreach (string file in files)
            {
                ITokenCollection semi = Factory.create();
                if (!semi.open(file as string))
                {
                    Console.Write("\n  Can't open {0}\n\n", args[0]);
                    return;
                }
                BuildCodeAnalyzer builder = new BuildCodeAnalyzer(semi);
                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; semi.close();
            }
            test.setAllParameters(files);
            foreach (string file in files)
            {
                Console.Write("\nFilename : {0}\n", System.IO.Path.GetFileName(file));
                DAnalysis        depAnls = new DAnalysis();
                ITokenCollection semi    = Factory.create();
                if (!semi.open(file as string))
                {
                    Console.Write("\n  Can't open {0}\n\n", args[0]);
                    return;
                }
                try{
                    while (semi.get().Count > 0)
                    {
                        depAnls.parse(semi, file);
                    }
                }
                catch (Exception ex) {
                    Console.Write("\n\n  {0}\n", ex.Message);
                }
                semi.close(); Graph.addGraph();
            }
            test.setAllParams();
            test.requirementSix();
            test.requirementSeven();
        }
        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();
            }
        }
예제 #12
0
        //----< Test Stub >--------------------------------------------------

#if (TEST_PARSER)
        static void Main(string[] args)
        {
            List <List <Elem> > allTables = new List <List <Elem> >();

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

                BuildCodeAnalyzer builder = new BuildCodeAnalyzer(semi, file);
                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;
                allTables.Add(table);
                Console.Write("\n");

                semi.close();
            }
            Display.showMetricsNamespace(allTables);
            Display.showMetricsClass(allTables);
            Display.showMetricsFunction(allTables);
            Display.showMetricsAlias(allTables);
            Display.showMetricsEnum(allTables);
            Display.showMetricsStruct(allTables);
            Display.showMetricsDelegate(allTables);
            Display.showMetricsUsing(allTables);
            Display.showMetricsInterface(allTables);
            Console.Write("\n\n");
        }
예제 #13
0
            static void Main(string[] args)
            {
                Console.Write("\n  Demonstrating TypeAnalysis");
                Console.Write("\n ======================\n");

                TypeAnalysis typeanalysis = new TypeAnalysis();

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

                    BuildCodeAnalyzer builder = new BuildCodeAnalyzer(semi);
                    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;
                    File        f      = file.Substring(file.LastIndexOf('\\') + 1);
                    string      namesp = "";
                    foreach (Elem ele in table)
                    {
                        if (ele.type == "namespace")
                        {
                            namesp = ele.name;
                        }
                        typeanalysis.add(f, ele, namesp);
                    }
                    typeanalysis.display();
                    Console.Write("\n");

                    semi.close();
                }
                Console.Write("\n\n");
            }
예제 #14
0
        //--------<GetTable implement opreation to get a typetable from semi and retrun a whole typetable>-----

        public TypeTable GetTable(string[] args)
        {
            TestType  tp = new TestType();
            TypeTable tt = new TypeTable();

            //FileFinder filef = new FileFinder();
            //args = filef.get_cs();
            foreach (var item in args)
            {
                //Console.WriteLine(item);
            }
            foreach (string file in args)
            {
                ITokenCollection semiexp = Factory.create();
                if (!semiexp.open(file as string))
                {
                    Console.Write("\n  Can't open {0}\n\n", args[0]);
                    break;
                }
                BuildCodeAnalyzers builder = new BuildCodeAnalyzers(semiexp);
                Parser             parser  = builder.build();
                try
                {
                    while (semiexp.get().Count > 0)
                    {
                        parser.parse(semiexp);
                    }
                }
                catch (Exception ex)
                {
                    Console.Write("\n\n  {0}\n", ex.Message);
                }
                Repository  rep   = Repository.getInstance();
                List <Elem> table = rep.locations;
                string      name  = "";
                foreach (Elem e in table)
                {
                    if (e.type == "namespace")
                    {
                        name = e.name;
                    }
                    else
                    {
                        if (e.type == "Alias" || e.type == "function")
                        {
                            continue;
                        }

                        tt.add(e.name, System.IO.Path.GetFileName(file), name, e.type);
                        //Console.WriteLine("Pass this route");
                    }
                }
                semiexp.close();
            }
            Console.WriteLine(tt.table.Count);
            return(tt);
        }
        //----< 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();
        }
 //determines the dependency is due to the use of class,interface,structure or enum and generates graph
 public static void findDependency(ITokenCollection semi, String fileName1, String fileName2, List <string> classNames, List <string> interfaceNames, List <string> structureNames, List <string> enumNames, List <string> delegateNames, List <Tuple <string, string> > graph)
 {
     while (semi.get().Count > 0)
     {
         D_class(semi, fileName1, fileName2, classNames, interfaceNames, structureNames, enumNames, delegateNames, graph);
         D_interface(semi, fileName1, fileName2, classNames, interfaceNames, structureNames, enumNames, delegateNames, graph);
         D_struct(semi, fileName1, fileName2, classNames, interfaceNames, structureNames, enumNames, delegateNames, graph);
         D_enum(semi, fileName1, fileName2, classNames, interfaceNames, structureNames, enumNames, delegateNames, graph);
         D_delegate(semi, fileName1, fileName2, classNames, interfaceNames, structureNames, enumNames, delegateNames, graph);
     }
 }
        //----< Test Stub >--------------------------------------------------

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

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

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

            foreach (string file in files)
            {
                Console.Write("\n  Processing file {0}\n", System.IO.Path.GetFileName(file));
                repo.currentFile = 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 ----------------------------");

                //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);
                }
                Repository  rep   = Repository.getInstance();
                List <Elem> table = rep.locations;
                Display.showMetricsTable(table);
                Console.Write("\n");

                semi.close();
            }
            Console.Write("\n\n");
        }
예제 #18
0
        //Generates the Type Table for all the different types that are used
        //in the given files
        static TypeTable makeTT(string[] args)
        {
            StringBuilder msg = new StringBuilder();
            TypeTable     tt  = new TypeTable();
            //Console.Write("\n  Demonstrating Parser");
            //Console.Write("\n ======================\n");

            //ShowCommandLine(args);

            List <string> files = ProcessCommandline(args);

            foreach (string file in files)   //loops through all the available files
            {
                //msg.Append(Environment.NewLine+"  Processing file "+ System.IO.Path.GetFileName(file));
                ITokenCollection semi = Factory.create();
                //semi.displayNewLines = false;
                if (!semi.open(file as string))
                {
                    throw new Exception("\n  Can't open file!\n\n");
                }
                BuildCodeAnalyzer builder = new BuildCodeAnalyzer(semi);
                Parser            parser  = builder.build();

                try
                {
                    while (semi.get().Count > 0) //This is where the semi expressions
                    {
                        parser.parse(semi);      //are getting parsed, above we had just defined the parser
                    }
                    //rememeber to remove the comment from the foreach in side parse
                }
                catch (Exception ex)
                {
                    Console.Write("\n\n  {0}\n", ex.Message);
                }
                Repository  rep      = Repository.getInstance();
                List <Elem> table    = rep.locations;
                string[]    fullname = file.Split('\\');
                string      filename = fullname[fullname.Length - 1];
                foreach (var element in table)
                {
                    //Console.WriteLine("Name: {0}  Type: {1}  Filename: {2}", element.name, element.type, filename);
                    tt.add(element.type, filename, element.name);
                }
                //Display.showMetricsTable(table);
                semi.close();
            }
            //Console.WriteLine("\n\n     The TypeTable\n     ============\n");
            //tt.show();   //my TypeTable
            //Console.Write("\n\n");
            return(tt);
            //Console.ReadKey();
        }
        public void analyze()
        {
            if (dirpath == null)
            {
                Console.Write("dirpath not set");
                return;
            }
            buildTypeTable();
            BuildDependencyParser builder = new BuildDependencyParser();
            Parser        parser          = builder.build();
            List <String> files           = FileManger.ProcessDirtory(dirpath);

            foreach (String file in files)
            {
                // Console.Write("\n  Dependency Analyzsis, Processing file {0}\n", System.IO.Path.GetFileName(file));                   //print on the console which file is being processed
                ITokenCollection semi = Factory.create();
                Repository.changeFileName(System.IO.Path.GetFileName(file));                                                          //update the current file name
                Repository.emptyUsingList();                                                                                          // empty the using namespace list whenever start parsing a new file
                Repository.resetAliasList();
                if (!Repository.getInstance().dependencyTable.ContainsKey(System.IO.Path.GetFileName(file)))
                {
                    Repository.getInstance().dependencyTable.Add(System.IO.Path.GetFileName(file), new HashSet <string>());           // create a dependency node for each file
                }
                //semi.displayNewLines = false;
                if (!semi.open(file as string))
                {
                    Console.Write("\n  Can't open {0}\n\n", file);
                    continue;
                }

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

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

                semi.close();
            }
            Console.Write("\n\n");
            DependencyTable = Repository.getInstance().dependencyTable;
            Repository.clear();
        }
예제 #20
0
 public static void TestOperation(ITokenCollection semi)
 {
     string source = "../../semi.cs";
     if (!semi.open(source))
     {
         Console.Write("\n  Can't open {0}\n", source);
         return;
     }
     while (!semi.isDone())
     {
         semi.get();
         semi.show();
     }
 }
        public static TypeTable buildTypeTable(String[] args) // the input should be the valid path and file names
        {                                                     //Console.Write("\n  Demonstrating building typeTable");
            //Console.Write("\n ======================\n")
            //ShowCommandLine(arg);
            TypeTable     table = new TypeTable();
            List <string> files = FileManger.ProcessDirtory(args);
            Repository    r     = new Repository();

            foreach (string file in files)
            {
                if (System.IO.Path.GetFileName(file).Contains("AssemblyInfo.cs"))                               // ignore all the .cs file that are generated by visual studio
                {
                    continue;
                }
                Console.Write("\n  Processing file {0}\n", System.IO.Path.GetFileName(file));                   //print on the console which file is being processed
                ITokenCollection     semi    = Factory.create();
                BuildTpyeTablePareer builder = new BuildTpyeTablePareer(semi);
                Parser parser = builder.build();
                Repository.changeFileName(System.IO.Path.GetFileName(file));                                     //update the current file name
                //semi.displayNewLines = false;
                if (!semi.open(file as string))
                {
                    Console.Write("\n  Can't open {0}\n\n", file);
                    continue;
                }

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



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

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


            return(Repository.getInstance().table);
        }
예제 #22
0
        //---------<checks if the enum of one file is present on the other file with same namespace or using or alias name>---------//
        public static bool secondParseDelegate(ITokenCollection semi, string file1, string file2, List <string> delegateList, List <string> files, List <Tuple <string, string> > graph)
        {
            int il = delegateList.Count;

            while (semi.get().Count > 0)
            {
                for (int i = 0; i < il; i++)
                {
                    if (semi.Contains(delegateList[i]))
                    {
                        graph.Add(new Tuple <string, string>(file2, file1));
                        return(true);
                    }
                }
            }
            return(false);
        }
        void DependencyResult(List <string> files, string dependencyresult, bool flag)
        {
            Repository       repo     = Repository.getInstance();
            ITokenCollection semi     = Factory.create();
            BuildDepAnalyzer builder2 = new BuildDepAnalyzer(semi);
            Parser           parser   = builder2.build();

            repo.locations.Clear();

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

                if (!semi.open(file as string))
                {
                    Console.Write("\n  Can't open {0}\n\n", file);
                    break;
                }
                List <string> deps = new List <string>();
                repo.dependencyTable.addParent(file);

                repo.currentFile = file;

                try
                {
                    while (semi.get().Count > 0)
                    {
                        //semi.show();
                        parser.parse(semi);
                    }
                }
                catch (Exception ex)
                {
                    Console.Write("\n\n  {0}\n", ex.Message);
                }
            }
            if (flag)
            {
                repo.dependencyTable.show();
                repo.dependencyTable.DependencyFile(dependencyresult);
            }
        }
예제 #24
0
        //-------------<Build the Typetable for analysis>--------------------------
        public void Testpre(string[] args)
        {
            Console.Write("\n\n  Construct the TypeTable by semi and parser");
            Console.Write("\n =========================================\n");

            FindFile(args[0]);

            foreach (string file in files)
            {
                ITokenCollection semi = Factory.create();

                if (!semi.open(file as string))
                {
                    Console.Write("\n  Can't open {0}\n\n", args[0]);
                    return;
                }
                BuildCodeAnalyzer builder = new BuildCodeAnalyzer(semi);
                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();
                table=rep.locations;
                File f = file.Substring(file.LastIndexOf('\\') + 1);
                string namesp = "";
                foreach (Elem ele in table)
                {
                    if (ele.type == "namespace")
                    {
                        namesp = ele.name;
                    }
                    typeana.add(f, ele, namesp);
                }
                semi.close();
            }
            typeana.display();
        }
        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);
            }
        }
        //-----------------< Parse the second file to check for delegate instance >---------
        public static bool ParseForDelegate(string firstFile, string SecondFile, ITokenCollection semi, List <List <Elem> > listOfTables, List <Tuple <string, string> > graph)
        {
            List <string> listofDelegates = new List <string>();

            listofDelegates = GetTypes.delegateList(firstFile, listOfTables);
            int n = listofDelegates.Count;

            while (semi.get().Count > 0)
            {
                for (int i = 0; i < n; i++)
                {
                    if (semi.Contains(listofDelegates[i]))
                    {
                        graph.Add(new Tuple <string, string>(SecondFile, firstFile));
                        return(true);
                    }
                }
            }
            return(false);
        }
        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);
            }
        }
예제 #28
0
        //----< Test Stub >--------------------------------------------------

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

            args = filef.get_cs();
            foreach (string file in args)
            {
                Console.Write("\n  Processing file {0}\n", System.IO.Path.GetFileName(file));
                ITokenCollection semi = Factory.create();
                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.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");
            Console.ReadKey();
        }
예제 #29
0
        //------<DepenAnalysises was used to compare semi with what inside typetable to get dependency relations>------

        public DepenAnalysis DepenAnalysises(string[] args)
        {
            TypeTable tt = new TypeTable();

            tt = tt.GetTable(args);
            DepenAnalysis dp = new DepenAnalysis();

            foreach (string file in args)
            {
                ITokenCollection semi = Factory.create();
                if (!semi.open(file))
                {
                    Console.Write("\n  Can't open {0}\n\n", args[0]); break;
                }
                while (!semi.isDone())
                {
                    semi.get();
                    getttt(tt, semi, dp, file);
                }
                semi.close();
            }
            return(dp);
        }
예제 #30
0
        //---------------< Requirement 5 >---------------------------------
        public void TestReq5(string[] args)
        {
            Console.Write("\n Req 5 : \n Demostrate uesr-defined types");
            Console.Write("\n ========================================\n");
            

            foreach (string file in files)
            {
                ITokenCollection semi = Factory.create();

                if (!semi.open(file as string))
                {
                    Console.Write("\n  Can't open {0}\n\n", args[0]);
                    return;
                }
                BuildCodeAnalyzer builder = new BuildCodeAnalyzer(semi);
                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();
                table = rep.locations;
                Console.Write("\n");
                File f = file.Substring(file.LastIndexOf('\\') + 1);
                Console.Write("Processing file: " + f + "\n");
                Display.showMetricsTable(table);
                semi.close();
            }

            Console.Write("\n");
        }