public override bool test(ITokenCollection semi)
        {
            Display.displayRules(actionDelegate, "rule   DetectDelegate");
            int index;

            semi.find("delegate", out index);
            if (index != -1 && semi.size() > index + 1)
            {
                ITokenCollection local = Factory.create();

                local.add(semi[index]).add(semi[index + 2]);
                doActions(local);
                return(true);
            }
            return(false);
        }
Ejemplo n.º 2
0
        public override bool test(ITokenCollection semi)
        {
            Display.displayRules(actionDelegate, "rule   DetectClass");
            int index = indexOfType(semi);

            if (index != -1 && semi.size() > index + 1)
            {
                ITokenCollection local = Factory.create();
                local.filePath = semi.filePath;
                // local semiExp with tokens for type and name
                local.add(semi[index]).add(semi[index + 1]);
                doActions(local);
                return(true);
            }
            return(false);
        }
Ejemplo n.º 3
0
        public override bool test(ITokenCollection semi)//Added semi.find function in ITok ss
        {
            Display.displayRules(actionDelegate, "rule   DetectDelegate");
            int index;

            semi.find("delegate", out index);
            if (index != -1 && semi.size() > index + 1)
            {
                ITokenCollection local = Factory.create();//need factory bcoz i dont have semi class but interface ss
                // create local semiExp with tokens for type and name
                local.add(semi[index]).add(semi[index + 2]);
                doActions(local);
                return(true);//Fully satisfied no more parsing required ss
            }
            return(false);
        }
        public override bool test(ITokenCollection semi)
        {
            int indexusing;
            int indexeq;

            semi.find("using", out indexusing);
            semi.find("=", out indexeq);
            if (indexeq != -1 && semi.size() > indexusing + 1 && indexusing != -1)
            {
                ITokenCollection local = Factory.create();
                local.add("alias").add(semi[indexusing + 1]);
                doActions(local);
                return(true);
            }
            return(false);
        }
Ejemplo n.º 5
0
        public override bool test(ITokenCollection semi)
        {
            //Display.displayRules(actionDelegate, "rule   DetectNamespace");
            int index;

            semi.find("namespace", out index);
            if (index != -1 && semi.size() > index + 1)
            {
                ITokenCollection local = Factory.create();
                // create local semiExp with tokens for type and name
                local.add(semi[index]).add(semi[index + 1]);
                doActions(local);
                return(true);
            }
            return(false);
        }
        public override bool test(ITokenCollection semi)
        {
            Display.displayRules(actionDelegate, "rule   DetectAnonymousScope");
            int index;

            semi.find("{", out index);
            if (index != -1)
            {
                ITokenCollection local = Factory.create();
                // create local semiExp with tokens for type and name
                local.add("control").add("anonymous");
                doActions(local);
                return(true);
            }
            return(false);
        }
Ejemplo n.º 7
0
    public override bool test(ITokenCollection semi)
    {
      Display.displayRules(actionDelegate, "rule   DetectFunction");
      if (semi[semi.size() - 1] != "{")
        return false;

      int index;
      semi.find("(", out index);
      if (index > 0 && !isSpecialToken(semi[index - 1]))
      {
        ITokenCollection local = Factory.create();
        local.add("function").add(semi[index - 1]);
        doActions(local);
        return true;
      }
      return false;
    }
        public override bool test(ITokenCollection semi)
        {
            Display.displayRules(actionDelegate, "rule    DetectMember");
            int index;

            semi.find("{", out index);
            if (index < 2)
            {
                return(false);
            }
            string[]      Dec = { "namespace", "class", "interface", "struct", "enum", "(", "]" };
            List <string> acc = new List <string> {
                "public", "private", "internal", "static"
            };

            foreach (string term in Dec)
            {
                if (semi.find(term, out index))
                {
                    return(false);
                }
            }
            semi.find("{", out index);
            Console.WriteLine("index: {0}", index);
            index -= 2;
            while (index >= 0)
            {
                //public List<CsEdge<CsNode<List<CsEdge<string,string>>,A.string>, string>> dummy {;
                if (semi[index] == "<" || semi[index] == ">>" || semi[index] == ">" || semi[index] == "," || acc.Contains(semi[index]))
                {
                    index--; continue;
                }
                ITokenCollection local = Factory.create();
                StringBuilder    temp  = new StringBuilder();
                while (index >= 0 && semi[index] != "<" && semi[index] != ">" && semi[index] != "," && !acc.Contains(semi[index]))
                {
                    temp.Insert(0, semi[index]);
                    index--;
                }
                local.add(temp.ToString());
                Console.WriteLine("This strange thing: {0}", temp.ToString());
                doActions(local);
                index--;
            }
            return(true);
        }
        //---------------<Extract the semi expression of parameter>-------------
        private ITokenCollection getPara(ITokenCollection semi)
        {
            ITokenCollection current = Factory.create();
            int index;

            semi.find("(", out index);
            index++;
            while (index < semi.size())
            {
                if (semi[index] != "}")
                {
                    current.add(semi[index]);
                }
                index++;
            }
            return(current);
        }
