Exemplo n.º 1
0
        public override bool test(CSsemi.CSemiExp semi)
        {
            int index = semi.Contains("enum");

            if (index != -1)
            {
                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);
                return(true);
            }
            return(false);
        }
Exemplo n.º 2
0
        //----< remove new lines from semi expression >------------------------------
        static public CSsemi.CSemiExp RemoveNewLines(CSsemi.CSemiExp s)
        {
            CSsemi.CSemiExp newSemi = new CSsemi.CSemiExp();

            for (int i = 0; i < s.count; i++)
            {
                string cleanString = RemoveNewLinesFromString(s[i]);
                if (cleanString.Length>0)
                {
                    newSemi.Add(cleanString);
                }
            }

            return newSemi;
        }
Exemplo n.º 3
0
        public override bool test(CSsemi.CSemiExp semi)
        {
            int loc = semi.Contains("new");

            if (loc != -1)
            {
                CSsemi.CSemiExp local = new CSsemi.CSemiExp();
                local.displayNewLines = false;
                local.Add(semi[loc]).Add(semi[loc + 1]);
                doActions(local);
                return(true);
            }
            return(false);/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            /////////////////////////////////////////////
        }
        public override bool test(CSsemi.CSemiExp semi, string filename)
        {
            int index = semi.Contains("delegate");

            if (index != -1)
            {
                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 + 2]);
                doActions(local, filename);
                return(true);
            }
            return(false);
        }
Exemplo n.º 5
0
        public override bool test(CSsemi.CSemiExp semi)
        {
            int index = semi.Contains("{");

            if (index != -1)
            {
                CSsemi.CSemiExp local = new CSsemi.CSemiExp();
                // create local semiExp with tokens for type and name
                local.displayNewLines = false;
                local.Add("control").Add("anonymous");
                doActions(local);
                return(true);
            }
            return(false);
        }
