private void DoDumpCompact(TreeDumperNode node, string indent)
        {
            Debug.Assert(node != null);
            Debug.Assert(indent != null);

            // Precondition: indentation and prefix has already been output
            // Precondition: indent is correct for node's *children*
            sb.Append(node.Text);
            if (node.Value != null)
            {
                sb.AppendFormat(": {0}", DumperString(node.Value));
            }

            sb.AppendLine();
            var children = node.Children.ToList();
            for (int i = 0; i < children.Count; ++i)
            {
                var child = children[i];
                if (child == null)
                {
                    continue;
                }

                sb.Append(indent);
                sb.Append(i == children.Count - 1 ? '└' : '├');
                sb.Append('─');

                // First precondition met; now work out the string needed to indent 
                // the child node's children:
                DoDumpCompact(child, indent + (i == children.Count - 1 ? "  " : "│ "));
            }
        }
예제 #2
0
        private void DoDumpCompact(TreeDumperNode node, string indent)
        {
            RoslynDebug.Assert(node != null);
            RoslynDebug.Assert(indent != null);

            // Precondition: indentation and prefix has already been output
            // Precondition: indent is correct for node's *children*
            _sb.Append(node.Text);
            if (node.Value != null)
            {
                _sb.AppendFormat(": {0}", DumperString(node.Value));
            }

            _sb.AppendLine();
            var children = node.Children.ToList();

            for (int i = 0; i < children.Count; ++i)
            {
                var child = children[i];
                if (child == null)
                {
                    continue;
                }

                _sb.Append(indent);
                _sb.Append(i == children.Count - 1 ? '\u2514' : '\u251C');
                _sb.Append('\u2500');

                // First precondition met; now work out the string needed to indent
                // the child node's children:
                DoDumpCompact(child, indent + (i == children.Count - 1 ? "  " : "\u2502 "));
            }
        }
예제 #3
0
        public static string DumpXML(TreeDumperNode root, string?indent = null)
        {
            var dumper = new TreeDumper();

            dumper.DoDumpXML(root, string.Empty, indent ?? string.Empty);
            return(dumper._sb.ToString());
        }
예제 #4
0
파일: TreeDumper.cs 프로젝트: zyonet/roslyn
        public static string DumpXML(TreeDumperNode root, string indent = null)
        {
            var dumper = new TreeDumper();

            dumper.DoDumpXML(root, string.Empty, string.IsNullOrEmpty(indent) ? string.Empty : indent);
            return(dumper._sb.ToString());
        }
예제 #5
0
        public static string DumpCompact(TreeDumperNode root)
        {
            var dumper = new TreeDumper();

            dumper.DoDumpCompact(root, string.Empty);
            return(dumper._sb.ToString());
        }
예제 #6
0
            static bool skip(TreeDumperNode node)
            {
                if (node is null)
                {
                    return(true);
                }

                if (node.Text is "locals" or "localFunctions" &&
                    node.Value is IList {
                    Count : 0
                })
예제 #7
0
        // enumerates all edges of the tree yielding (parent, node) pairs. The first yielded value is (null, this).
        public IEnumerable <KeyValuePair <TreeDumperNode, TreeDumperNode> > PreorderTraversal()
        {
            Stack <KeyValuePair <TreeDumperNode, TreeDumperNode> > stack = new Stack <KeyValuePair <TreeDumperNode, TreeDumperNode> >();

            stack.Push(new KeyValuePair <TreeDumperNode, TreeDumperNode>(null, this));
            while (stack.Count != 0)
            {
                KeyValuePair <TreeDumperNode, TreeDumperNode> currentEdge = stack.Pop();
                yield return(currentEdge);

                TreeDumperNode currentNode = currentEdge.Value;
                foreach (TreeDumperNode child in currentNode.Children.Where(x => x != null).Reverse())
                {
                    stack.Push(new KeyValuePair <TreeDumperNode, TreeDumperNode>(currentNode, child));
                }
            }
        }
예제 #8
0
        private void DoDumpXML(TreeDumperNode node, string indent, string relativeIndent)
        {
            RoslynDebug.Assert(node != null);
            if (node.Children.All(child => child == null))
            {
                _sb.Append(indent);
                if (node.Value != null)
                {
                    _sb.AppendFormat("<{0}>{1}</{0}>", node.Text, DumperString(node.Value));
                }
                else
                {
                    _sb.AppendFormat("<{0} />", node.Text);
                }
                _sb.AppendLine();
            }
            else
            {
                _sb.Append(indent);
                _sb.AppendFormat("<{0}>", node.Text);
                _sb.AppendLine();
                if (node.Value != null)
                {
                    _sb.Append(indent);
                    _sb.AppendFormat("{0}", DumperString(node.Value));
                    _sb.AppendLine();
                }

                var childIndent = indent + relativeIndent;
                foreach (var child in node.Children)
                {
                    if (child == null)
                    {
                        continue;
                    }

                    DoDumpXML(child, childIndent, relativeIndent);
                }

                _sb.Append(indent);
                _sb.AppendFormat("</{0}>", node.Text);
                _sb.AppendLine();
            }
        }
예제 #9
0
 protected string DoDumpCompact(TreeDumperNode root)
 {
     DoDumpCompact(root, string.Empty);
     return(_sb.ToString());
 }
예제 #10
0
 public static string DumpCompact(TreeDumperNode root)
 {
     return(new TreeDumper().DoDumpCompact(root));
 }
 public static string DumpCompact(TreeDumperNode root)
 {
     var dumper = new TreeDumper();
     dumper.DoDumpCompact(root, string.Empty);
     return dumper.sb.ToString();
 }
        private void DoDumpXML(TreeDumperNode node, string indent, string relativeIndent)
        {
            Debug.Assert(node != null);
            if (!node.Children.Any(child => child != null))
            {
                sb.Append(indent);
                if (node.Value != null)
                {
                    sb.AppendFormat("<{0}>{1}</{0}>", node.Text, DumperString(node.Value));
                }
                else
                {
                    sb.AppendFormat("<{0} />", node.Text);
                }
                sb.AppendLine();
            }
            else
            {
                sb.Append(indent);
                sb.AppendFormat("<{0}>", node.Text);
                sb.AppendLine();
                if (node.Value != null)
                {
                    sb.Append(indent);
                    sb.AppendFormat("{0}", DumperString(node.Value));
                    sb.AppendLine();
                }

                var childIndent = indent + relativeIndent;
                foreach (var child in node.Children)
                {
                    if (child == null)
                    {
                        continue;
                    }

                    DoDumpXML(child, childIndent, relativeIndent);
                }

                sb.Append(indent);
                sb.AppendFormat("</{0}>", node.Text);
                sb.AppendLine();
            }
        }
 public static string DumpXML(TreeDumperNode root, string indent = null)
 {
     var dumper = new TreeDumper();
     dumper.DoDumpXML(root, string.Empty, string.IsNullOrEmpty(indent) ? string.Empty : indent);
     return dumper.sb.ToString();
 }