Exemple #1
0
        public override bool test(CSsemi.CSemiExp semi)
        {
            Repository rep = Repository.getInstance();

            //if (!rep.isFirstPass)
            //{
            //return false;
            //}

            if (rep.stack.count <= 0)
            {
                // we are not in a class or function scope
                return(false);
            }
            else if (rep.stack[rep.stack.count - 1].type != "class")
            {
                return(false);
            }
            else if (rep.stack.count > 2)
            {
                //Console.WriteLine("skip: found class in a class, unhandled");
                return(false);
            }

            Display.displayRules(actionDelegate, "rule   DetectClassMembers");

            int index = semi.Contains(";");

            if (index != -1)
            {
                CSsemi.CSemiExp clean = TokenHelper.RemoveNewLines(semi);
                clean = TokenHelper.GetLeftOfEqual(clean);
                clean = TokenHelper.RemoveGenerics(clean);
                clean = TokenHelper.RemoveIndicies(clean);
                clean = TokenHelper.RemoveKeywords(clean);
                clean = TokenHelper.RemoveAccess(clean);
                clean = TokenHelper.CombineNamespace(clean);

                // "if", "for", "foreach", "while", "catch", "using"
                if ((clean[0] == "using") || (clean[0] == "return") || (clean[0] == "if") || (clean[0] == "for") || (clean[0] == "break") || (clean.Contains("(") != -1) || (clean[0] == "get") || (clean[0] == "set"))
                {
                    return(false);
                }

                CSsemi.CSemiExp local = new CSsemi.CSemiExp();
                // create local semiExp with tokens for type and name
                local.displayNewLines = false;

                if (rep.stack.count < 2)
                {
                    return(false);
                }

                string ns = rep.stack[0].name;
                string cl = rep.stack[1].name;

                if (clean.count >= 2)
                {
                    local.Add(clean[0]).Add(clean[1]);

                    if (rep.isFirstPass)
                    {
                        /////////////////////////////////////////////////////////////////
                        //
                        // Parse Class to get class members
                        //
                        /////////////////////////////////////////////////////////////////

                        if (rep.stack.count == 2)
                        {
                            string type = clean[0];
                            string name = clean[1];

                            CClassInfo currentClassInfo = rep.parsedData.getClassInfo(cl);
                            currentClassInfo.addDataMember(type, name);
                        }
                    }
                    else
                    {
                        /////////////////////////////////////////////////////////////////
                        //
                        // Parse Class body to detect class use dependency
                        //
                        /////////////////////////////////////////////////////////////////

                        if (rep.stack.count == 2)
                        {
                            foreach (CClassInfo ci in rep.parsedData.classList)
                            {
                                if (semi.Contains(ci.className) != -1)
                                {
                                    CClassInfo currentClassInfoList = rep.parsedData.getClassInfo(cl);
                                    currentClassInfoList.addDependency(ci.className);
                                }
                            }
                        }
                    }

                    return(true);
                }
            }

            return(false);
        }
Exemple #2
0
        public override bool test(CSsemi.CSemiExp semi)
        {
            Display.displayRules(actionDelegate, "rule   DetectClass");

            int indexCL = semi.Contains("class");
            int indexIF = semi.Contains("interface");
            int indexST = semi.Contains("struct");

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

            index = Math.Max(index, indexST);
            if (index != -1)
            {
                /////////////////////////////////////////////////////////////////
                //
                // Parse Class to get class names
                //
                /////////////////////////////////////////////////////////////////
                Repository rep = Repository.getInstance();

                CSsemi.CSemiExp local = new CSsemi.CSemiExp();

                // local semiExp with tokens for type and name
                local.displayNewLines = false;
                local.Add(semi[index]).Add(semi[index + 1]);
                doActions(local);

                if (rep.stack.count < 2)
                {
                    return(false);
                }

                string ns = rep.stack[0].name;
                string cl = rep.stack[1].name;

                // If it's not there, it's automatically added in getClassInfo()
                CClassInfo currentClassInfo = rep.parsedData.getClassInfo(cl);

                /////////////////////////////////////////////////////////////////
                //
                // Parse Class to detect inheritance
                //
                /////////////////////////////////////////////////////////////////
                if (!rep.isFirstPass)
                {
                    index = semi.Contains(":");
                    if (index != -1)
                    {
                        if (index + 1 < semi.count)
                        {
                            string baseClass = semi[index + 1];
                            currentClassInfo.addDependency(baseClass);
                        }
                    }
                }

                return(true);
            }

            return(false);
        }