示例#1
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);
        }
示例#2
0
        public override bool test(CSsemi.CSemiExp semi)
        {
            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.Add(semi[index]).Add(semi[index + 1]);
                int colonToken = semi.Contains(":");
                if (colonToken != -1)
                {
                    local.Add("Inherit").Add(semi[colonToken + 1]);
                    for (int i = colonToken + 3; i < semi.count - 1; i += 2)
                    {
                        local.Add("Inherit").Add(semi[i]);
                    }
                }

                doActions(local);
                return(true);
            }
            return(false);
        }
示例#3
0
        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);
        }
示例#4
0
        public override bool test(CSsemi.CSemiExp semi)
        {
            int brIndex = semi.Contains("{");

            if (brIndex != -1)
            {
                return(false);
            }
            int hashIndex = semi.Contains("#");

            if (hashIndex != -1)
            {
                return(false);
            }

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

            if (index > 0 && DetectFunction.isSpecialToken(semi[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);
        }
示例#5
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);
        }
示例#6
0
        public override void doAction(CSsemi.CSemiExp semi)
        {
            Repository_types reporel_ = Repository_types.getInstance();

            //************************checks for inheritance***********************
            if (semi.Contains("inheritance") != -1)
            {
                int loc = semi.Contains("inheritance");
                if (loc != -1)
                {
                    Elem e = new Elem();
                    e.type = semi[loc + 3];
                    e.name = semi[loc + 1];
                    repo_.stack.push(e);
                    relationelem r_elem = new relationelem();
                    r_elem.a_class       = semi[loc + 1].ToString();
                    r_elem.b_class       = semi[loc + 2].ToString();
                    r_elem.isInheritance = true;
                    repo_.classrelations.Add(r_elem);
                }
            }

            //**************************** check for aggregation**************//
            if (semi.Contains("aggregation") != -1)
            {
                int loc = semi.Contains("aggregation");
                if (loc != -1)
                {
                    Elem e = new Elem();
                    e.type = semi[loc + 2];
                    e.name = semi[loc + 1];
                    repo_.stack.push(e);
                    int  i    = rep.locations.Count;
                    Elem temp = rep.locations[i - 1];
                    if (semi[1] != temp.name)
                    {
                        relationelem r_elem = new relationelem();
                        r_elem.a_class       = temp.name;
                        r_elem.b_class       = semi[1].ToString();
                        r_elem.isAggregation = true;
                        repo_.classrelations.Add(r_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();
            }
        }
示例#7
0
        public override bool test(CSsemi.CSemiExp semi)
        {
            Display.displayRules(actionDelegate, "rule  DetectComment");
            if (semi.Contains("//") != -1 || semi.Contains("/*") != -1)
            {
                doActions(semi);
                return(true);
            }

            return(false);
        }
示例#8
0
        public int indexOfType(CSsemi.CSemiExp semi)
        {
            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);
            return(index);
        }
示例#9
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);
        }
示例#10
0
        public override bool test(CSsemi.CSemiExp semi)
        {
            int loc = semi.Contains("class");

            if (loc != -1)
            {
                Repository rep = new Repository();
                if (semi[loc + 2] == ":")
                {
                    foreach (Elem e in Repository.Copy_buffer)
                    {
                        if ((e.name == semi[loc + 3]) && (e.type == "class"))
                        {
                            CSsemi.CSemiExp local = new CSsemi.CSemiExp();
                            local.displayNewLines = false;
                            local.Add("inheritance").Add(semi[loc + 1]).Add(semi[loc + 3]).Add("class");
                            //  local.Add(semi[loc]).Add(semi[loc + 1]);
                            doActions(local);
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
示例#11
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);
        }
示例#12
0
        public override bool test(CSsemi.CSemiExp semi, string file)
        {
            try
            {
                List <Elem> output = OutputRepository.output_;

                int index = semi.Contains("new");
                if (index != -1)
                {
                    foreach (Elem e in output)
                    {
                        if (semi[index - 3].Equals(e.name) || semi[index + 1].Equals(e.name))
                        {
                            CSsemi.CSemiExp local = new CSsemi.CSemiExp();
                            // create local semiExp with tokens for type and name
                            local.displayNewLines = false;
                            if (semi[index + 2].Equals("."))
                            {
                                local.Add("Aggregation").Add(semi[index + 3]);
                            }
                            else
                            {
                                local.Add("Aggregation").Add(semi[index + 1]);
                            }
                            doActions(local, file);
                            return(true);
                        }
                    }
                }
            }
            catch { }
            return(false);
        }
示例#13
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]))
            {
                Repository rep = Repository.getInstance();

                CSsemi.CSemiExp local = new CSsemi.CSemiExp();
                local.Add("function").Add(semi[index - 1]);
                doActions(local);

                if (!rep.isFirstPass)
                {
                    /////////////////////////////////////////////////////////////////
                    //
                    // Parse function parameters to look for class dependencies
                    //
                    /////////////////////////////////////////////////////////////////
                    CSsemi.CSemiExp parameters = TokenHelper.GetFunctionParameters(semi);
                    for (int i = 0; i < TokenHelper.GetNumberOfParameters(parameters); i++)
                    {
                        parameters = TokenHelper.RemoveNewLines(parameters);
                        parameters = TokenHelper.RemoveIndicies(parameters);
                        parameters = TokenHelper.RemoveGenerics(parameters);
                        List <string> l = TokenHelper.GetFunctionParameterAtIndex(parameters, i);

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

                                string ns = rep.stack[0].name;                   // namespace
                                string cl = rep.stack[1].name;                   // class
                                string fn = rep.stack[rep.stack.count - 1].name; // function

                                CClassInfo    currentClassInfo    = rep.parsedData.getClassInfo(cl);
                                CFunctionInfo currentFunctioninfo = rep.parsedData.getClassFunctionInfo(cl, fn);

                                currentFunctioninfo.addDependency(l[l.Count - 2]);
                            }
                        }
                    }
                }

                return(true);
            }
            return(false);
        }
