コード例 #1
0
        public override bool test(ITokenCollection semi)
        {
            Display.displayRules(actionDelegate, "rule   DetectNamespace");
            int index;

            semi.find("namespace", out index);
            if (index != -1 && semi.size() > index + 1)
            {
                var local = Factory.create();
                // create local semiExp with tokens for type and name
                local.add(semi[index]).add(semi[index + 1]);
                doActions(local);
                var repo = Repository.getInstance();
                repo.currentNameSpace = semi[index + 1];
                return(true);
            }

            return(false);
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
        //----< build dependency table by parsing for type usage >-------

        public void dependencyAnalysis(List <string> files)
        {
            var repo     = Repository.getInstance();
            var semi     = Factory.create();
            var builder2 = new BuildDepAnalyzer(semi);
            var parser   = builder2.build();

            repo.locations.Clear();

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

                if (!semi.open(file))
                {
                    Console.Write("\n  Can't open {0}\n\n", file);
                    break;
                }

                var 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);
                }
            }
        }
コード例 #4
0
        public override bool test(CSsemi.CSemiExp semi)
        {
            Display.displayRules(actionDelegate, "rule   DetectNamespace");
            int index = semi.Contains("namespace");

            if (index != -1)
            {
                Repository rep = Repository.getInstance();
                //if (rep.isFirstPass)
                {
                    CSsemi.CSemiExp local = new CSsemi.CSemiExp();
                    // create local semiExp with tokens for type and name
                    local.displayNewLines = false;
                    local.Add(semi[index]).Add(semi[index + 1]);
                    doActions(local);
                    return(true);
                }
            }
            return(false);
        }
コード例 #5
0
ファイル: Display.cs プロジェクト: monishalp/CodeAnalyzer
        /// /////////// Displays the type information //////////////

        public void DisplayReport(List <Elem> list_elem)
        {
            Repository rep = Repository.getInstance();

            Console.WriteLine("PROCESSING DISLAY PACKAGE");
            Console.WriteLine("--------------------------------------------------------------------");
            string type    = "type";
            string name    = "name";
            string begin   = "start#";
            string end     = "end#";
            string size    = "size";
            string complex = "function complexity";

            Console.WriteLine("\n  {0,-9}  {1,-24}  {2,-4}  {3,-4}  {4,-4}  {5,4} ", type, name, begin, end, size, complex);
            Console.WriteLine("--------------------------------------------------------------------");
            foreach (Elem e in list_elem)
            {
                Console.Write("\n  {0,-10}  {1,-25}  {2,-5}  {3,-5}  {4,-5}  {5,5} ", e.type, e.name, e.begin, e.end, e.size, e.prog_complexity);
            }
        }
コード例 #6
0
        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);
            }
        }
コード例 #7
0
ファイル: RulesAndActions.cs プロジェクト: prmk/CodeAnalyzer
        static public string getClassName(int lineno)
        {
            string     classname = "";
            Repository repo_     = Repository.getInstance();
            Elem       elem      = new Elem();
            int        begin     = 0;

            for (int i = 0; i < repo_.analyzedata.Count; i++)
            {
                elem = repo_.analyzedata[i];
                if (elem.type == "class")
                {
                    if (elem.begin > begin && elem.begin < lineno && elem.end > lineno)
                    {
                        begin     = elem.begin;
                        classname = elem.name;
                    }
                }
            }

            return(classname);
        }
コード例 #8
0
        public override bool test(ITokenCollection semi)
        {
            Display.displayRules(actionDelegate, "rule   DetectClass");
            int indexCL;

            semi.find("class", out indexCL);
            int indexIF;

            semi.find("interface", out indexIF);
            int indexST;

            semi.find("struct", out indexST);
            int indexDL;

            semi.find("delegate", out indexDL);

            var index = Math.Max(indexCL, indexIF);

            index = Math.Max(index, indexST);
            index = Math.Max(index, indexDL);

            if (index != -1 && semi.size() > index + 1)
            {
                var local = Factory.create();
                // local semiExp with tokens for type and name
                local.add(semi[index]).add(semi[index + 1]);
                doActions(local);

                var repo_ = Repository.getInstance();
                TypeTable.LocPair pair;
                pair.file      = repo_.currentFile;
                pair.nameSpace = repo_.currentNameSpace;
                repo_.typeTable.add(semi[index + 1], pair);

                return(true);
            }

            return(true);
        }
