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");
        }
Beispiel #2
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);
        }
        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();
            }
        }
Beispiel #4
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);
        }
        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();
            }
        }
        //----< 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");
        }
Beispiel #8
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);
        }
            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");
            }
        //----< 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();
        }
        //----< 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");
        }
        //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();
        }
        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);
        }
Beispiel #15
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();
        }
Beispiel #16
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();
        }
Beispiel #17
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);
        }
Beispiel #18
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");
        }
        public List <List <Elem> > generateTypeTable()
        {
            string nameofFile;
            List <List <Elem> > listOfTables = new List <List <Elem> >();

            foreach (string file in files)
            {
                nameofFile = 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", nameofFile);
                }

                BuildCodeAnalyzer builder = new BuildCodeAnalyzer(semi, nameofFile);
                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;
                listOfTables.Add(table);
                semi.close();
            }
            return(listOfTables);
        }
Beispiel #20
0
        static void Main(string[] args)
        {
            Console.Write("This project contains 13 packages demonstrating requirement 3:\n");
            Console.Write("1) DemoExecutive\n");
            Console.Write("2) DemoReqs\n");
            Console.Write("3) DependencyAnalysis\n");
            Console.Write("4) Display\n");
            Console.Write("5) Element\n");
            Console.Write("6) FileMgr\n");
            Console.Write("7) Parser\n");
            Console.Write("8) SemiExp\n");
            Console.Write("9) StrongComponent\n");
            Console.Write("10) TestHarness\n");
            Console.Write("11) Toker\n");
            Console.Write("12) TypeTable\n");
            Console.Write("13) AutomatedTestUnit\n");
            Console.Write("\n ======================\n");
            Console.Write("\n  Demonstrating Parser");
            Console.Write("\n ======================\n");

            ShowCommandLine(args);

            List <string> files = ProcessCommandline(args);
            DepAnalysis   da    = new DepAnalysis();

            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;
                TypeTable.TypeTable tt    = new TypeTable.TypeTable();
                ///shows typetable
                foreach (Elem e in table)
                {
                    tt.add(e.type, e.name);
                    if (e.type == "using")
                    {
                        da.add(System.IO.Path.GetFileName(file), e.name);
                    }
                }
                tt.show();
                Console.WriteLine("Showing TypeTables of files demonstrating requirement 5:\n");
                Console.Write("\n  TypeTable contains types: ");
                foreach (var elem in tt.table)
                {
                    Console.Write("{0} ", elem.Key);
                }
                ////Display.showMetricsTable(table);

                Console.Write("\n");
                semi.close();
            }
            var nodes = new List <CsNode <string, string> >();

            foreach (var elem in da.table)
            {
                nodes.Add(new CsNode <string, string>(elem.Key));
                //Console.Write("\n  {0} depends on", elem.Key);
            }
            nodes.ToArray();

            //foreach (var elem in da.table)
            //{
            //    foreach (var item in elem.Value)
            //    {
            //        //nodes[IndexOf(elem.Key)].addChild(nodes[IndexOf(item.file)], "edge" + elem.Key + " " + item.file);
            //        //nodes[0].addChild(item.file, "edge" + elem.Key + " " + item.file);
            //        //nodes[nodes.IndexOf(elem.Value)].addChild(nodes[nodes.IndexOf(item.file)], "edge" + elem.Key + " " + item.file);

            //        Console.Write("\n    {0}.cs", item.file);
            //    }
            //}
            //iterate through list of list elements of a file
            //da.table --gets table,
            for (int i = 0; i < da.table.Count; i++)
            {
                var item = da.table.ElementAt(i);
                for (int j = 0; j < item.Value.Count; j++)
                {
                    //Console.WriteLine(i+"^"+ da.table.Values);
                    nodes[i].addChild(nodes[j], "edge" + i + j);
                }
            }
            Graph <string, string> graph = new Graph <string, string>("Fred");

            for (int i = 0; i < da.table.Count; i++)
            {
                graph.addNode(nodes[i]);
            }

            graph.startNode = nodes[0];
            //Console.WriteLine("\n Showing graph walk starting at node[0]\n");
            //Console.Write("\n\n  starting walk at {0}", graph.startNode.name);
            //Console.Write("\n  not showing backtracks");
            //graph.walk();

            Console.WriteLine("Showing dependencies between files demonstrating requrement 4:\n\n");
            //shows dependency analysis
            da.show();
            Console.Write("\n\n");
            Console.Write("Showing all strong components, if any, in the file collection, based on the dependency analysis demonstrating requirement 6:\n\n");
            graph.startNode = nodes[0];
            graph.Tarjan();
            Console.Write("\n\n");
            Console.WriteLine("This demo executive file demonstrates all the outputs and is well formatted as per requirement 7 and 8\n");
            Console.ReadLine();
        }
