/ICSharpCode.Decompiler/FlowAnalysis/ControlFlowEdge.cs

http://github.com/icsharpcode/ILSpy · C# · 78 lines · 34 code · 5 blank · 39 comment · 1 complexity · a1eef77857003fc7b9b4c34005a28ef3 MD5 · raw file

  1. // Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy of this
  4. // software and associated documentation files (the "Software"), to deal in the Software
  5. // without restriction, including without limitation the rights to use, copy, modify, merge,
  6. // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
  7. // to whom the Software is furnished to do so, subject to the following conditions:
  8. //
  9. // The above copyright notice and this permission notice shall be included in all copies or
  10. // substantial portions of the Software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  13. // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  14. // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
  15. // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  16. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  17. // DEALINGS IN THE SOFTWARE.
  18. using System;
  19. namespace ICSharpCode.Decompiler.FlowAnalysis
  20. {
  21. /// <summary>
  22. /// Describes the type of a control flow egde.
  23. /// </summary>
  24. public enum JumpType
  25. {
  26. /// <summary>
  27. /// A regular control flow edge.
  28. /// </summary>
  29. Normal,
  30. /// <summary>
  31. /// Jump to exception handler (an exception occurred)
  32. /// </summary>
  33. JumpToExceptionHandler,
  34. /// <summary>
  35. /// Jump from try block to leave target:
  36. /// This is not a real jump, as the finally handler is executed first!
  37. /// </summary>
  38. LeaveTry,
  39. /// <summary>
  40. /// Jump at endfinally (to any of the potential leave targets).
  41. /// For any leave-instruction, control flow enters the finally block - the edge to the leave target (LeaveTry) is not a real control flow edge.
  42. /// EndFinally edges are inserted at the end of the finally block, jumping to any of the targets of the leave instruction.
  43. /// This edge type is only used when copying of finally blocks is disabled (with copying, a normal deterministic edge is used at each copy of the endfinally node).
  44. /// </summary>
  45. EndFinally
  46. }
  47. /// <summary>
  48. /// Represents an edge in the control flow graph, pointing from Source to Target.
  49. /// </summary>
  50. public sealed class ControlFlowEdge
  51. {
  52. public readonly ControlFlowNode Source;
  53. public readonly ControlFlowNode Target;
  54. public readonly JumpType Type;
  55. public ControlFlowEdge(ControlFlowNode source, ControlFlowNode target, JumpType type)
  56. {
  57. this.Source = source;
  58. this.Target = target;
  59. this.Type = type;
  60. }
  61. public override string ToString()
  62. {
  63. switch (Type) {
  64. case JumpType.Normal:
  65. return "#" + Target.BlockIndex;
  66. case JumpType.JumpToExceptionHandler:
  67. return "e:#" + Target.BlockIndex;
  68. default:
  69. return Type.ToString() + ":#" + Target.BlockIndex;
  70. }
  71. }
  72. }
  73. }