本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.BoundTryStatement.Update方法的典型用法代码示例。如果您正苦于以下问题:C# BoundTryStatement.Update方法的具体用法?C# BoundTryStatement.Update怎么用?C# BoundTryStatement.Update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.CSharp.BoundTryStatement
的用法示例。
在下文中一共展示了BoundTryStatement.Update方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitTryStatement
public override BoundNode VisitTryStatement(BoundTryStatement node)
{
BoundBlock tryBlock = (BoundBlock)this.Visit(node.TryBlock);
var origSawAwait = _sawAwait;
_sawAwait = false;
var optimizing = _compilation.Options.OptimizationLevel == OptimizationLevel.Release;
ImmutableArray<BoundCatchBlock> catchBlocks =
// When optimizing and we have a try block without side-effects, we can discard the catch blocks.
(optimizing && !HasSideEffects(tryBlock)) ? ImmutableArray<BoundCatchBlock>.Empty
: this.VisitList(node.CatchBlocks);
BoundBlock finallyBlockOpt = (BoundBlock)this.Visit(node.FinallyBlockOpt);
_sawAwaitInExceptionHandler |= _sawAwait;
_sawAwait |= origSawAwait;
if (optimizing && !HasSideEffects(finallyBlockOpt))
{
finallyBlockOpt = null;
}
return (catchBlocks.IsDefaultOrEmpty && finallyBlockOpt == null)
? (BoundNode)tryBlock
: (BoundNode)node.Update(tryBlock, catchBlocks, finallyBlockOpt, node.PreferFaultHandler);
}
示例2: VisitTryStatement
public override BoundNode VisitTryStatement(BoundTryStatement node)
{
BoundBlock tryBlock = (BoundBlock)this.Visit(node.TryBlock);
this.ExceptionHandleNesting++;
ImmutableArray<BoundCatchBlock> catchBlocks = (ImmutableArray<BoundCatchBlock>)this.VisitList(node.CatchBlocks);
BoundBlock finallyBlockOpt = (BoundBlock)this.Visit(node.FinallyBlockOpt);
this.ExceptionHandleNesting--;
return node.Update(tryBlock, catchBlocks, finallyBlockOpt, node.PreferFaultHandler);
}
示例3: VisitTryStatement
public override BoundNode VisitTryStatement(BoundTryStatement node)
{
BoundBlock tryBlock = (BoundBlock)this.Visit(node.TryBlock);
var origSawAwait = _sawAwait;
_sawAwait = false;
ImmutableArray<BoundCatchBlock> catchBlocks = (ImmutableArray<BoundCatchBlock>)this.VisitList(node.CatchBlocks);
BoundBlock finallyBlockOpt = (BoundBlock)this.Visit(node.FinallyBlockOpt);
_sawAwaitInExceptionHandler |= _sawAwait;
_sawAwait |= origSawAwait;
return node.Update(tryBlock, catchBlocks, finallyBlockOpt, node.PreferFaultHandler);
}
示例4: VisitTryStatement
/// <summary>
/// The try statement is the most complex part of the state machine transformation.
/// Since the CLR will not allow a 'goto' into the scope of a try statement, we must
/// generate the dispatch to the state's label stepwise. That is done by translating
/// the try statements from the inside to the outside. Within a try statement, we
/// start with an empty dispatch table (representing the mapping from state numbers
/// to labels). During translation of the try statement's body, the dispatch table
/// will be filled in with the data necessary to dispatch once we're inside the try
/// block. We generate that at the head of the translated try statement. Then, we
/// copy all of the states from that table into the table for the enclosing construct,
/// but associate them with a label just before the translated try block. That way
/// the enclosing construct will generate the code necessary to get control into the
/// try block for all of those states.
/// </summary>
public override BoundNode VisitTryStatement(BoundTryStatement node)
{
var oldDispatches = dispatches;
var oldFinalizerState = currentFinalizerState;
var oldHasFinalizerState = hasFinalizerState;
dispatches = null;
currentFinalizerState = -1;
hasFinalizerState = false;
BoundBlock tryBlock = F.Block((BoundStatement)this.Visit(node.TryBlock));
GeneratedLabelSymbol dispatchLabel = null;
if (dispatches != null)
{
dispatchLabel = F.GenerateLabel("tryDispatch");
if (hasFinalizerState)
{
// cause the current finalizer state to arrive here and then "return false"
var finalizer = F.GenerateLabel("finalizer");
dispatches.Add(finalizer, new List<int>() { this.currentFinalizerState });
var skipFinalizer = F.GenerateLabel("skipFinalizer");
tryBlock = F.Block(
F.HiddenSequencePoint(),
Dispatch(),
F.Goto(skipFinalizer),
F.Label(finalizer), // code for the finalizer here
F.Assignment(F.Field(F.This(), stateField), F.AssignmentExpression(F.Local(cachedState), F.Literal(StateMachineStates.NotStartedStateMachine))),
GenerateReturn(false),
F.Label(skipFinalizer),
tryBlock
);
}
else
{
tryBlock = F.Block(
F.HiddenSequencePoint(),
Dispatch(),
tryBlock
);
}
if (oldDispatches == null)
{
Debug.Assert(!oldHasFinalizerState);
oldDispatches = new Dictionary<LabelSymbol, List<int>>();
}
oldDispatches.Add(dispatchLabel, new List<int>(from kv in dispatches.Values from n in kv orderby n select n));
}
hasFinalizerState = oldHasFinalizerState;
currentFinalizerState = oldFinalizerState;
dispatches = oldDispatches;
ImmutableArray<BoundCatchBlock> catchBlocks = this.VisitList(node.CatchBlocks);
BoundBlock finallyBlockOpt = node.FinallyBlockOpt == null ? null : F.Block(
F.HiddenSequencePoint(),
F.If(
condition: F.IntLessThan(F.Local(cachedState), F.Literal(StateMachineStates.FirstUnusedState)),
thenClause: (BoundBlock)this.Visit(node.FinallyBlockOpt)
),
F.HiddenSequencePoint());
BoundStatement result = node.Update(tryBlock, catchBlocks, finallyBlockOpt, node.PreferFaultHandler);
if ((object)dispatchLabel != null)
{
result = F.Block(
F.HiddenSequencePoint(),
F.Label(dispatchLabel),
result);
}
return result;
}
示例5: VisitTryStatement
public override BoundNode VisitTryStatement(BoundTryStatement node)
{
// if node contains no yields, do regular rewrite in the current frame.
if (!ContainsYields(node))
{
_tryNestingLevel++;
var result = node.Update(
(BoundBlock)Visit(node.TryBlock),
VisitList(node.CatchBlocks),
(BoundBlock)Visit(node.FinallyBlockOpt),
node.PreferFaultHandler);
_tryNestingLevel--;
return result;
}
Debug.Assert(node.CatchBlocks.IsEmpty, "try with yields must have no catches");
Debug.Assert(node.FinallyBlockOpt != null, "try with yields must have finally");
// rewrite TryBlock in a new frame.
var frame = PushFrame(node);
_tryNestingLevel++;
var rewrittenBody = (BoundStatement)this.Visit(node.TryBlock);
Debug.Assert(!frame.IsRoot());
Debug.Assert(frame.parent.knownStates.ContainsValue(frame), "parent must be aware about states in the child frame");
var finallyMethod = frame.handler;
var origMethod = F.CurrentMethod;
// rewrite finally block into a Finally method.
F.CurrentMethod = finallyMethod;
var rewrittenHandler = (BoundStatement)this.Visit(node.FinallyBlockOpt);
_tryNestingLevel--;
PopFrame();
// {
// this.state = parentFinalizeState;
// body;
// return;
// }
Debug.Assert(frame.parent.finalizeState == _currentFinallyFrame.finalizeState);
rewrittenHandler = F.Block(
F.Assignment(F.Field(F.This(), stateField), F.Literal(frame.parent.finalizeState)),
rewrittenHandler,
F.Return()
);
F.CloseMethod(rewrittenHandler);
F.CurrentMethod = origMethod;
var bodyStatements = ArrayBuilder<BoundStatement>.GetInstance();
// add a call to the handler after the try body.
//
// {
// this.state = finalizeState;
// body;
// this.Finally(); // will reset the state to the finally state of the parent.
// }
bodyStatements.Add(F.Assignment(F.Field(F.This(), stateField), F.Literal(frame.finalizeState)));
bodyStatements.Add(rewrittenBody);
bodyStatements.Add(F.ExpressionStatement(F.Call(F.This(), finallyMethod)));
// handle proxy labels if have any
if (frame.proxyLabels != null)
{
var dropThrough = F.GenerateLabel("dropThrough");
bodyStatements.Add(F.Goto(dropThrough));
var parent = frame.parent;
foreach (var p in frame.proxyLabels)
{
var proxy = p.Value;
var destination = p.Key;
// branch lands here
bodyStatements.Add(F.Label(proxy));
// finalize current state, proceed to destination.
bodyStatements.Add(F.ExpressionStatement(F.Call(F.This(), finallyMethod)));
// let the parent forward the branch appropriately
var parentProxy = parent.ProxyLabelIfNeeded(destination);
bodyStatements.Add(F.Goto(parentProxy));
}
bodyStatements.Add(F.Label(dropThrough));
}
return F.Block(bodyStatements.ToImmutableAndFree());
}