PageRenderTime 5ms CodeModel.GetById 1ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/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
19using System;
20
21namespace ICSharpCode.Decompiler.FlowAnalysis
22{
23	/// <summary>
24	/// Describes the type of a control flow egde.
25	/// </summary>
26	public enum JumpType
27	{
28		/// <summary>
29		/// A regular control flow edge.
30		/// </summary>
31		Normal,
32		/// <summary>
33		/// Jump to exception handler (an exception occurred)
34		/// </summary>
35		JumpToExceptionHandler,
36		/// <summary>
37		/// Jump from try block to leave target:
38		/// This is not a real jump, as the finally handler is executed first!
39		/// </summary>
40		LeaveTry,
41		/// <summary>
42		/// Jump at endfinally (to any of the potential leave targets).
43		/// For any leave-instruction, control flow enters the finally block - the edge to the leave target (LeaveTry) is not a real control flow edge.
44		/// EndFinally edges are inserted at the end of the finally block, jumping to any of the targets of the leave instruction.
45		/// 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).
46		/// </summary>
47		EndFinally
48	}
49	
50	/// <summary>
51	/// Represents an edge in the control flow graph, pointing from Source to Target.
52	/// </summary>
53	public sealed class ControlFlowEdge
54	{
55		public readonly ControlFlowNode Source;
56		public readonly ControlFlowNode Target;
57		public readonly JumpType Type;
58		
59		public ControlFlowEdge(ControlFlowNode source, ControlFlowNode target, JumpType type)
60		{
61			this.Source = source;
62			this.Target = target;
63			this.Type = type;
64		}
65		
66		public override string ToString()
67		{
68			switch (Type) {
69				case JumpType.Normal:
70					return "#" + Target.BlockIndex;
71				case JumpType.JumpToExceptionHandler:
72					return "e:#" + Target.BlockIndex;
73				default:
74					return Type.ToString() + ":#" + Target.BlockIndex;
75			}
76		}
77	}
78}