Example #1
0
        private FieldSymbol GetAwaiterField(TypeSymbol awaiterType)
        {
            FieldSymbol result;

            // Awaiters of the same type always share the same slot, regardless of what await expressions they belong to.
            // Even in case of nested await expressions only one awaiter is active.
            // So we don't need to tie the awaiter variable to a particular await expression and only use its type
            // to find the previous awaiter field.
            if (!awaiterFields.TryGetValue(awaiterType, out result))
            {
                int slotIndex = -1;
                if (slotAllocatorOpt != null)
                {
                    slotIndex = slotAllocatorOpt.GetPreviousAwaiterSlotIndex((Cci.ITypeReference)awaiterType);
                }

                if (slotIndex == -1)
                {
                    slotIndex = nextAwaiterId++;
                }

                string fieldName = GeneratedNames.AsyncAwaiterFieldName(slotIndex);
                result = F.StateMachineField(awaiterType, fieldName, SynthesizedLocalKind.AwaiterField, slotIndex);
                awaiterFields.Add(awaiterType, result);
            }

            return(result);
        }
            private FieldSymbol GetAwaiterField(TypeSymbol awaiterType)
            {
                FieldSymbol result;

                if (!awaiterFields.TryGetValue(awaiterType, out result))
                {
                    result = F.SynthesizeField(awaiterType, GeneratedNames.AsyncAwaiterFieldName(CompilationState.GenerateTempNumber()));
                    awaiterFields.Add(awaiterType, result);
                }
                return(result);
            }
Example #3
0
        private FieldSymbol GetAwaiterField(TypeSymbol awaiterType)
        {
            FieldSymbol result;

            // Awaiters of the same type always share the same slot, regardless of what await expressions they belong to.
            // Even in case of nested await expressions only one awaiter is active.
            // So we don't need to tie the awaiter variable to a particular await expression and only use its type
            // to find the previous awaiter field.
            if (!_awaiterFields.TryGetValue(awaiterType, out result))
            {
                int slotIndex;
                if (
                    slotAllocatorOpt == null ||
                    !slotAllocatorOpt.TryGetPreviousAwaiterSlotIndex(
                        F.ModuleBuilderOpt.Translate(
                            awaiterType,
                            F.Syntax,
                            F.Diagnostics.DiagnosticBag
                            ),
                        F.Diagnostics.DiagnosticBag,
                        out slotIndex
                        )
                    )
                {
                    slotIndex = _nextAwaiterId++;
                }

                string fieldName = GeneratedNames.AsyncAwaiterFieldName(slotIndex);
                result = F.StateMachineField(
                    awaiterType,
                    fieldName,
                    SynthesizedLocalKind.AwaiterField,
                    slotIndex
                    );
                _awaiterFields.Add(awaiterType, result);
            }

            return(result);
        }