本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.BoundTryStatement类的典型用法代码示例。如果您正苦于以下问题:C# BoundTryStatement类的具体用法?C# BoundTryStatement怎么用?C# BoundTryStatement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BoundTryStatement类属于Microsoft.CodeAnalysis.CSharp命名空间,在下文中一共展示了BoundTryStatement类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:RoryVL,项目名称:roslyn,代码行数:26,代码来源:LocalRewriter_TryStatement.cs
示例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);
}
开发者ID:riversky,项目名称:roslyn,代码行数:11,代码来源:LocalRewriter_TryStatement.cs
示例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);
}
开发者ID:daking2014,项目名称:roslyn,代码行数:15,代码来源:LocalRewriter_TryStatement.cs
示例4: VisitTryStatement
public override BoundNode VisitTryStatement(BoundTryStatement node)
{
var origSeenYield = _seenYield;
var origLabels = this.currentLabels;
// sibling try blocks do not see each other's yields
_seenYield = false;
this.currentLabels = null;
base.VisitTryStatement(node);
if (_seenYield)
{
// this try yields !
var yieldingTryLabels = _labelsInYieldingTrys;
if (yieldingTryLabels == null)
{
_labelsInYieldingTrys = yieldingTryLabels = new Dictionary<BoundTryStatement, HashSet<LabelSymbol>>();
}
yieldingTryLabels.Add(node, currentLabels);
currentLabels = origLabels;
}
else
{
// this is a boring non-yielding try
// currentLabels = currentLabels U origLabels ;
if (currentLabels == null)
{
currentLabels = origLabels;
}
else if (origLabels != null)
{
currentLabels.UnionWith(origLabels);
}
}
_seenYield = _seenYield | origSeenYield;
return null;
}
开发者ID:noahstein,项目名称:roslyn,代码行数:42,代码来源:IteratorMethodToStateMachineRewriter.YieldsInTryAnalysis.cs
示例5: ContainsYields
private bool ContainsYields(BoundTryStatement statement)
{
return _yieldsInTryAnalysis.ContainsYields(statement);
}
开发者ID:daking2014,项目名称:roslyn,代码行数:4,代码来源:IteratorMethodToStateMachineRewriter.cs
示例6: PushFrame
private IteratorFinallyFrame PushFrame(BoundTryStatement statement)
{
var state = _nextFinalizeState--;
var finallyMethod = MakeSynthesizedFinally(state);
var newFrame = new IteratorFinallyFrame(_currentFinallyFrame, state, finallyMethod, _yieldsInTryAnalysis.Labels(statement));
newFrame.AddState(state);
_currentFinallyFrame = newFrame;
return newFrame;
}
开发者ID:daking2014,项目名称:roslyn,代码行数:11,代码来源:IteratorMethodToStateMachineRewriter.cs
示例7: 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());
}
开发者ID:daking2014,项目名称:roslyn,代码行数:94,代码来源:IteratorMethodToStateMachineRewriter.cs
示例8: PushFrame
private AwaitFinallyFrame PushFrame(BoundTryStatement statement)
{
var newFrame = new AwaitFinallyFrame(currentAwaitFinallyFrame, analysis.Labels(statement));
currentAwaitFinallyFrame = newFrame;
return newFrame;
}
开发者ID:nagyist,项目名称:roslyn,代码行数:6,代码来源:AsyncHandlerRewriter.cs
示例9: ContainsYields
/// <summary>
/// Returns true if given try or any of its nested try blocks contain yields
/// </summary>
public bool ContainsYields(BoundTryStatement statement)
{
return _labelsInYieldingTrys != null && _labelsInYieldingTrys.ContainsKey(statement);
}
开发者ID:noahstein,项目名称:roslyn,代码行数:7,代码来源:IteratorMethodToStateMachineRewriter.YieldsInTryAnalysis.cs
示例10: FinallyContainsAwaits
/// <summary>
/// Returns true if a finally of the given try contains awaits
/// </summary>
public bool FinallyContainsAwaits(BoundTryStatement statement)
{
return _labelsInInterestingTry != null && _labelsInInterestingTry.ContainsKey(statement);
}
开发者ID:rafaellincoln,项目名称:roslyn,代码行数:7,代码来源:AsyncExceptionHandlerRewriter.cs
示例11: PushFrame
private AwaitFinallyFrame PushFrame(BoundTryStatement statement)
{
var newFrame = new AwaitFinallyFrame(_currentAwaitFinallyFrame, _analysis.Labels(statement), (TryStatementSyntax)statement.Syntax);
_currentAwaitFinallyFrame = newFrame;
return newFrame;
}
开发者ID:rafaellincoln,项目名称:roslyn,代码行数:6,代码来源:AsyncExceptionHandlerRewriter.cs
示例12: RewriteFinalizedRegion
/// <summary>
/// Rewrites Try/Catch part of the Try/Catch/Finally
/// </summary>
private BoundStatement RewriteFinalizedRegion(BoundTryStatement node)
{
var rewrittenTry = (BoundBlock)this.VisitBlock(node.TryBlock);
var catches = node.CatchBlocks;
if (catches.IsDefaultOrEmpty)
{
return rewrittenTry;
}
var origAwaitCatchFrame = _currentAwaitCatchFrame;
_currentAwaitCatchFrame = null;
var rewrittenCatches = this.VisitList(node.CatchBlocks);
BoundStatement tryWithCatches = _F.Try(rewrittenTry, rewrittenCatches);
var currentAwaitCatchFrame = _currentAwaitCatchFrame;
if (currentAwaitCatchFrame != null)
{
var handledLabel = _F.GenerateLabel("handled");
var handlersList = currentAwaitCatchFrame.handlers;
var handlers = ArrayBuilder<BoundSwitchSection>.GetInstance(handlersList.Count);
for (int i = 0, l = handlersList.Count; i < l; i++)
{
handlers.Add(_F.SwitchSection(
i + 1,
_F.Block(
handlersList[i],
_F.Goto(handledLabel))));
}
tryWithCatches = _F.Block(
ImmutableArray.Create<LocalSymbol>(
currentAwaitCatchFrame.pendingCaughtException,
currentAwaitCatchFrame.pendingCatch).
AddRange(currentAwaitCatchFrame.GetHoistedLocals()),
ImmutableArray<LocalFunctionSymbol>.Empty,
_F.HiddenSequencePoint(),
_F.Assignment(
_F.Local(currentAwaitCatchFrame.pendingCatch),
_F.Default(currentAwaitCatchFrame.pendingCatch.Type)),
tryWithCatches,
_F.HiddenSequencePoint(),
_F.Switch(
_F.Local(currentAwaitCatchFrame.pendingCatch),
handlers.ToImmutableAndFree()),
_F.HiddenSequencePoint(),
_F.Label(handledLabel));
}
_currentAwaitCatchFrame = origAwaitCatchFrame;
return tryWithCatches;
}
开发者ID:rafaellincoln,项目名称:roslyn,代码行数:57,代码来源:AsyncExceptionHandlerRewriter.cs
示例13: VisitTryStatement
public override BoundNode VisitTryStatement(BoundTryStatement node)
{
var tryStatementSyntax = node.Syntax;
// If you add a syntax kind to the assertion below, please also ensure
// that the scenario has been tested with Edit-and-Continue.
Debug.Assert(
tryStatementSyntax.IsKind(SyntaxKind.TryStatement) ||
tryStatementSyntax.IsKind(SyntaxKind.UsingStatement) ||
tryStatementSyntax.IsKind(SyntaxKind.ForEachStatement));
BoundStatement finalizedRegion;
BoundBlock rewrittenFinally;
var finallyContainsAwaits = _analysis.FinallyContainsAwaits(node);
if (!finallyContainsAwaits)
{
finalizedRegion = RewriteFinalizedRegion(node);
rewrittenFinally = (BoundBlock)this.Visit(node.FinallyBlockOpt);
if (rewrittenFinally == null)
{
return finalizedRegion;
}
var asTry = finalizedRegion as BoundTryStatement;
if (asTry != null)
{
// since finalized region is a try we can just attach finally to it
Debug.Assert(asTry.FinallyBlockOpt == null);
return asTry.Update(asTry.TryBlock, asTry.CatchBlocks, rewrittenFinally, asTry.PreferFaultHandler);
}
else
{
// wrap finalizedRegion into a Try with a finally.
return _F.Try((BoundBlock)finalizedRegion, ImmutableArray<BoundCatchBlock>.Empty, rewrittenFinally);
}
}
// rewrite finalized region (try and catches) in the current frame
var frame = PushFrame(node);
finalizedRegion = RewriteFinalizedRegion(node);
rewrittenFinally = (BoundBlock)this.VisitBlock(node.FinallyBlockOpt);
PopFrame();
var exceptionType = _F.SpecialType(SpecialType.System_Object);
var pendingExceptionLocal = new SynthesizedLocal(_F.CurrentMethod, exceptionType, SynthesizedLocalKind.TryAwaitPendingException, tryStatementSyntax);
var finallyLabel = _F.GenerateLabel("finallyLabel");
var pendingBranchVar = new SynthesizedLocal(_F.CurrentMethod, _F.SpecialType(SpecialType.System_Int32), SynthesizedLocalKind.TryAwaitPendingBranch, tryStatementSyntax);
var catchAll = _F.Catch(_F.Local(pendingExceptionLocal), _F.Block());
var catchAndPendException = _F.Try(
_F.Block(
finalizedRegion,
_F.HiddenSequencePoint(),
_F.Goto(finallyLabel),
PendBranches(frame, pendingBranchVar, finallyLabel)),
ImmutableArray.Create(catchAll));
var syntheticFinally = _F.Block(
_F.HiddenSequencePoint(),
_F.Label(finallyLabel),
rewrittenFinally,
_F.HiddenSequencePoint(),
UnpendException(pendingExceptionLocal),
UnpendBranches(
frame,
pendingBranchVar,
pendingExceptionLocal));
var locals = ArrayBuilder<LocalSymbol>.GetInstance();
var statements = ArrayBuilder<BoundStatement>.GetInstance();
statements.Add(_F.HiddenSequencePoint());
locals.Add(pendingExceptionLocal);
statements.Add(_F.Assignment(_F.Local(pendingExceptionLocal), _F.Default(pendingExceptionLocal.Type)));
locals.Add(pendingBranchVar);
statements.Add(_F.Assignment(_F.Local(pendingBranchVar), _F.Default(pendingBranchVar.Type)));
LocalSymbol returnLocal = frame.returnValue;
if (returnLocal != null)
{
locals.Add(returnLocal);
}
statements.Add(catchAndPendException);
statements.Add(syntheticFinally);
var completeTry = _F.Block(
locals.ToImmutableAndFree(),
ImmutableArray<LocalFunctionSymbol>.Empty,
statements.ToImmutableAndFree());
return completeTry;
}
开发者ID:rafaellincoln,项目名称:roslyn,代码行数:97,代码来源:AsyncExceptionHandlerRewriter.cs
示例14: VisitTryStatement
public override BoundNode VisitTryStatement(BoundTryStatement node)
{
this.Visit(node.TryBlock);
this.VisitList(node.CatchBlocks);
this.Visit(node.FinallyBlockOpt);
return null;
}
开发者ID:abock,项目名称:roslyn,代码行数:7,代码来源:DiagnosticsPass_ExpressionTrees.cs
示例15: RewriteEnumeratorForEachStatement
//.........这里部分代码省略.........
localFunctions: ImmutableArray<LocalFunctionSymbol>.Empty,
statements: ImmutableArray.Create<BoundStatement>(disposeStmt));
}
else
{
Debug.Assert(!enumeratorType.IsSealed);
// IDisposable d
LocalSymbol disposableVar = _factory.SynthesizedLocal(idisposableTypeSymbol);
// Reference to d.
BoundLocal boundDisposableVar = MakeBoundLocal(forEachSyntax, disposableVar, idisposableTypeSymbol);
BoundTypeExpression boundIDisposableTypeExpr = new BoundTypeExpression(forEachSyntax,
aliasOpt: null,
type: idisposableTypeSymbol);
// e as IDisposable
BoundExpression disposableVarInitValue = new BoundAsOperator(forEachSyntax,
operand: boundEnumeratorVar,
targetType: boundIDisposableTypeExpr,
conversion: Conversion.ExplicitReference, // Explicit so the emitter won't optimize it away.
type: idisposableTypeSymbol);
// IDisposable d = e as IDisposable;
BoundStatement disposableVarDecl = MakeLocalDeclaration(forEachSyntax, disposableVar, disposableVarInitValue);
// if (d != null) d.Dispose();
BoundStatement ifStmt = RewriteIfStatement(
syntax: forEachSyntax,
rewrittenCondition: new BoundBinaryOperator(forEachSyntax,
operatorKind: BinaryOperatorKind.NotEqual, // reference equality
left: boundDisposableVar,
right: MakeLiteral(forEachSyntax,
constantValue: ConstantValue.Null,
type: null),
constantValueOpt: null,
methodOpt: null,
resultKind: LookupResultKind.Viable,
type: _compilation.GetSpecialType(SpecialType.System_Boolean)),
rewrittenConsequence: new BoundExpressionStatement(forEachSyntax,
expression: BoundCall.Synthesized(
syntax: forEachSyntax,
receiverOpt: boundDisposableVar,
method: disposeMethod)),
rewrittenAlternativeOpt: null,
hasErrors: false);
// IDisposable d = e as IDisposable;
// if (d != null) d.Dispose();
finallyBlockOpt = new BoundBlock(forEachSyntax,
locals: ImmutableArray.Create<LocalSymbol>(disposableVar),
localFunctions: ImmutableArray<LocalFunctionSymbol>.Empty,
statements: ImmutableArray.Create<BoundStatement>(disposableVarDecl, ifStmt));
}
// try {
// while (e.MoveNext()) {
// V v = (V)(T)e.Current;
// /* loop body */
// }
// }
// finally {
// /* dispose of e */
// }
BoundStatement tryFinally = new BoundTryStatement(forEachSyntax,
tryBlock: new BoundBlock(forEachSyntax,
locals: ImmutableArray<LocalSymbol>.Empty,
localFunctions: ImmutableArray<LocalFunctionSymbol>.Empty,
statements: ImmutableArray.Create<BoundStatement>(whileLoop)),
catchBlocks: ImmutableArray<BoundCatchBlock>.Empty,
finallyBlockOpt: finallyBlockOpt);
// E e = ((C)(x)).GetEnumerator();
// try {
// /* as above */
result = new BoundBlock(
syntax: forEachSyntax,
locals: ImmutableArray.Create(enumeratorVar),
localFunctions: ImmutableArray<LocalFunctionSymbol>.Empty,
statements: ImmutableArray.Create<BoundStatement>(enumeratorVarDecl, tryFinally));
}
else
{
// E e = ((C)(x)).GetEnumerator();
// while (e.MoveNext()) {
// V v = (V)(T)e.Current;
// /* loop body */
// }
result = new BoundBlock(
syntax: forEachSyntax,
locals: ImmutableArray.Create(enumeratorVar),
localFunctions: ImmutableArray<LocalFunctionSymbol>.Empty,
statements: ImmutableArray.Create<BoundStatement>(enumeratorVarDecl, whileLoop));
}
AddForEachKeywordSequencePoint(forEachSyntax, ref result);
return result;
}
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:101,代码来源:LocalRewriter_ForEachStatement.cs
示例16: 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;
}
开发者ID:nagyist,项目名称:roslyn,代码行数:87,代码来源:StateMachineMethodToClassRewriter.cs
示例17: VisitTryStatement
public override BoundNode VisitTryStatement(BoundTryStatement node)
{
var origSeenYieldInCurrentTry = _seenYieldInCurrentTry;
_seenYieldInCurrentTry = false;
base.VisitTryStatement(node);
_seenYieldInCurrentTry |= origSeenYieldInCurrentTry;
return null;
}
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:8,代码来源:IteratorAndAsyncCaptureWalker.cs
示例18: Labels
/// <summary>
/// Labels reachable from within this frame without invoking its finally.
/// null if there are no such labels.
/// </summary>
internal HashSet<LabelSymbol> Labels(BoundTryStatement statement)
{
return _labelsInInterestingTry[statement];
}
开发者ID:rafaellincoln,项目名称:roslyn,代码行数:8,代码来源:AsyncExceptionHandlerRewriter.cs
示例19: Labels
/// <summary>
/// Labels reachable from within this frame without invoking its finally.
/// null if there are none such labels.
/// </summary>
internal HashSet<LabelSymbol> Labels(BoundTryStatement statement)
{
return _labelsInYieldingTrys[statement];
}
开发者ID:noahstein,项目名称:roslyn,代码行数:8,代码来源:IteratorMethodToStateMachineRewriter.YieldsInTryAnalysis.cs
示例20: RewriteUsingStatementTryFinally
//.........这里部分代码省略.........
//
// Second: if the type is a nullable value type then we can similarly elide the boxing.
// We can generate
//
// {
// ResourceType resource = expr;
// try { statement; }
// finally { if (resource.HasValue) resource.GetValueOrDefault().Dispose(); }
// }
//
// Where again we do a constrained virtual call to Dispose, rather than boxing
// the value to IDisposable.
//
// Note that this optimization is *not* what the native compiler does; in this case
// the native compiler behavior is to test for HasValue, then *box* and convert
// the boxed value to IDisposable. There's no need to do that.
//
// Third: if we have "using(x)" and x is dynamic then obviously we need not generate
// "{ dynamic temp1 = x; IDisposable temp2 = (IDisposable) temp1; ... }". Rather, we elide
// the completely unnecessary first temporary.
BoundExpression disposedExpression;
bool isNullableValueType = local.Type.IsNullableType();
if (isNullableValueType)
{
MethodSymbol getValueOrDefault = GetNullableMethod(syntax, local.Type, SpecialMember.System_Nullable_T_GetValueOrDefault);
// local.GetValueOrDefault()
disposedExpression = BoundCall.Synthesized(syntax, local, getValueOrDefault);
}
else
{
// local
disposedExpression = local;
}
// local.Dispose()
BoundExpression disposeCall;
MethodSymbol disposeMethodSymbol;
if (TryGetSpecialTypeMember(syntax, SpecialMember.System_IDisposable__Dispose, out disposeMethodSymbol))
{
disposeCall = BoundCall.Synthesized(syntax, disposedExpression, disposeMethodSymbol);
}
else
{
disposeCall = new BoundBadExpression(syntax, LookupResultKind.NotInvocable, ImmutableArray<Symbol>.Empty, ImmutableArray.Create<BoundNode>(disposedExpression), ErrorTypeSymbol.UnknownResultType);
}
// local.Dispose();
BoundStatement disposeStatement = new BoundExpressionStatement(syntax, disposeCall);
BoundExpression ifCondition;
if (isNullableValueType)
{
MethodSymbol hasValue = GetNullableMethod(syntax, local.Type, SpecialMember.System_Nullable_T_get_HasValue);
// local.HasValue
ifCondition = BoundCall.Synthesized(syntax, local, hasValue);
}
else if (local.Type.IsValueType)
{
ifCondition = null;
}
else
{
// local != null
ifCondition = MakeNullCheck(syntax, local, BinaryOperatorKind.NotEqual);
}
BoundStatement finallyStatement;
if (ifCondition == null)
{
// local.Dispose();
finallyStatement = disposeStatement;
}
else
{
// if (local != null) local.Dispose();
// or
// if (local.HasValue) local.GetValueOrDefault().Dispose();
finallyStatement = RewriteIfStatement(
syntax: syntax,
locals: ImmutableArray<LocalSymbol>.Empty,
rewrittenCondition: ifCondition,
rewrittenConsequence: disposeStatement,
rewrittenAlternativeOpt: null,
hasErrors: false);
}
// try { ... } finally { if (local != null) local.Dispose(); }
BoundStatement tryFinally = new BoundTryStatement(
syntax: syntax,
tryBlock: tryBlock,
catchBlocks: ImmutableArray<BoundCatchBlock>.Empty,
finallyBlockOpt: BoundBlock.SynthesizedNoLocals(syntax, finallyStatement));
return tryFinally;
}
开发者ID:EkardNT,项目名称:Roslyn,代码行数:101,代码来源:LocalRewriter_UsingStatement.cs
注:本文中的Microsoft.CodeAnalysis.CSharp.BoundTryStatement类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论