public override bool Equals(InternalSyntaxNode other)
 {
     return((object)other != null &&
            ((object)this == (object)other ||
             (base.Equals(other) &&
              Equals(other as NameInternalNode))));
 }
Beispiel #2
0
 /// <summary>
 /// Creates a new <see cref="SyntaxNode"/> from the given <see cref="InternalSyntaxNode"/>.
 /// Most often used in manipulative functions to generate a new immutable <see cref="SyntaxNode"/> from a <see cref="InternalSyntaxNode"/>.
 /// </summary>
 /// <param name="node">The internal node that the new <see cref="SyntaxNode"/> should be created from.</param>
 /// <returns>Returns a new <see cref="SyntaxNode"/>.</returns>
 /// <exception cref="ArgumentNullException"><paramref name="node"/> is <see langword="null" />.</exception>
 protected virtual SyntaxNode CreateNewNodeFromThisNode(InternalSyntaxNode node)
 {
     if (node == null)
     {
         throw new ArgumentNullException("node");
     }
     return(node.CreateSyntaxNode(n => Parent?.ReplaceNode(this, n), root => Tree.SetRoot(root)));
 }
Beispiel #3
0
        public virtual TResult Visit(InternalSyntaxNode node)
        {
            if (node == null)
            {
                return(default(TResult));
            }

            return(node.Accept(this));
        }
Beispiel #4
0
        /// <summary>
        /// Creates a new syntax node that represents the given mutable node.
        /// </summary>
        /// <param name="internalNode">The internal persistant representation of this node.</param>
        /// <param name="parent">
        /// A function that, when given an instance of 'this', produces a <see cref="SyntaxNode"/> that represents the parent of 'this' node.
        /// This function is used internally to help manage the immutability of a tree while differring generation of parent and tree entities.
        /// </param>
        /// <param name="tree">A function that, when given an instance of the generated root of the tree, produces a tree that represents the root.</param>
        /// <remarks>
        /// The arguments that you should take note of are the 'parent' and 'tree' arguments.
        /// The 'parent' function is used to create the immutable parent of the newly created syntax node.
        /// This is used so that when the 'ReplaceNode' method is called, references can still be kept between the parent and child
        /// without requiring that the entire immutable facade tree be recreated once that happens.
        /// So, when a node is replaced, a couple things happen in order:
        ///
        /// 1). First, A new InternalSyntaxNode is created containing the new children
        /// 2). Second, A new SyntaxNode is created with the new InternalSyntaxNode
        ///		a). While creating the new SyntaxNode, a 'parent' function is constructed.
        ///			- This function is used to retrieve the new immutable parent of the newly created SyntaxNode so that they can reference each other.
        ///			- This function is also used lazily, which means that it won't be called unless the SyntaxNode.Parent property is accessed.
        ///			  That is important to note, because it is the main benefit of this approach.
        ///			- The single SyntaxNode paramater to the function is used to reference the new child of the parent. (That is the 'this' property)
        ///
        ///         b). Also while creating the new SyntaxNode, a 'tree' function is constructed.
        ///			- This function is used to retrieve the new immutable tree that contains the newly created SyntaxNode.
        ///			- This function is used lazily, means that it won't be called unless the SyntaxNode.Tree property is accessed.
        ///			- The single SyntaxNode parameter is used to reference the new immutable root of the tree, which was generated by repeatedly following the 'Parent' property until the top of the tree is reached.
        ///
        /// </remarks>
        /// <exception cref="ArgumentNullException">The value of 'internalNode' cannot be null. </exception>
        protected SyntaxNode(InternalSyntaxNode internalNode, Func <SyntaxNode, SyntaxNode> parent, Func <SyntaxNode, SyntaxTree> tree)
        {
            if (internalNode == null)
            {
                throw new ArgumentNullException("internalNode");
            }
            if (parent == null)
            {
                parent = n => null;
            }
            if (tree == null)
            {
                tree = n => null;
            }
            InternalNode = internalNode;

            lazyParent = new Lazy <SyntaxNode>(() => parent(this));
            lazyTree   = new Lazy <SyntaxTree>(() =>
            {
                SyntaxNode p = this;
                while (p != null) // Walk all the way to the root
                {
                    if (p.Parent != null)
                    {
                        p = p.Parent;
                    }
                    else
                    {
                        break;
                    }
                }
                return(tree(p));
            });

            lazyPosition = new Lazy <int>(() =>
            {
                return(Parent != null ? (Parent.Position + Parent.InternalNode.Children.Where(c => c != null).TakeWhile(c => !ReferenceEquals(c, internalNode)).Sum(c => c.Length)) : 0);
            });

            children = new Lazy <ReadOnlyCollection <SyntaxNode> >(() => new ReadOnlyCollection <SyntaxNode>(InternalNode.Children.Select(c => c?.CreateSyntaxNode(this, Tree)).ToArray()));
        }
Beispiel #5
0
 public virtual TResult DefaultVisit(InternalSyntaxNode node)
 {
     return(default(TResult));
 }
Beispiel #6
0
 public NameNode(InternalSyntaxNode internalNode, Func <SyntaxNode, SyntaxNode> parent, Func <SyntaxNode, SyntaxTree> tree) : base(internalNode, parent, tree)
 {
 }