示例#1
0
        public override bool test(CSsemi.CSemiExp semi)
        {
            int index    = -1;
            int braIndex = -1;

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

            foreach (Elem e in temp)
            {
                if (e.type.Equals("struct"))
                {
                    index    = semi.Contains(e.name);
                    braIndex = semi.Contains("{");
                }
                if (e.type.Equals("enum"))
                {
                    index    = semi.Contains(e.name);
                    braIndex = semi.Contains("{");
                }

                if (index != -1 && braIndex == -1)
                {
                    CSsemi.CSemiExp local = new CSsemi.CSemiExp();
                    // local semiExp with tokens for type and name
                    local.displayNewLines = false;
                    if (e.type.Equals("struct"))
                    {
                        local.Add("Composition").Add("struct").Add(semi[index]);
                    }
                    else
                    {
                        local.Add("Composition").Add("enum").Add(semi[index]);
                    }

                    doActions(local);
                    return(true);
                }
            }
            return(false);
        }
示例#2
0
        public override bool test(CSsemi.CSemiExp semi)
        {
            int index     = -1;
            int braIndex  = -1;
            int realUsing = -1;
            int dotIndex  = -1;

            //Adding using rule for detecting strings

            int strIndex = -1;
            int strOpen  = -1;
            int strClose = -1;
            int realStr  = -1;

            Repository     rep     = Repository.getInstance();
            List <Elem>    temp    = rep.locations;
            List <RelElem> tempRel = rep.inheritance;
            List <RelElem> tempUse = rep.inheritance;


            //adding using rule for string

            strIndex = semi.Contains("string");
            strOpen  = semi.Contains("(");
            strClose = semi.Contains(")");

            if ((strIndex != -1) && (strOpen != -1) && (strClose != -1) && (semi[strClose - 1] != "(") && (semi[strClose - 1] != ")") && (semi.Contains("<") == -1) && (semi.Contains("[") == -1))
            {
                CSsemi.CSemiExp local = new CSsemi.CSemiExp();
                // local semiExp with tokens for type and name
                local.displayNewLines = false;
                local.Add("UsingStr").Add(semi[strIndex]).Add(semi[strClose - 1]);
                doActions(local);
                return(true);
            }

            foreach (Elem e in temp)
            {
                if (e.type.Equals("class"))
                {
                    index    = semi.Contains(e.name);
                    braIndex = semi.Contains("(");
                    dotIndex = semi.Contains(".");
                }

                if (index != -1 && braIndex != -1 && dotIndex == -1 && semi[index + 1] != "(" && semi[index + 1] != ")")
                {
                    CSsemi.CSemiExp local = new CSsemi.CSemiExp();
                    // local semiExp with tokens for type and name
                    local.displayNewLines = false;
                    local.Add("UsingTemp").Add(semi[index]).Add(semi[index + 1]);
                    doActions(local);
                    return(true);
                }
            }
            foreach (RelElem rel in tempRel)
            {
                realUsing = semi.Contains(rel.withName);
                if (realUsing != -1 && rel.type.Equals("UsingTemp"))
                {
                    // foreach(RelElem rr in tempUse)
                    //{

                    CSsemi.CSemiExp local = new CSsemi.CSemiExp();
                    // local semiExp with tokens for type and name
                    local.displayNewLines = false;
                    local.Add("Using").Add(semi[realUsing]).Add(rel.name);
                    doActions(local);
                    return(true);
                    //}
                }
            }

            //adding using for string
            foreach (RelElem rel in tempRel)
            {
                realStr = semi.Contains(rel.withName);
                if (realStr != -1 && rel.type.Equals("UsingStr"))
                {
                    // foreach(RelElem rr in tempUse)
                    //{

                    CSsemi.CSemiExp local = new CSsemi.CSemiExp();
                    // local semiExp with tokens for type and name
                    local.displayNewLines = false;
                    local.Add("Using").Add(rel.withName).Add(rel.withName);
                    doActions(local);
                    return(true);
                    //}
                }
            }

            return(false);
        }
