예제 #1
0
        public void parse(Lexer.ITokenCollection semi, string currentFile)
        {
            DetectUsing dusing = new DetectUsing();

            if (dusing.test(semi))
            {
                namespacesUsed.Add(semi[1]);
            }
            if (semi.ToString().ToLower().Contains('='))
            {
                string classType = null;
                classType = (semi.ToString().Split('=')[0]).ToString().Split(' ')[0];
                if (TypeTable.TTable.table.ContainsKey(classType))
                {
                    List <TypeItem> function_list = new List <TypeItem>();
                    TypeTable.TTable.table.TryGetValue(classType, out function_list);
                    for (var i = 0; i < function_list.Count; i++)
                    {
                        if (namespacesUsed.Contains(function_list[i].namesp))
                        {
                            Console.WriteLine("    Dependency : " + function_list[i].file);
                            string fullPathParent = System.IO.Path.GetFileName(currentFile);
                            string fullPathChild = System.IO.Path.GetFileName(function_list[i].file);
                            int    parent, child;
                            FileNames.TryGetValue(fullPathChild, out child);
                            FileNames.TryGetValue(fullPathParent, out parent);
                            Graph.setDependency(parent, child);
                        }
                    }
                }
            }
        }
예제 #2
0
        public int indexOfType(Lexer.ITokenCollection semi)
        {
            int indexCL;

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

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

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

            semi.find("enum", out indexEN);
            int indexDE;

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

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

            index = Math.Max(index, indexST);
            index = Math.Max(index, indexEN);
            index = Math.Max(index, indexDE);
            return(index);
        }
예제 #3
0
 public void doActions(Lexer.ITokenCollection semi)
 {
     foreach (IAction action in actions)
     {
         action.doAction(semi);
     }
 }
 //------------------<Build up dependency analyzer>---------------
 public BuildDependencyAnalyzer(Lexer.ITokenCollection semi,
                                string file)
 {
     repo.semi             = semi;
     file_                 = file;
     currentNode           = new CsNode <string, string>(file);
     currentNode.nodeValue = file;
     currentNode.name      = file;
 }
예제 #5
0
        static void testDepAnlPackage()
        {
            DAnalysis depAnls = new DAnalysis();

            Lexer.ITokenCollection semi = null;
            string currentFile          = "../../../TestFile.testZero.cs";

            depAnls.parse(semi, currentFile);
        }
예제 #6
0
 public virtual void display(Lexer.ITokenCollection semi)
 {
     if (displaySemi)
     {
         for (int i = 0; i < semi.size(); ++i)
         {
             Console.Write("{0} ", semi[i]);
         }
     }
 }
예제 #7
0
 public override void display(Lexer.ITokenCollection semi)
 {
   Console.Write("\n    line# {0}", repo_.semi.lineCount() - 1);
   Console.Write("\n    ");
   for (int i = 0; i < semi.size(); ++i)
   {
     if (semi[i] != "\n")
       Console.Write("{0} ", semi[i]);
   }
 }
        public override void doAction(ITokenCollection semi)
        {
            Elem elem;

            try
            {
                // if stack is empty (shouldn't be) pop() will throw exception

                elem = repo_.stack.pop();

                // record ending line count and scope level
                if (elem.type == "namespace")                                  // if a end of namespace scope detected, we pop the namespaceStack
                {
                    repo_.namespaceStack.Pop();
                }
                for (int i = 0; i < repo_.locations.Count; ++i)
                {
                    Elem temp = repo_.locations[i];
                    if (elem.type == temp.type)
                    {
                        if (elem.name == temp.name)
                        {
                            if ((repo_.locations[i]).endLine == 0)
                            {
                                (repo_.locations[i]).endLine       = repo_.semi.lineCount();
                                (repo_.locations[i]).endScopeCount = repo_.scopeCount;
                                break;
                            }
                        }
                    }
                }
            }
            catch
            {
                return;
            }

            if (AAction.displaySemi)
            {
                Lexer.ITokenCollection local = Factory.create();
                local.add(elem.type).add(elem.name);
                if (local[0] == "control")
                {
                    return;
                }

                Console.Write("\n  line# {0,-5}", repo_.semi.lineCount());
                Console.Write("leaving  ");
                string indent = new string(' ', 2 * (repo_.stack.count + 1));
                Console.Write("{0}", indent);
                this.display(local); // defined in abstract action
            }
        }
