-
Notifications
You must be signed in to change notification settings - Fork 4k
/
ControlFlowGraphExtensions.cs
74 lines (65 loc) · 3.05 KB
/
ControlFlowGraphExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Threading;
namespace Microsoft.CodeAnalysis.FlowAnalysis
{
public static partial class ControlFlowGraphExtensions
{
/// <summary>
/// Gets or creates a control flow graph for the given <paramref name="localFunction"/> defined in
/// the given <paramref name="controlFlowGraph"/> or any of it's parent control flow graphs.
/// </summary>
#pragma warning disable IDE0060 // Remove unused parameter
public static ControlFlowGraph GetLocalFunctionControlFlowGraphInScope(this ControlFlowGraph controlFlowGraph, IMethodSymbol localFunction, CancellationToken cancellationToken = default)
#pragma warning restore IDE0060 // Remove unused parameter
{
if (controlFlowGraph == null)
{
throw new ArgumentNullException(nameof(controlFlowGraph));
}
if (localFunction == null)
{
throw new ArgumentNullException(nameof(localFunction));
}
ControlFlowGraph? currentGraph = controlFlowGraph;
do
{
if (currentGraph.TryGetLocalFunctionControlFlowGraph(localFunction, out ControlFlowGraph? localFunctionControlFlowGraph))
{
return localFunctionControlFlowGraph;
}
}
while ((currentGraph = currentGraph.Parent) != null);
throw new ArgumentOutOfRangeException(nameof(localFunction));
}
/// <summary>
/// Gets or creates a control flow graph for the given <paramref name="anonymousFunction"/> defined in
/// the given <paramref name="controlFlowGraph"/> or any of it's parent control flow graphs.
/// </summary>
#pragma warning disable IDE0060 // Remove unused parameter
public static ControlFlowGraph GetAnonymousFunctionControlFlowGraphInScope(this ControlFlowGraph controlFlowGraph, IFlowAnonymousFunctionOperation anonymousFunction, CancellationToken cancellationToken = default)
#pragma warning restore IDE0060 // Remove unused parameter
{
if (controlFlowGraph == null)
{
throw new ArgumentNullException(nameof(controlFlowGraph));
}
if (anonymousFunction == null)
{
throw new ArgumentNullException(nameof(anonymousFunction));
}
ControlFlowGraph? currentGraph = controlFlowGraph;
do
{
if (currentGraph.TryGetAnonymousFunctionControlFlowGraph(anonymousFunction, out ControlFlowGraph? localFunctionControlFlowGraph))
{
return localFunctionControlFlowGraph;
}
}
while ((currentGraph = currentGraph.Parent) != null);
throw new ArgumentOutOfRangeException(nameof(anonymousFunction));
}
}
}