Ejemplo n.º 1
0
        private static bool EquivalentToInternal(GreenNode node1, GreenNode node2)
        {
            if (node1.Kind != node2.Kind)
            {
                // A single-element list is usually represented as just a single node,
                // but can be represented as a List node with one child. Move to that
                // child if necessary.
                if (node1.IsList && node1.SlotCount == 1)
                {
                    node1 = node1.GetSlot(0);
                }

                if (node2.IsList && node2.SlotCount == 1)
                {
                    node2 = node2.GetSlot(0);
                }

                if (node1.Kind != node2.Kind)
                {
                    return(false);
                }
            }

            if (node1.FullWidth != node2.FullWidth)
            {
                return(false);
            }

            var n = node1.SlotCount;

            if (n != node2.SlotCount)
            {
                return(false);
            }

            for (var i = 0; i < n; i++)
            {
                var node1Child = node1.GetSlot(i);
                var node2Child = node2.GetSlot(i);
                if (node1Child != null && node2Child != null && !node1Child.IsEquivalentTo(node2Child))
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 2
0
        private static int GetLastNonNullChildIndex(GreenNode node)
        {
            int n         = node.SlotCount;
            int lastIndex = n - 1;

            for (; lastIndex >= 0; lastIndex--)
            {
                var child = node.GetSlot(lastIndex);
                if (child != null)
                {
                    break;
                }
            }

            return(lastIndex);
        }
Ejemplo n.º 3
0
        private static int GetFirstNonNullChildIndex(GreenNode node)
        {
            int n          = node.SlotCount;
            int firstIndex = 0;

            for (; firstIndex < n; firstIndex++)
            {
                var child = node.GetSlot(firstIndex);
                if (child != null)
                {
                    break;
                }
            }

            return(firstIndex);
        }
Ejemplo n.º 4
0
        internal static int CountNodes(GreenNode green)
        {
            var n = 0;

            for (int i = 0, s = green.SlotCount; i < s; i++)
            {
                var child = green.GetSlot(i);
                if (child != null)
                {
                    if (!child.IsList)
                    {
                        n++;
                    }
                    else
                    {
                        n += child.SlotCount;
                    }
                }
            }

            return(n);
        }