-
Notifications
You must be signed in to change notification settings - Fork 4.8k
/
Copy pathFirstMarkLogStrategy.cs
122 lines (104 loc) · 4.43 KB
/
FirstMarkLogStrategy.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Collections.Generic;
using System.Diagnostics;
namespace ILCompiler.DependencyAnalysisFramework
{
public struct FirstMarkLogStrategy<DependencyContextType> : IDependencyAnalysisMarkStrategy<DependencyContextType>
{
private sealed class MarkData
{
public MarkData(string reason, DependencyNodeCore<DependencyContextType> reason1, DependencyNodeCore<DependencyContextType> reason2)
{
Reason = reason;
Reason1 = reason1;
Reason2 = reason2;
}
public string Reason
{
get;
}
public DependencyNodeCore<DependencyContextType> Reason1
{
get;
}
public DependencyNodeCore<DependencyContextType> Reason2
{
get;
}
}
private HashSet<string> _reasonStringOnlyNodes;
bool IDependencyAnalysisMarkStrategy<DependencyContextType>.MarkNode(
DependencyNodeCore<DependencyContextType> node,
DependencyNodeCore<DependencyContextType> reasonNode,
DependencyNodeCore<DependencyContextType> reasonNode2,
string reason)
{
if (node.Marked)
return false;
if ((reasonNode == null) && (reasonNode2 == null))
{
Debug.Assert(reason != null);
_reasonStringOnlyNodes ??= new HashSet<string>();
_reasonStringOnlyNodes.Add(reason);
}
node.SetMark(new MarkData(reason, reasonNode, reasonNode2));
return true;
}
void IDependencyAnalysisMarkStrategy<DependencyContextType>.VisitLogNodes(IEnumerable<DependencyNodeCore<DependencyContextType>> nodeList, IDependencyAnalyzerLogNodeVisitor<DependencyContextType> logNodeVisitor)
{
var combinedNodesReported = new HashSet<Tuple<DependencyNodeCore<DependencyContextType>, DependencyNodeCore<DependencyContextType>>>();
if (_reasonStringOnlyNodes != null)
{
foreach (string reasonOnly in _reasonStringOnlyNodes)
{
logNodeVisitor.VisitRootNode(reasonOnly);
}
}
foreach (DependencyNodeCore<DependencyContextType> node in nodeList)
{
if (node.Marked)
{
MarkData markData = (MarkData)node.GetMark();
if (markData.Reason2 != null)
{
var combinedNode = new Tuple<DependencyNodeCore<DependencyContextType>, DependencyNodeCore<DependencyContextType>>(markData.Reason1, markData.Reason2);
if (combinedNodesReported.Add(combinedNode))
{
logNodeVisitor.VisitCombinedNode(combinedNode);
}
}
}
}
}
void IDependencyAnalysisMarkStrategy<DependencyContextType>.VisitLogEdges(IEnumerable<DependencyNodeCore<DependencyContextType>> nodeList, IDependencyAnalyzerLogEdgeVisitor<DependencyContextType> logEdgeVisitor)
{
foreach (DependencyNodeCore<DependencyContextType> node in nodeList)
{
if (node.Marked)
{
MarkData markData = (MarkData)node.GetMark();
if (markData.Reason2 != null)
{
Debug.Assert(markData.Reason1 != null);
logEdgeVisitor.VisitEdge(markData.Reason1, markData.Reason2, node, markData.Reason);
}
else if (markData.Reason1 != null)
{
logEdgeVisitor.VisitEdge(markData.Reason1, node, markData.Reason);
}
else
{
Debug.Assert(markData.Reason != null);
logEdgeVisitor.VisitEdge(markData.Reason, node);
}
}
}
}
void IDependencyAnalysisMarkStrategy<DependencyContextType>.AttachContext(DependencyContextType context)
{
// This logger does not need to use the context
}
}
}