Пример #1
0
        public int GetPointerCount(bool isPointerOrVariable = false)
        {
            int     c = 0;
            ELEMENT p = this;

            for (int i = 0; i < 100; i++)
            {
                if (p == null || p.isNONE())
                {
                    break;
                }
                if (isPointerOrVariable)
                {
                    if (p.isPOINTER() || p.isVARIABLE())
                    {
                        c++;
                    }
                }
                else
                {
                    c++;
                }
                p = p.GetPointerNext();
            }
            return(c);
        }
Пример #2
0
        public static bool FindFunction(STACKVAL istack, string name, out ELEMENT funcElement, out ELEMENT pgmElement) // pgmElement will be needed when get stack.
        {
            STACKVAL stack = istack;

            while (stack.OwnerElement.isPROGRAM() == false)
            {
                stack = stack.Parent;
                if (stack == null)
                {
                    Debug.Log("Unexpected!");
                }
            }

            pgmElement  = stack.OwnerElement;
            funcElement = new ELEMENT()
            {
                group = GROUP.NONE
            };

            for (int i = 0; i < pgmElement.GetListCount(); i++)
            {
                var e = pgmElement.GetListElement(i);
                if (e.isSENTENCE() && e.GetListElement(0).isDEC_FUNC())
                {
                    var cd = e.GetListElement(0);
                    if (name == cd.decname)
                    {
                        funcElement = cd;
                        return(true);
                    }
                }
            }
            return(false);
        }
Пример #3
0
 public static bool AddElement(List <ELEMENT> list, ELEMENT e)
 {
     if (e != null)
     {
         list.Add(e); return(true);
     }
     return(false);
 }
Пример #4
0
        public ELEMENT CreateClone()
        {
            ELEMENT ne = new ELEMENT();

            ne.group   = group;
            ne.raw     = raw;
            ne.list    = list;
            ne.decname = decname;
            return(ne);
        }
Пример #5
0
 public static void Traverse(ELEMENT e, Action <ELEMENT> act)
 {
     act(e);
     if (e.list != null && e.list.Count > 0)
     {
         foreach (var i in e.list)
         {
             Traverse(i, act);
         }
     }
 }
Пример #6
0
 public static ELEMENT[] GetRange(List <ELEMENT> list, int start, int num = 5)
 {
     ELEMENT[] l = new ELEMENT[num];
     for (int i = 0; i < num; i++)
     {
         l[i] = (i + start < list.Count ? list[i + start] : new ELEMENT()
         {
             group = GROUP.NONE
         });
     }
     return(l);
 }
Пример #7
0
        public ELEMENT GetPointerNext(int n)
        {
            ELEMENT p = this;

            for (int i = 0; i < n; i++)
            {
                if (p == null || p.isNONE())
                {
                    return(null);
                }
                p = p.GetPointerNext();
            }
            return(p);
        }
Пример #8
0
        public STACKVAL CreateStack(string istackname, ELEMENT e)
        {
            var newstack  = new STACKVAL();
            var stackname = "<" + istackname + ">";

            newstack.m_stackname    = stackname;
            newstack.m_root         = m_root;
            newstack.m_parent       = this;
            newstack.m_ownerElement = e;
            newstack.m_idInParent   = m_stackList.Count - 1;

            m_curStack[stackname] = newstack;
            return(newstack);
        }
Пример #9
0
        public static ELEMENT CreateListUnkown(GROUP g, int c)
        {
            var e = new ELEMENT()
            {
                group = g
            };

            e.list = new List <ELEMENT>();
            for (int i = 0; i < c; i++)
            {
                e.list.Add(new ELEMENT()
                {
                    group = GROUP.UNKNOWN
                });
            }
            return(e);
        }
Пример #10
0
 public void Fix(ELEMENT e)
 {
     if (list == null)
     {
         list = new List <ELEMENT>();
         list.Add(e);
     }
     else
     {
         var t = list[list.Count - 1];
         if (t.group == GROUP.UNKNOWN)
         {
             list[list.Count - 1] = e;
         }
         else
         {
             list.Add(e);
         }
     }
 }
Пример #11
0
        //---- for output

        public static bool FindFunctionFromRoot(ELEMENT root, string name, out ELEMENT funcElement, out ELEMENT pgmElement) // pgmElement will be needed when get stack.
        {
            funcElement = new ELEMENT()
            {
                group = GROUP.NONE
            };
            pgmElement = new ELEMENT()
            {
                group = GROUP.NONE
            };

            if (root.list == null)
            {
                return(false);
            }

            foreach (var v in root.list)
            {
                pgmElement = v;

                //UnityEngine.Debug.LogError("v ="+v);


                for (int i = 0; i < v.GetListCount(); i++)
                {
                    var e = v.GetListElement(i);
                    if (e.isSENTENCE() && e.GetListElement(0).isDEC_FUNC())
                    {
                        var cd = e.GetListElement(0);
                        if (name == cd.decname)
                        {
                            funcElement = cd;
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }