示例#1
0
        public static ImmutableArray <SyntaxNode> GetFilteredNodes(SyntaxNode root, Func <SyntaxNode, CancellationToken, bool> func, CancellationToken token)
        {
            var walker = new IncrementalGeneratorSyntaxWalker(func, token);

            walker.Visit(root);
            return(walker._results.ToImmutableOrEmptyAndFree());
        }
示例#2
0
            public void VisitTree(SyntaxNode root, EntryState state, SemanticModel?model, CancellationToken cancellationToken)
            {
                if (state == EntryState.Removed)
                {
                    // mark both syntax *and* transform nodes removed
                    _filterTable.RemoveEntries();
                    _transformTable.RemoveEntries();
                }
                else
                {
                    Debug.Assert(model is object);

                    // get the syntax nodes from cache, or a syntax walk using the filter
                    ImmutableArray <SyntaxNode> nodes;
                    if (state != EntryState.Cached || !_filterTable.TryUseCachedEntries(out nodes))
                    {
                        nodes = IncrementalGeneratorSyntaxWalker.GetFilteredNodes(root, _owner._filterFunc, cancellationToken);
                        _filterTable.AddEntries(nodes, EntryState.Added);
                    }

                    // now, using the obtained syntax nodes, run the transform
                    foreach (var node in nodes)
                    {
                        var value       = new GeneratorSyntaxContext(node, model);
                        var transformed = ImmutableArray.Create(_owner._transformFunc(value, cancellationToken));

                        if (state == EntryState.Added || !_transformTable.TryModifyEntries(transformed, _owner._comparer))
                        {
                            _transformTable.AddEntries(transformed, EntryState.Added);
                        }
                    }
                }
            }