示例#3
0
        public void process(bool relationship)
        {
            XmlDocument doc1 = new XmlDocument();

            doc1.LoadXml(" <codeAnalysis>   </codeAnalysis> ");

            XmlNode root = doc1.DocumentElement;

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

            //FOR DISPLAYING NAMESCAPE,CLASSES AND FUNCTIONS

            foreach (Elem e in table)
            {
                if (e.type.Equals("namespace"))
                {
                    //Create a new node.
                    XmlElement nameNode = doc1.CreateElement("namespace");
                    nameNode.SetAttribute("name", e.name);
                    root.AppendChild(nameNode);
                }

                if (e.type.Equals("inheritance"))
                {
                    XmlElement inhertNode = doc1.CreateElement("inheritance");
                    inhertNode.SetAttribute("name", e.name);
                    root.AppendChild(inhertNode);
                }

                if (e.type.Equals("class"))
                {
                    XmlElement classNode = doc1.CreateElement("class");
                    classNode.SetAttribute("name", e.name);
                    root.AppendChild(classNode);
                }

                if (e.type.Equals("function"))
                {
                    int size       = e.end - e.begin;
                    int complexity = 0;
                    foreach (Elem t in temp)
                    {
                        if (t.type.Equals("control") && (t.begin > e.begin) && (t.end < e.end))
                        {
                            complexity++;
                        }
                        if (t.type.Equals("braceless") && (t.begin > e.begin) && (t.end < e.end))
                        {
                            complexity++;
                        }
                    }

                    XmlElement funtNode = doc1.CreateElement("function");
                    funtNode.SetAttribute("name", e.name);
                    funtNode.SetAttribute("size", size.ToString());
                    funtNode.SetAttribute("complexity", complexity.ToString());
                    root.AppendChild(funtNode);
                }
            }
            doc1.Save("Functions.xml");


            //FOR DISPLAYING RELATIONSHIPS
            if (relationship)
            {
                XmlDocument doc2 = new XmlDocument();
                doc2.LoadXml(" <codeAnalysis>   </codeAnalysis> ");

                XmlNode root2 = doc2.DocumentElement;

                List <RelElem> table2 = rep.inheritance;

                List <RelElem> temp2 = rep.inheritance;

                foreach (Elem ee in table)
                {
                    if (ee.type.Equals("class"))
                    {
                        //CREATE NODE

                        XmlElement classNode = doc2.CreateElement("class");
                        classNode.SetAttribute("name", ee.name);
                        root2.AppendChild(classNode);



                        foreach (RelElem rr in table2)
                        {
                            if ((rr.beginRel >= ee.begin) && (rr.endRel <= ee.end) && (rr.type != "UsingTemp") && (rr.type != "UsingStr"))
                            {
                                XmlElement relNode = doc2.CreateElement("relationship");
                                relNode.SetAttribute("type", rr.type);
                                relNode.SetAttribute("with", rr.withName);
                                relNode.SetAttribute("atline", rr.beginRel.ToString());
                                classNode.AppendChild(relNode);
                            }
                        }
                    }
                }

                doc2.Save("Relationships.xml");
            }
        }
示例#4
0
        static void Main(string[] args)
        {
            Executive e = new Executive();


            try
            {
                CommandLineParser argument = new CommandLineParser();

                //  Console.WriteLine("testing ");
                // Console.WriteLine("Command Line Argument is = \n" + args);
                argument.splitArgument(args, out e.path, out e.pattern, out e.options);

                // Console.WriteLine("path is {0}", e.path);
                if (e.path.Length == 0)
                {
                    e.path = "../../";
                }
                if (e.pattern.Count == 0)
                {
                    e.pattern.Add("*.cs");
                }



                // Console.WriteLine("File Path is {0}\nFile Pattern is {1}\nOptions are{2}", e.Path, e.pattern, e.options);
            }

            catch (Exception exp)
            {
                Console.WriteLine("There is an error in command line {0} \n", args);
                Console.WriteLine("\n Error Message {0} \n \n", exp.Message);
            }


            e.Recurse       = e.options.Contains("/S");
            e.Relationship  = e.options.Contains("/R");
            e.XMLProcessing = e.options.Contains("/X");



            string[] files = Executive.getFiles(e.path, e.pattern, e.Recurse);



            Analyzer ana = new Analyzer();

            Display d = new Display();


            ana.doAnalysis(files);
            //d.display(files,e.Relationship);

            TypeBuilder tb = new TypeBuilder();

            tb.addTypes();

            Repository r = Repository.getInstance();


            foreach (KeyValuePair <string, TypeElem> k in r.typeTable)
            {
                Console.WriteLine(" {0} and {1}", k.Key, k.Value);
            }


            if (e.XMLProcessing)
            {
                XMLProcessor xp = new XMLProcessor();

                xp.process(e.Relationship);
            }

            Console.ReadLine();
        }
