Example #1
0
        // some nodes don't have direct semantic meaning by themselves and so we need to bind a different node that does
        internal protected LanguageSyntaxNode GetBindableSyntaxNode(LanguageSyntaxNode node)
        {
            Debug.Assert(node != null);

            IsBindableNodeVisitor visitor = _isBindableNodeVisitorPool.Allocate();
            bool isBindable = false;

            while ((object)node != null)
            {
                int position    = node.Position;
                var state       = node.Parent != null ? BoundNodeFactoryState.InParent : BoundNodeFactoryState.InNode;
                var nodeToVisit = node.Parent != null ? node.Parent : node;
                visitor.Initialize(position, false, state);
                isBindable = visitor.Visit(nodeToVisit);
                if (isBindable)
                {
                    break;
                }
                else
                {
                    node = node.ParentOrStructuredTriviaParent;
                }
            }
            _isBindableNodeVisitorPool.Free(visitor);

            return(node ?? this.Root);
        }
Example #2
0
        // We might not have actually been given a bindable expression or statement; the caller can
        // give us variable declaration nodes, for example. If we're not at an expression or
        // statement, back up until we find one.
        public LanguageSyntaxNode GetBindingRoot(LanguageSyntaxNode node)
        {
            Debug.Assert(node != null);

#if DEBUG
            for (LanguageSyntaxNode current = node; current != this.Root; current = current.ParentOrStructuredTriviaParent)
            {
                // make sure we never go out of Root
                Debug.Assert(current != null, "How did we get outside the root?");
            }
#endif

            IsBindableNodeVisitor visitor = _isBindableNodeVisitorPool.Allocate();
            bool isBindable = false;
            while ((object)node != null)
            {
                int position    = node.Position;
                var state       = node.Parent != null ? BoundNodeFactoryState.InParent : BoundNodeFactoryState.InNode;
                var nodeToVisit = node.Parent != null ? node.Parent : node;
                visitor.Initialize(position, true, state);
                isBindable = visitor.Visit(nodeToVisit);
                if (isBindable)
                {
                    break;
                }
                else
                {
                    node = node.ParentOrStructuredTriviaParent;
                }
            }
            _isBindableNodeVisitorPool.Free(visitor);

            return(node ?? this.Root);
        }
Example #3
0
        protected virtual bool IsBindableNode(LanguageSyntaxNode node)
        {
            Debug.Assert(node != null);

            IsBindableNodeVisitor visitor = _isBindableNodeVisitorPool.Allocate();
            int position    = node.Position;
            var state       = node.Parent != null ? BoundNodeFactoryState.InParent : BoundNodeFactoryState.InNode;
            var nodeToVisit = node.Parent != null ? node.Parent : node;

            visitor.Initialize(position, true, state);
            bool result = visitor.Visit(nodeToVisit);

            _isBindableNodeVisitorPool.Free(visitor);

            return(result);
        }