コード例 #9
0
ファイル: Analyzer.cs プロジェクト: monishalp/CodeAnalyzer
        //*****second parse************//
        public void reldoAnalysis(string[] files)
        {
            foreach (object file in files)
            {
                Console.Write("\n  Processing file {0}\n", file as string);

                CSsemi.CSemiExp semi = new CSsemi.CSemiExp();
                semi.displayNewLines = false;
                if (!semi.open(file as string))
                {
                    Console.Write("\n  Can't open {0}\n\n", file);
                    return;
                }


                Repository rep_inst = Repository.getInstance();
                Repository.Copy_buffer = typesBetweenFiles;

                BuildCodeAnalyzer_types builder_ty = new BuildCodeAnalyzer_types(semi);
                Parser parser = builder_ty.build();
                // sends every semi again for relationship analysis
                try
                {
                    while (semi.getSemi())
                    {
                        parser.parse(semi);
                    }
                }
                catch (Exception ex)
                {
                    Console.Write("\n\n  {0}\n", ex.Message);
                }

                //stores all the updation to the type and relationship list back to the repository
                Repository_types    rep   = Repository_types.getInstance();
                List <relationelem> table = rep.classrelations;
                rel_BetweenFiles = (rep.classrelations);
            }
        }
コード例 #10
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();
        }
        public override bool test(ITokenCollection semi)
        {
            Repository rep = Repository.getInstance();

            if (semi[0][0] == '/')                                                      // comments will not cause any dependency
            {
                return(false);
            }
            foreach (String token in semi)
            {
                if (token == "\n" || token == "}" || token == "{")
                {
                    continue;                                                            //ignore tokens that is impossible to cause a dependency
                }
                if (rep.table.containsKey(token) && isUsingType(semi, token))            //only when we make sure it is using a type can we determine it is using a type. not a instance name or function name
                {                                                                        // for example : we need to eliminate the cases like        int ITokenCollection =0; or       public void ITokenCollection()
                    List <TypeTableEle> list  = rep.table.get(token);
                    ITokenCollection    local = Factory.create();
                    if (list.Count == 1 && list[0].file_ != rep.filename)
                    {
                        local.add(rep.filename).add(list[0].file_);                  // if there is only 1 element in the TypeTable[key], dependency detected and add it to teh dependencyTable
                        doActions(local);
                    }
                    else if (list.Count > 1)
                    {
                        foreach (TypeTableEle ele in list)
                        {
                            if (rep.usingList.Contains(ele.namespace_))
                            {
                                local.add(rep.filename).add(ele.file_);              // if there are more than 1 element in the TypeTable[key], find the one with the namespace that is currently using and add it to dependency table
                                doActions(local);
                            }
                        }
                    }
                }
            }
            return(false);
        }
コード例 #12
0
ファイル: RulesAndActions.cs プロジェクト: ravisjce/Programs
        /*Checks whether the input semi expression contains composition relationship
         * If it is present then the action method for composition is called
         */
        public override bool test(CSsemi.CSemiExp semi)
        {
            List <string> variablecountlist = null;
            Repository    repo_             = Repository.getInstance();

            if (semi.count >= 2)
            {
                variablecountlist = semi.DetectVariables();
            }

            if (variablecountlist != null && variablecountlist.Count == 2)
            {
                string currclassName = FindParentClass.getClassName(repo_.semi.lineCount);

                CSsemi.CSemiExp local = new CSsemi.CSemiExp();
                local.displayNewLines = false;
                local.Add(variablecountlist[0]).Add(variablecountlist[1]).Add(currclassName);
                doActionsForComposition(local);
                return(true);
            }

            return(false);
        }
コード例 #13
0
ファイル: RulesAndActions.cs プロジェクト: ravisjce/Programs
        /*Checks whether the input semi expression contains aggregation relationship
         * If it is present then the action method for aggregation is called
         */
        public override bool test(CSsemi.CSemiExp semi)
        {
            Repository repo_ = Repository.getInstance();
            int        index = semi.FindFirst("new");

            if (index != -1)
            {
                string currclassName = FindParentClass.getClassName(repo_.semi.lineCount);

                //if (currclassName.CompareTo("") == 0)
                //{
                //    return true;
                //}
                CSsemi.CSemiExp local = new CSsemi.CSemiExp();
                // local semiExp with tokens for type and name
                local.displayNewLines = false;
                local.Add(semi[index + 1]).Add(semi[index - 2]).Add(currclassName);
                doActionsForAggregation(local);
                return(true);
            }

            return(false);
        }
コード例 #14
0
        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);
        }
