54 lines
2.0 KiB
C#
54 lines
2.0 KiB
C#
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<NamedTypeSymbol> _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<NamedTypeSymbol> instance = ArrayBuilder<NamedTypeSymbol>.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<NamedTypeSymbol> InterfacesNoUseSiteDiagnostics(ConsList<TypeSymbol> basesBeingResolved)
|
|
{
|
|
return _interfaces;
|
|
}
|
|
|
|
internal override bool HasPossibleWellKnownCloneMethod()
|
|
{
|
|
return false;
|
|
}
|
|
}
|