-
Notifications
You must be signed in to change notification settings - Fork 4k
/
OperationWalker.cs
55 lines (48 loc) · 1.64 KB
/
OperationWalker.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
// 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.Collections.Generic;
namespace Microsoft.CodeAnalysis.Operations
{
/// <summary>
/// Represents a <see cref="OperationVisitor"/> that descends an entire <see cref="IOperation"/> tree
/// visiting each IOperation and its child IOperation nodes in depth-first order.
/// </summary>
public abstract class OperationWalker : OperationVisitor
{
private int _recursionDepth;
internal void VisitArray<T>(IEnumerable<T> operations) where T : IOperation
{
foreach (var operation in operations)
{
VisitOperationArrayElement(operation);
}
}
internal void VisitOperationArrayElement<T>(T operation) where T : IOperation
{
Visit(operation);
}
public override void Visit(IOperation operation)
{
if (operation != null)
{
_recursionDepth++;
try
{
StackGuard.EnsureSufficientExecutionStack(_recursionDepth);
operation.Accept(this);
}
finally
{
_recursionDepth--;
}
}
}
public override void DefaultVisit(IOperation operation)
{
VisitArray(operation.Children);
}
internal override void VisitNoneOperation(IOperation operation)
{
VisitArray(operation.Children);
}
}
}