コード例 #1
0
        /// <summary>
        /// Add fields to the state machine class that control the state machine.
        /// </summary>
        protected virtual void GenerateControlFields()
        {
            // Add a field: int _state
            var intType = F.SpecialType(SpecialType.System_Int32);

            this.stateField = F.StateMachineField(intType, GeneratedNames.MakeStateMachineStateName(), IsStateFieldPublic);
        }
コード例 #2
0
        internal IteratorConstructor(IteratorStateMachine container)
            : base(container)
        {
            var intType = container.DeclaringCompilation.GetSpecialType(SpecialType.System_Int32);

            parameters = ImmutableArray.Create <ParameterSymbol>(
                new SynthesizedParameterSymbol(this, intType, 0, RefKind.None, GeneratedNames.MakeStateMachineStateName()));
        }
コード例 #3
0
        protected BoundStatement Rewrite()
        {
            if (this.body.HasErrors)
            {
                return(this.body);
            }

            TypeMap TypeMap = stateMachineClass.TypeMap;

            F.OpenNestedType(stateMachineClass);
            F.CompilationState.StateMachineImplementationClass[method] = stateMachineClass;

            // Add a field: int _state
            var intType = F.SpecialType(SpecialType.System_Int32);

            stateField = F.SynthesizeField(intType, GeneratedNames.MakeStateMachineStateName(), isPublic: IsStateFieldPublic);

            GenerateFields();

            // and fields for the initial values of all the parameters of the method
            if (PreserveInitialLocals)
            {
                initialParameters = new Dictionary <Symbol, CapturedSymbolReplacement>();
            }

            // add fields for the captured variables of the method
            var dictionary = IteratorAndAsyncCaptureWalker.Analyze(compilationState.ModuleBuilder.Compilation, method, body);
            IOrderedEnumerable <Symbol> captured =
                from local in dictionary.Keys
                orderby local.Name, local.Locations.Length == 0 ? 0 : local.Locations[0].SourceSpan.Start
            select local;

            this.variablesCaptured = new HashSet <Symbol>(captured);
            this.variableProxies   = new Dictionary <Symbol, CapturedSymbolReplacement>();

            CreateInitialProxies(TypeMap, captured, dictionary);
            GenerateMethodImplementations();

            // Return a replacement body for the original method
            return(ReplaceOriginalMethod());
        }
コード例 #4
0
        protected BoundStatement Rewrite()
        {
            if (this.body.HasErrors)
            {
                return(this.body);
            }

            F.OpenNestedType(stateMachineClass);

            // Add a field: int _state
            var intType = F.SpecialType(SpecialType.System_Int32);

            stateField = F.StateMachineField(intType, GeneratedNames.MakeStateMachineStateName(), IsStateFieldPublic);

            GenerateFields();

            // and fields for the initial values of all the parameters of the method
            if (PreserveInitialParameterValues)
            {
                initialParameters = new Dictionary <Symbol, CapturedSymbolReplacement>();
            }

            // add fields for the captured variables of the method
            var captured = IteratorAndAsyncCaptureWalker.Analyze(compilationState.ModuleBuilderOpt.Compilation, method, body);

            this.variablesCaptured = new HashSet <Symbol>(captured.Keys);

            this.variableProxies = new Dictionary <Symbol, CapturedSymbolReplacement>();

            CreateInitialProxies(captured);

            GenerateMethodImplementations();

            // Return a replacement body for the original method
            return(ReplaceOriginalMethod());
        }