示例#14
0
        //helper function to detect class
        private static int isClassExpression(CSsemi.CSemiExp semi)
        {
            //parser.parse(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)
            {
                return(index);
            }

            return(-1);
        }
示例#15
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);
        }
示例#16
0
        public override bool test(CSsemi.CSemiExp semi)
        {
            int index = semi.Contains("}");

            if (index != -1)
            {
                doActions(semi);
                return(true);
            }
            return(false);
        }
示例#17
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);
        }
示例#18
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);
        }
示例#19
0
        public override bool test(CSsemi.CSemiExp semi)
        {
            Display.displayRules(actionDelegate, "rule   DetectLeavingScope");
            int index = semi.Contains("}");

            if (index != -1)
            {
                doActions(semi);
                return(true);
            }
            return(false);
        }
示例#20
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);
        }
示例#21
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").Add("anonymous2");;
                doActions(local);
                return(true);
            }
            return(false);
        }
示例#22
0
        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);
        }
示例#23
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);/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            /////////////////////////////////////////////
        }
示例#24
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);
        }
示例#25
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);
        }
示例#26
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);
        }
示例#27
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);
        }
示例#28
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);
        }
示例#29
0
        public override bool test(CSsemi.CSemiExp semi)
        {
            int         index       = -1;
            int         braIndex    = -1;
            int         newIndex    = -1;
            int         strIndex    = -1;
            int         eqlIndex    = -1;
            int         otherIndex  = -1;
            int         otherIndex2 = -1;
            Repository  rep         = Repository.getInstance();
            List <Elem> temp        = rep.locations;

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

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

            strIndex    = semi.FindFirst("string");
            eqlIndex    = semi.Contains("=");
            otherIndex  = semi.Contains("<");
            otherIndex2 = semi.Contains("[");

            if (strIndex != -1 && eqlIndex != -1 && otherIndex2 == -1 && otherIndex == -1)
            {
                CSsemi.CSemiExp local = new CSsemi.CSemiExp();
                // local semiExp with tokens for type and name
                local.displayNewLines = false;
                local.Add("Aggregation").Add(semi[strIndex]).Add(semi[strIndex + 1]);
                doActions(local);
                return(true);
            }

            return(false);
        }
示例#30
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);
        }
 public int complexityAnalysis(Elem e, object file, List<Elem> fileSetInfo)
 {
     int count = 0;
       CSsemi.CSemiExp semi = new CSsemi.CSemiExp();
       semi.open(file as string);
       do
       {
       semi.getSemi();
       } while (semi.lineCount < e.begin);       // ignore all the semi before function begin
       while (semi.lineCount <= e.end)
       {
       if (semi.Contains("if") != -1)
           count++;
       if (semi.Contains("else") != -1)
           count++;
       if (semi.Contains("for") != -1)
           count++;
       if (semi.Contains("foreach") != -1)
           count++;
       if (semi.Contains("while") != -1 && semi[semi.count - 1] != ";")
           count++;
       if (semi.Contains("do") != -1)
           count++;
       if (semi.Contains("case") != -1)
           count++;
       if (semi.Contains("try") != -1)
           count++;
       if (semi.Contains("catch") != -1)
           count++;
       if (specialCB(semi))      // special curly brace
           count++;
       semi.getSemi();
       }
       return count;
 }
 public int ComplexityAnalyze(Elem e, Object file)
 {
     CSsemi.CSemiExp local = new CSsemi.CSemiExp();
       local.open(file as string);
       int complexity = 1;
       while(local.lineCount<e.begin)
       {
       local.getSemi();
       }
       while(local.lineCount <= e.end)
       {
       local.getSemi();
       if (local.Contains("if") != -1)
           complexity++;
       if (local.Contains("else") != -1)
           complexity++;
       if (local.Contains("for") != -1)
           complexity++;
       if (local.Contains("foreach") != -1)
           complexity++;
       if (local.Contains("while") != -1)
           complexity++;
       if (local.Contains("try") != -1)
           complexity++;
       if (local.Contains("catch") != -1)
           complexity++;
       if (local.Contains("case") != -1)
           complexity++;
       }
       return complexity;
 }