Beispiel #1
0
        static void Main()
        {
            Console.Write("\n  Test ScopeStack");
            Console.Write("\n =================\n");

            ScopeStack <Elem> mystack = new ScopeStack <Elem>();

            Test.Elem e;
            e.type  = "namespace";
            e.name  = "foobar";
            e.place = 14;
            mystack.push(e);
            e.make("class", "feebar", 21);
            mystack.push(e);
            e.make("function", "doTest", 44);
            mystack.push(e);
            e.make("control", "for", 56);
            mystack.push(e);

            mystack.display();
            Console.WriteLine();

            Elem test = mystack.lastPopped();

            Console.Write("\n  last popped:\n  {0}\n", test);

            e = mystack.pop();
            Console.Write("\n  popped:\n  {0}", e);
            e = mystack.pop();
            Console.Write("\n  popped:\n  {0}\n", e);
            Console.Write("\n  last popped:\n  {0}\n", mystack.lastPopped());

            mystack.display();

            Console.Write("\n\n");
        }
 public override void doAction(CSsemi.CSemiExp semi, string filename)
 {
     if (semi[1].Equals("Inheritance")) //Action for Inheritance
     {
         inheritance(semi, filename);
         return;
     }
     if (semi[0].Contains("Aggregation"))
     {
         aggregation(semi, filename);
         return;
     }
     if (semi[0].Contains("Composition"))
     {
         composition(semi, filename);
         return;
     }
     if (semi[0].Contains("Using"))
     {
         usingRelation(semi, filename);
         return;
     }
     if (semi[0].Contains("function") || semi[0].Contains("control") || semi[0].Contains("anonymous"))
         return;
     if (semi[0].Contains("class"))
     {
         Elem ele = new Elem();
         ele.type = semi[0];
         ele.name = semi[1];
         ele.filename = filename;
         repo_.locations.Add(ele);
     }
     if (AAction.displaySemi)
     {
         Console.Write("\n  line# {0,-5}", repo_.semi.lineCount - 1);
         Console.Write("entering ");
         string indent = new string(' ', 2 * repo_.stack.count);
         Console.Write("{0}", indent);
         this.display(semi); // defined in abstract action
     }
     if (AAction.displayStack)
         repo_.stack.display();
 }
 public override void doAction(CSsemi.CSemiExp semi, string filename)
 {
     if (semi[0].Equals("complexity"))
     {
         try
         {
             int x = repo_.locations.Count;
             Elem temp = repo_.locations[x - 1];
             if (temp.type.Equals("function"))
                 temp.complexity += 1;
         }
         catch
         {
         }
         return;
     }
     else
     {
         Elem elem = new Elem();
         elem.type = semi[0];  // expects type
         elem.name = semi[1];  // expects name
         elem.begin = repo_.semi.lineCount - 1;
         elem.end = 0;
         elem.filename = filename;
         elem.complexity = 1;
         repo_.stack.push(elem);
         if (elem.type == "control" || elem.name == "anonymous")
             return;
         repo_.locations.Add(elem);
         RepositoryForOutput.storageForOutput_.Add(elem);
         if (AAction.displaySemi)
         {
             Console.Write("\n  line# {0,-5}", repo_.semi.lineCount - 1);
             Console.Write("entering ");
             string indent = new string(' ', 2 * repo_.stack.count);
             Console.Write("{0}", indent);
             this.display(semi); // defined in abstract action
         }
         if (AAction.displayStack)
             repo_.stack.display();
     }
 }
 private static void repositoryForTestUP()
 {
     Elem e = new Elem();
     e.type = "namespace";
     e.name = "karan";
     e.begin = 10;
     e.end = 70;
     RepositoryForOutput.storageForOutput_.Add(e);
     Elem e1 = new Elem();
     e1.type = "class";
     e1.name = "Display";
     e1.begin = 12;
     e1.end = 68;
     RepositoryForOutput.storageForOutput_.Add(e1);
     Elem e2 = new Elem();
     e2.type = "function";
     e2.name = "test";
     e2.begin = 30;
     e2.end = 65;
     e2.complexity = 5;
     RepositoryForOutput.storageForOutput_.Add(e2);
     ElemRelation er = new ElemRelation();
     er.relationType = "Aggregation";
     er.fromName = "Display";
     er.toName = "Xyz";
     RepositoryForRelation.storageForRelationship_.Add(er);
     ElemRelation er1 = new ElemRelation();
     er1.relationType = "Inheritance";
     er1.fromName = "Display";
     er1.toName = "Test";
     RepositoryForRelation.storageForRelationship_.Add(er1);
     ElemRelation er2 = new ElemRelation();
     er2.relationType = "Composition";
     er2.fromName = "Display";
     er2.toName = "ValueType";
     RepositoryForRelation.storageForRelationship_.Add(er2);
 }
Beispiel #5
0
        /* This method is used to call the relationship and complexity analysis
         * for each file in the input set
         */
        public void analyze()
        {
            CSsemi.CSemiExp semi = new CSsemi.CSemiExp();
            semi.displayNewLines = false;

            /* These are the supported file formats in this tool. If input file is not in this format,
             * then analysis will not be done*/
            string[] supportedFileFormatList = { ".cs", ".c", ".cpp", ".java", ".txt", ".bat" };

            foreach (object file in files)
            {
                string fileExtension       = Path.GetExtension(file.ToString());
                bool   supportedFileFormat = false;

                foreach (string currentFileExtension in supportedFileFormatList)
                {
                    if (fileExtension == currentFileExtension)
                    {
                        supportedFileFormat = true;
                    }
                }

                if (!supportedFileFormat)
                {
                    Console.WriteLine("\nThe file {0} is of unsupported format", file.ToString());
                    continue;
                }
                if (!semi.open(file as string))
                {
                    Console.Write("\n  Can't open {0}\n\n", file);
                    return;
                }

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

                Repository repo = Repository.getInstance();
                Elem       elem = getDefaultElemData(file.ToString());
                repo.locations.Add(elem);

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

                //Only when the user specifies the /R option, we do relationship analysis
                if (findRelationship)
                {
                    semi = new CSsemi.CSemiExp();
                    semi.displayNewLines = false;
                    if (!semi.open(file as string))
                    {
                        Console.Write("\n  Can't open {0}\n\n", file);
                        return;
                    }

                    BuildCodeAnalyzerForRelationshipTypes builderreln = new BuildCodeAnalyzerForRelationshipTypes(semi);
                    parser = builderreln.build();

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