Пример #1
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);
                    }
                }
            }
        }
Пример #2
0
            public TwoEnumeratorListStack(SyntaxNode startingNode, Func <SyntaxNode, bool> descendIntoChildren)
            {
                this.nodeStack = new ChildSyntaxListEnumeratorStack(startingNode, descendIntoChildren);
                if (this.nodeStack.IsNotEmpty)
                {
                    this.discriminatorStack = ArrayBuilder <Which> .GetInstance();

                    this.discriminatorStack.Push(Which.Node);
                }
                else
                {
                    this.discriminatorStack = null;
                }
            }
Пример #3
0
            public ThreeEnumeratorListStack(SyntaxNode startingNode, Func <SyntaxNode, bool> descendIntoChildren)
            {
                _nodeStack   = new ChildSyntaxListEnumeratorStack(startingNode, descendIntoChildren);
                _triviaStack = new TriviaListEnumeratorStack();
                if (_nodeStack.IsNotEmpty)
                {
                    _tokenStack = ArrayBuilder <SyntaxNodeOrToken> .GetInstance();

                    _discriminatorStack = ArrayBuilder <Which> .GetInstance();

                    _discriminatorStack.Push(Which.Node);
                }
                else
                {
                    _tokenStack         = null;
                    _discriminatorStack = null;
                }
            }
Пример #4
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);
                                }
                            }
                        }
                    }
                }
            }
        }