using System.Collections.Immutable; using Microsoft.CodeAnalysis.CSharp.Symbols; using Microsoft.CodeAnalysis.CodeGen; using Microsoft.CodeAnalysis.PooledObjects; using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.CSharp; internal sealed class IteratorStateMachine : StateMachineTypeSymbol { private readonly MethodSymbol _constructor; private readonly ImmutableArray _interfaces; internal readonly TypeWithAnnotations ElementType; public override TypeKind TypeKind => (TypeKind)2; internal override MethodSymbol Constructor => _constructor; internal override NamedTypeSymbol BaseTypeNoUseSiteDiagnostics => ContainingAssembly.GetSpecialType((SpecialType)1); internal override bool IsRecord => false; internal override bool IsRecordStruct => false; public IteratorStateMachine(VariableSlotAllocator slotAllocatorOpt, TypeCompilationState compilationState, MethodSymbol iteratorMethod, int iteratorMethodOrdinal, bool isEnumerable, TypeWithAnnotations elementType) : base(slotAllocatorOpt, compilationState, iteratorMethod, iteratorMethodOrdinal) { ElementType = base.TypeMap.SubstituteType(elementType); ArrayBuilder instance = ArrayBuilder.GetInstance(); if (isEnumerable) { instance.Add(ContainingAssembly.GetSpecialType((SpecialType)25).Construct(ElementType.Type)); instance.Add(ContainingAssembly.GetSpecialType((SpecialType)24)); } instance.Add(ContainingAssembly.GetSpecialType((SpecialType)29).Construct(ElementType.Type)); instance.Add(ContainingAssembly.GetSpecialType((SpecialType)35)); instance.Add(ContainingAssembly.GetSpecialType((SpecialType)28)); _interfaces = instance.ToImmutableAndFree(); _constructor = new IteratorConstructor(this); } internal override ImmutableArray InterfacesNoUseSiteDiagnostics(ConsList basesBeingResolved) { return _interfaces; } internal override bool HasPossibleWellKnownCloneMethod() { return false; } }