예제 #1
0
        public void ToString(StringBuilder builder, int indent, bool firstOnTop)
        {
            RCClosure      closure = this;
            Stack <string> lines   = new Stack <string> ();

            // Do not include the global namespace in the stack trace.
            while (closure != null && closure.Parent != null)
            {
                if (closure.Code != null)
                {
                    RCOperator op = closure.Code as RCOperator;
                    if (op != null)
                    {
                        lines.Push(string.Format("-- {0}", op.ToString()));
                    }
                }
                RCBlock result = closure.Result;
                while (result != null)
                {
                    if (result.Value != null)
                    {
                        RCCube acube = result.Value as RCCube;
                        if (acube != null)
                        {
                            string value = acube.FlatPack().Format(RCFormat.Default);
                            lines.Push(value);
                        }
                        else
                        {
                            string value = result.Value.Format(RCFormat.Default);
                            value = string.Format("{0}:{1}", result.Name, value);
                            value = value.Substring(0, Math.Min(80, value.Length));
                            lines.Push(value);
                        }
                    }
                    result = result.Previous;
                }
                closure = closure.Parent;
            }
            if (firstOnTop)
            {
                builder.AppendFormat("--- BEGIN STACK (bot:{0},fiber:{1},lines:{2}) ---\n",
                                     closure.Bot,
                                     closure.Fiber,
                                     lines.Count);
                while (lines.Count > 0)
                {
                    builder.AppendLine(lines.Pop());
                }
                builder.AppendFormat("--- END STACK ---\n");
            }
            else
            {
                builder.AppendFormat("--- END STACK (bot:{0},fiber:{1},lines:{2}) ---\n",
                                     closure.Bot,
                                     closure.Fiber,
                                     lines.Count);
                string[] linesInOrder = lines.ToArray();
                for (int i = linesInOrder.Length - 1; i >= 0; --i)
                {
                    builder.AppendLine(linesInOrder[i]);
                }
                builder.AppendFormat("--- BEGIN STACK ---\n");
            }
        }