1 write to F
Microsoft.CodeAnalysis.CSharp (1)
Lowering\StateMachineRewriter\MethodToStateMachineRewriter.cs (1)
124this.F = F;
428 references to F
Microsoft.CodeAnalysis.CSharp (428)
Lowering\AsyncRewriter\AsyncIteratorMethodToStateMachineRewriter.cs (60)
84var iteratorDispatch = _iteratorStateAllocator.GenerateThrowMissingStateDispatch(F, F.Local(cachedState), HotReloadExceptionCode.CannotResumeSuspendedIteratorMethod); 90return (asyncDispatch != null) ? F.Block(asyncDispatch, iteratorDispatch) : iteratorDispatch; 130F.Return(), 131F.Label(_exprReturnLabelTrue), 135return F.Block(builder.ToImmutableAndFree()); 141BoundFieldAccess promiseField = F.InstanceField(_asyncIteratorInfo.PromiseOfValueOrEndField); 142return F.ExpressionStatement(F.Call(promiseField, _asyncIteratorInfo.SetResultMethod, F.Literal(result))); 150return F.Assignment(F.InstanceField(currentField), F.Default(currentField.Type)); 157return F.ExpressionStatement( 158F.Call( 159F.Field(F.This(), _asyncMethodBuilderField), 169var combinedTokens = F.Field(F.This(), _asyncIteratorInfo.CombinedTokensField); 173F.If(F.ObjectNotEqual(combinedTokens, F.Null(combinedTokensType)), 174thenClause: F.Block( 175F.ExpressionStatement(F.Call(combinedTokens, F.WellKnownMethod(WellKnownMember.System_Threading_CancellationTokenSource__Dispose))), 176F.Assignment(combinedTokens, F.Null(combinedTokensType))))); 194builder.Add(F.ExpressionStatement(F.Call( 195F.InstanceField(_asyncIteratorInfo.PromiseOfValueOrEndField), 197F.Local(exceptionLocal)))); 199return F.Block(builder.ToImmutableAndFree()); 205return F.If( 207F.InstanceField(_asyncIteratorInfo.DisposeModeField), 209thenClause: F.Goto(_currentDisposalLabel)); 218return F.Block( 231return F.IntEqual(F.Local(cachedState), F.Literal(StateMachineState.NotStartedOrRunningState)); 255return F.Block( 256F.Label(resumeLabel), // initialStateResumeLabel: 284F.Assignment(F.InstanceField(_asyncIteratorInfo.CurrentField), rewrittenExpression)); 292F.Goto(_exprReturnLabelTrue)); 296F.Label(resumeLabel)); 298blockBuilder.Add(F.HiddenSequencePoint()); 310F.HiddenSequencePoint()); 312return F.Block(blockBuilder.ToImmutableAndFree()); 324return F.Block( 328F.Goto(_currentDisposalLabel)); 333var useSiteInfo = new CompoundUseSiteInfo<AssemblySymbol>(F.Diagnostics, F.Compilation.Assembly); 336F.Diagnostics.Add(field.GetFirstLocationOrNone(), useSiteInfo); 349return F.Assignment(F.InstanceField(_asyncIteratorInfo.DisposeModeField), F.Literal(value)); 371var finallyEntry = F.GenerateLabel("finallyEntry"); 382tryBlock: F.Block(node.TryBlock, F.Label(finallyEntry)),
Lowering\AsyncRewriter\AsyncMethodToStateMachineRewriter.cs (170)
119if (slotAllocator == null || !slotAllocator.TryGetPreviousAwaiterSlotIndex(F.ModuleBuilderOpt.Translate(awaiterType, F.Syntax, F.Diagnostics.DiagnosticBag), F.Diagnostics.DiagnosticBag, out slotIndex)) 125result = F.StateMachineField(awaiterType, fieldName, SynthesizedLocalKind.AwaiterField, slotIndex); 143F.CurrentFunction = moveNextMethod; 151bodyBuilder.Add(F.HiddenSequencePoint()); 152bodyBuilder.Add(F.Assignment(F.Local(cachedState), F.Field(F.This(), stateField))); 155var exceptionLocal = F.SynthesizedLocal(F.WellKnownType(WellKnownType.System_Exception)); 158F.Block(ImmutableArray<LocalSymbol>.Empty, 160F.HiddenSequencePoint(), 165F.CatchBlocks(generateExceptionHandling(exceptionLocal, rootScopeHoistedLocals))) 169bodyBuilder.Add(F.Label(_exprReturnLabel)); 172var stateDone = F.Assignment(F.Field(F.This(), stateField), F.Literal(StateMachineState.FinishedState)); 181bodyBuilder.Add(F.SequencePointWithSpan(block, block.CloseBraceToken.Span, stateDone)); 182bodyBuilder.Add(F.HiddenSequencePoint()); 191bodyBuilder.Add(F.Label(_exitLabel)); 192bodyBuilder.Add(F.Return()); 202F.SequencePoint( 204F.Block( 213newBody = F.Instrument(newBody, instrumentation); 215F.CloseMethod(newBody); 233F.ExpressionStatement(F.AssignmentExpression(F.Field(F.This(), stateField), F.Literal(StateMachineState.FinishedState))); 239F.Syntax, 241F.Local(exceptionLocal), 245body: F.Block( 255=> F.Try(tryBlock, catchBlocks); 260return F.ExpressionStatement( 261F.Call( 262F.Field(F.This(), _asyncMethodBuilderField), 264_method.IsAsyncEffectivelyReturningGenericTask(F.Compilation) 265? ImmutableArray.Create<BoundExpression>(F.Local(_exprRetValue)) 277var useSiteInfo = new CompoundUseSiteInfo<AssemblySymbol>(F.Diagnostics, F.Compilation.Assembly); 279F.Diagnostics.Add(hoistedLocal.GetFirstLocationOrNone(), useSiteInfo); 285builder.Add(F.Assignment(F.Field(F.This(), hoistedLocal), F.NullOrDefault(hoistedLocal.Type))); 288return F.Block(builder.ToImmutableAndFree()); 296return F.ExpressionStatement( 297F.Call( 298F.Field(F.This(), _asyncMethodBuilderField), 300F.Local(exceptionLocal))); 305return F.Goto(_exitLabel); 329return (expr != null) ? node.Update(expr) : (BoundStatement)F.StatementList(); 378var awaiterTemp = F.SynthesizedLocal(getAwaiter.Type, syntax: node.Syntax, kind: SynthesizedLocalKind.Awaiter); 379var awaitIfIncomplete = F.Block( 381F.Assignment( 382F.Local(awaiterTemp), 386F.HiddenSequencePoint(), 389F.If( 390condition: F.Not(GenerateGetIsCompleted(awaiterTemp, isCompletedMethod)), 393F.Local(awaiterTemp), 400F.Assignment(resultPlace, getResultCall) : 401F.ExpressionStatement(getResultCall); 411return F.Block([awaiterTemp], statementsBuilder.ToImmutableAndFree()); 431? F.StaticCall(methodSymbol.ContainingType, methodSymbol, receiver) 432: F.Call(receiver, methodSymbol); 454F.Local(awaiterTemp), 460resultType: F.SpecialType(SpecialType.System_Boolean)).ToExpression(); 463return F.Call(F.Local(awaiterTemp), getIsCompletedMethod); 472? F.SpecialType(SpecialType.System_Object) 485F.NoOp(NoOpStatementFlavor.AwaitYieldPoint)); 489F.Assignment( 490F.Field(F.This(), awaiterField), 492? F.Local(awaiterTemp) 493: F.Convert(awaiterFieldType, F.Local(awaiterTemp)))); 502if (F.Compilation.Options.EnableEditAndContinue) 507blockBuilder.Add(F.Label(dummyResumeLabel)); 512F.Label(resumeLabel)); 516F.NoOp(NoOpStatementFlavor.AwaitResumePoint)); 521F.Assignment( 522F.Local(awaiterTemp), 524? F.Field(F.This(), awaiterField) 525: F.Convert(awaiterTemp.Type, F.Field(F.This(), awaiterField)))); 528F.Assignment(F.Field(F.This(), awaiterField), F.NullOrDefault(awaiterField.Type))); 534return F.Block(blockBuilder.ToImmutableAndFree()); 554var criticalNotifyCompletedTemp = F.SynthesizedLocal( 555F.WellKnownType(WellKnownType.System_Runtime_CompilerServices_ICriticalNotifyCompletion), 558var notifyCompletionTemp = F.SynthesizedLocal( 559F.WellKnownType(WellKnownType.System_Runtime_CompilerServices_INotifyCompletion), 562LocalSymbol thisTemp = (F.CurrentType.TypeKind == TypeKind.Class) ? F.SynthesizedLocal(F.CurrentType) : null; 567F.Assignment( 568F.Local(criticalNotifyCompletedTemp), 570F.As(F.Local(awaiterTemp), criticalNotifyCompletedTemp.Type))); 574blockBuilder.Add(F.Assignment(F.Local(thisTemp), F.This())); 578F.If( 579condition: F.ObjectEqual(F.Local(criticalNotifyCompletedTemp), F.Null(criticalNotifyCompletedTemp.Type)), 581thenClause: F.Block( 583F.Assignment( 584F.Local(notifyCompletionTemp), 586F.Convert(notifyCompletionTemp.Type, F.Local(awaiterTemp), Conversion.ExplicitReference)), 587F.ExpressionStatement( 588F.Call( 589F.Field(F.This(), _asyncMethodBuilderField), 592F.This().Type), 593F.Local(notifyCompletionTemp), F.This(thisTemp))), 594F.Assignment( 595F.Local(notifyCompletionTemp), 596F.NullOrDefault(notifyCompletionTemp.Type))), 598elseClauseOpt: F.Block( 599F.ExpressionStatement( 600F.Call( 601F.Field(F.This(), _asyncMethodBuilderField), 604F.This().Type), 605F.Local(criticalNotifyCompletedTemp), F.This(thisTemp)))))); 608F.Assignment( 609F.Local(criticalNotifyCompletedTemp), 610F.NullOrDefault(criticalNotifyCompletedTemp.Type))); 612return F.Block( 623LocalSymbol thisTemp = (F.CurrentType.TypeKind == TypeKind.Class) ? F.SynthesizedLocal(F.CurrentType) : null; 626var useUnsafeOnCompleted = F.Compilation.Conversions.ClassifyImplicitConversionFromType( 628F.Compilation.GetWellKnownType(WellKnownType.System_Runtime_CompilerServices_ICriticalNotifyCompletion), 633_asyncMethodBuilderMemberCollection.AwaitOnCompleted).Construct(loweredAwaiterType, F.This().Type); 636onCompleted.CheckConstraints(new ConstraintsHelper.CheckConstraintsArgs(F.Compilation, F.Compilation.Conversions, includeNullability: false, F.Syntax.Location, this.Diagnostics)); 640F.Call( 641F.Field(F.This(), _asyncMethodBuilderField), 643F.Local(awaiterTemp), F.This(thisTemp)); 647result = F.Sequence( 649ImmutableArray.Create<BoundExpression>(F.AssignmentExpression(F.Local(thisTemp), F.This())), 653return F.ExpressionStatement(result); 665Debug.Assert(_method.IsAsyncEffectivelyReturningGenericTask(F.Compilation)); 666return F.Block( 667F.Assignment(F.Local(_exprRetValue), (BoundExpression)Visit(node.ExpressionOpt)), 668F.Goto(_exprReturnLabel)); 671return F.Goto(_exprReturnLabel);
Lowering\IteratorRewriter\IteratorMethodToStateMachineRewriter.cs (115)
103F.CurrentFunction = moveNextMethod; 117newBody = F.Block((object)cachedThis == null ? 121F.HiddenSequencePoint(), 122F.Assignment(F.Local(cachedState), F.Field(F.This(), stateField)), 126F.Label(initialLabel), 127F.Assignment(F.Field(F.This(), stateField), F.Literal(StateMachineState.NotStartedOrRunningState)), 152var faultBlock = F.Block(F.ExpressionStatement(F.Call(F.This(), disposeMethod))); 153newBody = F.Fault((BoundBlock)newBody, faultBlock); 156newBody = F.Instrument(F.SequencePoint(body.Syntax, HandleReturn(newBody)), instrumentation); 158F.CloseMethod(newBody); 163F.CurrentFunction = disposeMethod; 169var disposeBody = F.Block( 171F.Assignment(F.Field(F.This(), stateField), F.Literal(StateMachineState.FinishedState)), 172F.Return()); 174F.CloseMethod(disposeBody); 178var stateLocal = F.SynthesizedLocal(stateField.Type); 179var state = F.Local(stateLocal); 181var disposeBody = F.Block( 183F.Assignment(F.Local(stateLocal), F.Field(F.This(), stateField)), 186F.Assignment(F.Field(F.This(), stateField), F.Literal(StateMachineState.FinishedState)), 187F.Return()); 189F.CloseMethod(disposeBody); 199return F.Block( 201F.Return(F.Literal(false))); 209return F.Block( 212F.Assignment(this.F.Local(_methodValue), this.F.Literal(true)), 213F.Label(_exitLabel), 214F.Return(this.F.Local(_methodValue))); 269var breakLabel = F.GenerateLabel("break"); 272select F.SwitchSection( 275F.Goto(breakLabel)); 277body = F.Block( 278F.Switch(state, sections.ToImmutableArray()), 279F.Label(breakLabel)); 284var tryBlock = body != null ? F.Block(body) : F.Block(); 285body = F.Try( 288F.Block(F.ExpressionStatement(F.Call(F.This(), frame.handler)))); 297BoundLiteral result = this.F.Literal(!finished); 301return F.Return(result); 307_exitLabel = this.F.GenerateLabel("exitLabel"); 308_methodValue = F.SynthesizedLocal(result.Type); 311var gotoExit = F.Goto(_exitLabel); 319return this.F.Block( 320F.Assignment(this.F.Local(_methodValue), result), 347return F.Block( 348F.Assignment(F.Field(F.This(), _current), rewrittenExpression), 349F.Assignment(F.Field(F.This(), stateField), F.Literal(stateNumber)), 351F.Label(resumeLabel), 352F.HiddenSequencePoint(), 353F.Assignment(F.Field(F.This(), stateField), F.Literal(_currentFinallyFrame.finalizeState))); 361Debug.Assert(node.Label == proxyLabel || !(F.CurrentFunction is IteratorFinallyMethodSymbol), "should not be proxying branches in finally"); 400var origMethod = F.CurrentFunction; 403F.CurrentFunction = finallyMethod; 415rewrittenHandler = F.Block((object)this.cachedThis != null ? 418F.Assignment(F.Field(F.This(), stateField), F.Literal(frame.parent.finalizeState)), 421F.Return() 424F.CloseMethod(rewrittenHandler); 425F.CurrentFunction = origMethod; 436bodyStatements.Add(F.Assignment(F.Field(F.This(), stateField), F.Literal(frame.finalizeState))); 438bodyStatements.Add(F.ExpressionStatement(F.Call(F.This(), finallyMethod))); 443var dropThrough = F.GenerateLabel("dropThrough"); 444bodyStatements.Add(F.Goto(dropThrough)); 453bodyStatements.Add(F.Label(proxy)); 456bodyStatements.Add(F.ExpressionStatement(F.Call(F.This(), finallyMethod))); 460bodyStatements.Add(F.Goto(parentProxy)); 463bodyStatements.Add(F.Label(dropThrough)); 466return F.Block(bodyStatements.ToImmutableAndFree()); 501var stateMachineType = (IteratorStateMachine)F.CurrentType; 504F.ModuleBuilderOpt.AddSynthesizedDefinition(stateMachineType, finallyMethod.GetCciAdapter());
Lowering\StateMachineRewriter\MethodToStateMachineRewriter.cs (83)
183get { return ((SynthesizedContainer)F.CurrentType).TypeMap; } 188get { return F.CurrentFunction; } 206var oldSyntax = F.Syntax; 207F.Syntax = syntax; 208var result = F.This(); 210F.Syntax = oldSyntax; 236resumeLabel = F.GenerateLabel("stateMachine"); 250select F.SwitchSection(kv.Value.SelectAsArray(state => (int)state), F.Goto(kv.Key)); 252var result = F.Switch(F.Local(cachedState), sections.ToImmutableArray()); 265result = F.Block(result, missingStateDispatch); 273=> _resumableStateAllocator.GenerateThrowMissingStateDispatch(F, F.Local(cachedState), EncMissingStateErrorCode); 382translatedStatement = F.Block( 384F.Block(variableCleanup.SelectAsArray((e, f) => (BoundStatement)f.ExpressionStatement(e), F))); 405return F.Block(new BoundStateMachineScope(F.Syntax, hoistedLocals, statement)); 436var useSiteInfo = new CompoundUseSiteInfo<AssemblySymbol>(F.Diagnostics, F.Compilation.Assembly); 438F.Diagnostics.Add(field.GetFirstLocationOrNone(), useSiteInfo); 441cleanup.Add(F.AssignmentExpression(F.Field(F.This(), field), F.NullOrDefault(field.Type))); 455var result = F.Block(variableCleanup.SelectAsArray((e, f) => (BoundStatement)f.ExpressionStatement(e), F)); 480createdField = F.StateMachineField(type, fieldName, SynthesizedLocalKind.UserDefined, slotIndex); 484createdField = F.StateMachineField(type, GeneratedNames.ReusableHoistedLocalFieldName(slotIndex)); 537if (F.Compilation.Options.OptimizationLevel == OptimizationLevel.Debug) 565var sacrificialTemp = F.SynthesizedLocal(type, refKind: RefKind.Ref); 567return F.Sequence(ImmutableArray.Create(sacrificialTemp), sideEffects.ToImmutableAndFree(), F.AssignmentExpression(F.Local(sacrificialTemp), replacement, isRef: true)); 578return F.Sequence(ImmutableArray<LocalSymbol>.Empty, sideEffects.ToImmutableAndFree(), last); 630return F.Field(receiver, field.FieldSymbol); 650F.Diagnostics.Add(ErrorCode.ERR_RefReturningCallAndAwait, F.Syntax.Location, call.Method); 668F.Diagnostics.Add(ErrorCode.ERR_RefConditionalAndAwait, F.Syntax.Location); 687if (F.Compilation.Options.OptimizationLevel == OptimizationLevel.Debug) 702F.ModuleBuilderOpt.Translate(fieldType, awaitSyntaxOpt, Diagnostics.DiagnosticBag), 712hoistedField = F.StateMachineField(expr.Type, fieldName, new LocalSlotDebugInfo(kind, id), slotIndex); 722var replacement = F.Field(F.This(), hoistedField); 723sideEffects.Add(F.AssignmentExpression(replacement, expr)); 733var oldSyntax = F.Syntax; 734F.Syntax = node.Syntax; 736F.Syntax = oldSyntax; 752=> F.Field(F.This(), instanceIdField); 889BoundBlock tryBlock = F.Block((BoundStatement)this.Visit(node.TryBlock)); 893dispatchLabel = F.GenerateLabel("tryDispatch"); 895tryBlock = F.Block( 896F.HiddenSequencePoint(), 908BoundBlock finallyBlockOpt = node.FinallyBlockOpt == null ? null : F.Block( 909F.HiddenSequencePoint(), 910F.If( 914F.HiddenSequencePoint()); 920result = F.Block( 921F.HiddenSequencePoint(), 922F.Label(dispatchLabel), 936return F.IntLessThan(F.Local(cachedState), F.Literal(StateMachineState.FirstUnusedState)); 945return F.Assignment(F.Field(F.This(), stateField), F.AssignmentExpression(F.Local(cachedState), F.Literal(stateNumber))); 954var fetchThis = proxy.Replacement(F.Syntax, static (frameType, F) => F.This(), F); 955return F.Assignment(F.Local(this.cachedThis), fetchThis); 959return F.StatementList(); 967return F.Local(this.cachedThis); 990return proxy.Replacement(F.Syntax, static (frameType, F) => F.This(), F); 1001return F.Local(this.cachedThis); 1006return proxy.Replacement(F.Syntax, static (frameType, F) => F.This(), F);