Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
c4362ba1
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,发现更多精彩内容 >>
提交
c4362ba1
编写于
10月 27, 2016
作者:
N
Neal Gafter
提交者:
GitHub
10月 27, 2016
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add a hidden sequence point around the code that assigns pattern variables in switch (#14789)
Fixes #14740
上级
9acf656e
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
58 addition
and
25 deletion
+58
-25
src/Compilers/CSharp/Portable/Lowering/Instrumentation/CompoundInstrumenter.cs
...Portable/Lowering/Instrumentation/CompoundInstrumenter.cs
+5
-0
src/Compilers/CSharp/Portable/Lowering/Instrumentation/DebugInfoInjector.cs
...rp/Portable/Lowering/Instrumentation/DebugInfoInjector.cs
+6
-0
src/Compilers/CSharp/Portable/Lowering/Instrumentation/Instrumenter.cs
.../CSharp/Portable/Lowering/Instrumentation/Instrumenter.cs
+5
-0
src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_PatternSwitchStatement.cs
...ing/LocalRewriter/LocalRewriter_PatternSwitchStatement.cs
+39
-25
src/Compilers/CSharp/Test/Emit/PDB/PDBTests.cs
src/Compilers/CSharp/Test/Emit/PDB/PDBTests.cs
+3
-0
未找到文件。
src/Compilers/CSharp/Portable/Lowering/Instrumentation/CompoundInstrumenter.cs
浏览文件 @
c4362ba1
...
...
@@ -208,6 +208,11 @@ public override BoundExpression InstrumentSwitchStatementExpression(BoundStateme
return
Previous
.
InstrumentSwitchStatementExpression
(
original
,
rewrittenExpression
,
factory
);
}
public
override
BoundStatement
InstrumentPatternSwitchBindCasePatternVariables
(
BoundStatement
bindings
)
{
return
Previous
.
InstrumentPatternSwitchBindCasePatternVariables
(
bindings
);
}
public
override
BoundStatement
InstrumentForEachStatementDeconstructionVariablesDeclaration
(
BoundForEachStatement
original
,
BoundStatement
iterationVarDecl
)
{
return
Previous
.
InstrumentForEachStatementDeconstructionVariablesDeclaration
(
original
,
iterationVarDecl
);
...
...
src/Compilers/CSharp/Portable/Lowering/Instrumentation/DebugInfoInjector.cs
浏览文件 @
c4362ba1
...
...
@@ -431,5 +431,11 @@ public override BoundExpression InstrumentSwitchStatementExpression(BoundStateme
return
AddConditionSequencePoint
(
base
.
InstrumentSwitchStatementExpression
(
original
,
rewrittenExpression
,
factory
),
original
.
Syntax
,
factory
);
}
public
override
BoundStatement
InstrumentPatternSwitchBindCasePatternVariables
(
BoundStatement
bindings
)
{
// Mark the code that binds pattern variables to their values as hidden.
// We do it to tell that this is not a part of previous statement.
return
new
BoundSequencePoint
(
null
,
base
.
InstrumentPatternSwitchBindCasePatternVariables
(
bindings
));
}
}
}
\ No newline at end of file
src/Compilers/CSharp/Portable/Lowering/Instrumentation/Instrumenter.cs
浏览文件 @
c4362ba1
...
...
@@ -298,5 +298,10 @@ public virtual BoundExpression InstrumentSwitchStatementExpression(BoundStatemen
Debug
.
Assert
(
factory
!=
null
);
return
rewrittenExpression
;
}
public
virtual
BoundStatement
InstrumentPatternSwitchBindCasePatternVariables
(
BoundStatement
bindings
)
{
return
bindings
;
}
}
}
\ No newline at end of file
src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_PatternSwitchStatement.cs
浏览文件 @
c4362ba1
...
...
@@ -278,6 +278,43 @@ private void LowerConstantValueDecision(DecisionTree.ByValue byValue)
LowerDecisionTree
(
byValue
.
Expression
,
byValue
.
Default
);
}
/// <summary>
/// Add a branch in the lowered decision tree to a label for a matched
/// pattern, and then produce a statement for the target of that branch
/// that binds the pattern variables.
/// </summary>
/// <param name="bindings">The source/destination pairs for the assignments</param>
private
BoundStatement
BindingsForCase
(
ImmutableArray
<
KeyValuePair
<
BoundExpression
,
BoundExpression
>>
bindings
)
{
var
patternMatched
=
_factory
.
GenerateLabel
(
"patternMatched"
);
_loweredDecisionTree
.
Add
(
_factory
.
Goto
(
patternMatched
));
var
addBindings
=
ArrayBuilder
<
BoundStatement
>.
GetInstance
();
addBindings
.
Add
(
_factory
.
Label
(
patternMatched
));
if
(!
bindings
.
IsDefaultOrEmpty
)
{
foreach
(
var
kv
in
bindings
)
{
var
source
=
kv
.
Key
;
var
dest
=
kv
.
Value
;
var
rewriter
=
this
.
LocalRewriter
;
addBindings
.
Add
(
_factory
.
ExpressionStatement
(
rewriter
.
MakeStaticAssignmentOperator
(
_factory
.
Syntax
,
rewriter
.
VisitExpression
(
dest
),
rewriter
.
VisitExpression
(
source
),
RefKind
.
None
,
dest
.
Type
,
false
)));
}
}
BoundStatement
result
=
_factory
.
Block
(
addBindings
.
ToImmutableAndFree
());
if
(
this
.
LocalRewriter
.
Instrument
)
{
// Hide the code that binds pattern variables in a hidden sequence point
result
=
this
.
LocalRewriter
.
_instrumenter
.
InstrumentPatternSwitchBindCasePatternVariables
(
result
);
}
return
result
;
}
private
void
LowerDecisionTree
(
DecisionTree
.
Guarded
guarded
)
{
var
sectionBuilder
=
this
.
SwitchSections
[
guarded
.
Section
];
...
...
@@ -294,20 +331,13 @@ private void LowerDecisionTree(DecisionTree.Guarded guarded)
else
{
// with bindings
var
matched
=
_factory
.
GenerateLabel
(
"matched"
);
_loweredDecisionTree
.
Add
(
_factory
.
Goto
(
matched
));
sectionBuilder
.
Add
(
_factory
.
Label
(
matched
));
AddBindings
(
sectionBuilder
,
guarded
.
Bindings
);
sectionBuilder
.
Add
(
BindingsForCase
(
guarded
.
Bindings
));
sectionBuilder
.
Add
(
_factory
.
Goto
(
targetLabel
));
}
}
else
{
var
checkGuard
=
_factory
.
GenerateLabel
(
"checkGuard"
);
_loweredDecisionTree
.
Add
(
_factory
.
Goto
(
checkGuard
));
sectionBuilder
.
Add
(
_factory
.
Label
(
checkGuard
));
AddBindings
(
sectionBuilder
,
guarded
.
Bindings
);
sectionBuilder
.
Add
(
BindingsForCase
(
guarded
.
Bindings
));
var
guardTest
=
_factory
.
ConditionalGoto
(
LocalRewriter
.
VisitExpression
(
guarded
.
Guard
),
targetLabel
,
true
);
// Only add instrumentation (such as a sequence point) if the node is not compiler-generated.
...
...
@@ -326,22 +356,6 @@ private void LowerDecisionTree(DecisionTree.Guarded guarded)
}
}
private
void
AddBindings
(
ArrayBuilder
<
BoundStatement
>
sectionBuilder
,
ImmutableArray
<
KeyValuePair
<
BoundExpression
,
BoundExpression
>>
bindings
)
{
if
(!
bindings
.
IsDefaultOrEmpty
)
{
foreach
(
var
kv
in
bindings
)
{
var
source
=
kv
.
Key
;
var
dest
=
kv
.
Value
;
var
rewriter
=
this
.
LocalRewriter
;
sectionBuilder
.
Add
(
_factory
.
ExpressionStatement
(
rewriter
.
MakeStaticAssignmentOperator
(
_factory
.
Syntax
,
rewriter
.
VisitExpression
(
dest
),
rewriter
.
VisitExpression
(
source
),
RefKind
.
None
,
dest
.
Type
,
false
)));
}
}
}
// For switch statements, we have an option of completely rewriting the switch header
// and switch sections into simpler constructs, i.e. we can rewrite the switch header
// using bound conditional goto statements and the rewrite the switch sections into
...
...
src/Compilers/CSharp/Test/Emit/PDB/PDBTests.cs
浏览文件 @
c4362ba1
...
...
@@ -2305,9 +2305,12 @@ class Student : Person { public double GPA; }
<entry offset=""0x0"" startLine=""19"" startColumn=""5"" endLine=""19"" endColumn=""6"" />
<entry offset=""0x1"" startLine=""20"" startColumn=""9"" endLine=""20"" endColumn=""19"" />
<entry offset=""0x4"" hidden=""true"" />
<entry offset=""0x32"" hidden=""true"" />
<entry offset=""0x35"" startLine=""22"" startColumn=""28"" endLine=""22"" endColumn=""44"" />
<entry offset=""0x49"" startLine=""23"" startColumn=""17"" endLine=""23"" endColumn=""57"" />
<entry offset=""0x6a"" hidden=""true"" />
<entry offset=""0x6f"" startLine=""25"" startColumn=""17"" endLine=""25"" endColumn=""57"" />
<entry offset=""0x90"" hidden=""true"" />
<entry offset=""0x95"" startLine=""27"" startColumn=""17"" endLine=""27"" endColumn=""59"" />
<entry offset=""0xb1"" startLine=""29"" startColumn=""17"" endLine=""29"" endColumn=""43"" />
<entry offset=""0xc5"" startLine=""31"" startColumn=""5"" endLine=""31"" endColumn=""6"" />
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录