Exemple #1
0
        private static SyntaxTree ComputeSyntaxTree(LuaSyntaxNode node)
        {
            ArrayBuilder <LuaSyntaxNode>?nodes = null;
            SyntaxTree?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)
                {
                    // set the tree on the root node atomically
                    Interlocked.CompareExchange(ref node._syntaxTree, LuaSyntaxTree.CreateWithoutClone(node), null);
                    tree = node._syntaxTree;
                    break;
                }

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

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

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

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

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

                nodes.Free();
            }

            return(tree !);
        }
 public DebuggerSyntaxTree(LuaSyntaxNode root, SourceText text, LuaParseOptions options)
     : base(
         text,
         text.Encoding,
         text.ChecksumAlgorithm,
         path: "",
         options: options,
         root: root,
         cloneRoot: true)
 {
 }
Exemple #3
0
            internal ParsedSyntaxTree(
                SourceText?textOpt,
                Encoding?encodingOpt,
                SourceHashAlgorithm checksumAlgorithm,
                string path,
                LuaParseOptions options,
                LuaSyntaxNode root,
                bool cloneRoot)
            {
                RoslynDebug.Assert(root != null);
                RoslynDebug.Assert(options != null);
                RoslynDebug.Assert(textOpt == null || textOpt.Encoding == encodingOpt && textOpt.ChecksumAlgorithm == checksumAlgorithm);

                _lazyText          = textOpt;
                _encodingOpt       = encodingOpt ?? textOpt?.Encoding;
                _checksumAlgorithm = checksumAlgorithm;
                _options           = options;
                _path = path ?? string.Empty;
                _root = cloneRoot ? CloneNodeAsRoot(root) : root;
                _hasCompilationUnitRoot = root.Kind() == SyntaxKind.CompilationUnit;
            }
Exemple #4
0
 public override bool TryGetRoot(out LuaSyntaxNode root)
 {
     root = _node;
     return(true);
 }