Ver Fonte

2006-11-30 Atsushi Enomoto <[email protected]>

	* XslStylesheet.cs, XslTemplate.cs : added XSLT stack frame debug
	  support, based on the patch by Michael Meeks.

	* XslTransform.cs, XsltException.cs : added XSLT stack frame debug
	  support, based on the patch by Michael Meeks.


svn path=/trunk/mcs/; revision=68730
Atsushi Eno há 19 anos atrás
pai
commit
679a1121b6

+ 5 - 0
mcs/class/System.XML/Mono.Xml.Xsl/ChangeLog

@@ -1,3 +1,8 @@
+2006-11-30  Atsushi Enomoto  <[email protected]>
+
+	* XslStylesheet.cs, XslTemplate.cs : added XSLT stack frame debug
+	  support, based on the patch by Michael Meeks.
+
 2006-04-07  Atsushi Enomoto  <[email protected]>
 
 	* XslTransformProcessor.cs : push current node context after iterating

+ 7 - 0
mcs/class/System.XML/Mono.Xml.Xsl/XslStylesheet.cs

@@ -64,6 +64,8 @@ namespace Mono.Xml.Xsl {
 
 		XslTemplateTable templates;
 
+		string baseURI;
+
 		// stylesheet attributes
 		string version;
 		XmlQualifiedName [] extensionElementPrefixes;
@@ -107,6 +109,10 @@ namespace Mono.Xml.Xsl {
 			get { return templates; }
 		}
 
+		public string BaseURI {
+			get { return baseURI; }
+		}
+
 		public string Version {
 			get { return version; }
 		}
@@ -120,6 +126,7 @@ namespace Mono.Xml.Xsl {
 			c.PushStylesheet (this);
 			
 			templates = new XslTemplateTable (this);
+			baseURI = c.Input.BaseURI;
 
 			// move to root element
 			while (c.Input.NodeType != XPathNodeType.Element)

+ 37 - 1
mcs/class/System.XML/Mono.Xml.Xsl/XslTemplate.cs

@@ -350,9 +350,45 @@ namespace Mono.Xml.Xsl {
 				c.Input.MoveToParent ();
 			}
 		}
-		
+
+		string LocationMessage {
+			get {
+				XslCompiledElementBase op = (XslCompiledElementBase) content;
+				return String.Format (" from\nxsl:template {0} at {1} ({2},{3})", Match, style.BaseURI, op.LineNumber, op.LinePosition);
+			}
+		}
+
+		void AppendTemplateFrame (XsltException ex)
+		{
+			ex.AddTemplateFrame (LocationMessage);
+		}
+
 		public virtual void Evaluate (XslTransformProcessor p, Hashtable withParams)
 		{
+			if (XslTransform.TemplateStackFrameError) {
+				try {
+					EvaluateCore (p, withParams);
+				} catch (XsltException ex) {
+					AppendTemplateFrame (ex);
+					throw ex;
+				} catch (Exception ex) {
+					// Note that this catch causes different
+					// type of error to be thrown (esp.
+					// this causes NUnit test regression).
+					XsltException e = new XsltException ("Error during XSLT processing: ", null, p.CurrentNode);
+					AppendTemplateFrame (e);
+					throw e;
+				}
+			}
+			else
+				EvaluateCore (p, withParams);
+		}
+
+		void EvaluateCore (XslTransformProcessor p, Hashtable withParams)
+		{
+			if (XslTransform.TemplateStackFrameOutput != null)
+				XslTransform.TemplateStackFrameOutput.WriteLine (LocationMessage);
+
 			p.PushStack (stackSize);
 
 			if (parameters != null) {

+ 5 - 0
mcs/class/System.XML/System.Xml.Xsl/ChangeLog

@@ -1,3 +1,8 @@
+2006-11-30  Atsushi Enomoto  <[email protected]>
+
+	* XslTransform.cs, XsltException.cs : added XSLT stack frame debug
+	  support, based on the patch by Michael Meeks.
+
 2006-10-27  Atsushi Enomoto  <[email protected]>
 
 	* XsltContext.cs : finally created a non-copyright-infringing test

+ 19 - 0
mcs/class/System.XML/System.Xml.Xsl/XslTransform.cs

@@ -42,6 +42,25 @@ using Mono.Xml.Xsl;
 namespace System.Xml.Xsl {
 	public sealed class XslTransform {
 
+		internal static readonly bool TemplateStackFrameError;
+		internal static readonly TextWriter TemplateStackFrameOutput;
+
+		static XslTransform ()
+		{
+			string env = Environment.GetEnvironmentVariable ("MONO_XSLT_STACK_FRAME");
+			switch (env) {
+			case "stdout":
+				TemplateStackFrameOutput = Console.Out;
+				break;
+			case "stderr":
+				TemplateStackFrameOutput = Console.Error;
+				break;
+			case "error":
+				TemplateStackFrameError = true;
+				break;
+			}
+		}
+
 		CompiledStylesheet s;
 		XmlResolver xmlResolver = new XmlUrlResolver ();
 

+ 9 - 1
mcs/class/System.XML/System.Xml.Xsl/XsltException.cs

@@ -64,6 +64,7 @@ namespace System.Xml.Xsl
 		int lineNumber;
 		int linePosition;
 		string sourceUri;
+		string templateFrames;
 
 		#endregion
 
@@ -91,6 +92,7 @@ namespace System.Xml.Xsl
 			lineNumber = info.GetInt32 ("lineNumber");
 			linePosition = info.GetInt32 ("linePosition");
 			sourceUri = info.GetString ("sourceUri");
+			templateFrames = info.GetString ("templateFrames");
 		}
 
 		internal XsltException (string msgFormat, string message, Exception innerException, int lineNumber, int linePosition, string sourceUri)
@@ -132,7 +134,7 @@ namespace System.Xml.Xsl
 
 		public override string Message {
 			get {
-				return base.Message;
+				return templateFrames != null ? base.Message + templateFrames : base.Message;
 			}
 		}
 
@@ -155,6 +157,12 @@ namespace System.Xml.Xsl
 			info.AddValue ("lineNumber", lineNumber);
 			info.AddValue ("linePosition", linePosition);
 			info.AddValue ("sourceUri", sourceUri);
+			info.AddValue ("templateFrames", templateFrames);
+		}
+
+		internal void AddTemplateFrame (string frame)
+		{
+			templateFrames += frame;
 		}
 
 		#endregion