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 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;
                if (semi[index] == "class" || semi[index] == "interface" || semi[index] == "struct" || semi[index] == "enum")
                {
                    local.Add(semi[index]).Add(semi[index + 1]);
                }
                else
                {
                    local.Add(semi[index]).Add(semi[index + 2]);
                }
                doActions(local);
                return(true);
            }
            return(false);
        }
Exemple #2
0
        //----< collect semiExpression from filtered token stream >----------

        public bool getSemi()
        {
            semiExp.RemoveRange(0, semiExp.Count);  // empty container
            do
            {
                get();
                if (currTok == "")
                {
                    return(false);  // end of file
                }
                if (returnNewLines || currTok != "\n")
                {
                    semiExp.Add(currTok);
                }
            } while (!isTerminator(currTok) || count == 0);

            // if for then append next two semiExps, e.g., for(int i=0; i<se.count; ++i) {

            if (semiExp.Contains("for"))
            {
                CSemiExp se = clone();
                getSemi();
                se.Add(semiExp.ToArray());
                getSemi();
                se.Add(semiExp.ToArray());
                semiExp.Clear();
                for (int i = 0; i < se.count; ++i)
                {
                    semiExp.Add(se[i]);
                }
            }
            return(semiExp.Count > 0);
        }
Exemple #3
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]);

                //search for all arguments in the function and add to local
                for (int i = index; i < semi.count; i++)
                {
                    if (UserType.userDefinedSet.Contains(semi[i]))
                    {
                        local.Add(semi[i]);
                    }
                }

                doActions(local);
                return(true);
            }
            return(false);
        }
Exemple #4
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)
            {
                CSsemi.CSemiExp local = new CSsemi.CSemiExp();
                // local semiExp with tokens for type and name
                local.displayNewLines = false;

                //check for inheritance
                if (semi.Contains(":") != -1)
                {
                    local.userInheritance = true;
                    local.Add(semi[index]).Add(semi[index + 1]).Add(semi[semi.Contains(":") + 1]);
                }
                else
                {
                    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   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);
        }
Exemple #6
0
        //
        //----< make a copy of semiEpression >-------------------------------

        public CSemiExp clone()
        {
            CSemiExp copy = new CSemiExp();

            for (int i = 0; i < count; ++i)
            {
                copy.Add(this[i]);
            }
            return(copy);
        }
Exemple #7
0
        public override void doAction(CSsemi.CSemiExp semi)
        {
            Display.displayActions(actionDelegate, "action SaveDeclar");
            Elem elem;

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

                //clear the function scope if we are exiting from it
                if (elem.name.Equals(repo_.currentFunctionScope))
                {
                    repo_.currentFunctionScope = "";
                }

                for (int i = 0; i < repo_.locations.Count; ++i)
                {
                    Elem temp = repo_.locations[i];
                    if (elem.type == temp.type)
                    {
                        if (elem.name == temp.name)
                        {
                            if ((repo_.locations[i]).endLine == 0)
                            {
                                (repo_.locations[i]).endLine       = repo_.semi.lineCount;
                                (repo_.locations[i]).endScopeCount = repo_.scopeCount;
                                break;
                            }
                        }
                    }
                }
            }
            catch
            {
                return;
            }
            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)
        {
            Display.displayRules(actionDelegate, "rule   DetecAlias");
            int indexF = semi.Contains("using");
            int indexS = semi.Contains("=");

            if (indexF != -1 && indexS != -1 && (indexS - indexF) == 2)
            {
                CSsemi.CSemiExp local = new CSsemi.CSemiExp();
                local.displayNewLines = false;
                local.Add("Alias").Add(semi[indexF + 1]);
                doActions(local);
                return(true);
            }
            return(false);
        }
        public override bool test(CSsemi.CSemiExp semi)
        {
            Display.displayRules(actionDelegate, "rule   DetectAnonymousScope");
            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);
        }
        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);
        }
        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);
        }
    //
    //----< make a copy of semiEpression >-------------------------------

    public CSemiExp clone()
    {
      CSemiExp copy = new CSemiExp();
      for (int i = 0; i < count; ++i)
      {
        copy.Add(this[i]);
      }
      return copy;
    }