Beispiel #21
0
        /*----< define how each message will be processed >------------*/

        void initializeDispatcher()
        {
            Func <CommMessage, CommMessage> getTopFiles = (CommMessage msg) =>
            {
                localFileMgr.currentPath = "";
                CommMessage reply = new CommMessage(CommMessage.MessageType.reply);
                reply.to        = msg.from;
                reply.from      = msg.to;
                reply.command   = "getTopFiles";
                reply.arguments = localFileMgr.getFiles().ToList <string>();
                return(reply);
            };

            messageDispatcher["getTopFiles"] = getTopFiles;

            Func <CommMessage, CommMessage> getTopDirs = (CommMessage msg) =>
            {
                localFileMgr.currentPath = "";
                CommMessage reply = new CommMessage(CommMessage.MessageType.reply);
                reply.to        = msg.from;
                reply.from      = msg.to;
                reply.command   = "getTopDirs";
                reply.arguments = localFileMgr.getDirs().ToList <string>();
                return(reply);
            };

            messageDispatcher["getTopDirs"] = getTopDirs;

            Func <CommMessage, CommMessage> moveIntoFolderFiles = (CommMessage msg) =>
            {
                if (msg.arguments.Count() == 1)
                {
                    localFileMgr.currentPath = msg.arguments[0];
                }
                CommMessage reply = new CommMessage(CommMessage.MessageType.reply);
                reply.to        = msg.from;
                reply.from      = msg.to;
                reply.command   = "moveIntoFolderFiles";
                reply.arguments = localFileMgr.getFiles().ToList <string>();
                return(reply);
            };

            messageDispatcher["moveIntoFolderFiles"] = moveIntoFolderFiles;

            Func <CommMessage, CommMessage> moveIntoFolderDirs = (CommMessage msg) =>
            {
                if (msg.arguments.Count() == 1)
                {
                    localFileMgr.currentPath = msg.arguments[0];
                }
                CommMessage reply = new CommMessage(CommMessage.MessageType.reply);
                reply.to        = msg.from;
                reply.from      = msg.to;
                reply.command   = "moveIntoFolderDirs";
                reply.arguments = localFileMgr.getDirs().ToList <string>();
                return(reply);
            };

            messageDispatcher["moveIntoFolderDirs"] = moveIntoFolderDirs;

            Func <CommMessage, CommMessage> analyzeFiles = (CommMessage msg) =>
            {
                CommMessage reply = new CommMessage(CommMessage.MessageType.reply);
                reply.to      = msg.from;
                reply.from    = msg.to;
                reply.command = "analyzeFiles";
                TypeAnalysis typeana    = new TypeAnalysis();
                DepAnalys    depana     = new DepAnalys();
                StrongComp   strongcomp = new StrongComp();
                List <Elem>  table      = new List <Elem>();
                foreach (string file in msg.arguments)
                {
                    ITokenCollection semi = Factory.create();

                    if (!semi.open(file as string))
                    {
                        Console.Write("\n  Can't open {0}\n\n", file);
                        return(null);
                    }
                    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();
                }
                depana.BuildGraph(msg.arguments);
                foreach (string f in msg.arguments)
                {
                    depana.ConnectNode(typeana, f);
                }
                //move to reply.arguments[0];
                foreach (CsNode <string, string> node in depana.csgraph.adjList)
                {
                    StringBuilder temp = new StringBuilder();
                    temp.Append(node.name.Substring(node.name.LastIndexOf('/') + 1));
                    temp.Append(" \n Dependency : [");
                    foreach (CsEdge <string, string> edge in node.children)
                    {
                        temp.Append(edge.targetNode.name.Substring(edge.targetNode.name.LastIndexOf('/') + 1));
                        temp.Append(" ");
                    }
                    temp.Append(" ] \n");
                    reply.arguments.Add(temp.ToString());
                }
                strongcomp.FindConnect(depana.csgraph);
                //move to reply.arguments[1];
                int i = 1;
                foreach (List <CsNode <string, string> > nodes in strongcomp.result)
                {
                    StringBuilder temp = new StringBuilder();
                    temp.Append("Components " + i.ToString() + ": ");
                    foreach (CsNode <string, string> node in nodes)
                    {
                        temp.Append(node.name.Substring(node.name.LastIndexOf('/') + 1) + " ");
                    }
                    temp.Append("\n");
                    i++;
                    reply.arguments.Add(temp.ToString());
                }
                return(reply);
            };

            messageDispatcher["analyzeFiles"] = analyzeFiles;

            Func <CommMessage, CommMessage> demo456 = (CommMessage msg) =>
            {
                CommMessage reply = new CommMessage(CommMessage.MessageType.reply);
                reply.to      = msg.from;
                reply.from    = msg.to;
                reply.command = "demo456";
                reply.arguments.Add("");
                return(reply);
            };

            messageDispatcher["demo456"] = demo456;
        }
        //Finds all the different types and names used in different files



        static TypeTable makett(string[] args)
        {
            TypeTable tt = new TypeTable();
            //Console.WriteLine("\nFine till now");
            List <string> files = ProcessCommandline(args);

            foreach (string file in files)   //loops through all the available files
            {
                //Console.WriteLine("\n  Processing file {0}", file);

                ITokenCollection semi = Factory.create();
                //semi.displayNewLines = false;
                if (!semi.open(file as string))
                {
                    throw new Exception("\n  Can't open file!\n\n");
                }
                NameCodeAnalyzer builder = new NameCodeAnalyzer(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];
                //Console.WriteLine("\n\n              Alias Table\n           =============\n");
                //Console.WriteLine("        Name                inFile");
                //Console.WriteLine("       ======               =======\n");
                foreach (var element in table)
                {
                    //Console.WriteLine("Name: {0}  Type: {1}  Filename: {2}", element.name, element.type, filename);
                    //Console.Write("   |  {0}  ", element.name.PadRight(15));
                    //Console.Write("   |  {0}  ", filename.PadRight(10));
                    //Console.Write(" | \n");

                    //if (tt.constains(element.name))

                    //TAB table contains all the different types and all names along with file names

                    tt.add(element.type, filename, element.name);
                }
                //Display.showMetricsTable(table);

                //Console.Write("\n");
                //tt.show();
                semi.close();
            }
            //Console.Write("\n");
            //tt.show();
            return(tt);
        }
Beispiel #23
0
        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  \n");
            ShowCommandLine(args);

            List<string> files = ProcessCommandline(args);


            foreach (string file in files)
            {
                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;
                }
                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();
            }


            DepAnalysis.DepAnalysis dep = new DepAnalysis.DepAnalysis();
            StrongComp.filesGraph = files;
            StrongComp.filesGraphs = files;
            StrongComp.filenumber = files.Count();
            StrongComp.setGraph();
            StrongComp.filesGraph = files;
            StrongComp.setGraphDictionary();
            DepAnalysis.DepAnalysis.filesDepAnalysis = files;
            DepAnalysis.DepAnalysis.setDictionary();


            foreach (string file in files)
            {
                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;
                }


                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", args[0]);
                    return;
                }
                try
                {
                    while (semi.get().Count > 0)
                        dep.analyze(semi, file);
                }

                catch (Exception ex)
                {
                    Console.Write("\n\n  {0}\n", ex.Message);
                }

                semi.close();
                StrongComp.addGraph();


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