提交 3cb2531e 编写于 作者: N Neal Gafter 提交者: GitHub

Add a hidden sequence point around the code that assigns pattern variables in switch (#14790)

Fixes #14740
上级 ad7fb97f
......@@ -371,35 +371,28 @@ private void LowerConstantValueDecision(DecisionTree.ByValue byValue)
/// 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)
/// <param name="addBindings">A builder to which the label and binding assignments are added</param>
private void AddBindingsForCase(
ImmutableArray<KeyValuePair<BoundExpression, BoundExpression>> bindings,
ArrayBuilder<BoundStatement> addBindings)
{
var patternMatched = _factory.GenerateLabel("patternMatched");
_loweredDecisionTree.Add(_factory.Goto(patternMatched));
var addBindings = ArrayBuilder<BoundStatement>.GetInstance();
// Hide the code that binds pattern variables in a hidden sequence point
addBindings.Add(_factory.HiddenSequencePoint());
addBindings.Add(_factory.Label(patternMatched));
if (!bindings.IsDefaultOrEmpty)
{
foreach (var kv in bindings)
{
var source = kv.Key;
var dest = kv.Value;
var rewriter = _localRewriter;
var loweredRight = kv.Key;
var loweredLeft = kv.Value;
addBindings.Add(_factory.ExpressionStatement(
rewriter.MakeStaticAssignmentOperator(
_factory.Syntax, rewriter.VisitExpression(dest), rewriter.VisitExpression(source), RefKind.None, dest.Type, false)));
_localRewriter.MakeStaticAssignmentOperator(
_factory.Syntax, loweredLeft, loweredRight, RefKind.None, loweredLeft.Type, false)));
}
}
BoundStatement result = _factory.Block(addBindings.ToImmutableAndFree());
if (_localRewriter.Instrument)
{
// Hide the code that binds pattern variables in a hidden sequence point
result = _localRewriter._instrumenter.InstrumentPatternSwitchBindCasePatternVariables(result);
}
return result;
}
private void LowerDecisionTree(DecisionTree.Guarded guarded)
......@@ -418,14 +411,14 @@ private void LowerDecisionTree(DecisionTree.Guarded guarded)
else
{
// with bindings
sectionBuilder.Add(BindingsForCase(guarded.Bindings));
AddBindingsForCase(guarded.Bindings, sectionBuilder);
sectionBuilder.Add(_factory.Goto(targetLabel));
}
}
else
{
sectionBuilder.Add(BindingsForCase(guarded.Bindings));
var guardTest = _factory.ConditionalGoto(_localRewriter.VisitExpression(guarded.Guard), targetLabel, true);
AddBindingsForCase(guarded.Bindings, sectionBuilder);
var guardTest = _factory.ConditionalGoto(guarded.Guard, targetLabel, true);
// Only add instrumentation (such as a sequence point) if the node is not compiler-generated.
if (!guarded.Guard.WasCompilerGenerated && _localRewriter.Instrument)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册