Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
cc1dfa9a
R
roslyn
项目概览
lwm1986
/
roslyn
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roslyn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
cc1dfa9a
编写于
1月 28, 2020
作者:
S
Sam Harwell
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Document concurrent objects in SimplifyTypeNamesDiagnosticAnalyzerBase
上级
9f4b2ef2
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
37 addition
and
1 deletion
+37
-1
src/Features/Core/Portable/SimplifyTypeNames/SimplifyTypeNamesDiagnosticAnalyzerBase.cs
...plifyTypeNames/SimplifyTypeNamesDiagnosticAnalyzerBase.cs
+37
-1
未找到文件。
src/Features/Core/Portable/SimplifyTypeNames/SimplifyTypeNamesDiagnosticAnalyzerBase.cs
浏览文件 @
cc1dfa9a
...
@@ -199,7 +199,31 @@ public DiagnosticAnalyzerCategory GetAnalyzerCategory()
...
@@ -199,7 +199,31 @@ public DiagnosticAnalyzerCategory GetAnalyzerCategory()
private
class
AnalyzerImpl
private
class
AnalyzerImpl
{
{
private
readonly
SimplifyTypeNamesDiagnosticAnalyzerBase
<
TLanguageKindEnum
>
_analyzer
;
private
readonly
SimplifyTypeNamesDiagnosticAnalyzerBase
<
TLanguageKindEnum
>
_analyzer
;
private
readonly
ConcurrentDictionary
<
SyntaxTree
,
(
StrongBox
<
bool
>
completed
,
SimpleIntervalTree
<
TextSpan
,
TextSpanIntervalIntrospector
>?
intervalTree
)>
_codeBlockIntervals
=
new
ConcurrentDictionary
<
SyntaxTree
,
(
StrongBox
<
bool
>
completed
,
SimpleIntervalTree
<
TextSpan
,
TextSpanIntervalIntrospector
>?
intervalTree
)>();
/// <summary>
/// Tracks the analysis state of syntax trees in a compilation. Each syntax tree has the properties:
/// <list type="bullet">
/// <item><description>
/// <para><c>completed</c>: <see langword="true"/> to indicate that <c>intervalTree</c> has been obtained
/// for use in a <see cref="SemanticModelAnalysisContext"/> callback; otherwise, <see langword="false"/> to
/// indicate that <c>intervalTree</c> may be updated by adding a new non-overlapping <see cref="TextSpan"/>
/// for analysis performed by a <see cref="CodeBlockAnalysisContext"/> callback.</para>
///
/// <para>This field also serves as the lock object for updating both <c>completed</c> and
/// <c>intervalTree</c>.</para>
/// </description></item>
/// <item><description>
/// <para><c>intervalTree</c>: the set of intervals analyzed by <see cref="CodeBlockAnalysisContext"/>
/// callbacks, and therefore do not need to be analyzed again by a
/// <see cref="SemanticModelAnalysisContext"/> callback.</para>
///
/// <para>This field may only be accessed while <c>completed</c> is locked, and is not valid after
/// <c>completed</c> is <see langword="true"/>.</para>
/// </description></item>
/// </list>
/// </summary>
private
readonly
ConcurrentDictionary
<
SyntaxTree
,
(
StrongBox
<
bool
>
completed
,
SimpleIntervalTree
<
TextSpan
,
TextSpanIntervalIntrospector
>?
intervalTree
)>
_codeBlockIntervals
=
new
ConcurrentDictionary
<
SyntaxTree
,
(
StrongBox
<
bool
>
completed
,
SimpleIntervalTree
<
TextSpan
,
TextSpanIntervalIntrospector
>?
intervalTree
)>();
public
AnalyzerImpl
(
SimplifyTypeNamesDiagnosticAnalyzerBase
<
TLanguageKindEnum
>
analyzer
)
public
AnalyzerImpl
(
SimplifyTypeNamesDiagnosticAnalyzerBase
<
TLanguageKindEnum
>
analyzer
)
{
{
...
@@ -232,9 +256,21 @@ public void AnalyzeCodeBlock(CodeBlockAnalysisContext context)
...
@@ -232,9 +256,21 @@ public void AnalyzeCodeBlock(CodeBlockAnalysisContext context)
public
void
AnalyzeSemanticModel
(
SemanticModelAnalysisContext
context
)
public
void
AnalyzeSemanticModel
(
SemanticModelAnalysisContext
context
)
{
{
// Get the state information for the syntax tree. If the state information is not available, it is
// initialized directly to a completed state, ensuring that concurrent (or future) calls to
// AnalyzeCodeBlock will always read completed==true, and intervalTree does not need to be initialized
// to a non-null value.
var
(
completed
,
intervalTree
)
=
_codeBlockIntervals
.
GetOrAdd
(
context
.
SemanticModel
.
SyntaxTree
,
syntaxTree
=>
(
new
StrongBox
<
bool
>(
true
),
null
));
var
(
completed
,
intervalTree
)
=
_codeBlockIntervals
.
GetOrAdd
(
context
.
SemanticModel
.
SyntaxTree
,
syntaxTree
=>
(
new
StrongBox
<
bool
>(
true
),
null
));
// Since SemanticModel callbacks only occur once per syntax tree, the completed state can be safely read
// here. It will have one of the values:
//
// false: the state was initialized in AnalyzeCodeBlock, and intervalTree will be a non-null tree.
// true: the state was initialized on the previous line, and intervalTree will be null.
if
(!
completed
.
Value
)
if
(!
completed
.
Value
)
{
{
// This lock ensures we do not use intervalTree while it is being updated by a concurrent call to
// AnalyzeCodeBlock.
lock
(
completed
)
lock
(
completed
)
{
{
// Prevent future code block callbacks from analyzing more spans within this tree
// Prevent future code block callbacks from analyzing more spans within this tree
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录