Ejemplo n.º 10
0
        public override bool test(ITokenCollection semi)
        {
            Display.displayRules(actionDelegate, "rule   DetectAlias");
            int index;

            semi.find("using", out index);
            if (index != -1 && semi.size() > index + 1)
            {
                ITokenCollection local = Factory.create();
                if (semi[index + 1] != "System" && semi[index + 2] == "=")
                {
                    local.add(semi[index]).add(semi[index + 1]).add(semi[index + 3]);
                    doActions(local);
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 11
0
        public override bool test(ITokenCollection semi)
        {
            Display.displayRules(actionDelegate, "rule   DetectClass");
            int indexDG;

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

            if (indexDG != -1 && semi.size() > indexDG + 1 &&
                semi[semi.size() - 1] == ";")
            {
                ITokenCollection local = Factory.create();
                local.filePath = semi.filePath;
                // local semiExp with tokens for type and name
                local.add(semi[indexDG]).add(semi[indexDG + 1]).add(semi[indexDG + 2]);
                doActions(local);
                return(true);
            }
            return(false);
        }
        public override bool test(ITokenCollection semi)
        {
            Display.displayRules(actionDelegate, "rule   DetectUsingNamespace");
            int index;

            if (!semi.find("=", out index) && semi.find("using", out index))
            {
                ITokenCollection local = Factory.create();
                index++;
                while (semi[index] != ";")
                {
                    local.add(semi[index]);
                    index++;
                }
                doActions(local);
                return(true);
            }
            return(false);
        }
Ejemplo n.º 13
0
        public override bool test(ITokenCollection semi)
        {
            if (semi[semi.size() - 1] != "{")
            {
                return(false);
            }

            int index;

            semi.find("(", out index);
            if (index > 0 && !isSpecialToken(semi[index - 1]))
            {
                ITokenCollection local = Factory.create();
                local.add("function").add(semi[index - 1]);
                doActions(local);
                return(true);
            }
            return(false);
        }
        public override bool test(ITokenCollection semi)
        {
            Display.displayRules(actionDelegate, "rule   DetectClass");

            if (!semi.hasSequence("class", ":", "{"))
            {
                return(true);
            }

            int indexColon;

            semi.find(":", out indexColon);

            ITokenCollection local = Factory.create();

            local.add(semi[indexColon + 1]).add("base").add(";");
            doActions(local);

            return(true);
        }
        public override bool test(ITokenCollection semi)
        {
            Display.displayRules(actionDelegate, "rule   DetectAlias");
            int index;

            semi.find("using", out index);
            if (index != -1)
            {
                semi.find("=", out index);
                if (index != -1)
                {
                    ITokenCollection local = Factory.create();
                    local.add("Alias").add(semi[index - 1]);
                    doActions(local);
                    return(true);
                }
                return(false);
            }
            return(false);
        }
Ejemplo n.º 16
0
        public override bool test(ITokenCollection semi)
        {
            Display.displayRules(actionDelegate, "rule   DetectUsing");
            int index;

            semi.find("using", out index);
            if (index != -1 && semi.size() > index + 1)
            {
                ITokenCollection local = Factory.create();
                // create local semiExp with tokens for type and name
                if (!semi[index + 1].Equals("System"))
                {
                    local.add(semi[index]).add(semi[index + 1]);
                    local.currentFilename = semi.currentFilename;
                    doActions(local);
                    return(true);
                }
            }
            return(false);
        }
        public override bool test(ITokenCollection semi)
        {
            Display.displayRules(actionDelegate, "rule   DetectNewOperator");
            int index;

            if (semi.find("=", out index) && semi.find("new", out index))
            {
                ITokenCollection local1 = Factory.create();
                index++;
                while (index < semi.size() && semi[index] != "(")
                {
                    local1.add(semi[index]);
                    index++;
                }
                index = local1.size() - 1;
                while (index >= 0)
                {
                    List <string> acc = new List <string> {
                        "public", "private", "internal", "static"
                    };
                    //public List<CsEdge<CsNode<List<CsEdge<string,string>>,A.string>, string>> dummy {;
                    if (local1[index] == "<" || local1[index] == ">>" || local1[index] == ">" || local1[index] == "," || acc.Contains(local1[index]))
                    {
                        index--; continue;
                    }
                    ITokenCollection local = Factory.create();
                    StringBuilder    temp  = new StringBuilder();
                    while (index >= 0 && local1[index] != "<" && local1[index] != ">" && local1[index] != "," && !acc.Contains(local1[index]))
                    {
                        temp.Insert(0, local1[index]);
                        index--;
                    }
                    local.add(temp.ToString());
                    Console.WriteLine("This strange thing: {0}", temp.ToString());
                    doActions(local);
                    index--;
                }
                return(true);
            }
            return(false);
        }
        public override bool test(ITokenCollection semi)
        {
            Display.displayRules(actionDelegate, "rule   DetectClass");
            int i;

            if (semi.find("public", out i) || semi.find("internal", out i))//may not need here
            {
                int index;
                semi.find("delegate", out index);
                if (index != -1)
                {
                    ITokenCollection local = Factory.create();
                    // local semiExp with tokens for type and name
                    local.add(semi[index]).add(semi[index + 2]);
                    doActions(local);
                    return(true);
                }
                return(false);
            }
            return(false);
        }
Ejemplo n.º 19
0
        public override bool test(ITokenCollection semi)
        {
            Display.displayRules(actionDelegate, "rule   DetectUsing");
            int index;

            semi.find("using", out index);
            if (index != -1 && semi.size() > index + 1)
            {
                ITokenCollection local = Factory.create();
                // create local semiExp with tokens for type and name
                //Console.WriteLine(semi[index]+"!!!!");
                //Console.WriteLine(semi[index + 1]);
                if (semi[index + 1] != "System")
                {
                    local.add(semi[index]).add(semi[index + 1]);
                    doActions(local);
                }
                return(true);
            }
            return(false);
        }
        public override bool test(ITokenCollection semi)
        {
            int index = indexOfType(semi);
            int indexColon;

            semi.find(":", out indexColon);
            if (index != -1 && semi.size() > index + 1)
            {
                if (indexColon != -1 && semi.size() > indexColon + 1)
                {
                    for (int i = indexColon + 1; i < semi.size() - 1; i++)
                    {
                        if (this.isPossibleType(semi[i]))
                        {
                            ITokenCollection local = Factory.create();
                            local.filePath = semi.filePath;

                            int indexBegin = i;
                            for (int j = i - 1; j >= 0; j = j - 2)
                            {
                                if (semi[j] != ".")
                                {
                                    indexBegin = j + 1;
                                    break;
                                }
                                indexBegin = j - 1;
                            }

                            for (int k = indexBegin; k <= i; k = k + 2)
                            {
                                local.add(semi[k]);
                            }
                            doActions(local);
                        }
                    }
                }
                return(true);
            }
            return(false);
        }
Ejemplo n.º 21
0
    public override bool test(ITokenCollection semi)
    {
      Display.displayRules(actionDelegate, "rule   DetectClass");
      int indexCL;
      semi.find("class", out indexCL);
      int indexIF;
      semi.find("interface", out indexIF);
      int indexST;
      semi.find("struct", out indexST);

      int index = Math.Max(indexCL, indexIF);
      index = Math.Max(index, indexST);
      if (index != -1 && semi.size() > index + 1)
      {
        ITokenCollection local = Factory.create();
        // local semiExp with tokens for type and name
        local.add(semi[index]).add(semi[index + 1]);
        doActions(local);
        return true;
      }
      return false;
    }
        public override bool test(ITokenCollection semi)
        {
            Display.displayRules(actionDelegate, "rule   DetectClass");
            int indexCL;

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

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

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

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

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

            index = Math.Max(index, indexST);
            index = Math.Max(index, indexDL);

            if (index != -1 && semi.size() > index + 1)
            {
                ITokenCollection local = Factory.create();
                // local semiExp with tokens for type and name
                local.add(semi[index]).add(semi[index + 1]);
                doActions(local);

                Repository        repo_ = Repository.getInstance();
                TypeTable.LocPair pair;
                pair.file      = repo_.currentFile;
                pair.nameSpace = repo_.currentNameSpace;
                repo_.typeTable.add(semi[index + 1], pair);

                return(true);
            }
            return(true);
        }
Ejemplo n.º 23
0
        public override bool test(ITokenCollection semi)
        {
            int    index;
            string type = String.Empty;

            semi.find("using", out index);
            if (index != -1 && semi.size() > index + 1 && (!(semi[index + 1].ToString().ToLower().Equals("system"))))
            {
                ITokenCollection local = Factory.create();
                if ((semi.contains("=") && semi.Count() > 3) || semi[index + 1].Contains("("))
                {
                    ;
                }
                else
                {
                    type = "using";
                    local.add(semi[index]).add(semi[index + 1]);
                    doActions(local);
                }
                return(true);
            }
            return(false);
        }
Ejemplo n.º 24
0
    static void Main(string[] args)
    {
      Console.Write("\n  testing Semi");
      Console.Write("\n ==============");

      

      ITokenCollection semi = Factory.create();

      string source = "../../semi.cs";
      if (!semi.open(source))
      {
        Console.Write("\n  Can't open {0}\n", source);
        return;
      }
      while (!semi.isDone())
      {
        semi.get();
        semi.show();
      }
      Console.Write("\n");

      Console.Write("\n  demonstrating semi operations");
      Console.Write("\n -------------------------------");

      ITokenCollection test = Factory.create();

      test.add("one").add("two").add("three");
      test.show();
      if (test.hasSequence("one", "three"))
        Console.Write("\n  semi has token \"one\" followed by token \"three\"");
      if (!test.hasSequence("foo", "two"))
        Console.Write("\n  semi does not have token \"foo\" followed by token \"two\"");
      if (!test.hasTerminator())
        Console.Write("\n  semi does not have terminator");

      Console.Write("\n  demonstrate changing semi with insert and add");
      test.insert(0, "#");
      test.add("\n");
      test.show();

      Console.Write("\n  demonstrate semi tests");
      if (test.hasTerminator())
        Console.Write("\n  semi has terminator");
      else
        Console.Write("\n  semi does not have terminator");

      int index;
      Token tok = "two";
      if (test.find(tok, out index))
        Console.Write("\n  found token \"{0}\" at position {1}", tok, index);
      else
        Console.Write("\n  did not find token \"{0}\"", tok);
      tok = "foo";
      if (test.find(tok, out index))
        Console.Write("\n  found token \"{0}\" at position {1}", tok, index);
      else
        Console.Write("\n  did not find token \"{0}\"", tok);

      tok = "one";
      Token tok2 = test.predecessor(tok);
      Console.Write("\n  predecessor of \"{0}\" is \"{1}\"", tok, tok2);
      tok = "bar";
      tok2 = test.predecessor(tok);
      Console.Write("\n  predecessor of \"{0}\" is \"{1}\"", tok, tok2);

      Console.Write("\n  indexing semi\n  ");
      for (int i = 0; i < test.size(); ++i)
        Console.Write("{0} ", test[i]);
      Console.Write("\n  using foreach:\n  ");
      foreach (var tk in test)
        Console.Write("{0} ", tk);

      Console.Write("\n\n");
    }
Ejemplo n.º 25
0
    static void Main(string[] args)
    {
      Console.Write("\n  testing Semi");
      Console.Write("\n ==============");

      // Access Semi through interface and object factory.
      // That isolates client from any changes that may occur to Semi
      // as long as ITokenCollection doesn't change.

      ITokenCollection semi = Factory.create();

      string source = "C:\\Project2\\TestTypeAnaylyzer\\RulesAndActions.cs";
      if (!semi.open(source))
      {
        Console.Write("\n  Can't open {0}\n", source);
        return;
      }
      while (!semi.isDone())
      {
        semi.get();
        semi.show();
      }
      Console.Write("\n");

      Console.Write("\n  demonstrating semi operations");
      Console.Write("\n -------------------------------");

      ITokenCollection test = Factory.create();

      test.add("one").add("two").add("three");
      test.show();
      if (test.hasSequence("one", "three"))
        Console.Write("\n  semi has token \"one\" followed by token \"three\"");
      if (!test.hasSequence("foo", "two"))
        Console.Write("\n  semi does not have token \"foo\" followed by token \"two\"");
      if (!test.hasTerminator())
        Console.Write("\n  semi does not have terminator");

      Console.Write("\n  demonstrate changing semi with insert and add");
      test.insert(0, "#");
      test.add("\n");
      test.show();

      Console.Write("\n  demonstrate semi tests");
      if (test.hasTerminator())
        Console.Write("\n  semi has terminator");
      else
        Console.Write("\n  semi does not have terminator");

      int index;
      Token tok = "two";
      if (test.find(tok, out index))
        Console.Write("\n  found token \"{0}\" at position {1}", tok, index);
      else
        Console.Write("\n  did not find token \"{0}\"", tok);
      tok = "foo";
      if (test.find(tok, out index))
        Console.Write("\n  found token \"{0}\" at position {1}", tok, index);
      else
        Console.Write("\n  did not find token \"{0}\"", tok);

      tok = "one";
      Token tok2 = test.predecessor(tok);
      Console.Write("\n  predecessor of \"{0}\" is \"{1}\"", tok, tok2);
      tok = "bar";
      tok2 = test.predecessor(tok);
      Console.Write("\n  predecessor of \"{0}\" is \"{1}\"", tok, tok2);

      Console.Write("\n  indexing semi\n  ");
      for (int i = 0; i < test.size(); ++i)
        Console.Write("{0} ", test[i]);
      Console.Write("\n  using foreach:\n  ");
      foreach (var tk in test)
        Console.Write("{0} ", tk);

      Console.Write("\n\n");
            Console.ReadKey();
    }