public TwoEnumeratorListStack(SyntaxNode startingNode, Func <SyntaxNode, bool>?descendIntoChildren)
            {
                _nodeStack   = new ChildSyntaxListEnumeratorStack(startingNode, descendIntoChildren);
                _triviaStack = new TriviaListEnumeratorStack();
                if (_nodeStack.IsNotEmpty)
                {
                    _discriminatorStack = ArrayBuilder <Which> .GetInstance();

                    _discriminatorStack.Push(Which.Node);
                }
                else
                {
                    _discriminatorStack = null;
                }
            }
Esempio n. 2
0
    private IEnumerable <SyntaxNode> DescendantNodesImpl(TextSpan span, Func <SyntaxNode, bool> descendIntoChildren, bool includeSelf)
    {
        if (includeSelf && IsInSpan(in span, FullSpan))
        {
            yield return(this);
        }

        using (var stack = new ChildSyntaxListEnumeratorStack(this, descendIntoChildren))
        {
            while (stack.IsNotEmpty)
            {
                var nodeValue = stack.TryGetNextAsNodeInSpan(in span);
                if (nodeValue != null)
                {
                    // PERF: Push before yield return so that "nodeValue" is 'dead' after the yield
                    // and therefore doesn't need to be stored in the iterator state machine. This
                    // saves a field.
                    stack.PushChildren(nodeValue, descendIntoChildren);

                    yield return(nodeValue);
                }
            }
        }
    }
Esempio n. 3
0
        private IEnumerable<SyntaxTrivia> DescendantTriviaOnly(TextSpan span, Func<SyntaxNode, bool> descendIntoChildren)
        {
            using (var stack = new ChildSyntaxListEnumeratorStack(this, descendIntoChildren))
            {
                SyntaxNodeOrToken value;
                while (stack.IsNotEmpty)
                {
                    if (stack.TryGetNextInSpan(ref span, out value))
                    {
                        if (value.IsNode)
                        {
                            var nodeValue = value.AsNode();

                            stack.PushChildren(nodeValue, descendIntoChildren);
                        }
                        else if (value.IsToken)
                        {
                            var token = value.AsToken();

                            foreach (var trivia in token.LeadingTrivia)
                            {
                                if (IsInSpan(ref span, trivia.FullSpan))
                                {
                                    yield return trivia;
                                }
                            }

                            foreach (var trivia in token.TrailingTrivia)
                            {
                                if (IsInSpan(ref span, trivia.FullSpan))
                                {
                                    yield return trivia;
                                }
                            }
                        }
                    }
                }
            }
        }
Esempio n. 4
0
        private IEnumerable<SyntaxNodeOrToken> DescendantNodesAndTokensOnly(TextSpan span, Func<SyntaxNode, bool> descendIntoChildren, bool includeSelf)
        {
            if (includeSelf && IsInSpan(ref span, this.FullSpan))
            {
                yield return this;
            }

            using (var stack = new ChildSyntaxListEnumeratorStack(this, descendIntoChildren))
            {
                while (stack.IsNotEmpty)
                {
                    SyntaxNodeOrToken value;
                    if (stack.TryGetNextInSpan(ref span, out value))
                    {
                        // PERF: Push before yield return so that "value" is 'dead' after the yield
                        // and therefore doesn't need to be stored in the iterator state machine. This
                        // saves a field.
                        var nodeValue = value.AsNode();
                        if (nodeValue != null)
                        {
                            stack.PushChildren(nodeValue, descendIntoChildren);
                        }

                        yield return value;
                    }
                }
            }
        }
Esempio n. 5
0
 public ThreeEnumeratorListStack(SyntaxNode startingNode, Func<SyntaxNode, bool> descendIntoChildren)
 {
     this.nodeStack = new ChildSyntaxListEnumeratorStack(startingNode, descendIntoChildren);
     if (this.nodeStack.IsNotEmpty)
     {
     this.tokenStack = ArrayBuilder<SyntaxNodeOrToken>.GetInstance();
     this.discriminatorStack = ArrayBuilder<Which>.GetInstance();
     this.discriminatorStack.Push(Which.Node);
 }
     else
     {
         this.tokenStack = null;
         this.discriminatorStack = null;
     }
 }
Esempio n. 6
0
 public TwoEnumeratorListStack(SyntaxNode startingNode, Func<SyntaxNode, bool> descendIntoChildren)
 {
     _nodeStack = new ChildSyntaxListEnumeratorStack(startingNode, descendIntoChildren);
     _triviaStack = new TriviaListEnumeratorStack();
     if (_nodeStack.IsNotEmpty)
     {
         _discriminatorStack = ArrayBuilder<Which>.GetInstance();
         _discriminatorStack.Push(Which.Node);
     }
     else
     {
         _discriminatorStack = null;
     }
 }