예제 #9
0
        public void parse(Lexer.ITokenCollection semi)
        {
            Display.displaySemiString(semi.ToString());

            foreach (IRule rule in Rules)
            {
                if (rule.test(semi))
                {
                    break;
                }
            }
        }
예제 #10
0
        public void parse(Lexer.ITokenCollection semi)
        {
            // Note: rule returns true to tell parser to stop
            //       processing the current semiExp


            foreach (IRule rule in Rules)
            {
                if (rule.test(semi))
                {
                    break;
                }
            }
        }
        public override void doAction(ITokenCollection semi)
        {
            Display.displayActions(actionDelegate, "action SaveDeclar");
            Elem elem;

            try
            {
                elem = repo_.stack.pop();
                TypeInfo tempT = new TypeInfo();
                tempT.file = file_;
                extractType(elem);
                for (int i = 0; i < repo_.locations.Count; ++i)
                {
                    Elem temp = repo_.locations[i];
                    if (elem.type == temp.type)
                    {
                        if (elem.name == temp.name)
                        {
                            if ((repo_.locations[i]).endLine == 0)
                            {
                                (repo_.locations[i]).endLine       = repo_.semi.lineCount();
                                (repo_.locations[i]).endScopeCount = repo_.scopeCount;
                                break;
                            }
                        }
                    }
                }
            }
            catch
            {
                return;
            }

            if (AAction.displaySemi)
            {
                Lexer.ITokenCollection local = Factory.create();
                local.add(elem.type).add(elem.name);
                if (local[0] == "control")
                {
                    return;
                }

                Console.Write("\n  line# {0,-5}", repo_.semi.lineCount());
                Console.Write("leaving  ");
                string indent = new string(' ', 2 * (repo_.stack.count + 1));
                Console.Write("{0}", indent);
                this.display(local); // defined in abstract action
            }
        }
예제 #12
0
        public void parse(Lexer.ITokenCollection semi)
        {
            // Note: rule returns true to tell parser to stop
            //       processing the current semiExp

            Display.displaySemiString(semi.ToString());

            foreach (CodeAnalysis.IRule rule in Rules)
            {
                if (rule.test(semi))
                {
                    break;
                }
            }
        }
예제 #13
0
        public void parse(Lexer.ITokenCollection semi)
        {
            // Note: rule returns true to tell parser to stop
            //       processing the current semiExp

            Display.displaySemiString(semi.ToString());

            foreach (IRule rule in Rules)
            {
                if (rule.test(semi))
                { //////////////////////////////////////////////////////////////////////
                    //        Console.WriteLine("Matched Rule:{0} for {1}", rule,semi);
                    break;
                }
            }
        }
예제 #14
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();
            }
        }
예제 #15
0
 abstract public bool test(Lexer.ITokenCollection semi);
 //--------------<Build up type anlyzer>--------------
 public BuildTypeAnalyzer(Lexer.ITokenCollection semi, string file)
 {
     repo.semi = semi;
     file_     = file;
 }
 public BuildTpyeTablePareer(Lexer.ITokenCollection semi)
 {
     repo.semi = semi;
 }
예제 #18
0
        //static public Action<string> actionDelegate;

        public abstract void doAction(Lexer.ITokenCollection semi);
예제 #19
0
 public BuildCodeAnalyzer(Lexer.ITokenCollection semi, string file)
 {
     repo.semi     = semi;
     repo.filename = file;
 }
예제 #20
0
 public BuildCodeAnalyzer(Lexer.ITokenCollection semi)
 {
   repo.semi = semi;
 }