2003-09-20 Ben Maurer <bmaurer@users.sourceforge.net>
[mono.git] / mcs / class / System.XML / Mono.Xml.Xsl / Debug.cs
1 //
2 // Debug.cs
3 //
4 // Authors:
5 //      Ben Maurer (bmaurer@users.sourceforge.net)
6 //      Atsushi Enomoto (ginga@kit.hi-ho.ne.jp)
7 //      
8 // (C) 2003 Ben Maurer
9 // (C) 2003 Atsushi Enomoto
10 //
11
12 using System;
13 using System.Collections;
14 using System.Xml;
15 using System.Xml.XPath;
16 using System.Xml.Xsl;
17
18 namespace Mono.Xml.Xsl {
19         internal class Debug {
20                 [System.Diagnostics.Conditional("DEBUG")]
21                 internal static void TraceContext(XPathNavigator context) {
22                         string output = "(null)";
23                         
24                         if (context != null) {
25                                 context = context.Clone ();
26                                 switch (context.NodeType) {
27                                         case XPathNodeType.Element:
28                                                 output = string.Format("<{0}:{1}", context.Prefix, context.LocalName);
29                                                 for (bool attr = context.MoveToFirstAttribute(); attr; attr = context.MoveToNextAttribute()) {
30                                                         output += string.Format(" {0}:{1}={2}", context.Prefix, context.LocalName, context.Value);
31                                                 }
32                                                  output += ">";
33                                                 break;
34                                         default:
35                                                 break;
36                                 }
37                         }
38         
39                         WriteLine(output);
40                 }
41
42                 [System.Diagnostics.Conditional("DEBUG")]
43                 internal static void Assert (bool condition, string message)
44                 {
45                         if (!condition)
46                                 throw new Exception (message);
47                 }
48
49                 [System.Diagnostics.Conditional("DEBUG")]
50                 internal static void WriteLine (object value)
51                 {
52                         Console.Error.WriteLine (value);
53                 }
54
55                 [System.Diagnostics.Conditional("DEBUG")]
56                 internal static void WriteLine (string message)
57                 {
58                         Console.Error.WriteLine (message);
59                 }
60                 
61                 static Stack eleStack = new Stack ();
62                 
63                 [System.Diagnostics.Conditional("DEBUG")]
64                 internal static void EnterNavigator (Compiler c)
65                 {
66                         eleStack.Push (c.Input.Clone ());
67                 }
68                 
69                 [System.Diagnostics.Conditional("DEBUG")]
70                 internal static void ExitNavigator (Compiler c)
71                 {
72                         XPathNavigator x = (XPathNavigator)eleStack.Pop();
73                         if (!x.IsSamePosition (c.Input))
74                                 throw new Exception ("Position must be the same on enter/exit. Enter node: " + x.Name + " exit node " + c.Input.Name);
75                         
76                 }
77         }
78 }