コード例 #15
0
        public static void performTypeAnalysis(List <string> files)
        {
            foreach (string file in files)
            {
                // Console.Write("\n  Processing file {0}\n", System.IO.Path.GetFileName(file));

                Lexer.ITokenCollection semi = Factory.create();
                //semi.displayNewLines = false;
                if (!semi.open(file as string))
                {
                    Console.Write("\n  Can't open {0}\n\n", files);
                    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;

                Console.Write("\n");
                rep.nameSpace = "";
                semi.close();
            }
        }
コード例 #16
0
ファイル: Analyzer.cs プロジェクト: nisha-choudhary/Projects
        //---------<parse2 starts here, it identifies relationships betn all the types>------------
        public void doAnalysisRelationship(string[] files)
        {
            foreach (object file in files)
            {
                string filename = Convert.ToString(file);


                CSsemi.CSemiExp semi = new CSsemi.CSemiExp();
                semi.displayNewLines = false;
                if (!semi.open(file as string))
                {
                    Console.Write("\n  Can't open {0}\n\n", file);
                    return;
                }

                BuildCodeAnalyzerRelation builderForRelationship = new BuildCodeAnalyzerRelation(semi);
                Parser parser = builderForRelationship.build();

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

                Repository  rep   = Repository.getInstance();
                List <Elem> table = rep.locations;

                semi.close();
            }
        }
 public CollectMember(ref CsNode <string, string> node)
 {
     repo_        = Repository.getInstance();
     currentNode_ = node;
 }
 public PrintFunction(Repository repo)
 {
     repo_ = Repository.getInstance();
 }
 public PopStack(Repository repo, string file)
 {
     repo_ = Repository.getInstance();
     file_ = file;
 }
 public CollectAliases(Repository repo)
 {
     repo_ = Repository.getInstance();
 }
 public CollectNamespace(Repository repo, string file)
 {
     repo_ = Repository.getInstance();
     file_ = file;
 }
 public SaveAll(ref CsNode <string, string> node)
 {
     repo_        = Repository.getInstance();
     currentNode_ = node;
 }
コード例 #23
0
        public override bool test(ITokenCollection semi)
        {
            var repo = Repository.getInstance();

            int parIndex;

            if (!semi.find("(", out parIndex))
            {
                return(false);
            }

            var local = semi.clone().getFunctionParams();

            if (local.size() == 0 || local[0] == "using")
            {
                return(false);
            }

            Display.displayRules(actionDelegate, "rule   DetectDeclar");
            int index;

            local.find(";", out index);
            if (index != -1)
            {
                local = compactGeneric(local);
                var pos = 0;
                while (pos < local.size())
                {
                    if (repo.qualTable.contains(local[pos]))
                    {
                        local.remove(pos);
                    }
                    else
                    {
                        ++pos;
                    }
                }

                local.find("=", out index);
                if (index != -1)
                {
                    while (index < local.size() - 1)
                    {
                        local.remove(index);
                    }
                }

                int indexPar;
                local.find("(", out indexPar);
                if (indexPar > -1)
                {
                    return(false);
                }

                if (local.size() == 3)
                {
                    doActions(local);
                    return(false);
                }

                if (local.size() == 5 && local[1] == ".")
                {
                    doActions(local);
                    return(false);
                }
            }

            return(false);
        }
 public SaveDeclar(Repository repo)
 {
     repo_ = Repository.getInstance();
 }
コード例 #25
0
ファイル: Parser.cs プロジェクト: SimHuang/RemoteCodeAnalyzer
        //----< Test Stub >--------------------------------------------------

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

            ShowCommandLine(args);

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

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

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

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

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

                CSsemi.CSemiExp semi = new CSsemi.CSemiExp();
                semi.displayNewLines = false;
                if (!semi.open(file as string))
                {
                    Console.Write("\n  Can't open {0}\n\n", args[0]);
                    return;
                }

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

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

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

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

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

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

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

                semi.close();
            }
            Console.Write("\n\n");
        }
 public PrintSemi(Repository repo)
 {
     repo_ = Repository.getInstance();
 }
 public CollectNew(ref CsNode <string, string> node)
 {
     currentNode_ = node;
     repo_        = Repository.getInstance();
 }
 public PushStack(Repository repo)
 {
     repo_ = Repository.getInstance();
 }
コード例 #29
0
        //----< Test Stub >--------------------------------------------------

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

            ShowCommandLine(args);

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

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

                CSsemi.CSemiExp semi = new CSsemi.CSemiExp();
                semi.displayNewLines = false;
                if (!semi.open(file as string))
                {
                    Console.Write("\n  Can't open {0}\n\n", args[0]);
                    return;
                }

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

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

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

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

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



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

                CSsemi.CSemiExp semi = new CSsemi.CSemiExp();
                semi.displayNewLines = false;
                if (!semi.open(file as string))
                {
                    Console.Write("\n  Can't open {0}\n\n", args[0]);
                    return;
                }

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

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

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

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

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

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

                Console.Write("\n");
                semi.close();
            }
            Console.Write("\n\n");
        }
コード例 #30
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();
        }