コード例 #1
0
        private static SyntaxTreeBase ComputeSyntaxTree(SyntaxNodeBase node)
        {
            ArrayBuilder <SyntaxNodeBase> nodes = null;
            SyntaxTreeBase tree = null;

            // Find the nearest parent with a non-null syntax tree
            while (true)
            {
                tree = node._syntaxTree;
                if (tree != null)
                {
                    break;
                }

                var parent = node.Parent;
                if (parent == null)
                {
                    // root node: unexpected, root node should have a tree.
                    //Interlocked.CompareExchange(ref node._syntaxTree, CSharpSyntaxTree.CreateWithoutClone(node), null);
                    //tree = node._syntaxTree;
                    break;
                }

                tree = parent._syntaxTree;
                if (tree != null)
                {
                    node._syntaxTree = tree;
                    break;
                }

                (nodes ?? (nodes = ArrayBuilder <SyntaxNodeBase> .GetInstance())).Add(node);
                node = parent;
            }

            // Propagate the syntax tree downwards if necessary
            if (nodes != null)
            {
                Debug.Assert(tree != null);

                foreach (var n in nodes)
                {
                    var existingTree = n._syntaxTree;
                    if (existingTree != null)
                    {
                        Debug.Assert(existingTree == tree, "how could this node belong to a different tree?");

                        // yield the race
                        break;
                    }
                    n._syntaxTree = tree;
                }

                nodes.Free();
            }

            return(tree);
        }
コード例 #2
0
 internal void SetSyntaxTree(SyntaxTreeBase syntaxTree)
 {
     _syntaxTree = syntaxTree;
 }