1 write to F
Microsoft.CodeAnalysis.CSharp (1)
Lowering\StateMachineRewriter\MethodToStateMachineRewriter.cs (1)
122this.F = F;
411 references to F
Microsoft.CodeAnalysis.CSharp (411)
Lowering\AsyncRewriter\AsyncIteratorMethodToStateMachineRewriter.cs (57)
83var iteratorDispatch = _iteratorStateAllocator.GenerateThrowMissingStateDispatch(F, F.Local(cachedState), HotReloadExceptionCode.CannotResumeSuspendedIteratorMethod); 89return (asyncDispatch != null) ? F.Block(asyncDispatch, iteratorDispatch) : iteratorDispatch; 119F.Return(), 120F.Label(_exprReturnLabelTrue), 124return F.Block(builder.ToImmutableAndFree()); 130BoundFieldAccess promiseField = F.InstanceField(_asyncIteratorInfo.PromiseOfValueOrEndField); 131return F.ExpressionStatement(F.Call(promiseField, _asyncIteratorInfo.SetResultMethod, F.Literal(result))); 139return F.Assignment(F.InstanceField(currentField), F.Default(currentField.Type)); 146return F.ExpressionStatement( 147F.Call( 148F.Field(F.This(), _asyncMethodBuilderField), 158var combinedTokens = F.Field(F.This(), _asyncIteratorInfo.CombinedTokensField); 162F.If(F.ObjectNotEqual(combinedTokens, F.Null(combinedTokensType)), 163thenClause: F.Block( 164F.ExpressionStatement(F.Call(combinedTokens, F.WellKnownMethod(WellKnownMember.System_Threading_CancellationTokenSource__Dispose))), 165F.Assignment(combinedTokens, F.Null(combinedTokensType))))); 183builder.Add(F.ExpressionStatement(F.Call( 184F.InstanceField(_asyncIteratorInfo.PromiseOfValueOrEndField), 186F.Local(exceptionLocal)))); 188return F.Block(builder.ToImmutableAndFree()); 194return F.If( 196F.InstanceField(_asyncIteratorInfo.DisposeModeField), 198thenClause: F.Goto(_currentDisposalLabel)); 207return F.Block( 220return F.IntEqual(F.Local(cachedState), F.Literal(StateMachineState.NotStartedOrRunningState)); 244return F.Block( 245F.Label(resumeLabel), // initialStateResumeLabel: 273F.Assignment(F.InstanceField(_asyncIteratorInfo.CurrentField), rewrittenExpression)); 281F.Goto(_exprReturnLabelTrue)); 285F.Label(resumeLabel)); 287blockBuilder.Add(F.HiddenSequencePoint()); 299F.HiddenSequencePoint()); 301return F.Block(blockBuilder.ToImmutableAndFree()); 313return F.Block( 317F.Goto(_currentDisposalLabel)); 322return F.Assignment(F.InstanceField(_asyncIteratorInfo.DisposeModeField), F.Literal(value)); 344var finallyEntry = F.GenerateLabel("finallyEntry"); 355tryBlock: F.Block(node.TryBlock, F.Label(finallyEntry)),
Lowering\AsyncRewriter\AsyncMethodToStateMachineRewriter.cs (170)
112if (slotAllocator == null || !slotAllocator.TryGetPreviousAwaiterSlotIndex(F.ModuleBuilderOpt.Translate(awaiterType, F.Syntax, F.Diagnostics.DiagnosticBag), F.Diagnostics.DiagnosticBag, out slotIndex)) 118result = F.StateMachineField(awaiterType, fieldName, SynthesizedLocalKind.AwaiterField, slotIndex); 136F.CurrentFunction = moveNextMethod; 144bodyBuilder.Add(F.HiddenSequencePoint()); 145bodyBuilder.Add(F.Assignment(F.Local(cachedState), F.Field(F.This(), stateField))); 148var exceptionLocal = F.SynthesizedLocal(F.WellKnownType(WellKnownType.System_Exception)); 151F.Block(ImmutableArray<LocalSymbol>.Empty, 153F.HiddenSequencePoint(), 158F.CatchBlocks(GenerateExceptionHandling(exceptionLocal, rootScopeHoistedLocals))) 162bodyBuilder.Add(F.Label(_exprReturnLabel)); 165var stateDone = F.Assignment(F.Field(F.This(), stateField), F.Literal(StateMachineState.FinishedState)); 174bodyBuilder.Add(F.SequencePointWithSpan(block, block.CloseBraceToken.Span, stateDone)); 175bodyBuilder.Add(F.HiddenSequencePoint()); 184bodyBuilder.Add(F.Label(_exitLabel)); 185bodyBuilder.Add(F.Return()); 195F.SequencePoint( 197F.Block( 206newBody = F.Instrument(newBody, instrumentation); 208F.CloseMethod(newBody); 212=> F.Try(tryBlock, catchBlocks); 217return F.ExpressionStatement( 218F.Call( 219F.Field(F.This(), _asyncMethodBuilderField), 221_method.IsAsyncEffectivelyReturningGenericTask(F.Compilation) 222? ImmutableArray.Create<BoundExpression>(F.Local(_exprRetValue)) 241F.ExpressionStatement(F.AssignmentExpression(F.Field(F.This(), stateField), F.Literal(StateMachineState.FinishedState))); 247F.Syntax, 249F.Local(exceptionLocal), 253body: F.Block( 269var useSiteInfo = new CompoundUseSiteInfo<AssemblySymbol>(F.Diagnostics, F.Compilation.Assembly); 271F.Diagnostics.Add(hoistedLocal.GetFirstLocationOrNone(), useSiteInfo); 277builder.Add(F.Assignment(F.Field(F.This(), hoistedLocal), F.NullOrDefault(hoistedLocal.Type))); 280return F.Block(builder.ToImmutableAndFree()); 288return F.ExpressionStatement( 289F.Call( 290F.Field(F.This(), _asyncMethodBuilderField), 292F.Local(exceptionLocal))); 297return F.Goto(_exitLabel); 321return (expr != null) ? node.Update(expr) : (BoundStatement)F.StatementList(); 364var awaiterTemp = F.SynthesizedLocal(getAwaiter.Type, syntax: node.Syntax, kind: SynthesizedLocalKind.Awaiter); 365var awaitIfIncomplete = F.Block( 367F.Assignment( 368F.Local(awaiterTemp), 372F.HiddenSequencePoint(), 375F.If( 376condition: F.Not(GenerateGetIsCompleted(awaiterTemp, isCompletedMethod)), 379F.Local(awaiterTemp), 386F.Assignment(resultPlace, getResultCall) : 387F.ExpressionStatement(getResultCall); 389return F.Block( 412? F.StaticCall(methodSymbol.ContainingType, methodSymbol, receiver) 413: F.Call(receiver, methodSymbol); 435F.Local(awaiterTemp), 441resultType: F.SpecialType(SpecialType.System_Boolean)).ToExpression(); 444return F.Call(F.Local(awaiterTemp), getIsCompletedMethod); 453? F.SpecialType(SpecialType.System_Object) 466F.NoOp(NoOpStatementFlavor.AwaitYieldPoint)); 470F.Assignment( 471F.Field(F.This(), awaiterField), 473? F.Local(awaiterTemp) 474: F.Convert(awaiterFieldType, F.Local(awaiterTemp)))); 483if (F.Compilation.Options.EnableEditAndContinue) 488blockBuilder.Add(F.Label(dummyResumeLabel)); 493F.Label(resumeLabel)); 497F.NoOp(NoOpStatementFlavor.AwaitResumePoint)); 502F.Assignment( 503F.Local(awaiterTemp), 505? F.Field(F.This(), awaiterField) 506: F.Convert(awaiterTemp.Type, F.Field(F.This(), awaiterField)))); 509F.Assignment(F.Field(F.This(), awaiterField), F.NullOrDefault(awaiterField.Type))); 515return F.Block(blockBuilder.ToImmutableAndFree()); 535var criticalNotifyCompletedTemp = F.SynthesizedLocal( 536F.WellKnownType(WellKnownType.System_Runtime_CompilerServices_ICriticalNotifyCompletion), 539var notifyCompletionTemp = F.SynthesizedLocal( 540F.WellKnownType(WellKnownType.System_Runtime_CompilerServices_INotifyCompletion), 543LocalSymbol thisTemp = (F.CurrentType.TypeKind == TypeKind.Class) ? F.SynthesizedLocal(F.CurrentType) : null; 548F.Assignment( 549F.Local(criticalNotifyCompletedTemp), 551F.As(F.Local(awaiterTemp), criticalNotifyCompletedTemp.Type))); 555blockBuilder.Add(F.Assignment(F.Local(thisTemp), F.This())); 559F.If( 560condition: F.ObjectEqual(F.Local(criticalNotifyCompletedTemp), F.Null(criticalNotifyCompletedTemp.Type)), 562thenClause: F.Block( 564F.Assignment( 565F.Local(notifyCompletionTemp), 567F.Convert(notifyCompletionTemp.Type, F.Local(awaiterTemp), Conversion.ExplicitReference)), 568F.ExpressionStatement( 569F.Call( 570F.Field(F.This(), _asyncMethodBuilderField), 573F.This().Type), 574F.Local(notifyCompletionTemp), F.This(thisTemp))), 575F.Assignment( 576F.Local(notifyCompletionTemp), 577F.NullOrDefault(notifyCompletionTemp.Type))), 579elseClauseOpt: F.Block( 580F.ExpressionStatement( 581F.Call( 582F.Field(F.This(), _asyncMethodBuilderField), 585F.This().Type), 586F.Local(criticalNotifyCompletedTemp), F.This(thisTemp)))))); 589F.Assignment( 590F.Local(criticalNotifyCompletedTemp), 591F.NullOrDefault(criticalNotifyCompletedTemp.Type))); 593return F.Block( 604LocalSymbol thisTemp = (F.CurrentType.TypeKind == TypeKind.Class) ? F.SynthesizedLocal(F.CurrentType) : null; 607var useUnsafeOnCompleted = F.Compilation.Conversions.ClassifyImplicitConversionFromType( 609F.Compilation.GetWellKnownType(WellKnownType.System_Runtime_CompilerServices_ICriticalNotifyCompletion), 614_asyncMethodBuilderMemberCollection.AwaitOnCompleted).Construct(loweredAwaiterType, F.This().Type); 617onCompleted.CheckConstraints(new ConstraintsHelper.CheckConstraintsArgs(F.Compilation, F.Compilation.Conversions, includeNullability: false, F.Syntax.Location, this.Diagnostics)); 621F.Call( 622F.Field(F.This(), _asyncMethodBuilderField), 624F.Local(awaiterTemp), F.This(thisTemp)); 628result = F.Sequence( 630ImmutableArray.Create<BoundExpression>(F.AssignmentExpression(F.Local(thisTemp), F.This())), 634return F.ExpressionStatement(result); 646Debug.Assert(_method.IsAsyncEffectivelyReturningGenericTask(F.Compilation)); 647return F.Block( 648F.Assignment(F.Local(_exprRetValue), (BoundExpression)Visit(node.ExpressionOpt)), 649F.Goto(_exprReturnLabel)); 652return F.Goto(_exprReturnLabel);
Lowering\IteratorRewriter\IteratorMethodToStateMachineRewriter.cs (106)
97F.CurrentFunction = moveNextMethod; 111newBody = F.Block((object)cachedThis == null ? 115F.HiddenSequencePoint(), 116F.Assignment(F.Local(cachedState), F.Field(F.This(), stateField)), 120F.Label(initialLabel), 121F.Assignment(F.Field(F.This(), stateField), F.Literal(StateMachineState.NotStartedOrRunningState)), 146var faultBlock = F.Block(F.ExpressionStatement(F.Call(F.This(), disposeMethod))); 147newBody = F.Fault((BoundBlock)newBody, faultBlock); 150newBody = F.Instrument(F.SequencePoint(body.Syntax, HandleReturn(newBody)), instrumentation); 152F.CloseMethod(newBody); 157F.CurrentFunction = disposeMethod; 163F.CloseMethod(F.Return()); 167var stateLocal = F.SynthesizedLocal(stateField.Type); 168var state = F.Local(stateLocal); 170var disposeBody = F.Block( 172F.Assignment(F.Local(stateLocal), F.Field(F.This(), stateField)), 174F.Return()); 176F.CloseMethod(disposeBody); 186return F.Block( 188F.Return(F.Literal(false))); 196return F.Block( 199F.Assignment(this.F.Local(_methodValue), this.F.Literal(true)), 200F.Label(_exitLabel), 201F.Return(this.F.Local(_methodValue))); 256var breakLabel = F.GenerateLabel("break"); 259select F.SwitchSection( 262F.Goto(breakLabel)); 264body = F.Block( 265F.Switch(state, sections.ToImmutableArray()), 266F.Label(breakLabel)); 271var tryBlock = body != null ? F.Block(body) : F.Block(); 272body = F.Try( 275F.Block(F.ExpressionStatement(F.Call(F.This(), frame.handler)))); 284BoundLiteral result = this.F.Literal(!finished); 288return F.Return(result); 294_exitLabel = this.F.GenerateLabel("exitLabel"); 295_methodValue = F.SynthesizedLocal(result.Type); 298var gotoExit = F.Goto(_exitLabel); 306return this.F.Block( 307F.Assignment(this.F.Local(_methodValue), result), 334return F.Block( 335F.Assignment(F.Field(F.This(), _current), rewrittenExpression), 336F.Assignment(F.Field(F.This(), stateField), F.Literal(stateNumber)), 338F.Label(resumeLabel), 339F.HiddenSequencePoint(), 340F.Assignment(F.Field(F.This(), stateField), F.Literal(_currentFinallyFrame.finalizeState))); 348Debug.Assert(node.Label == proxyLabel || !(F.CurrentFunction is IteratorFinallyMethodSymbol), "should not be proxying branches in finally"); 387var origMethod = F.CurrentFunction; 390F.CurrentFunction = finallyMethod; 402rewrittenHandler = F.Block((object)this.cachedThis != null ? 405F.Assignment(F.Field(F.This(), stateField), F.Literal(frame.parent.finalizeState)), 408F.Return() 411F.CloseMethod(rewrittenHandler); 412F.CurrentFunction = origMethod; 423bodyStatements.Add(F.Assignment(F.Field(F.This(), stateField), F.Literal(frame.finalizeState))); 425bodyStatements.Add(F.ExpressionStatement(F.Call(F.This(), finallyMethod))); 430var dropThrough = F.GenerateLabel("dropThrough"); 431bodyStatements.Add(F.Goto(dropThrough)); 440bodyStatements.Add(F.Label(proxy)); 443bodyStatements.Add(F.ExpressionStatement(F.Call(F.This(), finallyMethod))); 447bodyStatements.Add(F.Goto(parentProxy)); 450bodyStatements.Add(F.Label(dropThrough)); 453return F.Block(bodyStatements.ToImmutableAndFree()); 488var stateMachineType = (IteratorStateMachine)F.CurrentType; 491F.ModuleBuilderOpt.AddSynthesizedDefinition(stateMachineType, finallyMethod.GetCciAdapter());
Lowering\StateMachineRewriter\MethodToStateMachineRewriter.cs (78)
178get { return ((SynthesizedContainer)F.CurrentType).TypeMap; } 183get { return F.CurrentFunction; } 201var oldSyntax = F.Syntax; 202F.Syntax = syntax; 203var result = F.This(); 205F.Syntax = oldSyntax; 231resumeLabel = F.GenerateLabel("stateMachine"); 245select F.SwitchSection(kv.Value.SelectAsArray(state => (int)state), F.Goto(kv.Key)); 247var result = F.Switch(F.Local(cachedState), sections.ToImmutableArray()); 260result = F.Block(result, missingStateDispatch); 268=> _resumableStateAllocator.GenerateThrowMissingStateDispatch(F, F.Local(cachedState), EncMissingStateErrorCode); 377translatedStatement = F.Block( 379F.Block(variableCleanup.SelectAsArray((e, f) => (BoundStatement)f.ExpressionStatement(e), F))); 400return F.Block(new BoundStateMachineScope(F.Syntax, hoistedLocals, statement)); 429cleanup.Add(F.AssignmentExpression(F.Field(F.This(), field), F.NullOrDefault(field.Type))); 469return F.StateMachineField(type, fieldName, SynthesizedLocalKind.UserDefined, slotIndex); 472return F.StateMachineField(type, GeneratedNames.ReusableHoistedLocalFieldName(slotIndex)); 513if (F.Compilation.Options.OptimizationLevel == OptimizationLevel.Debug) 541var sacrificialTemp = F.SynthesizedLocal(type, refKind: RefKind.Ref); 543return F.Sequence(ImmutableArray.Create(sacrificialTemp), sideEffects.ToImmutableAndFree(), F.AssignmentExpression(F.Local(sacrificialTemp), replacement, isRef: true)); 554return F.Sequence(ImmutableArray<LocalSymbol>.Empty, sideEffects.ToImmutableAndFree(), last); 606return F.Field(receiver, field.FieldSymbol); 626F.Diagnostics.Add(ErrorCode.ERR_RefReturningCallAndAwait, F.Syntax.Location, call.Method); 644F.Diagnostics.Add(ErrorCode.ERR_RefConditionalAndAwait, F.Syntax.Location); 663if (F.Compilation.Options.OptimizationLevel == OptimizationLevel.Debug) 678F.ModuleBuilderOpt.Translate(fieldType, awaitSyntaxOpt, Diagnostics.DiagnosticBag), 688hoistedField = F.StateMachineField(expr.Type, fieldName, new LocalSlotDebugInfo(kind, id), slotIndex); 697var replacement = F.Field(F.This(), hoistedField); 698sideEffects.Add(F.AssignmentExpression(replacement, expr)); 708var oldSyntax = F.Syntax; 709F.Syntax = node.Syntax; 711F.Syntax = oldSyntax; 727=> F.Field(F.This(), instanceIdField); 864BoundBlock tryBlock = F.Block((BoundStatement)this.Visit(node.TryBlock)); 868dispatchLabel = F.GenerateLabel("tryDispatch"); 870tryBlock = F.Block( 871F.HiddenSequencePoint(), 883BoundBlock finallyBlockOpt = node.FinallyBlockOpt == null ? null : F.Block( 884F.HiddenSequencePoint(), 885F.If( 889F.HiddenSequencePoint()); 895result = F.Block( 896F.HiddenSequencePoint(), 897F.Label(dispatchLabel), 911return F.IntLessThan(F.Local(cachedState), F.Literal(StateMachineState.FirstUnusedState)); 920return F.Assignment(F.Field(F.This(), stateField), F.AssignmentExpression(F.Local(cachedState), F.Literal(stateNumber))); 929var fetchThis = proxy.Replacement(F.Syntax, static (frameType, F) => F.This(), F); 930return F.Assignment(F.Local(this.cachedThis), fetchThis); 934return F.StatementList(); 942return F.Local(this.cachedThis); 965return proxy.Replacement(F.Syntax, static (frameType, F) => F.This(), F); 976return F.Local(this.cachedThis); 981return proxy.Replacement(F.Syntax, static (frameType, F) => F.This(), F);