Exemplo n.º 1
0
 internal LockOrUsingBinder(Binder enclosing)
     : base(enclosing)
 {
 }
Exemplo n.º 2
0
        internal string Dump()
        {
            return(TreeDumper.DumpCompact(DumpAncestors()));

            TreeDumperNode DumpAncestors()
            {
                TreeDumperNode current = null;

                for (Binder scope = this; scope != null; scope = scope.Next)
                {
                    var(description, snippet, locals) = Print(scope);
                    var sub = new List <TreeDumperNode>();
                    if (!locals.IsEmpty())
                    {
                        sub.Add(new TreeDumperNode("locals", locals, null));
                    }
                    var currentContainer = scope.ContainingMemberOrLambda;
                    if (currentContainer != null && currentContainer != scope.Next?.ContainingMemberOrLambda)
                    {
                        sub.Add(new TreeDumperNode("containing symbol", currentContainer.ToDisplayString(), null));
                    }
                    if (snippet != null)
                    {
                        sub.Add(new TreeDumperNode($"scope", $"{snippet} ({scope.ScopeDesignator.Kind()})", null));
                    }
                    if (current != null)
                    {
                        sub.Add(current);
                    }
                    current = new TreeDumperNode(description, null, sub);
                }

                return(current);
            }

            (string description, string snippet, string locals) Print(Binder scope)
            {
                var    locals  = string.Join(", ", scope.Locals.SelectAsArray(s => s.Name));
                string snippet = null;

                if (scope.ScopeDesignator != null)
                {
                    var lines = scope.ScopeDesignator.ToString().Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                    if (lines.Length == 1)
                    {
                        snippet = lines[0];
                    }
                    else
                    {
                        var first    = lines[0];
                        var last     = lines[lines.Length - 1].Trim();
                        var lastSize = Math.Min(last.Length, 12);
                        snippet = first.Substring(0, Math.Min(first.Length, 12)) + " ... " + last.Substring(last.Length - lastSize, lastSize);
                    }
                    snippet = snippet.IsEmpty() ? null : snippet;
                }

                var description = scope.GetType().Name;

                return(description, snippet, locals);
            }
        }