Exemplo n.º 6
0
        public override void doAction(CSsemi.CSemiExp semi)
        {
            RelElem Relem;

            try
            {
                Relem = repo_.stack2.pop();
                for (int i = 0; i < repo_.inheritance.Count; ++i)
                {
                    RelElem temp = repo_.inheritance[i];
                    if (Relem.type == temp.type)
                    {
                        if (Relem.name == temp.name)
                        {
                            if (Relem.withName == temp.withName)
                            {
                                if ((repo_.inheritance[i]).endRel == 0)
                                {
                                    (repo_.inheritance[i]).endRel = repo_.semi.lineCount - repo_.prevLineCount;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            catch
            {
                Console.Write("popped empty stack on semiExp: ");
                semi.display();
                return;
            }
            CSsemi.CSemiExp local = new CSsemi.CSemiExp();
            local.Add(Relem.type).Add(Relem.name);
            if (local[0] == "control")
            {
                return;
            }

            if (AAction.displaySemi)
            {
                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
            }
        }
Exemplo n.º 7
0
        public override bool test(CSsemi.CSemiExp semi)
        {
            Display.displayRules(actionDelegate, "rule   DetectNamespace");
            int index = semi.Contains("namespace");

            if (index != -1)
            {
                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);
        }
Exemplo n.º 8
0
        public override void doAction(CSsemi.CSemiExp semi)
        {
            Display.displayActions(actionDelegate, "action SaveDeclar");
            Elem elem;

            try
            {
                elem = repo_.stack.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
            {
                Console.Write("popped empty stack on semiExp: ");
                semi.display();
                return;
            }
            CSsemi.CSemiExp local = new CSsemi.CSemiExp();
            local.Add(elem.type).Add(elem.name);
            if (local[0] == "control")
            {
                return;
            }

            if (AAction.displaySemi)
            {
                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
            }
        }
Exemplo n.º 9
0
        /*
         * Method to parse through list of user input files and parse
         * for all user defined types
         */
        public static void parseUserDefinedTypes(List <string> files)
        {
            if (files.Count == 0)
            {
                return;
            }

            foreach (String file in files)
            {
                Console.Write("Parsing for all user defined types");
                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.ToString());
                }

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

                //test against the detect class rule
                try
                {
                    //use the existing parser to test rule
                    while (semi.getSemi())
                    {
                        int index = isClassExpression(semi);
                        if (index != -1)
                        {
                            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]);
                            userDefinedSet.Add(semi[index + 1]);
                        }
                    }
                }
                catch (Exception ex) {
                    Console.Write("\n\n {0}", ex.Message);
                }
            }

            // return userDefinedSet;
        }
Exemplo n.º 10
0
        public override void doAction(CSsemi.CSemiExp semi)
        {
            Elem elem;

            try
            {
                elem = repo_.stack.pop();
                for (int i = 0; i < repo_.analyzedata.Count; ++i)
                {
                    Elem temp = repo_.analyzedata[i];
                    if (elem.type == temp.type)
                    {
                        if (elem.name == temp.name)
                        {
                            if ((repo_.analyzedata[i]).end == 0)
                            {
                                (repo_.analyzedata[i]).end = repo_.semi.lineCount;
                                break;
                            }
                        }
                    }
                    if (temp.end == 0 && temp.type == "function")
                    {
                        temp.scopecount++;
                    }
                }
            }
            catch
            {
                Console.Write("popped empty stack on semiExp: ");
                semi.display();
                return;
            }
            CSsemi.CSemiExp local = new CSsemi.CSemiExp();
            local.Add(elem.type).Add(elem.name);

            if (AAction.displaySemi)
            {
                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
            }
        }
Exemplo n.º 11
0
        public override bool test(CSsemi.CSemiExp semi)
        {
            Display.displayRules(actionDelegate, "rule   DetectAnonymousScope");

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

            if (index != -1)
            {
                Repository      rep   = Repository.getInstance();
                CSsemi.CSemiExp local = new CSsemi.CSemiExp();
                // create local semiExp with tokens for type and name
                local.displayNewLines = false;
                local.Add("control").Add("anonymous");
                doActions(local);
                return(true);
            }
            return(false);
        }
Exemplo n.º 12
0
        public override bool test(CSsemi.CSemiExp semi, string filename)
        {
            if (semi[semi.count - 1] != "{")
            {
                return(false);
            }

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

            if (index > 0 && !isSpecialToken(semi[index - 1]))
            {
                CSsemi.CSemiExp local = new CSsemi.CSemiExp();
                local.Add("function").Add(semi[index - 1]);
                doActions(local, filename);
                return(true);
            }
            return(false);
        }
Exemplo n.º 13
0
        public override bool test(CSsemi.CSemiExp semi)
        {
            Repository repo_ = Repository.getInstance();
            int        index = semi.FindFirst("new");

            if (index != -1)
            {
                string          currclassName = DetectParentClass.getClassName(repo_.semi.lineCount);
                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);
                doActionsAggregation(local);
                return(true);
            }

            return(false);
        }
Exemplo n.º 14
0
        public override bool test(CSsemi.CSemiExp semi)
        {
            int indexCL = semi.Contains("class");

            if (indexCL != -1)
            {
                if (semi.Contains(":") != -1)
                {
                    CSsemi.CSemiExp local = new CSsemi.CSemiExp();
                    // local semiExp with tokens for type and name
                    local.displayNewLines = false;
                    local.Add("Inheritance").Add(semi[indexCL + 1]).Add(semi[indexCL + 3]);
                    doActions(local);
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 15
0
        public override bool test(CSsemi.CSemiExp semi)
        {
            if (semi[semi.count - 1] != ";")
            {
                return(false);
            }

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

            if (index > 0 && isSpecialToken(semi[index - 1]))
            {
                CSsemi.CSemiExp local = new CSsemi.CSemiExp();
                local.Add("braceless").Add(semi[index - 1]);
                doActions(local);
                return(true);
            }
            return(false);
        }
Exemplo n.º 16
0
        /*This method will be called when we encounter the end
         * of scope for any type(class,function,struct etc).
         * At the end we append the ending line number for that type
         * */
        public override void doAction(CSsemi.CSemiExp semi)
        {
            Elem elem = null;

            try
            {
                if (repo_.stack.count >= 1)
                {
                    elem = repo_.stack.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]).end == 0)
                                {
                                    (repo_.locations[i]).end = repo_.semi.lineCount;
                                    break;
                                }
                            }
                        }
                        if (temp.end == 0 && temp.type == "function")
                        {
                            temp.scopecount++;
                        }
                    }
                }
            }
            catch
            {
                Console.Write("popped empty stack on semiExp: ");
                semi.display();
                return;
            }

            if (elem != null)
            {
                CSsemi.CSemiExp local = new CSsemi.CSemiExp();
                local.Add(elem.type).Add(elem.name);
            }
        }
