Beispiel #1
0
 public AsyncStateMachine(MethodSymbol asyncMethod, TypeKind typeKind)
     : base(GeneratedNames.MakeStateMachineTypeName(asyncMethod.Name, SequenceNumber(asyncMethod)), asyncMethod)
 {
     // TODO: report use-site errors on these types
     this.typeKind    = typeKind;
     this.asyncMethod = asyncMethod;
     this.interfaces  = ImmutableArray.Create(asyncMethod.DeclaringCompilation.GetWellKnownType(WellKnownType.System_Runtime_CompilerServices_IAsyncStateMachine));
     this.constructor = new AsyncConstructor(this);
 }
Beispiel #2
0
        public void TestStateMachineMethods()
        {
            var sourceTemplate =
                @"
using System.Collections.Generic;
using System.Threading.Tasks;

class Iterators
{{
    IEnumerable<int> {0}()
    {{
        yield return 1;
    }}

    IEnumerable<int> {0}1()
    {{
        yield return 1;
    }}
}}

class Async
{{
    async Task {0}()
    {{
        await {0}();
    }}

    async Task {0}1()
    {{
        await {0}1();
    }}
}}
";
            int    padding  = GeneratedNames.MakeStateMachineTypeName("A", 0, 0).Length - 1;
            string longName = s_longSymbolName.Substring(padding);
            var    source   = string.Format(sourceTemplate, longName);
            var    comp     = CreateCompilationWithMscorlib45(source);

            comp.VerifyDiagnostics();
            // CONSIDER: Location would light up if synthesized methods had them.
            comp.VerifyEmitDiagnostics(
                // error CS7013: Name '<longName1>d__1' exceeds the maximum length allowed in metadata.
                Diagnostic(ErrorCode.ERR_MetadataNameTooLong)
                .WithArguments("<" + longName + 1 + ">d__1")
                .WithLocation(1, 1),
                // error CS7013: Name '<longName1>d__1' exceeds the maximum length allowed in metadata.
                Diagnostic(ErrorCode.ERR_MetadataNameTooLong)
                .WithArguments("<" + longName + 1 + ">d__1")
                .WithLocation(1, 1)
                );
        }
Beispiel #3
0
 private static string MakeName(
     VariableSlotAllocator slotAllocatorOpt,
     TypeCompilationState compilationState,
     MethodSymbol kickoffMethod,
     int kickoffMethodOrdinal
     )
 {
     return(slotAllocatorOpt?.PreviousStateMachineTypeName
            ?? GeneratedNames.MakeStateMachineTypeName(
                kickoffMethod.Name,
                kickoffMethodOrdinal,
                compilationState.ModuleBuilderOpt.CurrentGenerationOrdinal
                ));
 }
        public IteratorStateMachine(MethodSymbol iteratorMethod, bool isEnumerable, TypeSymbol elementType, TypeCompilationState compilationState)
            : base(GeneratedNames.MakeStateMachineTypeName(iteratorMethod.Name, compilationState.GenerateTempNumber()), iteratorMethod)
        {
            this.iteratorMethod = iteratorMethod;
            this.ElementType    = TypeMap.SubstituteType(elementType);

            var interfaces = ArrayBuilder <NamedTypeSymbol> .GetInstance();

            if (isEnumerable)
            {
                interfaces.Add(ContainingAssembly.GetSpecialType(SpecialType.System_Collections_Generic_IEnumerable_T).Construct(ElementType));
                interfaces.Add(ContainingAssembly.GetSpecialType(SpecialType.System_Collections_IEnumerable));
            }

            interfaces.Add(ContainingAssembly.GetSpecialType(SpecialType.System_Collections_Generic_IEnumerator_T).Construct(ElementType));
            interfaces.Add(ContainingAssembly.GetSpecialType(SpecialType.System_IDisposable));
            interfaces.Add(ContainingAssembly.GetSpecialType(SpecialType.System_Collections_IEnumerator));
            this.interfaces = interfaces.ToImmutableAndFree();

            this.constructor = new IteratorConstructor(this);
        }