PageRenderTime 41ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/DLR_Main/Runtime/Microsoft.Scripting.Core/Ast/DebugInfoExpression.cs

https://bitbucket.org/mdavid/dlr
C# | 249 lines | 152 code | 34 blank | 63 comment | 16 complexity | 10cbb2490f9cfdc9b241a12a65d6a1a5 MD5 | raw file
  1. /* ****************************************************************************
  2. *
  3. * Copyright (c) Microsoft Corporation.
  4. *
  5. * This source code is subject to terms and conditions of the Apache License, Version 2.0. A
  6. * copy of the license can be found in the License.html file at the root of this distribution. If
  7. * you cannot locate the Apache License, Version 2.0, please send an email to
  8. * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
  9. * by the terms of the Apache License, Version 2.0.
  10. *
  11. * You must not remove this notice, or any other, from this software.
  12. *
  13. *
  14. * ***************************************************************************/
  15. using System;
  16. using System.Diagnostics;
  17. using System.Dynamic.Utils;
  18. #if SILVERLIGHT
  19. using System.Core;
  20. #endif
  21. #if CLR2
  22. namespace Microsoft.Scripting.Ast {
  23. #else
  24. namespace System.Linq.Expressions {
  25. #endif
  26. /// <summary>
  27. /// Emits or clears a sequence point for debug information.
  28. ///
  29. /// This allows the debugger to highlight the correct source code when
  30. /// debugging.
  31. /// </summary>
  32. #if !SILVERLIGHT
  33. [DebuggerTypeProxy(typeof(Expression.DebugInfoExpressionProxy))]
  34. #endif
  35. public class DebugInfoExpression : Expression {
  36. private readonly SymbolDocumentInfo _document;
  37. internal DebugInfoExpression(SymbolDocumentInfo document) {
  38. _document = document;
  39. }
  40. /// <summary>
  41. /// Gets the static type of the expression that this <see cref="Expression" /> represents. (Inherited from <see cref="Expression"/>.)
  42. /// </summary>
  43. /// <returns>The <see cref="Type"/> that represents the static type of the expression.</returns>
  44. public sealed override Type Type {
  45. get { return typeof(void); }
  46. }
  47. /// <summary>
  48. /// Returns the node type of this <see cref="Expression" />. (Inherited from <see cref="Expression" />.)
  49. /// </summary>
  50. /// <returns>The <see cref="ExpressionType"/> that represents this expression.</returns>
  51. public sealed override ExpressionType NodeType {
  52. get { return ExpressionType.DebugInfo; }
  53. }
  54. /// <summary>
  55. /// Gets the start line of this <see cref="DebugInfoExpression" />.
  56. /// </summary>
  57. public virtual int StartLine {
  58. get { throw ContractUtils.Unreachable; }
  59. }
  60. /// <summary>
  61. /// Gets the start column of this <see cref="DebugInfoExpression" />.
  62. /// </summary>
  63. public virtual int StartColumn {
  64. get { throw ContractUtils.Unreachable; }
  65. }
  66. /// <summary>
  67. /// Gets the end line of this <see cref="DebugInfoExpression" />.
  68. /// </summary>
  69. public virtual int EndLine {
  70. get { throw ContractUtils.Unreachable; }
  71. }
  72. /// <summary>
  73. /// Gets the end column of this <see cref="DebugInfoExpression" />.
  74. /// </summary>
  75. public virtual int EndColumn {
  76. get { throw ContractUtils.Unreachable; }
  77. }
  78. /// <summary>
  79. /// Gets the <see cref="SymbolDocumentInfo"/> that represents the source file.
  80. /// </summary>
  81. public SymbolDocumentInfo Document {
  82. get { return _document; }
  83. }
  84. /// <summary>
  85. /// Gets the value to indicate if the <see cref="DebugInfoExpression"/> is for clearing a sequence point.
  86. /// </summary>
  87. public virtual bool IsClear {
  88. get { throw ContractUtils.Unreachable; }
  89. }
  90. /// <summary>
  91. /// Dispatches to the specific visit method for this node type.
  92. /// </summary>
  93. protected internal override Expression Accept(ExpressionVisitor visitor) {
  94. return visitor.VisitDebugInfo(this);
  95. }
  96. }
  97. #region Specialized subclasses
  98. internal sealed class SpanDebugInfoExpression : DebugInfoExpression {
  99. private readonly int _startLine, _startColumn, _endLine, _endColumn;
  100. internal SpanDebugInfoExpression(SymbolDocumentInfo document, int startLine, int startColumn, int endLine, int endColumn)
  101. : base(document) {
  102. _startLine = startLine;
  103. _startColumn = startColumn;
  104. _endLine = endLine;
  105. _endColumn = endColumn;
  106. }
  107. public override int StartLine {
  108. get {
  109. return _startLine;
  110. }
  111. }
  112. public override int StartColumn {
  113. get {
  114. return _startColumn;
  115. }
  116. }
  117. public override int EndLine {
  118. get {
  119. return _endLine;
  120. }
  121. }
  122. public override int EndColumn {
  123. get {
  124. return _endColumn;
  125. }
  126. }
  127. public override bool IsClear {
  128. get {
  129. return false;
  130. }
  131. }
  132. protected internal override Expression Accept(ExpressionVisitor visitor) {
  133. return visitor.VisitDebugInfo(this);
  134. }
  135. }
  136. internal sealed class ClearDebugInfoExpression : DebugInfoExpression {
  137. internal ClearDebugInfoExpression(SymbolDocumentInfo document)
  138. : base(document) {
  139. }
  140. public override bool IsClear {
  141. get {
  142. return true;
  143. }
  144. }
  145. public override int StartLine {
  146. get {
  147. return 0xfeefee;
  148. }
  149. }
  150. public override int StartColumn {
  151. get {
  152. return 0;
  153. }
  154. }
  155. public override int EndLine {
  156. get {
  157. return 0xfeefee;
  158. }
  159. }
  160. public override int EndColumn {
  161. get {
  162. return 0;
  163. }
  164. }
  165. }
  166. #endregion
  167. public partial class Expression {
  168. /// <summary>
  169. /// Creates a <see cref="DebugInfoExpression"/> with the specified span.
  170. /// </summary>
  171. /// <param name="document">The <see cref="SymbolDocumentInfo"/> that represents the source file.</param>
  172. /// <param name="startLine">The start line of this <see cref="DebugInfoExpression" />. Must be greater than 0.</param>
  173. /// <param name="startColumn">The start column of this <see cref="DebugInfoExpression" />. Must be greater than 0.</param>
  174. /// <param name="endLine">The end line of this <see cref="DebugInfoExpression" />. Must be greater or equal than the start line.</param>
  175. /// <param name="endColumn">The end column of this <see cref="DebugInfoExpression" />. If the end line is the same as the start line, it must be greater or equal than the start column. In any case, must be greater than 0.</param>
  176. /// <returns>An instance of <see cref="DebugInfoExpression"/>.</returns>
  177. public static DebugInfoExpression DebugInfo(SymbolDocumentInfo document, int startLine, int startColumn, int endLine, int endColumn) {
  178. ContractUtils.RequiresNotNull(document, "document");
  179. if (startLine == 0xfeefee && startColumn == 0 && endLine == 0xfeefee && endColumn == 0) {
  180. return new ClearDebugInfoExpression(document);
  181. }
  182. ValidateSpan(startLine, startColumn, endLine, endColumn);
  183. return new SpanDebugInfoExpression(document, startLine, startColumn, endLine, endColumn);
  184. }
  185. /// <summary>
  186. /// Creates a <see cref="DebugInfoExpression"/> for clearing a sequence point.
  187. /// </summary>
  188. /// <param name="document">The <see cref="SymbolDocumentInfo"/> that represents the source file.</param>
  189. /// <returns>An instance of <see cref="DebugInfoExpression"/> for clearning a sequence point.</returns>
  190. public static DebugInfoExpression ClearDebugInfo(SymbolDocumentInfo document) {
  191. ContractUtils.RequiresNotNull(document, "document");
  192. return new ClearDebugInfoExpression(document);
  193. }
  194. private static void ValidateSpan(int startLine, int startColumn, int endLine, int endColumn) {
  195. if (startLine < 1) {
  196. throw Error.OutOfRange("startLine", 1);
  197. }
  198. if (startColumn < 1) {
  199. throw Error.OutOfRange("startColumn", 1);
  200. }
  201. if (endLine < 1) {
  202. throw Error.OutOfRange("endLine", 1);
  203. }
  204. if (endColumn < 1) {
  205. throw Error.OutOfRange("endColumn", 1);
  206. }
  207. if (startLine > endLine) {
  208. throw Error.StartEndMustBeOrdered();
  209. }
  210. if (startLine == endLine && startColumn > endColumn) {
  211. throw Error.StartEndMustBeOrdered();
  212. }
  213. }
  214. }
  215. }