Exemplo n.º 17
0
        public override bool test(CSsemi.CSemiExp semi)
        {
            Display.displayRules(actionDelegate, "rule   DetectFunction");
            if (semi[semi.count - 1] != "{")
            {
                return(false);
            }

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

            if (index > 0 && !isSpecialToken(semi[index - 1]))
            {
                CSsemi.CSemiExp local = new CSsemi.CSemiExp();
                local.Add("function").Add(semi[index - 1]);
                doActions(local);
                return(true);
            }
            return(false);
        }
Exemplo n.º 18
0
        public override bool test(CSsemi.CSemiExp semi, string file)
        {
            string[] scopeDetect = { "if", "for", "else", "switch", "try", "catch", "finally", "while", "foreach" };

            foreach (string s in scopeDetect)
            {
                int index1 = semi.Contains(s);
                if (index1 != -1)
                {
                    CSsemi.CSemiExp local = new CSsemi.CSemiExp();
                    // create local semiExp with tokens for type and name
                    local.displayNewLines = false;
                    local.Add("scopeDetect");
                    doActions(local, file);
                    return(false);
                }
            }
            return(false);
        }
Exemplo n.º 19
0
        public override bool test(CSsemi.CSemiExp semi)
        {
            string[] SplToks = { "for", "if", "else", "while", "foreach" };

            foreach (string toks in SplToks)
            {
                int index = semi.Contains(toks);
                if (index != -1)
                {
                    CSsemi.CSemiExp local = new CSsemi.CSemiExp();
                    // create local semiExp with tokens for type and name
                    local.displayNewLines = false;
                    local.Add("control").Add("anonymous");
                    doActions(local);
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 20
0
        public override bool test(CSsemi.CSemiExp semi)
        {
            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)
            {
                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);
                return(true);
            }
            return(false);
        }
Exemplo n.º 21
0
        public override bool test(CSsemi.CSemiExp semi, string filename)
        {
            string[] SpecialToken = { "try", "for", "foreach", "while", "switch", "if", "else", "catch", "using", "unsafe", "finally", "break" };
            int      index        = -1;

            foreach (string stoken in SpecialToken)
            {
                index = semi.Contains(stoken);
                if (index != -1)
                {
                    CSsemi.CSemiExp local = new CSsemi.CSemiExp();
                    // create local semiExp with tokens for type and name
                    local.displayNewLines = false;
                    local.Add("complexity");
                    doActions(local, filename);
                    return(false);
                }
            }
            return(false);
        }
Exemplo n.º 22
0
        public override bool test(CSsemi.CSemiExp semi)
        {
            int openBrace = semi.Contains(";");

            if (openBrace == -1)
            {
                return(false);
            }
            int index = semi.FindFirst("new");

            if (index > 0)
            {
                string          className = semi[index + 1];
                CSsemi.CSemiExp local     = new CSsemi.CSemiExp();
                local.Add("Aggregate").Add(className);
                doActions(local);
                return(true);
            }
            return(false);
        }
Exemplo n.º 23
0
        //----< get class inhertitance from semi expression >------------
        static public CSsemi.CSemiExp GetInheritance(CSsemi.CSemiExp s)
        {
            CSsemi.CSemiExp newSemi = new CSsemi.CSemiExp();

            int index = s.FindFirst(":");
            if (index != -1)
            {
                if (index + 1 < s.count)
                {
                    for (int i = index + 1; i < s.count; i++)
                    {
                        if (s[i] != "{")
                        {
                            newSemi.Add(s[i]);
                        }
                    }
                }
            }

            return newSemi;
        }
Exemplo n.º 24
0
        public override void doAction(CSsemi.CSemiExp semi)
        {
            Elem elem;

            try
            {
                elem = repo_.stack.pop();
            }
            catch
            {
                Console.Write("popped empty stack on semiExp: ");
                semi.display();
                return;
            }
            CSsemi.CSemiExp local = new CSsemi.CSemiExp();
            local.Add(elem.type).Add(elem.name);
            if (local[0] == "control")
            {
                return;
            }
        }
Exemplo n.º 25
0
        //----< remove bracket indicies from semi expression >------------------------------
        static public CSsemi.CSemiExp RemoveIndicies(CSsemi.CSemiExp s)
        {
            CSsemi.CSemiExp newSemi = new CSsemi.CSemiExp();

            int skip = 0;
            for (int i = 0; i < s.count; i++)
            {
                if (s[i] == "[")
                {
                    skip++;
                }
                if (skip == 0)
                {
                    newSemi.Add(s[i]);
                }
                if (s[i] == "]")
                {
                    --skip;
                }
            }

            return newSemi;
        }
Exemplo n.º 26
0
        public override bool test(CSsemi.CSemiExp semi)
        {
            int         index = semi.Contains("new");
            Repository  rep   = new Repository();
            List <Elem> e     = Repository.Copy_buffer;

            if (index != -1)
            {
                foreach (Elem e1 in e)
                {
                    if ((semi[index - 3] == e1.name) || (semi[index + 1] == e1.name))
                    {
                        CSsemi.CSemiExp local = new CSsemi.CSemiExp();
                        // create local semiExp with tokens for type and name
                        local.displayNewLines = false;
                        local.Add("Aggregation").Add(semi[index + 1]);
                        doActions(local);
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemplo n.º 27
0
        /*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);
        }
 public override bool test(CSsemi.CSemiExp semi, string filename)
 {
     int index = semi.Contains("delegate");
     if (index != -1)
     {
         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 + 2]);
         doActions(local, filename);
         return true;
     }
     return false;
 }
        private void inhertanceTest(CSsemi.CSemiExp semi, int index, string filename)
        {
            CSsemi.CSemiExp local = new CSsemi.CSemiExp();
            CSsemi.CSemiExp local1 = new CSsemi.CSemiExp();
            local.displayNewLines = false;
            local1.displayNewLines = false;

            if ((semi[index + 2].Equals(":")))
            {
                foreach (Elem check in table)
                {
                    if (check.name.Equals(semi[index + 3]))
                    {
                        local.Add(semi[index]).Add("Inheritance").Add(semi[index + 1]).Add(semi[index + 3]).Add(check.filename).Add(check.namespacename);
                        doActions(local, filename);
                        break;
                    }
                }
            }
            if ((semi[index + 2].Equals(":")) && (semi[index + 4].Equals(",")))
            {
                foreach (Elem check in table)
                {
                    if (check.name.Equals(semi[index + 5]))
                    {
                        local1.Add(semi[index]).Add("Inheritance").Add(semi[index + 1]).Add(semi[index + 5]).Add(check.filename).Add(check.namespacename);
                        doActions(local1, filename);
                        break;
                    }
                }
            }
        }
Exemplo n.º 30
0
        public override bool test(CSsemi.CSemiExp semi, string file)
        {
            try
            {
                List<Elem> output = OutputRepository.output_;

                int index = semi.Contains(":");
                if (index != -1)
                {
                    foreach (Elem e in output)
                    {
                        if (semi[index + 1].Equals(e.name))
                        {
                            CSsemi.CSemiExp local = new CSsemi.CSemiExp();
                            // create local semiExp with tokens for type and name
                            local.displayNewLines = false;
                            local.Add("Inheritance").Add(semi[index - 1]).Add(semi[index + 1]);
                            doActions(local, file);
                            return false;
                        }
                    }

                }
            }
            catch { }
            return false;
        }
Exemplo n.º 31
0
        public override bool test(CSsemi.CSemiExp semi, string file)
        {
            string[] scopeDetect = { "if", "for", "else", "switch", "try", "catch", "finally", "while", "foreach" };

            foreach (string s in scopeDetect)
            {
                int index1 = semi.Contains(s);
                if (index1 != -1)
                {
                    CSsemi.CSemiExp local = new CSsemi.CSemiExp();
                    // create local semiExp with tokens for type and name
                    local.displayNewLines = false;
                    local.Add("scopeDetect");
                    doActions(local, file);
                    return false;
                }
            }
            return false;
        }
Exemplo n.º 32
0
        public override bool test(CSsemi.CSemiExp semi)
        {
            string[] SpecialToken = { "if", "else", "for", "foreach", "while", "switch", "case", "do", "break" };
            int index = -1;
            int index2 = 0;
            CSsemi.CSemiExp local = new CSsemi.CSemiExp();
            bool flag = false;
            foreach (string stoken in SpecialToken)
            {
                index = semi.Contains(stoken);
                index2 = semi.FindFirst("{");
                if (index != -1 && index2 == -1)
                {
                    local = new CSsemi.CSemiExp();
                    // local semiExp with tokens for type and name
                    local.displayNewLines = false;
                    local.Add("Scope").Add(semi[index]);
                    doActions(local);
                    flag = false;
                }
            }
            if (flag)
                return true;

            return false;

        }
Exemplo n.º 33
0
        public override bool test(CSsemi.CSemiExp semi)
        {
            string[] SpecialToken = { "if", "else", "for", "foreach", "while", "catch", "try", "finally", "switch", "do" };
            int index = -1;
            foreach (string stoken in SpecialToken)
            {
                int tempindex = semi.Contains(stoken);
                if (tempindex != -1)
                    index = Math.Max(index, tempindex);

            }
            int index2 = semi.FindFirst("{");

            if (index != -1 && index2 != -1)
            {
                CSsemi.CSemiExp local = new CSsemi.CSemiExp();
                // local semiExp with tokens for type and name
                local.displayNewLines = false;
                local.Add("Scope").Add(semi[index]);
                doActions(local);
                return true;
            }

            return false;
        }
Exemplo n.º 34
0
 private CSsemi.CSemiExp scopeToSemi(Stack scope)
 {
   object[] StrArr = scope.ToArray();
   CSsemi.CSemiExp local = new CSsemi.CSemiExp();
   foreach (object str in StrArr)
     local.Add((string)str);
   return local;
 }
Exemplo n.º 35
0
        public override bool test(CSsemi.CSemiExp semi)
        {
            Repository repo_ = Repository.getInstance();
            int index = semi.FindFirst("new");
            if (index != -1)
            {
                string currclassName = DetectParentClass.getClassName(repo_.semi.lineCount);
                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);
                doActionsAggregation(local);
                return true;
            }

            return false;
        }
Exemplo n.º 36
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);
        }
 public override bool test(CSsemi.CSemiExp semi)
 {
     int indexEN = semi.Contains("enum");
       if (indexEN != -1)
       {
       CSsemi.CSemiExp local = new CSsemi.CSemiExp();
       local.displayNewLines = false;
       local.Add(semi[indexEN]).Add(semi[indexEN + 1]);
       doActions(local);
       return true;
       }
       return false;
 }
Exemplo n.º 38
0
        public override bool test(CSsemi.CSemiExp semi)
        {
            int indexDl = semi.Contains("delegate");

              if (indexDl != -1)
              {
              CSsemi.CSemiExp local = new CSsemi.CSemiExp();
              // local semiExp with tokens for type and name
              local.displayNewLines = false;
              local.Add(semi[indexDl]).Add(semi[indexDl+ 2]);
              doActions(local);
              return true;
              }
              return false;
        }
        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)
              {
            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);
            return true;
              }
              return false;
        }
        public override bool test(CSsemi.CSemiExp semi)
        {
            Display.displayRules(actionDelegate, "rule   DetectFunction");
              if (semi[semi.count - 1] != "{")
            return false;

              int index = semi.FindFirst("(");
              if (index > 0 && !isSpecialToken(semi[index - 1]))
              {
            CSsemi.CSemiExp local = new CSsemi.CSemiExp();
            local.Add("function").Add(semi[index - 1]);
            doActions(local);
            return true;
              }
              return false;
        }
 public override bool test(CSsemi.CSemiExp semi, string filename)
 {
     List<Elem> table = RepositoryForOutput.storageForOutput_;
     CSsemi.CSemiExp local = new CSsemi.CSemiExp();
     try
     {
         for (int i = 0; i < semi.count; i++)
         {
             foreach (Elem e in table)
             {
                 if ((e.name.Equals(semi[i])) && ((e.type.Equals("struct")) || (e.type.Equals("enum"))) && !(e.type.Equals("function")) && (semi[i + 2].Equals(";")))
                 {
                     local.Add("Composition").Add(semi[i]).Add(e.filename).Add(e.namespacename);
                     doActions(local, filename);
                     return true;
                 }
             }
         }
     }
     catch
     {
     }
     return false;
 }
Exemplo n.º 42
0
    public override bool test(CSsemi.CSemiExp semi)
    {
      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)
      {
        CSsemi.CSemiExp local = new CSsemi.CSemiExp();
        local.displayNewLines = false;
        local.Add(semi[index]).Add(semi[index + 1]);
        doActions(local);
      }
      return false;
    }
        public override bool test(CSsemi.CSemiExp semi)
        {
            Display.displayRules(actionDelegate, "rule   DetectPublicDeclar");
              int index = semi.Contains(";");
              if (index != -1)
              {
            index = semi.Contains("public");
            if (index == -1)
              return true;
            CSsemi.CSemiExp local = new CSsemi.CSemiExp();
            // create local semiExp with tokens for type and name
            local.displayNewLines = false;
            local.Add("public "+semi[index+1]).Add(semi[index+2]);

            index = semi.Contains("=");
            if (index != -1)
            {
              doActions(local);
              return true;
            }
            index = semi.Contains("(");
            if(index == -1)
            {
              doActions(local);
              return true;
            }
              }
              return false;
        }
 public override bool test(CSsemi.CSemiExp semi)
 {
     int index = semi.Contains("{");
       if (index != -1)
       {
     CSsemi.CSemiExp local = new CSsemi.CSemiExp();
     // create local semiExp with tokens for type and name
     local.displayNewLines = false;
     local.Add("control").Add("anonymous");
     doActions(local);
     return true;
       }
       return false;
 }
Exemplo n.º 45
0
        public override bool test(CSsemi.CSemiExp semi)
        {
            int indexCL = semi.Contains("class");
            int indexIF = semi.Contains("interface");

            int index = Math.Max(indexCL, indexIF);
            int index2 = semi.FindFirst(":");
            if (index != -1 && index2 != -1)
            {
                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 + 3]);
                doActionsInheritance(local);

                int multiInheritCount = semi.FindAll(",");
                while (multiInheritCount > 0)
                {
                    index2 = index2 + 2;
                    local = new CSsemi.CSemiExp();
                    local.displayNewLines = false;
                    local.Add(semi[index + 1]).Add(semi[index2 + 1]);
                    doActionsInheritance(local);
                    multiInheritCount--;
                }

                return true;
            }
            return false;
        }
        public override bool test(CSsemi.CSemiExp semi)
        {
            if (semi[semi.count - 1] != "{")
            return false;

              // strip off leading #if(TEST_XYZ) if it's in this semi

              if (semi.FindFirst("#") != -1)
              {
            int loc = semi.FindFirst(")");
            for (int i = 0; i <= loc; ++i)
              semi.remove(0);
              }
              // now find function

              int index = semi.FindFirst("(");
              if (index > 0 && !isSpecialToken(semi[index - 1]))
              {
            CSsemi.CSemiExp local = new CSsemi.CSemiExp();
            local.Add("function").Add(semi[index - 1]);
            doActions(local);
            return true;
              }
              return false;
        }
Exemplo n.º 47
0
        public override void doAction(CSsemi.CSemiExp semi)
        {
            Elem elem;

            try
            {
                elem = repo_.stack.pop();

                //reverse for loop for anonymous scope

                if (elem.type.Equals("control"))
                {
                    for (int i = repo_.locations.Count - 1; i >= 0; --i)
                    {
                        Elem temp = repo_.locations[i];
                        if (elem.type == temp.type)
                        {
                            if (elem.name == temp.name)
                            {
                                if ((repo_.locations[i]).end == 0)
                                {
                                    (repo_.locations[i]).end = repo_.semi.lineCount;
                                    break;
                                }
                            }
                        }
                    }
                }
                else
                {
                    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]).end == 0)
                                {
                                    (repo_.locations[i]).end = repo_.semi.lineCount;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            catch
            {
                Console.Write("popped empty stack on semiExp: ");
                semi.display();
                return;
            }
            CSsemi.CSemiExp local = new CSsemi.CSemiExp();
            local.Add(elem.type).Add(elem.name);
            //if(local[0] == "control")
            // return;

            if (AAction.displaySemi)
            {
                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
            }
        }
Exemplo n.º 48
0
 public override bool test(CSsemi.CSemiExp semi)
 {
   int index = semi.Contains("namespace");
   if (index != -1)
   {
     CSsemi.CSemiExp local = new CSsemi.CSemiExp();
     local.displayNewLines = false;
     local.Add(semi[index]).Add(semi[index + 1]);
     doActions(local);
   }
   return false;
 }
Exemplo n.º 49
0
        public override bool test(CSsemi.CSemiExp semi, string file)
        {
            try
            {
                if (semi[semi.count - 1] != "{")
                    return false;

                int index = semi.FindFirst("(");
                if (index > 0 && !isSpecialToken(semi[index - 1]))
                {
                    List<Elem> output = OutputRepository.output_;

                    foreach (Elem e in output)
                    {
                        for (int i = 0; i < semi.count - 1; i++)
                        {
                            if (e.name.Equals(semi[i]) && !e.type.Equals("namespace") && !e.type.Equals("function"))
                            {
                                CSsemi.CSemiExp local = new CSsemi.CSemiExp();
                                local.Add("Using").Add(semi[i]);
                                doActions(local, file);
                                return true;
                            }

                        }
                    }

                }
            }
            catch { }
            return false;
        }
Exemplo n.º 50
0
        public override bool test(CSsemi.CSemiExp semi)
        {
            Repository repo_ = Repository.getInstance();
            int index = semi.Contains("(");
            int endindex = semi.Contains(")");
            int loopindex = semi.FindAll(",");
            int currindex = 0;
            bool flag = false;

            if (index != -1 && !isSpecialToken(semi[index - 1]))
            {
                string currclassName = DetectParentClass.getClassName(repo_.semi.lineCount);
                currindex = index;
                string functionname = semi[currindex - 1];
                for (int i = 0; i <= loopindex; i++)
                {
                    CSsemi.CSemiExp local = new CSsemi.CSemiExp();
                    local.displayNewLines = false;
                    local.Add(currclassName).Add(functionname).Add(semi[currindex + 1]).Add(semi[currindex + 2]);
                    doActionsUsing(local);
                    flag = true;
                    currindex = index + 3;
                }
            }
            if (flag)
                return true;

            return false;
        }
Exemplo n.º 51
0
        public override bool test(CSsemi.CSemiExp semi, string file)
        {
            try
            {
                List<Elem> output = OutputRepository.output_;
                foreach (Elem e in output)
                {
                    for (int i = 0; i < semi.count; i++)
                    {
                        if (semi[i].Equals(e.name) && (semi[i + 2].Equals(";")) && (e.type.Equals("class") || e.type.Equals("enum") || e.type.Equals("struct")))
                        {

                            if (semi[i - 1].Equals("(") || semi[i - 1].Equals("new"))
                            {
                                return false;
                            }
                            CSsemi.CSemiExp local = new CSsemi.CSemiExp();
                            // create local semiExp with tokens for type and name
                            local.displayNewLines = false;
                            local.Add("Composition").Add(semi[i]);
                            doActions(local, file);
                            return true;
                        }
                    }
                }

            }
            catch
            {

            }
            return false;
        }
Exemplo n.º 52
0
        public override bool test(CSsemi.CSemiExp semi)
        {
            List<string> variablecountlist = null;
            Repository repo_ = Repository.getInstance();

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

            if (variablecountlist != null && variablecountlist.Count == 2)
            {
                string currclassName = DetectParentClass.getClassName(repo_.semi.lineCount);
                //if (currclassName != "")
                {
                    CSsemi.CSemiExp local = new CSsemi.CSemiExp();
                    local.displayNewLines = false;
                    local.Add(variablecountlist[0]).Add(variablecountlist[1]).Add(currclassName);
                    doActionsComposition(local);
                    return true;
                }
            }

            return false;
        }
Exemplo n.º 53
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);
        }
 public override bool test(CSsemi.CSemiExp semi, string filename)
 {
     string[] SpecialToken = { "try", "for", "foreach", "while", "switch", "if", "else", "catch", "using", "unsafe", "finally", "break" };
     int index = -1;
     foreach (string stoken in SpecialToken)
     {
         index = semi.Contains(stoken);
         if (index != -1)
         {
             CSsemi.CSemiExp local = new CSsemi.CSemiExp();
             // create local semiExp with tokens for type and name
             local.displayNewLines = false;
             local.Add("complexity");
             doActions(local, filename);
             return false;
         }
     }
     return false;
 }
        public override bool test(CSsemi.CSemiExp semi, string filename)
        {
            int indexCL = semi.Contains("class");
            int indexIF = semi.Contains("interface");
            int indexST = semi.Contains("struct");
            int indexEN = semi.Contains("enum");

            int index = Math.Max(indexCL, indexIF);
            index = Math.Max(index, indexST);
            index = Math.Max(index, indexEN);
            if (index != -1)
            {
                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, filename);
                return true;
            }
            return false;
        }
        public override bool test(CSsemi.CSemiExp semi, string filename)
        {
            if (semi[semi.count - 1] != "{")
                return false;

            int index = semi.FindFirst("(");
            if (index > 0 && !isSpecialToken(semi[index - 1]))
            {
                CSsemi.CSemiExp local = new CSsemi.CSemiExp();
                local.Add("function").Add(semi[index - 1]);
                doActions(local, filename);
                return true;
            }
            return false;
        }
 private void aggregationTest(CSsemi.CSemiExp semi, int index, string filename, string filenameto, string namespacename)
 {
     CSsemi.CSemiExp local = new CSsemi.CSemiExp();
     if ((semi[index + 2].Equals(".")))
     {
         local.Add("Aggregation").Add(semi[index + 3]).Add(semi[index - 2]).Add(filenameto).Add(namespacename);
         doActions(local, filename);
     }
     else
     {
         local.Add("Aggregation").Add(semi[index + 1]).Add(semi[index - 2]).Add(filenameto).Add(namespacename);
         doActions(local, filename);
     }
 }
        public override void doAction(CSsemi.CSemiExp semi, string filename)
        {
            Elem elem;
            try
            {
                elem = repo_.stack.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]).end == 0)
                            {
                                (repo_.locations[i]).end = repo_.semi.lineCount;
                                elem.end = repo_.semi.lineCount;
                                break;
                            }
                        }
                    }
                }
            }
            catch
            {
                Console.Write("popped empty stack on semiExp: ");
                semi.display();
                return;
            }
            CSsemi.CSemiExp local = new CSsemi.CSemiExp();
            local.Add(elem.type).Add(elem.name);
            if (local[0] == "control")
                return;

            if (AAction.displaySemi)
            {
                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
            }
        }
        public override bool test(CSsemi.CSemiExp semi, string filename)
        {
            if (semi[semi.count - 1] != "{")
                return false;
            int index = semi.FindFirst("(");

            List<Elem> table = RepositoryForOutput.storageForOutput_;
            CSsemi.CSemiExp local = new CSsemi.CSemiExp();
            try
            {
                if (index > 0 && !isSpecialToken(semi[index - 1]))
                {
                    for (int i = index - 1; i < semi.count; i++)
                    {
                        foreach (Elem e in table)
                        {
                            if ((e.name.Equals(semi[i])) && !(e.type.Equals("function")) && !(e.type.Equals("namespace")))
                            {
                                local.Add("Using").Add(semi[i]).Add(e.filename).Add(e.namespacename);
                                doActions(local, filename);
                                return false;
                            }
                        }
                    }
                }
            }
            catch
            {
            }
            return false;
        }
 public override bool test(CSsemi.CSemiExp semi)
 {
     Display.displayRules(actionDelegate, "rule   DetectNamespace");
       int index = semi.Contains("namespace");
       if (index != -1)
       {
     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;
 }