Beispiel #1
0
            protected GreenCrawlSyntaxNode[] ChildCopy()
            {
                GreenCrawlSyntaxNode[] newArray = new GreenCrawlSyntaxNode[ChildCount];
                Array.Copy(_children, newArray, ChildCount);

                return(newArray);
            }
Beispiel #2
0
        public CrawlSyntaxNode Translplant(CrawlSyntaxNode replacement)
        {
            Stack <int>          parrentIndex = new Stack <int>();
            int                  count        = 0;
            GreenCrawlSyntaxNode toInsert     = replacement.Green;
            CrawlSyntaxNode      self         = this;

            while (self.Parent != null)
            {
                parrentIndex.Push(self.IndexInParent);
                toInsert = self.Parent.Green.WithReplacedChild(toInsert, self.IndexInParent);
                self     = self.Parent;
                count++;
            }

            CrawlSyntaxNode newRoot = toInsert.CreateRed(null, 0);

            while (parrentIndex.Count != 0)
            {
                newRoot = newRoot.GetChildAt(parrentIndex.Pop());
                if (newRoot == null)
                {
                    throw new Exception();
                }
            }

            return(newRoot);
        }
Beispiel #3
0
            internal override GreenCrawlSyntaxNode WithReplacedChild(GreenCrawlSyntaxNode newChild, int index)
            {
                GreenCrawlSyntaxNode[] newArray = ChildCopy();

                newArray[index] = newChild;

                return(new GreenListNode <T>(Interval, newArray));
            }
Beispiel #4
0
        /// <param name="parent">The parent of this node.</param>
        /// <param name="self">The red counterpart of this node.</param>
        /// <param name="indexInParent">The index this node has in its parent.</param>
        protected internal CrawlSyntaxNode(CrawlSyntaxNode parent, GreenCrawlSyntaxNode self, int indexInParent)
        {
            Parent = parent;

            Green = self;
            //GreenNodes sometimes uses upper bits to encode extra information. Not allowed here
            // ReSharper disable once BitwiseOperatorOnEnumWithoutFlags
            Type          = self.Type;
            IndexInParent = indexInParent;
        }
Beispiel #5
0
            internal override GreenCrawlSyntaxNode WithReplacedChild(GreenCrawlSyntaxNode newChild, int index)
            {
                if (0 > index || index >= ChildCount)
                {
                    throw new ArgumentOutOfRangeException();
                }

                var newchildren = ChildCopy();

                newchildren[index] = newChild;

                return(new GreenBlockNode(Type, Interval, newchildren, Scope));
            }
Beispiel #6
0
        /// <summary>
        /// This is one of the big pieces of the puzzle of how the Red side of the tree.
        /// It tries to take the <paramref name="slot"/> child and either return the
        /// coresponding child or create it. This value is cached in <paramref name="field"/>.
        /// This would be rather simple to do, except that this needs to be done
        /// <b>thread safe</b>.
        /// </summary>
        /// <typeparam name="T">The type of child</typeparam>
        /// <param name="field">A field to cache the value in.</param>
        /// <param name="slot">The index of the child</param>
        /// <returns>A child node, either a new or from cache.</returns>
        protected T GetRed <T>(ref T field, int slot) where T : CrawlSyntaxNode
        {
            T result = field;

            if (result == null)
            {
                GreenCrawlSyntaxNode green = this.Green.GetChildAt(slot);
                if (green != null)
                {
                    Interlocked.CompareExchange(ref field, (T)green.CreateRed(this, slot), null);
                    result = field;
                }
            }

            return(result);
        }
Beispiel #7
0
 internal abstract GreenCrawlSyntaxNode WithReplacedChild(GreenCrawlSyntaxNode newChild, int index);
Beispiel #8
0
 public ListNode(CrawlSyntaxNode parent, GreenCrawlSyntaxNode self, int indexInParent) : base(parent, self, indexInParent)
 {
     _childNodes = new T[self.ChildCount];
 }
 public BlockNode(CrawlSyntaxNode parent, GreenCrawlSyntaxNode self, int indexInParent)
     : base(parent, self, indexInParent)
 {
     Scope = ((GreenBlockNode)self).Scope;
 }