示例#5
0
        public void display(string[] files, bool relationship)
        {
            Repository  rep   = Repository.getInstance();
            List <Elem> table = rep.locations;


            //DISPLAY FILES IN THE FILE SET
            Console.WriteLine("Files in fileset are \n");
            foreach (object file in files)
            {
                Console.WriteLine(file as string);
            }



            // COUNT FOR COMPLEXITY AND FUNCTION SIZES

            List <Elem> temp = rep.locations;

            foreach (Elem e in table)
            {
                if (e.type.Equals("namespace"))
                {
                    Console.WriteLine("\n{0,9},{1,10}, starts at line{2,5},end at line{3,5}", e.type, e.name, e.begin, e.end);
                }

                if (e.type.Equals("inheritance"))
                {
                    Console.WriteLine("\n{0,10},{1,10},starts at line{2,5},ends at line{3,5}", e.type, e.name, e.begin, e.end);
                }

                //search for the namespace for that particular class

                if (e.type.Equals("class"))
                {
                    foreach (Elem tt in temp)
                    {
                        if (tt.type.Equals("namespace"))
                        {
                            if ((tt.begin < e.begin) && (tt.end > e.end))
                            {
                                Console.WriteLine("\n{0,5},{1,10}.{2,5},starts at line{3,5},ends at line{4,5}", e.type, tt.name, e.name, e.begin, e.end);
                            }
                        }
                    }
                }
                if (e.type.Equals("function"))
                {
                    int size       = e.end - e.begin;
                    int complexity = 0;
                    foreach (Elem t in temp)
                    {
                        if (t.type.Equals("control") && (t.begin > e.begin) && (t.end < e.end))
                        {
                            complexity++;
                        }
                        if (t.type.Equals("braceless") && (t.begin > e.begin) && (t.end < e.end))
                        {
                            complexity++;
                        }
                    }

                    Console.WriteLine("\nFunction {0,10}, size={1,3} complexity={2,3}", e.name, size, complexity);
                }
            }

            //DISPLAY RELATIONSHIPS


            //Console.Write("\n\n  relationship table contains:");

            /*  List<RelElem> table2 = rep.inheritance;
             *
             * foreach (RelElem e in table2)
             * {
             *    Console.Write("\n  {0,10}, {1,25},{2,20}, {3,5}, {4,5}", e.type, e.name, e.withName, e.beginRel, e.endRel);
             * }
             * Console.WriteLine();
             * Console.Write("\n\n  That's all folks!\n\n");
             * Console.ReadLine(); */

            //DISPLAY FINAL RELATIONSHIPS
            if (relationship)
            {
                List <RelElem> table2 = rep.inheritance;

                List <RelElem> temp2 = rep.inheritance;

                foreach (Elem ee in table)
                {
                    if (ee.type.Equals("class"))
                    {
                        foreach (RelElem rr in table2)
                        {
                            if ((rr.beginRel >= ee.begin) && (rr.endRel <= ee.end) && (rr.type != "UsingTemp") && (rr.type != "UsingStr"))
                            {
                                Console.WriteLine("\nclass {0} has {1} relationship with {2} at line {3}", ee.name, rr.type, rr.withName, rr.beginRel);
                            }
                        }
                    }
                }
            }
        }
        public void doAnalysis(string[] files)
        {
            // Parser p = new Parser();
            //p.parseFiles(files);

            //NEW DESIGN

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

            foreach (object file in files)
            {
                semi.displayNewLines = false;
                if (!semi.open(file as string))
                {
                    Console.Write("\n  Can't open {0}\n\n", file);
                    return;
                }

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

                //  Console.WriteLine("processing file{0}", file as string);



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

                semi.close();
            }

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


            Parser parser2 = builder.build2(rep, semi2);

            foreach (object file in files)
            {
                // CSsemi.CSemiExp semi = new CSsemi.CSemiExp();
                semi2.displayNewLines = false;

                if (!semi2.open(file as string))
                {
                    Console.Write("\n  Can't open {0}\n\n", file);
                    return;
                }

                try
                {
                    do
                    {
                        parser2.parse(semi2);
                    } while (semi2.getSemi());
                }
                catch (Exception ex)
                {
                    Console.Write("\n\n  {0}\n", ex.Message);
                }
                //Repository rep = Repository.getInstance();

                semi2.close();
            }
        }