/
ControlFlowGraphExtensions.cs
66 lines (57 loc) · 2.71 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
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license 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>
public static ControlFlowGraph GetLocalFunctionControlFlowGraphInScope(this ControlFlowGraph controlFlowGraph, IMethodSymbol localFunction, CancellationToken cancellationToken = default)
{
if (controlFlowGraph == null)
{
throw new ArgumentNullException(nameof(controlFlowGraph));
}
if (localFunction == null)
{
throw new ArgumentNullException(nameof(localFunction));
}
do
{
if (controlFlowGraph.TryGetLocalFunctionControlFlowGraph(localFunction, cancellationToken, out ControlFlowGraph localFunctionControlFlowGraph))
{
return localFunctionControlFlowGraph;
}
}
while ((controlFlowGraph = controlFlowGraph.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>
public static ControlFlowGraph GetAnonymousFunctionControlFlowGraphInScope(this ControlFlowGraph controlFlowGraph, IFlowAnonymousFunctionOperation anonymousFunction, CancellationToken cancellationToken = default)
{
if (controlFlowGraph == null)
{
throw new ArgumentNullException(nameof(controlFlowGraph));
}
if (anonymousFunction == null)
{
throw new ArgumentNullException(nameof(anonymousFunction));
}
do
{
if (controlFlowGraph.TryGetAnonymousFunctionControlFlowGraph(anonymousFunction, cancellationToken, out ControlFlowGraph localFunctionControlFlowGraph))
{
return localFunctionControlFlowGraph;
}
}
while ((controlFlowGraph = controlFlowGraph.Parent) != null);
throw new ArgumentOutOfRangeException(nameof(anonymousFunction));
}
}
}