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)
114if (slotAllocator == null || !slotAllocator.TryGetPreviousAwaiterSlotIndex(F.ModuleBuilderOpt.Translate(awaiterType, F.Syntax, F.Diagnostics.DiagnosticBag), F.Diagnostics.DiagnosticBag, out slotIndex)) 120result = F.StateMachineField(awaiterType, fieldName, SynthesizedLocalKind.AwaiterField, slotIndex); 138F.CurrentFunction = moveNextMethod; 146bodyBuilder.Add(F.HiddenSequencePoint()); 147bodyBuilder.Add(F.Assignment(F.Local(cachedState), F.Field(F.This(), stateField))); 150var exceptionLocal = F.SynthesizedLocal(F.WellKnownType(WellKnownType.System_Exception)); 153F.Block(ImmutableArray<LocalSymbol>.Empty, 155F.HiddenSequencePoint(), 160F.CatchBlocks(generateExceptionHandling(exceptionLocal, rootScopeHoistedLocals))) 164bodyBuilder.Add(F.Label(_exprReturnLabel)); 167var stateDone = F.Assignment(F.Field(F.This(), stateField), F.Literal(StateMachineState.FinishedState)); 176bodyBuilder.Add(F.SequencePointWithSpan(block, block.CloseBraceToken.Span, stateDone)); 177bodyBuilder.Add(F.HiddenSequencePoint()); 186bodyBuilder.Add(F.Label(_exitLabel)); 187bodyBuilder.Add(F.Return()); 197F.SequencePoint( 199F.Block( 208newBody = F.Instrument(newBody, instrumentation); 210F.CloseMethod(newBody); 228F.ExpressionStatement(F.AssignmentExpression(F.Field(F.This(), stateField), F.Literal(StateMachineState.FinishedState))); 234F.Syntax, 236F.Local(exceptionLocal), 240body: F.Block( 250=> F.Try(tryBlock, catchBlocks); 255return F.ExpressionStatement( 256F.Call( 257F.Field(F.This(), _asyncMethodBuilderField), 259_method.IsAsyncEffectivelyReturningGenericTask(F.Compilation) 260? ImmutableArray.Create<BoundExpression>(F.Local(_exprRetValue)) 272var useSiteInfo = new CompoundUseSiteInfo<AssemblySymbol>(F.Diagnostics, F.Compilation.Assembly); 274F.Diagnostics.Add(hoistedLocal.GetFirstLocationOrNone(), useSiteInfo); 280builder.Add(F.Assignment(F.Field(F.This(), hoistedLocal), F.NullOrDefault(hoistedLocal.Type))); 283return F.Block(builder.ToImmutableAndFree()); 291return F.ExpressionStatement( 292F.Call( 293F.Field(F.This(), _asyncMethodBuilderField), 295F.Local(exceptionLocal))); 300return F.Goto(_exitLabel); 324return (expr != null) ? node.Update(expr) : (BoundStatement)F.StatementList(); 373var awaiterTemp = F.SynthesizedLocal(getAwaiter.Type, syntax: node.Syntax, kind: SynthesizedLocalKind.Awaiter); 374var awaitIfIncomplete = F.Block( 376F.Assignment( 377F.Local(awaiterTemp), 381F.HiddenSequencePoint(), 384F.If( 385condition: F.Not(GenerateGetIsCompleted(awaiterTemp, isCompletedMethod)), 388F.Local(awaiterTemp), 395F.Assignment(resultPlace, getResultCall) : 396F.ExpressionStatement(getResultCall); 406return F.Block([awaiterTemp], statementsBuilder.ToImmutableAndFree()); 426? F.StaticCall(methodSymbol.ContainingType, methodSymbol, receiver) 427: F.Call(receiver, methodSymbol); 449F.Local(awaiterTemp), 455resultType: F.SpecialType(SpecialType.System_Boolean)).ToExpression(); 458return F.Call(F.Local(awaiterTemp), getIsCompletedMethod); 467? F.SpecialType(SpecialType.System_Object) 480F.NoOp(NoOpStatementFlavor.AwaitYieldPoint)); 484F.Assignment( 485F.Field(F.This(), awaiterField), 487? F.Local(awaiterTemp) 488: F.Convert(awaiterFieldType, F.Local(awaiterTemp)))); 497if (F.Compilation.Options.EnableEditAndContinue) 502blockBuilder.Add(F.Label(dummyResumeLabel)); 507F.Label(resumeLabel)); 511F.NoOp(NoOpStatementFlavor.AwaitResumePoint)); 516F.Assignment( 517F.Local(awaiterTemp), 519? F.Field(F.This(), awaiterField) 520: F.Convert(awaiterTemp.Type, F.Field(F.This(), awaiterField)))); 523F.Assignment(F.Field(F.This(), awaiterField), F.NullOrDefault(awaiterField.Type))); 529return F.Block(blockBuilder.ToImmutableAndFree()); 549var criticalNotifyCompletedTemp = F.SynthesizedLocal( 550F.WellKnownType(WellKnownType.System_Runtime_CompilerServices_ICriticalNotifyCompletion), 553var notifyCompletionTemp = F.SynthesizedLocal( 554F.WellKnownType(WellKnownType.System_Runtime_CompilerServices_INotifyCompletion), 557LocalSymbol thisTemp = (F.CurrentType.TypeKind == TypeKind.Class) ? F.SynthesizedLocal(F.CurrentType) : null; 562F.Assignment( 563F.Local(criticalNotifyCompletedTemp), 565F.As(F.Local(awaiterTemp), criticalNotifyCompletedTemp.Type))); 569blockBuilder.Add(F.Assignment(F.Local(thisTemp), F.This())); 573F.If( 574condition: F.ObjectEqual(F.Local(criticalNotifyCompletedTemp), F.Null(criticalNotifyCompletedTemp.Type)), 576thenClause: F.Block( 578F.Assignment( 579F.Local(notifyCompletionTemp), 581F.Convert(notifyCompletionTemp.Type, F.Local(awaiterTemp), Conversion.ExplicitReference)), 582F.ExpressionStatement( 583F.Call( 584F.Field(F.This(), _asyncMethodBuilderField), 587F.This().Type), 588F.Local(notifyCompletionTemp), F.This(thisTemp))), 589F.Assignment( 590F.Local(notifyCompletionTemp), 591F.NullOrDefault(notifyCompletionTemp.Type))), 593elseClauseOpt: F.Block( 594F.ExpressionStatement( 595F.Call( 596F.Field(F.This(), _asyncMethodBuilderField), 599F.This().Type), 600F.Local(criticalNotifyCompletedTemp), F.This(thisTemp)))))); 603F.Assignment( 604F.Local(criticalNotifyCompletedTemp), 605F.NullOrDefault(criticalNotifyCompletedTemp.Type))); 607return F.Block( 618LocalSymbol thisTemp = (F.CurrentType.TypeKind == TypeKind.Class) ? F.SynthesizedLocal(F.CurrentType) : null; 621var useUnsafeOnCompleted = F.Compilation.Conversions.ClassifyImplicitConversionFromType( 623F.Compilation.GetWellKnownType(WellKnownType.System_Runtime_CompilerServices_ICriticalNotifyCompletion), 628_asyncMethodBuilderMemberCollection.AwaitOnCompleted).Construct(loweredAwaiterType, F.This().Type); 631onCompleted.CheckConstraints(new ConstraintsHelper.CheckConstraintsArgs(F.Compilation, F.Compilation.Conversions, includeNullability: false, F.Syntax.Location, this.Diagnostics)); 635F.Call( 636F.Field(F.This(), _asyncMethodBuilderField), 638F.Local(awaiterTemp), F.This(thisTemp)); 642result = F.Sequence( 644ImmutableArray.Create<BoundExpression>(F.AssignmentExpression(F.Local(thisTemp), F.This())), 648return F.ExpressionStatement(result); 660Debug.Assert(_method.IsAsyncEffectivelyReturningGenericTask(F.Compilation)); 661return F.Block( 662F.Assignment(F.Local(_exprRetValue), (BoundExpression)Visit(node.ExpressionOpt)), 663F.Goto(_exprReturnLabel)); 666return F.Goto(_exprReturnLabel);
Lowering\IteratorRewriter\IteratorMethodToStateMachineRewriter.cs (115)
98F.CurrentFunction = moveNextMethod; 112newBody = F.Block((object)cachedThis == null ? 116F.HiddenSequencePoint(), 117F.Assignment(F.Local(cachedState), F.Field(F.This(), stateField)), 121F.Label(initialLabel), 122F.Assignment(F.Field(F.This(), stateField), F.Literal(StateMachineState.NotStartedOrRunningState)), 147var faultBlock = F.Block(F.ExpressionStatement(F.Call(F.This(), disposeMethod))); 148newBody = F.Fault((BoundBlock)newBody, faultBlock); 151newBody = F.Instrument(F.SequencePoint(body.Syntax, HandleReturn(newBody)), instrumentation); 153F.CloseMethod(newBody); 158F.CurrentFunction = disposeMethod; 164var disposeBody = F.Block( 166F.Assignment(F.Field(F.This(), stateField), F.Literal(StateMachineState.FinishedState)), 167F.Return()); 169F.CloseMethod(disposeBody); 173var stateLocal = F.SynthesizedLocal(stateField.Type); 174var state = F.Local(stateLocal); 176var disposeBody = F.Block( 178F.Assignment(F.Local(stateLocal), F.Field(F.This(), stateField)), 181F.Assignment(F.Field(F.This(), stateField), F.Literal(StateMachineState.FinishedState)), 182F.Return()); 184F.CloseMethod(disposeBody); 194return F.Block( 196F.Return(F.Literal(false))); 204return F.Block( 207F.Assignment(this.F.Local(_methodValue), this.F.Literal(true)), 208F.Label(_exitLabel), 209F.Return(this.F.Local(_methodValue))); 264var breakLabel = F.GenerateLabel("break"); 267select F.SwitchSection( 270F.Goto(breakLabel)); 272body = F.Block( 273F.Switch(state, sections.ToImmutableArray()), 274F.Label(breakLabel)); 279var tryBlock = body != null ? F.Block(body) : F.Block(); 280body = F.Try( 283F.Block(F.ExpressionStatement(F.Call(F.This(), frame.handler)))); 292BoundLiteral result = this.F.Literal(!finished); 296return F.Return(result); 302_exitLabel = this.F.GenerateLabel("exitLabel"); 303_methodValue = F.SynthesizedLocal(result.Type); 306var gotoExit = F.Goto(_exitLabel); 314return this.F.Block( 315F.Assignment(this.F.Local(_methodValue), result), 342return F.Block( 343F.Assignment(F.Field(F.This(), _current), rewrittenExpression), 344F.Assignment(F.Field(F.This(), stateField), F.Literal(stateNumber)), 346F.Label(resumeLabel), 347F.HiddenSequencePoint(), 348F.Assignment(F.Field(F.This(), stateField), F.Literal(_currentFinallyFrame.finalizeState))); 356Debug.Assert(node.Label == proxyLabel || !(F.CurrentFunction is IteratorFinallyMethodSymbol), "should not be proxying branches in finally"); 395var origMethod = F.CurrentFunction; 398F.CurrentFunction = finallyMethod; 410rewrittenHandler = F.Block((object)this.cachedThis != null ? 413F.Assignment(F.Field(F.This(), stateField), F.Literal(frame.parent.finalizeState)), 416F.Return() 419F.CloseMethod(rewrittenHandler); 420F.CurrentFunction = origMethod; 431bodyStatements.Add(F.Assignment(F.Field(F.This(), stateField), F.Literal(frame.finalizeState))); 433bodyStatements.Add(F.ExpressionStatement(F.Call(F.This(), finallyMethod))); 438var dropThrough = F.GenerateLabel("dropThrough"); 439bodyStatements.Add(F.Goto(dropThrough)); 448bodyStatements.Add(F.Label(proxy)); 451bodyStatements.Add(F.ExpressionStatement(F.Call(F.This(), finallyMethod))); 455bodyStatements.Add(F.Goto(parentProxy)); 458bodyStatements.Add(F.Label(dropThrough)); 461return F.Block(bodyStatements.ToImmutableAndFree()); 496var stateMachineType = (IteratorStateMachine)F.CurrentType; 499F.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)); 530if (F.Compilation.Options.OptimizationLevel == OptimizationLevel.Debug) 558var sacrificialTemp = F.SynthesizedLocal(type, refKind: RefKind.Ref); 560return F.Sequence(ImmutableArray.Create(sacrificialTemp), sideEffects.ToImmutableAndFree(), F.AssignmentExpression(F.Local(sacrificialTemp), replacement, isRef: true)); 571return F.Sequence(ImmutableArray<LocalSymbol>.Empty, sideEffects.ToImmutableAndFree(), last); 623return F.Field(receiver, field.FieldSymbol); 643F.Diagnostics.Add(ErrorCode.ERR_RefReturningCallAndAwait, F.Syntax.Location, call.Method); 661F.Diagnostics.Add(ErrorCode.ERR_RefConditionalAndAwait, F.Syntax.Location); 680if (F.Compilation.Options.OptimizationLevel == OptimizationLevel.Debug) 695F.ModuleBuilderOpt.Translate(fieldType, awaitSyntaxOpt, Diagnostics.DiagnosticBag), 705hoistedField = F.StateMachineField(expr.Type, fieldName, new LocalSlotDebugInfo(kind, id), slotIndex); 715var replacement = F.Field(F.This(), hoistedField); 716sideEffects.Add(F.AssignmentExpression(replacement, expr)); 726var oldSyntax = F.Syntax; 727F.Syntax = node.Syntax; 729F.Syntax = oldSyntax; 745=> F.Field(F.This(), instanceIdField); 882BoundBlock tryBlock = F.Block((BoundStatement)this.Visit(node.TryBlock)); 886dispatchLabel = F.GenerateLabel("tryDispatch"); 888tryBlock = F.Block( 889F.HiddenSequencePoint(), 901BoundBlock finallyBlockOpt = node.FinallyBlockOpt == null ? null : F.Block( 902F.HiddenSequencePoint(), 903F.If( 907F.HiddenSequencePoint()); 913result = F.Block( 914F.HiddenSequencePoint(), 915F.Label(dispatchLabel), 929return F.IntLessThan(F.Local(cachedState), F.Literal(StateMachineState.FirstUnusedState)); 938return F.Assignment(F.Field(F.This(), stateField), F.AssignmentExpression(F.Local(cachedState), F.Literal(stateNumber))); 947var fetchThis = proxy.Replacement(F.Syntax, static (frameType, F) => F.This(), F); 948return F.Assignment(F.Local(this.cachedThis), fetchThis); 952return F.StatementList(); 960return F.Local(this.cachedThis); 983return proxy.Replacement(F.Syntax, static (frameType, F) => F.This(), F); 994return F.Local(this.cachedThis); 999return proxy.Replacement(F.Syntax, static (frameType, F) => F.This(), F);